Skip to content

Commit

Permalink
Ensure Tabulator sorters are correctly synced (#7036)
Browse files Browse the repository at this point in the history
* Ensure Tabulator sorters are correctly synced

* Add test

* Make other test more robust
  • Loading branch information
philippjfr committed Jul 29, 2024
1 parent eb9108e commit 1303408
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion panel/models/tabulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ export class DataTabulatorView extends HTMLBoxView {
}
if (this.model.pagination !== "remote") {
this._updating_sort = true
this.model.sorters = sorts
this.model.sorters = sorts.reverse()
this._updating_sort = false
}
})
Expand Down
19 changes: 19 additions & 0 deletions panel/tests/ui/widgets/test_tabulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,8 @@ def test_tabulator_sorters_set_after_init(page, df_mixed):

serve_component(page, widget)

expect(page.locator('.pnx-tabulator.tabulator')).to_have_count(1)

widget.sorters = [{'field': 'int', 'dir': 'desc'}]

sheader = page.locator('[aria-sort="descending"]:visible')
Expand Down Expand Up @@ -3019,6 +3021,23 @@ def test_tabulator_selection_header_filter_changed(page):
expected_selected = df.iloc[selection, :]
assert widget.selected_dataframe.equals(expected_selected)

def test_tabulator_sorter_not_reversed_after_init(page):
df = pd.DataFrame({
'col1': [1, 2, 3, 4],
'col2': [1, 4, 3, 2],
})

sorters = [
{'field': 'col1', 'dir': 'desc'},
{'field': 'col2', 'dir': 'asc'}
]
table = Tabulator(df, sorters=sorters)

serve_component(page, table)

expect(page.locator('.pnx-tabulator.tabulator')).to_have_count(1)
page.wait_for_timeout(300)
assert table.sorters == sorters

def test_tabulator_loading_no_horizontal_rescroll(page, df_mixed):
widths = 100
Expand Down

0 comments on commit 1303408

Please sign in to comment.