Skip to content

Commit

Permalink
Clear selection if value change from pagination=remote (#6008)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored and philippjfr committed Jul 10, 2024
1 parent 573ead7 commit 371573d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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

0 comments on commit 371573d

Please sign in to comment.