aboutsummaryrefslogtreecommitdiff
path: root/kvision-modules/kvision-tabulator/src
diff options
context:
space:
mode:
Diffstat (limited to 'kvision-modules/kvision-tabulator/src')
-rw-r--r--kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt82
-rw-r--r--kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/js/Tabulator.kt10
2 files changed, 88 insertions, 4 deletions
diff --git a/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt b/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt
index 34054545..9d9b7ae8 100644
--- a/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt
+++ b/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt
@@ -39,6 +39,15 @@ import kotlin.browser.window
import pl.treksoft.kvision.tabulator.js.Tabulator as JsTabulator
/**
+ * Tabulator download data set option.
+ */
+enum class DownloadSet(internal val set: String) {
+ ALL("all"),
+ VISIBLE("visible"),
+ ACTIVE("active")
+}
+
+/**
* Tabulator component.
*
* @constructor
@@ -350,6 +359,79 @@ open class Tabulator<T : Any>(
): Unit? = jsTabulator?.print(activeOnly, isStyled, printConfig)
/**
+ * Download the table content as CSV
+ * @param fileName downloaded file name
+ * @param dataSet a data set configuration
+ * @param delimiter CSV delimiter
+ * @param includeBOM determines if BOM should be included
+ * @param newTab determines if download should be open in a new tab
+ */
+ @Suppress("UnsafeCastFromDynamic")
+ open fun downloadCSV(
+ fileName: String? = null,
+ dataSet: DownloadSet = DownloadSet.ACTIVE,
+ delimiter: Char = ',',
+ includeBOM: Boolean = false,
+ newTab: Boolean = false
+ ): Unit? {
+ return if (newTab) {
+ jsTabulator?.downloadToTab("csv", fileName, obj {
+ this.delimiter = delimiter
+ this.bom = includeBOM
+ }, dataSet.set)
+ } else {
+ jsTabulator?.download("csv", fileName, obj {
+ this.delimiter = delimiter
+ this.bom = includeBOM
+ }, dataSet.set)
+ }
+ }
+
+ /**
+ * Download the table content as JSON
+ * @param fileName downloaded file name
+ * @param dataSet a data set configuration
+ * @param newTab determines if download should be open in a new tab
+ */
+ @Suppress("UnsafeCastFromDynamic")
+ open fun downloadJSON(
+ fileName: String? = null,
+ dataSet: DownloadSet = DownloadSet.ACTIVE,
+ newTab: Boolean = false
+ ): Unit? {
+ return if (newTab) {
+ jsTabulator?.downloadToTab("json", fileName, obj {}, dataSet.set)
+ } else {
+ jsTabulator?.download("json", fileName, obj {}, dataSet.set)
+ }
+ }
+
+ /**
+ * Download the table content as HTML
+ * @param fileName downloaded file name
+ * @param dataSet a data set configuration
+ * @param style download a html table with matching styling
+ * @param newTab determines if download should be open in a new tab
+ */
+ @Suppress("UnsafeCastFromDynamic")
+ open fun downloadHTML(
+ fileName: String? = null,
+ dataSet: DownloadSet = DownloadSet.ACTIVE,
+ style: Boolean = false,
+ newTab: Boolean = false
+ ): Unit? {
+ return if (newTab) {
+ jsTabulator?.downloadToTab("html", fileName, obj {
+ this.style = style
+ }, dataSet.set)
+ } else {
+ jsTabulator?.download("html", fileName, obj {
+ this.style = style
+ }, dataSet.set)
+ }
+ }
+
+ /**
* Scroll to the row given by id.
* @param row id of the row
* @param position the scrolling position
diff --git a/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/js/Tabulator.kt b/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/js/Tabulator.kt
index ea7c917f..508b4662 100644
--- a/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/js/Tabulator.kt
+++ b/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/js/Tabulator.kt
@@ -27,15 +27,17 @@ open external class Tabulator {
open var options: Options = definedExternally
open fun download(
downloadType: dynamic /* String /* "json" */ | String /* "csv" */ | String /* "xlsx" */ | String /* "pdf" */ | (columns: Array<Tabulator.ColumnDefinition>, data: Any, options: Any, setFileContents: Any) -> Any */,
- fileName: String,
- params: DownloadOptions? /*= null*/
+ fileName: String?,
+ params: DownloadOptions? /*= null*/,
+ set: String?
): Unit =
definedExternally
open fun downloadToTab(
downloadType: dynamic /* String /* "json" */ | String /* "csv" */ | String /* "xlsx" */ | String /* "pdf" */ */,
- fileName: String,
- params: DownloadOptions? /*= null*/
+ fileName: String?,
+ params: DownloadOptions? /*= null*/,
+ set: String?
): Unit =
definedExternally