kvision
kvision copied to clipboard
row.getPosition(false) is missing
Tabulator changed it. I was using it to get row number in original data set. Not all data sets have IDs. Some queries with group by for example.
How now in a click handler I can get row number in original data set?
thanks
Unfortunately I have no idea if it is still possible. The old API of Tabulator was completely rewritten (https://github.com/olifolkerd/tabulator/commit/49da96fff69f48b73bffb23b2bc8df0b5aca3217). Maybe you should open an issue with your question in the tabulator repository. Or just generate some IDs in your queries.
ok. I've added key. In the click listener I call cell.getRow() How from a row I can get keyValue if I know key field name? I've also tried cell.getData() but it returns Any (some untyped object)
Thanks
The RowComponent has getIndex() method which returns the key value for the given row data. The key field name is id by default, but can be changed with index = "" option.
@Serializable
data class MyData(val myKey: String, val ...)
val data: List<MyData> = ...
tabulator(data, options = TabulatorOptions(..., index = "myKey"), serializer = serializer()) {
rowClickTabulator = { e ->
console.log("myKeyValue = " + e.detail.unsafeCast<Tabulator.RowComponent>().getIndex())
}
}
e.detail.unsafeCast<Tabulator.RowComponent>()
is an ugly way to write it and it’s also difficult to figure out that it needs to written that way.
Could some type safe methods be added in future?
thanks
In this case it's hard to implement it better, because the data is passed as event.detail field (https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail), and it's different for different event types. You can do this 100% type safe by staying in Kotlin world with formatterComponentFunction, without touching JS internals of Tabulator ;-)
@Serializable
data class MyData(val myKey: String, val ...)
val data: List<MyData> = ...
tabulator(data, columns = listOf(
ColumnDefinition(...),
ColumnDefinition(...),
ColumnDefinition(
"Action",
formatterComponentFunction = { _, _, data ->
Icon("fas fa-times") {
onClick {
console.log("myKey value = " + data.myKey)
}
}
})
), options = TabulatorOptions(..., index = "myKey"), serializer = serializer())