holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.8k stars 519 forks source link

Tabulator: wrong selection displayed on the front-end with `add_filter` #7505

Open maximlt opened 3 days ago

maximlt commented 3 days ago

The wrong Tabulator row is selected in the front-end when the data is filtered with add_filter. The front-end seems to use the index of the selected row from the whole DataFrame (I'm selecting the row 2 in the whole df) which is incorrect when the data is filtered. It doesn't seem to affect header_filter.

import panel as pn
import pandas as pd

df = pd.DataFrame({"idx": ["idx0", "idx1", "idx2", "idx3", "idx4"], "col": ["a", "aa", "b", "bb", "bbb"]})
w_pat = pn.widgets.Select(value="b", options=["a", "b"])
w = pn.widgets.Tabulator(df, selectable=1)

def f(df, pattern):
    return df[df['col'].str.contains(pattern)]

w.add_filter(pn.bind(f, pattern=w_pat))
pn.Column(w_pat, w).servable()

Image