Bug: index (i) refers to wrong table row after sorting

I have a table with a custom column of type Button.

The button calls a js query which uses i to determine which row called it. If the table is not sorted, mytable.data[i] returns the correct row. However, if I sort table mytable.data[i] returns the wrong row.

i is always the displayed row number, i.e. it will always return 0 if the first row is selected no matter the table sort. As a result clicking the first row's button will always return mytable.data[0] even if the table is sorted in descending order.

@bradlymathews

Hey there :wave: Would you be able to use table.selectedRow to return the clicked row?

Yeah, that sounds like a good workaround.

Hi, I am having the same problem, and the workaround is not really a solution since I cannot make the row as selected in this case.
I have also tried to use the table.displayedData array but it seems like that there isn't an array that matches what is really shown in the table.
Do you plan to fix the "i" index? Is there any other solution I am missing?
Thanks for the help.
G.

Hey @gtron thanks for reaching out :wave: Linking my answer to this question in another thread: Sorting by custom column - #2 by lauren.gus

Depending on your use case, you could use an action button instead of a custom column with 'select row on click' toggled on :slightly_smiling_face: