diff options
Diffstat (limited to 'kvision-modules')
3 files changed, 39 insertions, 19 deletions
diff --git a/kvision-modules/kvision-bootstrap/src/main/resources/css/style.css b/kvision-modules/kvision-bootstrap/src/main/resources/css/style.css index 992a5a0b..7633ed6c 100644 --- a/kvision-modules/kvision-bootstrap/src/main/resources/css/style.css +++ b/kvision-modules/kvision-bootstrap/src/main/resources/css/style.css @@ -210,3 +210,8 @@ select.input-sm { -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, 0.6); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, 0.6); } + +.tabulator-row .tabulator-cell.tabulator-editing { + border-right: 1px solid #1d68cd !important; + padding: 2px !important; +} 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 dd3bff5f..08f2603b 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 @@ -448,22 +448,18 @@ fun <T : Any> ColumnDefinition<T>.toJs( this.sorter = sorter.sorter } if (sorterParams != null) this.sorterParams = sorterParams - if (tmpFormatterFunction != null) { - this.formatter = tmpFormatterFunction - } else if (formatterFunction != null) { - this.formatter = formatterFunction - } else if (formatter != null) { - this.formatter = formatter.formatter + when { + tmpFormatterFunction != null -> this.formatter = tmpFormatterFunction + formatterFunction != null -> this.formatter = formatterFunction + formatter != null -> this.formatter = formatter.formatter } if (formatterParams != null) this.formatterParams = formatterParams if (variableHeight != null) this.variableHeight = variableHeight if (editable != null) this.editable = editable - if (tmpEditorFunction != null) { - this.editor = tmpEditorFunction - } else if (editorFunction != null) { - this.editor = editorFunction - } else if (editor != null) { - this.editor = editor.editor + when { + tmpEditorFunction != null -> this.editor = tmpEditorFunction + editorFunction != null -> this.editor = editorFunction + editor != null -> this.editor = editor.editor } if (editorParams != null) this.editorParams = editorParams if (validator != null) this.validator = validator.validator @@ -690,6 +686,13 @@ fun <T : Any> TabulatorOptions<T>.toJs( i18nTranslator: (String) -> (String), dataSerializer: KSerializer<T>? = null ): Tabulator.Options { + val tmpCellEditCancelled = this.columns?.find { it.editorComponentFunction != null }?.let { + { cell: Tabulator.CellComponent -> + cellEditCancelled?.invoke(cell) + cell.getTable().redraw(true) + } + } ?: cellEditCancelled + return obj { if (height != null) this.height = height if (virtualDom != null) this.virtualDom = virtualDom @@ -817,7 +820,9 @@ fun <T : Any> TabulatorOptions<T>.toJs( if (cellMouseMove != null) this.cellMouseMove = cellMouseMove if (cellEditing != null) this.cellEditing = cellEditing if (cellEdited != null) this.cellEdited = cellEdited - if (cellEditCancelled != null) this.cellEditCancelled = cellEditCancelled + if (tmpCellEditCancelled != null) { + this.cellEditCancelled = tmpCellEditCancelled + } if (columnMoved != null) this.columnMoved = columnMoved if (columnResized != null) this.columnResized = columnResized if (columnVisibilityChanged != null) this.columnVisibilityChanged = columnVisibilityChanged 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 6c7480fc..72a2809a 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 @@ -38,6 +38,7 @@ 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 @@ -47,13 +48,16 @@ import pl.treksoft.kvision.tabulator.js.Tabulator as JsTabulator * @constructor * @param T serializable type * @param data a list of serializable 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(), @@ -191,6 +195,9 @@ open class Tabulator<T : Any>( val d = nativeToData(data, dataSerializer) @Suppress("UnsafeCastFromDynamic") this.dispatchEvent("tabulatorDataEdited", obj { detail = d }) + if (dataUpdateOnEdit && this.data is MutableList<T>) { + this.data.syncWithList(d) + } } } counter++ @@ -561,12 +568,13 @@ open class Tabulator<T : Any>( */ 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 ): Tabulator<T> { - val tabulator = create(data, options, types, classes) + val tabulator = create(data, dataUpdateOnEdit, options, types, classes) init?.invoke(tabulator) this.add(tabulator) return tabulator @@ -614,7 +622,7 @@ open class Tabulator<T : Any>( classes: Set<String> = setOf(), init: (Tabulator<T>.() -> Unit)? = null ): Tabulator<T> { - val tabulator = Tabulator<T>(options = options, types = types, classes = classes) + val tabulator = Tabulator(dataUpdateOnEdit = false, options = options, types = types, classes = classes) init?.invoke(tabulator) this.add(tabulator) return tabulator @@ -625,12 +633,14 @@ open class Tabulator<T : Any>( */ @UseExperimental(ImplicitReflectionSerializer::class) inline fun <reified T : Any> create( - data: List<T>? = null, options: TabulatorOptions<T> = TabulatorOptions(), + 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, options, types, classes, T::class.serializer()) + val tabulator = Tabulator(data, dataUpdateOnEdit, options, types, classes, T::class.serializer()) init?.invoke(tabulator) return tabulator } @@ -648,7 +658,7 @@ open class Tabulator<T : Any>( noinline init: (Tabulator<T>.() -> Unit)? = null ): Tabulator<T> { val data = dataFactory(store.getState()) - val tabulator = Tabulator(data, options, types, classes, T::class.serializer()) + val tabulator = Tabulator(data, false, options, types, classes, T::class.serializer()) init?.invoke(tabulator) store.subscribe { s -> tabulator.replaceData(dataFactory(s)) @@ -668,7 +678,7 @@ open class Tabulator<T : Any>( noinline init: (Tabulator<T>.() -> Unit)? = null ): Tabulator<T> { val data = store.getState() - val tabulator = Tabulator(data, options, types, classes, T::class.serializer()) + val tabulator = Tabulator(data, false, options, types, classes, T::class.serializer()) init?.invoke(tabulator) store.subscribe { s -> tabulator.replaceData(s) |