I am using Tabulator and providing a callback function for on_click in order to get the selected row list. However, this list seems to be updated after this event is fired because the list is always one click old. The CellClickEvent data is always correct.
This seems like a very common use case, but does this mean I need to create a custom version of Tabulator?
Hi, could you provide a working example that can be used to reproduce the problem? I tried the code below, and it worked as expected.
import pandas as pd
import panel as pn
df = pd.DataFrame({
'A': [1, 2, 3],
'B': [4, 5, 6],
'C': [7, 8, 9]
})
tabulator = pn.widgets.Tabulator(df, selectable='checkbox', show_index=False)
def callback(event):
selected_df = tabulator.value.iloc[tabulator.selection]
print("Row clicked:", event.row)
print("Selected rows:", selected_df)
tabulator.on_click(callback)
tabulator.servable()
I’m using the standard behavior for selection, which is the default(Ctrl-select for multi, Shift+select for range). Setting it to checkbox doesn’t give this behavior, nor does selecting the checkbox create an event, though an enhancement issue has been raised on Github for this event, Create `on_selected` event for tabulator · Issue #7095 · holoviz/panel · GitHub.
import pandas as pd
import panel as pn
df = pd.DataFrame({
‘A’: [1, 2, 3],
‘B’: [4, 5, 6],
‘C’: [7, 8, 9]
})
tabulator = pn.widgets.Tabulator(df, show_index=False, disabled=True)
def callback(event):
print(tabulator.selection)
tabulator.on_click(callback)
tabulator.servable()
OK, I see what you mean now, and I can reproduce the issue. I normally use a checkbox to select rows and an on_click handler to trigger an action based on the clicked row, and this works fine for me.