kvision icon indicating copy to clipboard operation
kvision copied to clipboard

row.getPosition(false) is missing

Open mgrouch opened this issue 3 years ago • 5 comments

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

mgrouch avatar Sep 13 '22 23:09 mgrouch

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.

rjaros avatar Sep 14 '22 04:09 rjaros

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

mgrouch avatar Sep 14 '22 12:09 mgrouch

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())
    }
}

rjaros avatar Sep 15 '22 04:09 rjaros

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

mgrouch avatar Sep 15 '22 11:09 mgrouch

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())

rjaros avatar Sep 15 '22 11:09 rjaros