panel icon indicating copy to clipboard operation
panel copied to clipboard

Tabulator: setting header_filters not taking effect.

Open dwr-psandhu opened this issue 6 months ago • 7 comments

ALL software version info

panel 1.6.0

Description of expected behavior and the observed behavior

Moving from discourse discussion Tabulator has a header_filters that is typically set on init and that works once the table is displayed. If the header_filters are changed after the table is displayed the change doesn’t take effect. See example below

#%% show that header filters are not working
import panel as pn
pn.extension('tabulator')

# create a dataframe
import pandas as pd
df = pd.DataFrame({
    'A': [1, 2, 3, 4],
    'B': ['a', 'b', 'c', 'd'],
    'C': [True, False, True, False]
})
# header filters
header_filters = { 
    'A': {'type': 'input', 'func': 'like', 'placeholder': 'Filter A'},
    'B': {'type': 'input', 'func': 'like', 'placeholder': 'Filter B'},
    'C': {'type': 'input', 'func': 'like', 'placeholder': 'Filter C'}
}
header_filters_regex = {
    'A': {'type': 'input', 'func': 'regex', 'placeholder': 'Filter A'},
    'B': {'type': 'input', 'func': 'regex', 'placeholder': 'Filter B'},
    'C': {'type': 'input', 'func': 'regex', 'placeholder': 'Filter C'}
}
# create a tabulator table with header filters
table = pn.widgets.Tabulator(df, header_filters=header_filters, width=400, height=300)
# display the table
table.show()
# %%
table.header_filters = header_filters_regex

The table displayed initially has func like matches but then it is assigned the regex filters after show and those dont take affect.

Reloading the displayed page does make it take affect.

dwr-psandhu avatar May 31 '25 14:05 dwr-psandhu

This issue has been mentioned on HoloViz Discourse. There might be relevant details there:

https://discourse.holoviz.org/t/tabulator-header-filters-change-after-display-not-working/8788/3

holovizbot avatar May 31 '25 14:05 holovizbot

show blocks the rest of the code from running.

Can you try with servable and a button which updates the filter?

hoxbro avatar May 31 '25 14:05 hoxbro

@hoxbro i added a checkbox to toggle. it only works if the app is reloaded after checking the box.

# %% show that header filters are not working
import panel as pn

pn.extension("tabulator")

# create a dataframe
import pandas as pd

df = pd.DataFrame(
    {"A": [1, 2, 3, 4], "B": ["a", "b", "c", "d"], "C": [True, False, True, False]}
)
# header filters
header_filters = {
    "A": {"type": "input", "func": "like", "placeholder": "Filter A"},
    "B": {"type": "input", "func": "like", "placeholder": "Filter B"},
    "C": {"type": "input", "func": "like", "placeholder": "Filter C"},
}
header_filters_regex = {
    "A": {"type": "input", "func": "regex", "placeholder": "Filter A"},
    "B": {"type": "input", "func": "regex", "placeholder": "Filter B"},
    "C": {"type": "input", "func": "regex", "placeholder": "Filter C"},
}
# create a tabulator table with header filters
table = pn.widgets.Tabulator(df, header_filters=header_filters, width=800, height=300)

# Create a checkbox to toggle between filter types
use_regex = pn.widgets.Checkbox(name="Use Regex Filters", value=False)


# Define a callback function to update the header filters when the checkbox changes
def update_filters(event):
    if event.new:
        table.header_filters = header_filters_regex
    else:
        table.header_filters = header_filters


# Link the checkbox value to the update function
use_regex.param.watch(update_filters, "value")

# display the table and the checkbox
pn.Column(use_regex, table).show()

dwr-psandhu avatar May 31 '25 14:05 dwr-psandhu

Can you try with servable and panel serve?

hoxbro avatar May 31 '25 14:05 hoxbro

I changed the last line to .servable() and tried with panel serve. Same exact behavior as in the screenshot recording

dwr-psandhu avatar May 31 '25 14:05 dwr-psandhu

https://github.com/holoviz/panel/blob/85150c61547c44a070d68ba0ab9c34b4e93ee2d5/panel/widgets/tables.py#L598

Why would this be unsupported? I guess a recent change trying to sync backend dataframe with the tabulator view. Could this be added?

dwr-psandhu avatar Jun 02 '25 00:06 dwr-psandhu