From 631bbc42ae4f7d806dcb66ed133e73eede860163 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Tue, 24 Sep 2019 13:28:17 +0200 Subject: Expose native tabulator object as public property. Add new methods for column manipulation. (#77) --- .../pl/treksoft/kvision/tabulator/Tabulator.kt | 50 +++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) 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 054bd9ee..da1f48de 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 @@ -64,7 +64,10 @@ open class Tabulator( */ var types by refreshOnUpdate(types) - protected var jsTabulator: JsTabulator? = null + /** + * Native Tabulator object. + */ + var jsTabulator: JsTabulator? = null private var pageSize: Number? = null private var currentPage: Number? = null @@ -547,6 +550,51 @@ open class Tabulator( jsTabulator?.navigateDown() } + /** + * Get column component by name. + * @param name column name + * @return column component + */ + open fun getColumn(name: String): JsTabulator.ColumnComponent? { + return jsTabulator?.getColumn(name) + } + + /** + * Delete column by name. + * @param name column name + */ + open fun deleteColumn(name: String) { + jsTabulator?.deleteColumn(name) + } + + /** + * Add new column to the tabulator. + * @param columnDefinition column definition + * @param insertRightOfTarget determines how to position the new column + * @param positionTarget the field to insert the new column next to + */ + open fun addColumn( + columnDefinition: ColumnDefinition, + insertRightOfTarget: Boolean? = null, + positionTarget: String? = null + ) { + jsTabulator?.addColumn(columnDefinition.toJs(this::translate), insertRightOfTarget, positionTarget) + } + + /** + * Add new column to the tabulator. + * @param columnDefinition column definition native object + * @param insertRightOfTarget determines how to position the new column + * @param positionTarget the field to insert the new column next to + */ + open fun addColumn( + columnDefinition: JsTabulator.ColumnDefinition, + insertRightOfTarget: Boolean? = null, + positionTarget: String? = null + ) { + jsTabulator?.addColumn(columnDefinition, insertRightOfTarget, positionTarget) + } + internal fun removeCustomEditors() { EditorRoot.cancel?.invoke(null) EditorRoot.disposeTimer?.let { window.clearTimeout(it) } -- cgit