Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear selection if value change from pagination=remote #6008

Merged
merged 7 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions panel/tests/widgets/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2284,3 +2284,15 @@ def test_bokeh_formatter_column_with_no_textalign_but_text_align_set(document, c

model = table.get_root(document, comm)
assert model.configuration['columns'][1]['hozAlign'] == 'center'


def test_selection_cleared_remote_pagination_new_values(document, comm):
df = pd.DataFrame(range(200))
table = Tabulator(df, page_size=50, pagination="remote", selectable="checkbox")
table.selection = [1, 2, 3]

table.value = df
assert table.selection == [1, 2, 3]

table.value = df.copy()
assert table.selection == []
5 changes: 5 additions & 0 deletions panel/widgets/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,7 @@ def __init__(self, value=None, **params):
super().__init__(value=value, **params)
self._configuration = configuration
self.param.watch(self._update_children, self._content_params)
self.param.watch(self._clear_selection_remote_pagination, 'value')
if click_handler:
self.on_click(click_handler)
if edit_handler:
Expand Down Expand Up @@ -1596,6 +1597,10 @@ def _update_max_page(self):
for ref, (model, _) in self._models.items():
self._apply_update([], {'max_page': max_page}, model, ref)

def _clear_selection_remote_pagination(self, event):
if event.new is not event.old and self.pagination == 'remote':
self.selection = []

def _update_selected(self, *events: param.parameterized.Event, indices=None):
kwargs = {}
if self.pagination == 'remote' and self.value is not None:
Expand Down
Loading