diff options
Diffstat (limited to 'kvision-modules/kvision-tabulator/src')
2 files changed, 343 insertions, 384 deletions
diff --git a/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Options.kt b/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Options.kt index 08f2603b..906b0c82 100644 --- a/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Options.kt +++ b/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Options.kt @@ -22,7 +22,6 @@ package pl.treksoft.kvision.tabulator -import kotlinx.serialization.KSerializer import org.w3c.dom.HTMLElement import pl.treksoft.kvision.core.Component import pl.treksoft.kvision.form.FormControl @@ -239,9 +238,9 @@ enum class AddRowMode(internal val mode: String) { * Download config options. */ data class DownloadConfig( - val columnGroups: Boolean? = null, - val rowGroups: Boolean? = null, - val columnCalcs: Boolean? = null + val columnGroups: Boolean? = null, + val rowGroups: Boolean? = null, + val columnCalcs: Boolean? = null ) /** @@ -260,98 +259,98 @@ fun DownloadConfig.toJs(): Tabulator.DownloadConfig { * Column definition options. */ data class ColumnDefinition<T : Any>( - val title: String, - val field: String? = null, - val visible: Boolean? = null, - val align: Align? = null, - val width: String? = null, - val minWidth: Int? = null, - val widthGrow: Int? = null, - val widthShrink: Int? = null, - val resizable: Boolean? = null, - val frozen: Boolean? = null, - val responsive: Int? = null, - val tooltip: ((cell: Tabulator.CellComponent) -> String)? = null, - val cssClass: String? = null, - val rowHandle: Boolean? = null, - val hideInHtml: Boolean? = null, - val sorter: Sorter? = null, - val sorterFunction: (( - a: dynamic, b: dynamic, aRow: Tabulator.RowComponent, bRow: Tabulator.RowComponent, - column: Tabulator.ColumnComponent, dir: SortingDir, sorterParams: dynamic - ) -> Number)? = null, - val sorterParams: dynamic = null, - val formatter: Formatter? = null, - val formatterFunction: (( - cell: Tabulator.CellComponent, formatterParams: dynamic, - onRendered: (callback: () -> Unit) -> Unit - ) -> dynamic)? = null, - val formatterComponentFunction: (( - cell: Tabulator.CellComponent, onRendered: (callback: () -> Unit) -> Unit, data: T - ) -> Component)? = null, - val formatterParams: dynamic = null, - val variableHeight: Boolean? = null, - val editable: ((cell: Tabulator.CellComponent) -> Boolean)? = null, - val editor: Editor? = null, - val editorFunction: (( - cell: Tabulator.CellComponent, - onRendered: (callback: () -> Unit) -> Unit, - success: (value: dynamic) -> Unit, cancel: (value: dynamic) -> Unit, editorParams: dynamic - ) -> dynamic)? = null, - val editorComponentFunction: (( - cell: Tabulator.CellComponent, - onRendered: (callback: () -> Unit) -> Unit, - success: (value: dynamic) -> Unit, cancel: (value: dynamic) -> Unit, data: T - ) -> Component)? = null, - val editorParams: dynamic = null, - val validator: Validator? = null, - val validatorFunction: dynamic = null, - val validatorParams: String? = null, - val download: Boolean? = null, - val downloadTitle: String? = null, - val topCalc: Calc? = null, - val topCalcParams: dynamic = null, - val topCalcFormatter: Formatter? = null, - val topCalcFormatterParams: dynamic = null, - val bottomCalc: Calc? = null, - val bottomCalcParams: dynamic = null, - val bottomCalcFormatter: Formatter? = null, - val bottomCalcFormatterParams: dynamic = null, - val headerSort: Boolean? = null, - val headerSortStartingDir: SortingDir? = null, - val headerSortTristate: Boolean? = null, - val headerClick: ((e: dynamic, column: Tabulator.ColumnComponent) -> Unit)? = null, - val headerDblClick: ((e: dynamic, column: Tabulator.ColumnComponent) -> Unit)? = null, - val headerContext: ((e: dynamic, column: Tabulator.ColumnComponent) -> Unit)? = null, - val headerTap: ((e: dynamic, column: Tabulator.ColumnComponent) -> Unit)? = null, - val headerDblTap: ((e: dynamic, column: Tabulator.ColumnComponent) -> Unit)? = null, - val headerTapHold: ((e: dynamic, column: Tabulator.ColumnComponent) -> Unit)? = null, - val headerTooltip: ((column: Tabulator.ColumnComponent) -> String)? = null, - val headerVertical: Boolean? = null, - val editableTitle: Boolean? = null, - val titleFormatter: Formatter? = null, - val titleFormatterParams: dynamic = null, - val headerFilter: Editor? = null, - val headerFilterParams: dynamic = null, - val headerFilterPlaceholder: String? = null, - val headerFilterEmptyCheck: ((value: Any) -> Boolean)? = null, - val headerFilterFunc: Filter? = null, - val headerFilterFuncParams: dynamic = null, - val headerFilterLiveFilter: Boolean? = null, - val cellClick: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, - val cellDblClick: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, - val cellContext: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, - val cellTap: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, - val cellDblTap: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, - val cellTapHold: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, - val cellMouseEnter: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, - val cellMouseLeave: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, - val cellMouseOver: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, - val cellMouseOut: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, - val cellMouseMove: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, - val cellEditing: ((cell: Tabulator.CellComponent) -> Unit)? = null, - val cellEdited: ((cell: Tabulator.CellComponent) -> Unit)? = null, - val cellEditCancelled: ((cell: Tabulator.CellComponent) -> Unit)? = null + val title: String, + val field: String? = null, + val visible: Boolean? = null, + val align: Align? = null, + val width: String? = null, + val minWidth: Int? = null, + val widthGrow: Int? = null, + val widthShrink: Int? = null, + val resizable: Boolean? = null, + val frozen: Boolean? = null, + val responsive: Int? = null, + val tooltip: ((cell: Tabulator.CellComponent) -> String)? = null, + val cssClass: String? = null, + val rowHandle: Boolean? = null, + val hideInHtml: Boolean? = null, + val sorter: Sorter? = null, + val sorterFunction: (( + a: dynamic, b: dynamic, aRow: Tabulator.RowComponent, bRow: Tabulator.RowComponent, + column: Tabulator.ColumnComponent, dir: SortingDir, sorterParams: dynamic + ) -> Number)? = null, + val sorterParams: dynamic = null, + val formatter: Formatter? = null, + val formatterFunction: (( + cell: Tabulator.CellComponent, formatterParams: dynamic, + onRendered: (callback: () -> Unit) -> Unit + ) -> dynamic)? = null, + val formatterComponentFunction: (( + cell: Tabulator.CellComponent, onRendered: (callback: () -> Unit) -> Unit, data: T + ) -> Component)? = null, + val formatterParams: dynamic = null, + val variableHeight: Boolean? = null, + val editable: ((cell: Tabulator.CellComponent) -> Boolean)? = null, + val editor: Editor? = null, + val editorFunction: (( + cell: Tabulator.CellComponent, + onRendered: (callback: () -> Unit) -> Unit, + success: (value: dynamic) -> Unit, cancel: (value: dynamic) -> Unit, editorParams: dynamic + ) -> dynamic)? = null, + val editorComponentFunction: (( + cell: Tabulator.CellComponent, + onRendered: (callback: () -> Unit) -> Unit, + success: (value: dynamic) -> Unit, cancel: (value: dynamic) -> Unit, data: T + ) -> Component)? = null, + val editorParams: dynamic = null, + val validator: Validator? = null, + val validatorFunction: dynamic = null, + val validatorParams: String? = null, + val download: Boolean? = null, + val downloadTitle: String? = null, + val topCalc: Calc? = null, + val topCalcParams: dynamic = null, + val topCalcFormatter: Formatter? = null, + val topCalcFormatterParams: dynamic = null, + val bottomCalc: Calc? = null, + val bottomCalcParams: dynamic = null, + val bottomCalcFormatter: Formatter? = null, + val bottomCalcFormatterParams: dynamic = null, + val headerSort: Boolean? = null, + val headerSortStartingDir: SortingDir? = null, + val headerSortTristate: Boolean? = null, + val headerClick: ((e: dynamic, column: Tabulator.ColumnComponent) -> Unit)? = null, + val headerDblClick: ((e: dynamic, column: Tabulator.ColumnComponent) -> Unit)? = null, + val headerContext: ((e: dynamic, column: Tabulator.ColumnComponent) -> Unit)? = null, + val headerTap: ((e: dynamic, column: Tabulator.ColumnComponent) -> Unit)? = null, + val headerDblTap: ((e: dynamic, column: Tabulator.ColumnComponent) -> Unit)? = null, + val headerTapHold: ((e: dynamic, column: Tabulator.ColumnComponent) -> Unit)? = null, + val headerTooltip: ((column: Tabulator.ColumnComponent) -> String)? = null, + val headerVertical: Boolean? = null, + val editableTitle: Boolean? = null, + val titleFormatter: Formatter? = null, + val titleFormatterParams: dynamic = null, + val headerFilter: Editor? = null, + val headerFilterParams: dynamic = null, + val headerFilterPlaceholder: String? = null, + val headerFilterEmptyCheck: ((value: Any) -> Boolean)? = null, + val headerFilterFunc: Filter? = null, + val headerFilterFuncParams: dynamic = null, + val headerFilterLiveFilter: Boolean? = null, + val cellClick: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, + val cellDblClick: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, + val cellContext: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, + val cellTap: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, + val cellDblTap: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, + val cellTapHold: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, + val cellMouseEnter: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, + val cellMouseLeave: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, + val cellMouseOver: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, + val cellMouseOut: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, + val cellMouseMove: ((e: dynamic, cell: Tabulator.CellComponent) -> Unit)? = null, + val cellEditing: ((cell: Tabulator.CellComponent) -> Unit)? = null, + val cellEdited: ((cell: Tabulator.CellComponent) -> Unit)? = null, + val cellEditCancelled: ((cell: Tabulator.CellComponent) -> Unit)? = null ) internal object EditorRoot { @@ -364,18 +363,14 @@ internal object EditorRoot { */ @Suppress("UNCHECKED_CAST_TO_EXTERNAL_INTERFACE", "ComplexMethod", "MagicNumber") fun <T : Any> ColumnDefinition<T>.toJs( - i18nTranslator: (String) -> (String), - dataSerializer: KSerializer<T>? = null + i18nTranslator: (String) -> (String) ): Tabulator.ColumnDefinition { val tmpEditorFunction = editorComponentFunction?.let { { cell: Tabulator.CellComponent, onRendered: (callback: () -> Unit) -> Unit, success: (value: dynamic) -> Unit, cancel: (value: dynamic) -> Unit, _: dynamic -> var onRenderedCallback: (() -> Unit)? = null - val str = kotlin.js.JSON.stringify(cell.getData()) - @Suppress("UNCHECKED_CAST") val data = dataSerializer?.let { - JSON.plain.parse(it, str) - } ?: cell.getData() as T + @Suppress("UNCHECKED_CAST") val data = cell.getData() as T val component = it(cell, { callback -> onRenderedCallback = callback }, { value -> @@ -408,9 +403,7 @@ fun <T : Any> ColumnDefinition<T>.toJs( { cell: Tabulator.CellComponent, _: dynamic, onRendered: (callback: () -> Unit) -> Unit -> var onRenderedCallback: (() -> Unit)? = null - val str = kotlin.js.JSON.stringify(cell.getData()) - @Suppress("UNCHECKED_CAST") val data = - dataSerializer?.let { JSON.plain.parse(it, str) } ?: cell.getData() as T + @Suppress("UNCHECKED_CAST") val data = cell.getData() as T val component = it(cell, { callback -> onRenderedCallback = callback }, data) @@ -522,160 +515,160 @@ fun <T : Any> ColumnDefinition<T>.toJs( * Tabulator options. */ data class TabulatorOptions<T : Any>( - val height: String? = null, - val virtualDom: Boolean? = null, - val virtualDomBuffer: Int? = null, - val placeholder: String? = null, - val footerElement: String? = null, - val tooltips: ((cell: Tabulator.CellComponent) -> String)? = null, - val tooltipGenerationMode: TooltipGenerationMode? = null, - val history: Boolean? = null, - val keybindings: dynamic = null, - val downloadDataFormatter: dynamic = null, - val downloadConfig: DownloadConfig? = null, - val reactiveData: Boolean? = null, - val autoResize: Boolean? = null, - val columns: List<ColumnDefinition<T>>? = null, - val autoColumns: Boolean? = null, - val layout: Layout? = null, - val layoutColumnsOnNewData: Boolean? = null, - val responsiveLayout: ResponsiveLayout? = null, - val responsiveLayoutCollapseStartOpen: Boolean? = null, - val responsiveLayoutCollapseUseFormatters: Boolean? = null, - val columnMinWidth: Int? = null, - val resizableColumns: Boolean? = null, - val movableColumns: Boolean? = null, - val tooltipsHeader: Boolean? = null, - val headerFilterPlaceholder: String? = null, - val scrollToColumnPosition: ColumnPosition? = null, - val scrollToColumnIfVisible: Boolean? = null, - val rowFormatter: ((row: Tabulator.RowComponent) -> Unit)? = null, - val addRowPos: RowPos? = null, - val selectable: dynamic = null, - val selectableRangeMode: RangeMode? = null, - val selectableRollingSelection: Boolean? = null, - val selectablePersistence: Boolean? = null, - val selectableCheck: ((row: Tabulator.RowComponent) -> Boolean)? = null, - val movableRows: Boolean? = null, - val movableRowsConnectedTables: dynamic = null, - val movableRowsSender: dynamic = null, - val movableRowsReceiver: dynamic = null, - val resizableRows: Boolean? = null, - val scrollToRowPosition: RowPosition? = null, - val scrollToRowIfVisible: Boolean? = null, - val index: String? = null, - @Suppress("ArrayInDataClass") var data: Array<dynamic>? = null, - val ajaxURL: String? = null, - val ajaxParams: dynamic = null, - val ajaxConfig: dynamic = null, - val ajaxContentType: dynamic = null, - val ajaxURLGenerator: ((url: String, config: dynamic, params: dynamic) -> String)? = null, - val ajaxRequestFunc: ((url: String, config: dynamic, params: dynamic) -> Promise<Any>)? = null, - val ajaxFiltering: Boolean? = null, - val ajaxSorting: Boolean? = null, - val ajaxProgressiveLoad: ProgressiveMode? = null, - val ajaxProgressiveLoadDelay: Int? = null, - val ajaxProgressiveLoadScrollMargin: Int? = null, - val ajaxLoader: Boolean? = null, - val ajaxLoaderLoading: String? = null, - val ajaxLoaderError: String? = null, - val initialSort: List<Tabulator.Sorter>? = null, - val sortOrderReverse: Boolean? = null, - val initialFilter: List<Tabulator.Filter>? = null, - val initialHeaderFilter: List<Any?>? = null, - val pagination: PaginationMode? = null, - val paginationSize: Int? = null, - val paginationSizeSelector: Boolean? = null, - val paginationElement: dynamic = null, - val paginationDataReceived: dynamic = null, - val paginationDataSent: dynamic = null, - val paginationAddRow: AddRowMode? = null, - val paginationButtonCount: Int? = null, - var persistenceID: String? = null, - var persistenceMode: Boolean? = null, - var persistentLayout: Boolean? = null, - var persistentSort: Boolean? = null, - var persistentFilter: Boolean? = null, - val locale: String? = null, - var langs: dynamic = null, - val localized: ((locale: String, lang: dynamic) -> Unit)? = null, - val dataTreeRowExpanded: ((row: Tabulator.RowComponent, level: Number) -> Unit)? = null, - val dataTreeRowCollapsed: ((row: Tabulator.RowComponent, level: Number) -> Unit)? = null, - val movableRowsSendingStart: ((toTables: Array<Any>) -> Unit)? = null, - val movableRowsSent: (( - fromRow: Tabulator.RowComponent, - toRow: Tabulator.RowComponent, toTable: Tabulator - ) -> Unit)? = null, - val movableRowsSentFailed: (( - fromRow: Tabulator.RowComponent, - toRow: Tabulator.RowComponent, toTable: Tabulator - ) -> Unit)? = null, - val movableRowsSendingStop: ((toTables: Array<Any>) -> Unit)? = null, - val movableRowsReceivingStart: ((fromRow: Tabulator.RowComponent, toTable: Tabulator) -> Unit)? = null, - val movableRowsReceived: (( - fromRow: Tabulator.RowComponent, - toRow: Tabulator.RowComponent, fromTable: Tabulator - ) -> Unit)? = null, - val movableRowsReceivedFailed: (( - fromRow: Tabulator.RowComponent, - toRow: Tabulator.RowComponent, fromTable: Tabulator - ) -> Unit)? = null, - val movableRowsReceivingStop: ((fromTable: Tabulator) -> Unit)? = null, - var rowClick: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, - var rowDblClick: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, - var rowContext: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, - var rowTap: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, - var rowDblTap: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, - var rowTapHold: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, - var rowMouseEnter: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, - var rowMouseLeave: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, - var rowMouseOver: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, - var rowMouseOut: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, - var rowMouseMove: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, - var rowAdded: ((row: Tabulator.RowComponent) -> Unit)? = null, - var rowUpdated: ((row: Tabulator.RowComponent) -> Unit)? = null, - var rowDeleted: ((row: Tabulator.RowComponent) -> Unit)? = null, - var rowMoved: ((row: Tabulator.RowComponent) -> Unit)? = null, - var rowResized: ((row: Tabulator.RowComponent) -> Unit)? = null, - var rowSelectionChanged: ((data: Array<Any>, rows: Array<Tabulator.RowComponent>) -> Unit)? = null, - var rowSelected: ((row: Tabulator.RowComponent) -> Unit)? = null, - var rowDeselected: ((row: Tabulator.RowComponent) -> Unit)? = null, - var cellClick: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, - var cellDblClick: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, - var cellContext: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, - var cellTap: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, - var cellDblTap: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, - var cellTapHold: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, - var cellMouseEnter: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, - var cellMouseLeave: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, - var cellMouseOver: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, - var cellMouseOut: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, - var cellMouseMove: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, - var cellEditing: ((cell: Tabulator.CellComponent) -> Unit)? = null, - var cellEdited: ((cell: Tabulator.CellComponent) -> Unit)? = null, - var cellEditCancelled: ((cell: Tabulator.CellComponent) -> Unit)? = null, - var columnMoved: ((column: Tabulator.ColumnComponent, columns: Array<dynamic>) -> Unit)? = null, - var columnResized: ((column: Tabulator.ColumnComponent) -> Unit)? = null, - var columnVisibilityChanged: ((column: Tabulator.ColumnComponent, visible: Boolean) -> Unit)? = null, - var columnTitleChanged: ((column: Tabulator.ColumnComponent) -> Unit)? = null, - var tableBuilding: (() -> Unit)? = null, - var tableBuilt: (() -> Unit)? = null, - var renderStarted: (() -> Unit)? = null, - var renderComplete: (() -> Unit)? = null, - var htmlImporting: (() -> Unit)? = null, - var htmlImported: (() -> Unit)? = null, - var dataLoading: ((data: Any) -> Unit)? = null, - var dataLoaded: ((data: Any) -> Unit)? = null, - var dataEdited: ((data: Any) -> Unit)? = null, - var pageLoaded: ((pageno: Int) -> Unit)? = null, - var dataSorting: ((sorters: Array<Tabulator.Sorter>) -> Unit)? = null, - var dataSorted: ((sorters: Array<Tabulator.Sorter>, rows: Array<Tabulator.RowComponent>) -> Unit)? = null, - var dataFiltering: ((filters: Array<Tabulator.Filter>) -> Unit)? = null, - var dataFiltered: ((filters: Array<Tabulator.Filter>, rows: Array<Tabulator.RowComponent>) -> Unit)? = null, - var validationFailed: ((cell: Tabulator.CellComponent, value: Any, validators: dynamic) -> Unit)? = null, - var ajaxRequesting: ((url: String, params: dynamic) -> Boolean)? = null, - var ajaxResponse: ((url: String, params: dynamic, response: dynamic) -> Any)? = null, - var ajaxError: ((xhr: dynamic, textStatus: String, errorThrown: dynamic) -> Unit)? = null + val height: String? = null, + val virtualDom: Boolean? = null, + val virtualDomBuffer: Int? = null, + val placeholder: String? = null, + val footerElement: String? = null, + val tooltips: ((cell: Tabulator.CellComponent) -> String)? = null, + val tooltipGenerationMode: TooltipGenerationMode? = null, + val history: Boolean? = null, + val keybindings: dynamic = null, + val downloadDataFormatter: dynamic = null, + val downloadConfig: DownloadConfig? = null, + val reactiveData: Boolean? = null, + val autoResize: Boolean? = null, + val columns: List<ColumnDefinition<T>>? = null, + val autoColumns: Boolean? = null, + val layout: Layout? = null, + val layoutColumnsOnNewData: Boolean? = null, + val responsiveLayout: ResponsiveLayout? = null, + val responsiveLayoutCollapseStartOpen: Boolean? = null, + val responsiveLayoutCollapseUseFormatters: Boolean? = null, + val columnMinWidth: Int? = null, + val resizableColumns: Boolean? = null, + val movableColumns: Boolean? = null, + val tooltipsHeader: Boolean? = null, + val headerFilterPlaceholder: String? = null, + val scrollToColumnPosition: ColumnPosition? = null, + val scrollToColumnIfVisible: Boolean? = null, + val rowFormatter: ((row: Tabulator.RowComponent) -> Unit)? = null, + val addRowPos: RowPos? = null, + val selectable: dynamic = null, + val selectableRangeMode: RangeMode? = null, + val selectableRollingSelection: Boolean? = null, + val selectablePersistence: Boolean? = null, + val selectableCheck: ((row: Tabulator.RowComponent) -> Boolean)? = null, + val movableRows: Boolean? = null, + val movableRowsConnectedTables: dynamic = null, + val movableRowsSender: dynamic = null, + val movableRowsReceiver: dynamic = null, + val resizableRows: Boolean? = null, + val scrollToRowPosition: RowPosition? = null, + val scrollToRowIfVisible: Boolean? = null, + val index: String? = null, + @Suppress("ArrayInDataClass") var data: Array<T>? = null, + val ajaxURL: String? = null, + val ajaxParams: dynamic = null, + val ajaxConfig: dynamic = null, + val ajaxContentType: dynamic = null, + val ajaxURLGenerator: ((url: String, config: dynamic, params: dynamic) -> String)? = null, + val ajaxRequestFunc: ((url: String, config: dynamic, params: dynamic) -> Promise<Any>)? = null, + val ajaxFiltering: Boolean? = null, + val ajaxSorting: Boolean? = null, + val ajaxProgressiveLoad: ProgressiveMode? = null, + val ajaxProgressiveLoadDelay: Int? = null, + val ajaxProgressiveLoadScrollMargin: Int? = null, + val ajaxLoader: Boolean? = null, + val ajaxLoaderLoading: String? = null, + val ajaxLoaderError: String? = null, + val initialSort: List<Tabulator.Sorter>? = null, + val sortOrderReverse: Boolean? = null, + val initialFilter: List<Tabulator.Filter>? = null, + val initialHeaderFilter: List<Any?>? = null, + val pagination: PaginationMode? = null, + val paginationSize: Int? = null, + val paginationSizeSelector: Boolean? = null, + val paginationElement: dynamic = null, + val paginationDataReceived: dynamic = null, + val paginationDataSent: dynamic = null, + val paginationAddRow: AddRowMode? = null, + val paginationButtonCount: Int? = null, + var persistenceID: String? = null, + var persistenceMode: Boolean? = null, + var persistentLayout: Boolean? = null, + var persistentSort: Boolean? = null, + var persistentFilter: Boolean? = null, + val locale: String? = null, + var langs: dynamic = null, + val localized: ((locale: String, lang: dynamic) -> Unit)? = null, + val dataTreeRowExpanded: ((row: Tabulator.RowComponent, level: Number) -> Unit)? = null, + val dataTreeRowCollapsed: ((row: Tabulator.RowComponent, level: Number) -> Unit)? = null, + val movableRowsSendingStart: ((toTables: Array<Any>) -> Unit)? = null, + val movableRowsSent: (( + fromRow: Tabulator.RowComponent, + toRow: Tabulator.RowComponent, toTable: Tabulator + ) -> Unit)? = null, + val movableRowsSentFailed: (( + fromRow: Tabulator.RowComponent, + toRow: Tabulator.RowComponent, toTable: Tabulator + ) -> Unit)? = null, + val movableRowsSendingStop: ((toTables: Array<Any>) -> Unit)? = null, + val movableRowsReceivingStart: ((fromRow: Tabulator.RowComponent, toTable: Tabulator) -> Unit)? = null, + val movableRowsReceived: (( + fromRow: Tabulator.RowComponent, + toRow: Tabulator.RowComponent, fromTable: Tabulator + ) -> Unit)? = null, + val movableRowsReceivedFailed: (( + fromRow: Tabulator.RowComponent, + toRow: Tabulator.RowComponent, fromTable: Tabulator + ) -> Unit)? = null, + val movableRowsReceivingStop: ((fromTable: Tabulator) -> Unit)? = null, + var rowClick: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, + var rowDblClick: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, + var rowContext: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, + var rowTap: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, + var rowDblTap: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, + var rowTapHold: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, + var rowMouseEnter: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, + var rowMouseLeave: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, + var rowMouseOver: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, + var rowMouseOut: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, + var rowMouseMove: ((e: dynamic, row: Tabulator.RowComponent) -> Unit)? = null, + var rowAdded: ((row: Tabulator.RowComponent) -> Unit)? = null, + var rowUpdated: ((row: Tabulator.RowComponent) -> Unit)? = null, + var rowDeleted: ((row: Tabulator.RowComponent) -> Unit)? = null, + var rowMoved: ((row: Tabulator.RowComponent) -> Unit)? = null, + var rowResized: ((row: Tabulator.RowComponent) -> Unit)? = null, + var rowSelectionChanged: ((data: Array<Any>, rows: Array<Tabulator.RowComponent>) -> Unit)? = null, + var rowSelected: ((row: Tabulator.RowComponent) -> Unit)? = null, + var rowDeselected: ((row: Tabulator.RowComponent) -> Unit)? = null, + var cellClick: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, + var cellDblClick: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, + var cellContext: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, + var cellTap: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, + var cellDblTap: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, + var cellTapHold: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, + var cellMouseEnter: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, + var cellMouseLeave: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, + var cellMouseOver: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, + var cellMouseOut: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, + var cellMouseMove: ((e: Any, cell: Tabulator.CellComponent) -> Unit)? = null, + var cellEditing: ((cell: Tabulator.CellComponent) -> Unit)? = null, + var cellEdited: ((cell: Tabulator.CellComponent) -> Unit)? = null, + var cellEditCancelled: ((cell: Tabulator.CellComponent) -> Unit)? = null, + var columnMoved: ((column: Tabulator.ColumnComponent, columns: Array<dynamic>) -> Unit)? = null, + var columnResized: ((column: Tabulator.ColumnComponent) -> Unit)? = null, + var columnVisibilityChanged: ((column: Tabulator.ColumnComponent, visible: Boolean) -> Unit)? = null, + var columnTitleChanged: ((column: Tabulator.ColumnComponent) -> Unit)? = null, + var tableBuilding: (() -> Unit)? = null, + var tableBuilt: (() -> Unit)? = null, + var renderStarted: (() -> Unit)? = null, + var renderComplete: (() -> Unit)? = null, + var htmlImporting: (() -> Unit)? = null, + var htmlImported: (() -> Unit)? = null, + var dataLoading: ((data: List<T>) -> Unit)? = null, + var dataLoaded: ((data: List<T>) -> Unit)? = null, + var dataEdited: ((data: List<T>) -> Unit)? = null, + var pageLoaded: ((pageno: Int) -> Unit)? = null, + var dataSorting: ((sorters: Array<Tabulator.Sorter>) -> Unit)? = null, + var dataSorted: ((sorters: Array<Tabulator.Sorter>, rows: Array<Tabulator.RowComponent>) -> Unit)? = null, + var dataFiltering: ((filters: Array<Tabulator.Filter>) -> Unit)? = null, + var dataFiltered: ((filters: Array<Tabulator.Filter>, rows: Array<Tabulator.RowComponent>) -> Unit)? = null, + var validationFailed: ((cell: Tabulator.CellComponent, value: Any, validators: dynamic) -> Unit)? = null, + var ajaxRequesting: ((url: String, params: dynamic) -> Boolean)? = null, + var ajaxResponse: ((url: String, params: dynamic, response: dynamic) -> Any)? = null, + var ajaxError: ((xhr: dynamic, textStatus: String, errorThrown: dynamic) -> Unit)? = null ) /** @@ -683,8 +676,7 @@ data class TabulatorOptions<T : Any>( */ @Suppress("UNCHECKED_CAST_TO_EXTERNAL_INTERFACE", "ComplexMethod") fun <T : Any> TabulatorOptions<T>.toJs( - i18nTranslator: (String) -> (String), - dataSerializer: KSerializer<T>? = null + i18nTranslator: (String) -> (String) ): Tabulator.Options { val tmpCellEditCancelled = this.columns?.find { it.editorComponentFunction != null }?.let { { cell: Tabulator.CellComponent -> @@ -707,7 +699,7 @@ fun <T : Any> TabulatorOptions<T>.toJs( if (downloadConfig != null) this.downloadConfig = downloadConfig.toJs() if (reactiveData != null) this.reactiveData = reactiveData if (autoResize != null) this.autoResize = autoResize - if (columns != null) this.columns = columns.map { it.toJs(i18nTranslator, dataSerializer) }.toTypedArray() + if (columns != null) this.columns = columns.map { it.toJs(i18nTranslator) }.toTypedArray() if (autoColumns != null) { this.autoColumns = autoColumns } else if (columns == null) { @@ -717,9 +709,9 @@ fun <T : Any> TabulatorOptions<T>.toJs( if (layoutColumnsOnNewData != null) this.layoutColumnsOnNewData = layoutColumnsOnNewData if (responsiveLayout != null) this.responsiveLayout = responsiveLayout.layout if (responsiveLayoutCollapseStartOpen != null) this.responsiveLayoutCollapseStartOpen = - responsiveLayoutCollapseStartOpen + responsiveLayoutCollapseStartOpen if (responsiveLayoutCollapseUseFormatters != null) this.responsiveLayoutCollapseUseFormatters = - responsiveLayoutCollapseUseFormatters + responsiveLayoutCollapseUseFormatters if (columnMinWidth != null) this.columnMinWidth = columnMinWidth if (resizableColumns != null) this.resizableColumns = resizableColumns if (movableColumns != null) this.movableColumns = movableColumns @@ -754,7 +746,7 @@ fun <T : Any> TabulatorOptions<T>.toJs( if (ajaxProgressiveLoad != null) this.ajaxProgressiveLoad = ajaxProgressiveLoad.mode if (ajaxProgressiveLoadDelay != null) this.ajaxProgressiveLoadDelay = ajaxProgressiveLoadDelay if (ajaxProgressiveLoadScrollMargin != null) this.ajaxProgressiveLoadScrollMargin = - ajaxProgressiveLoadScrollMargin + ajaxProgressiveLoadScrollMargin if (ajaxLoader != null) this.ajaxLoader = ajaxLoader if (ajaxLoaderLoading != null) this.ajaxLoaderLoading = i18nTranslator(ajaxLoaderLoading) if (ajaxLoaderError != null) this.ajaxLoaderError = i18nTranslator(ajaxLoaderError) 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 72a2809a..ed803109 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 @@ -23,7 +23,6 @@ package pl.treksoft.kvision.tabulator import com.github.snabbdom.VNode import com.lightningkite.kotlin.observable.list.ObservableList -import kotlinx.serialization.ImplicitReflectionSerializer import kotlinx.serialization.KSerializer import kotlinx.serialization.list import kotlinx.serialization.serializer @@ -33,37 +32,35 @@ import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.core.StringBoolPair import pl.treksoft.kvision.core.Widget import pl.treksoft.kvision.i18n.I18n -import pl.treksoft.kvision.redux.ReduxStore import pl.treksoft.kvision.table.TableType import pl.treksoft.kvision.utils.JSON import pl.treksoft.kvision.utils.createInstance import pl.treksoft.kvision.utils.obj import pl.treksoft.kvision.utils.syncWithList -import redux.RAction import pl.treksoft.kvision.tabulator.js.Tabulator as JsTabulator +import redux.RAction +import pl.treksoft.kvision.redux.* /** * Tabulator component. * * @constructor - * @param T serializable type - * @param data a list of serializable objects + * @param T type + * @param data a list of objects * @param dataUpdateOnEdit determines if the data model is automatically updated after tabulator edit action * @param options tabulator options * @param types a set of table types * @param classes a set of CSS class names - * @param dataSerializer a serializer for class T */ @Suppress("LargeClass", "TooManyFunctions") open class Tabulator<T : Any>( - protected val data: List<T>? = null, - protected val dataUpdateOnEdit: Boolean = true, - val options: TabulatorOptions<T> = TabulatorOptions(), - types: Set<TableType> = setOf(), - classes: Set<String> = setOf(), - protected val dataSerializer: KSerializer<T>? = null + protected val data: List<T>? = null, + protected val dataUpdateOnEdit: Boolean = true, + val options: TabulatorOptions<T> = TabulatorOptions(), + types: Set<TableType> = setOf(), + classes: Set<String> = setOf() ) : - Widget(classes) { + Widget(classes) { /** * Table types. @@ -79,12 +76,12 @@ open class Tabulator<T : Any>( init { this.vnkey = "kv_tabulator_$counter" - if (data != null && dataSerializer != null) { + if (data != null) { @Suppress("UnsafeCastFromDynamic") - options.data = dataToNative(data, dataSerializer) + options.data = data.toTypedArray() if (data is ObservableList) { data.onUpdate += { - replaceData(data) + replaceData(data.toTypedArray()) } } } @@ -176,27 +173,24 @@ open class Tabulator<T : Any>( this.dispatchEvent("tabulatorCellEditCancelled", obj { detail = cell }) } } - if (options.dataLoading == null && dataSerializer != null) { + if (options.dataLoading == null) { options.dataLoading = { data -> - val d = nativeToData(data, dataSerializer) @Suppress("UnsafeCastFromDynamic") - this.dispatchEvent("tabulatorDataLoading", obj { detail = d }) + this.dispatchEvent("tabulatorDataLoading", obj { detail = data }) } } - if (options.dataLoaded == null && dataSerializer != null) { + if (options.dataLoaded == null) { options.dataLoaded = { data -> - val d = nativeToData(data, dataSerializer) @Suppress("UnsafeCastFromDynamic") - this.dispatchEvent("tabulatorDataLoaded", obj { detail = d }) + this.dispatchEvent("tabulatorDataLoaded", obj { detail = data }) } } - if (options.dataEdited == null && dataSerializer != null) { + if (options.dataEdited == null) { options.dataEdited = { data -> - val d = nativeToData(data, dataSerializer) @Suppress("UnsafeCastFromDynamic") - this.dispatchEvent("tabulatorDataEdited", obj { detail = d }) + this.dispatchEvent("tabulatorDataEdited", obj { detail = data }) if (dataUpdateOnEdit && this.data is MutableList<T>) { - this.data.syncWithList(d) + this.data.syncWithList(data) } } } @@ -212,30 +206,13 @@ open class Tabulator<T : Any>( } /** - * Converts a list of objects of type T to native JS array - */ - protected fun dataToNative(data: List<T>, dataSerializer: KSerializer<T>): dynamic { - val json = JSON.plain.stringify(dataSerializer.list, data) - return kotlin.js.JSON.parse(json) - } - - /** - * Converts a native JS array to the list of objects of type T - */ - protected fun nativeToData(data: dynamic, dataSerializer: KSerializer<T>): List<T> { - @Suppress("UnsafeCastFromDynamic") - val str = kotlin.js.JSON.stringify(data) - return JSON.plain.parse(dataSerializer.list, str) - } - - /** * Creates internal JS Tabulator object */ protected fun createJsTabulator() { (this.getElement() as? HTMLElement)?.let { jsTabulator = - KVManagerTabulator.getConstructor() - .createInstance(it, options.toJs(this::translate, dataSerializer)) + KVManagerTabulator.getConstructor() + .createInstance(it, options.toJs(this::translate)) if (currentPage != null) { jsTabulator?.setPageSize(pageSize ?: 0) jsTabulator?.setPage(currentPage) @@ -269,26 +246,20 @@ open class Tabulator<T : Any>( * Silently replaces the data in a table. * @param data new data */ - open fun replaceData(data: List<T>) { - if (dataSerializer != null) { - val native = dataToNative(data, dataSerializer) - @Suppress("UnsafeCastFromDynamic") - options.data = native - jsTabulator?.replaceData(native, null, null) - } + open fun replaceData(data: Array<T>) { + @Suppress("UnsafeCastFromDynamic") + options.data = data + jsTabulator?.replaceData(data, null, null) } /** * Sets new data in a table. * @param data new data */ - open fun setData(data: List<T>) { - if (dataSerializer != null) { - val native = dataToNative(data, dataSerializer) - @Suppress("UnsafeCastFromDynamic") - options.data = native - jsTabulator?.setData(native, null, null) - } + open fun setData(data: Array<T>) { + @Suppress("UnsafeCastFromDynamic") + options.data = data + jsTabulator?.setData(data, null, null) } /** @@ -297,9 +268,9 @@ open class Tabulator<T : Any>( * @return current data */ open fun getData(active: Boolean): List<T>? { - return if (jsTabulator != null && dataSerializer != null) { - val native = jsTabulator?.getData(active) - nativeToData(native, dataSerializer) + return if (jsTabulator != null) { + val native = jsTabulator?.getData(active) as? List<T> + native } else { data } @@ -310,9 +281,9 @@ open class Tabulator<T : Any>( * @return selected data */ open fun getSelectedData(): List<T> { - return if (jsTabulator != null && dataSerializer != null) { - val native = jsTabulator?.getSelectedData() - nativeToData(native, dataSerializer) + return if (jsTabulator != null) { + val native = jsTabulator?.getSelectedData() as List<T> + native } else { listOf() } @@ -366,9 +337,9 @@ open class Tabulator<T : Any>( * @param ifVisible scroll to already visible row */ open fun scrollToRow( - row: Int, - position: RowPosition? = null, - ifVisible: Boolean? = null + row: Int, + position: RowPosition? = null, + ifVisible: Boolean? = null ) { jsTabulator?.scrollToRow(row, position, ifVisible) } @@ -409,10 +380,9 @@ open class Tabulator<T : Any>( * Applies the current filter. */ open fun applyFilter() { - if (dataSerializer != null && filter != null) { + if (filter != null) { jsTabulator?.setFilter({ data: dynamic, _: dynamic -> - val str = kotlin.js.JSON.stringify(data) - filter?.let { it(JSON.plain.parse(dataSerializer, str)) } + filter?.let { it(data) } }, null, null) } } @@ -567,12 +537,12 @@ open class Tabulator<T : Any>( * It takes the same parameters as the constructor of the built component. */ inline fun <reified T : Any> Container.tabulator( - data: List<T>? = null, - dataUpdateOnEdit: Boolean = true, - options: TabulatorOptions<T> = TabulatorOptions(), - types: Set<TableType> = setOf(), - classes: Set<String> = setOf(), - noinline init: (Tabulator<T>.() -> Unit)? = null + data: List<T>? = null, + dataUpdateOnEdit: Boolean = true, + options: TabulatorOptions<T> = TabulatorOptions(), + types: Set<TableType> = setOf(), + classes: Set<String> = setOf(), + noinline init: (Tabulator<T>.() -> Unit)? = null ): Tabulator<T> { val tabulator = create(data, dataUpdateOnEdit, options, types, classes) init?.invoke(tabulator) @@ -583,13 +553,13 @@ open class Tabulator<T : Any>( /** * DSL builder extension function for general redux store. */ - inline fun <reified T : Any, S : Any, A : RAction> Container.tabulator( - store: ReduxStore<S, A>, - noinline dataFactory: (S) -> List<T>, - options: TabulatorOptions<T> = TabulatorOptions(), - types: Set<TableType> = setOf(), - classes: Set<String> = setOf(), - noinline init: (Tabulator<T>.() -> Unit)? = null + inline fun <reified T : Any, S : Any, A: RAction> Container.tabulator( + store: ReduxStore<S, A>, + noinline dataFactory: (S) -> List<T>, + options: TabulatorOptions<T> = TabulatorOptions(), + types: Set<TableType> = setOf(), + classes: Set<String> = setOf(), + noinline init: (Tabulator<T>.() -> Unit)? = null ): Tabulator<T> { val tabulator = create(store, dataFactory, options, types, classes) init?.invoke(tabulator) @@ -600,12 +570,12 @@ open class Tabulator<T : Any>( /** * DSL builder extension function for dedicated redux store (backed with a list). */ - inline fun <reified T : Any, A : RAction> Container.tabulator( - store: ReduxStore<List<T>, A>, - options: TabulatorOptions<T> = TabulatorOptions(), - types: Set<TableType> = setOf(), - classes: Set<String> = setOf(), - noinline init: (Tabulator<T>.() -> Unit)? = null + inline fun <reified T : Any, A: RAction> Container.tabulator( + store: ReduxStore<List<T>, A>, + options: TabulatorOptions<T> = TabulatorOptions(), + types: Set<TableType> = setOf(), + classes: Set<String> = setOf(), + noinline init: (Tabulator<T>.() -> Unit)? = null ): Tabulator<T> { val tabulator = create(store, options, types, classes) init?.invoke(tabulator) @@ -617,10 +587,10 @@ open class Tabulator<T : Any>( * DSL builder extension function for dynamic data (send within options parameter). */ fun <T : Any> Container.tabulator( - options: TabulatorOptions<T> = TabulatorOptions(), - types: Set<TableType> = setOf(), - classes: Set<String> = setOf(), - init: (Tabulator<T>.() -> Unit)? = null + options: TabulatorOptions<T> = TabulatorOptions(), + types: Set<TableType> = setOf(), + classes: Set<String> = setOf(), + init: (Tabulator<T>.() -> Unit)? = null ): Tabulator<T> { val tabulator = Tabulator(dataUpdateOnEdit = false, options = options, types = types, classes = classes) init?.invoke(tabulator) @@ -631,16 +601,15 @@ open class Tabulator<T : Any>( /** * A helper function to create a Tabulator object with correct serializer. */ - @UseExperimental(ImplicitReflectionSerializer::class) inline fun <reified T : Any> create( - data: List<T>? = null, - dataUpdateOnEdit: Boolean = true, - options: TabulatorOptions<T> = TabulatorOptions(), - types: Set<TableType> = setOf(), - classes: Set<String> = setOf(), - noinline init: (Tabulator<T>.() -> Unit)? = null + data: List<T>? = null, + dataUpdateOnEdit: Boolean = true, + options: TabulatorOptions<T> = TabulatorOptions(), + types: Set<TableType> = setOf(), + classes: Set<String> = setOf(), + noinline init: (Tabulator<T>.() -> Unit)? = null ): Tabulator<T> { - val tabulator = Tabulator(data, dataUpdateOnEdit, options, types, classes, T::class.serializer()) + val tabulator = Tabulator(data, dataUpdateOnEdit, options, types, classes) init?.invoke(tabulator) return tabulator } @@ -648,20 +617,19 @@ open class Tabulator<T : Any>( /** * A helper function to create a Tabulator object with correct serializer and general redux store. */ - @UseExperimental(ImplicitReflectionSerializer::class) inline fun <reified T : Any, S : Any, A : RAction> create( - store: ReduxStore<S, A>, - noinline dataFactory: (S) -> List<T>, - options: TabulatorOptions<T> = TabulatorOptions(), - types: Set<TableType> = setOf(), - classes: Set<String> = setOf(), - noinline init: (Tabulator<T>.() -> Unit)? = null + store: ReduxStore<S, A>, + noinline dataFactory: (S) -> List<T>, + options: TabulatorOptions<T> = TabulatorOptions(), + types: Set<TableType> = setOf(), + classes: Set<String> = setOf(), + noinline init: (Tabulator<T>.() -> Unit)? = null ): Tabulator<T> { val data = dataFactory(store.getState()) - val tabulator = Tabulator(data, false, options, types, classes, T::class.serializer()) + val tabulator = Tabulator(data, false, options, types, classes) init?.invoke(tabulator) store.subscribe { s -> - tabulator.replaceData(dataFactory(s)) + tabulator.replaceData(dataFactory(s).toTypedArray()) } return tabulator } @@ -669,19 +637,18 @@ open class Tabulator<T : Any>( /** * A helper function to create a Tabulator object with correct serializer and dedicated redux store. */ - @UseExperimental(ImplicitReflectionSerializer::class) inline fun <reified T : Any, A : RAction> create( - store: ReduxStore<List<T>, A>, - options: TabulatorOptions<T> = TabulatorOptions(), - types: Set<TableType> = setOf(), - classes: Set<String> = setOf(), - noinline init: (Tabulator<T>.() -> Unit)? = null + store: ReduxStore<List<T>, A>, + options: TabulatorOptions<T> = TabulatorOptions(), + types: Set<TableType> = setOf(), + classes: Set<String> = setOf(), + noinline init: (Tabulator<T>.() -> Unit)? = null ): Tabulator<T> { val data = store.getState() - val tabulator = Tabulator(data, false, options, types, classes, T::class.serializer()) + val tabulator = Tabulator(data, false, options, types, classes) init?.invoke(tabulator) store.subscribe { s -> - tabulator.replaceData(s) + tabulator.replaceData(s.toTypedArray()) } return tabulator } |