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

Tabulator: sorters are no longer automatically applied on cell edits #3744

Merged
merged 3 commits into from
Aug 10, 2022
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
2 changes: 1 addition & 1 deletion examples/reference/widgets/Tabulator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"\n",
"##### Properties\n",
"\n",
"* **``current_view``** (``DataFrame``): The current view of the table that is displayed, i.e. after sorting and filtering are applied\n",
"* **``current_view``** (``DataFrame``): The current view of the table that is displayed, i.e. after sorting and filtering are applied. `current_view` isn't guaranteed to be in sync with the displayed current view when sorters are applied and values are edited, in which case `current_view` is sorted while the displayed table isn't.\n",
"* **``selected_dataframe``** (``DataFrame``): A DataFrame reflecting the currently selected rows.\n",
"\n",
"##### Callbacks\n",
Expand Down
1 change: 0 additions & 1 deletion panel/models/tabulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,6 @@ export class DataTabulatorView extends PanelHTMLBoxView {
this._tabulator_cell_updating = false
}
this.model.trigger_event(new TableEditEvent(field, index))
this.setSorters()
this.tabulator.scrollToRow(index, "top", false)
}
}
Expand Down
41 changes: 41 additions & 0 deletions panel/tests/ui/widgets/test_tabulator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import datetime as dt
import time

Expand Down Expand Up @@ -117,6 +119,16 @@ def count_per_page(count: int, page_size: int):
return count_per_page


def tabulator_column_values(page, col_name: str) -> list[str]:
"""Get the values of a column.

>>> tabulator_column_values(page, 'color')
['blue', 'red']
"""
cells = page.locator(f'[tabulator-field={col_name}][role=gridcell]')
return cells.all_inner_texts()


def test_tabulator_default(page, port, df_mixed, df_mixed_as_string):
nrows, ncols = df_mixed.shape
widget = Tabulator(df_mixed)
Expand Down Expand Up @@ -2503,6 +2515,35 @@ def test_tabulator_sorters_pagination(page, port, df_mixed, pagination):
wait_until(page, lambda: widget.current_view.equals(expected_sorted_df))


def test_tabulator_edit_event_sorters_not_automatically_applied(page, port, df_mixed):
widget = Tabulator(df_mixed, sorters=[{'field': 'str', 'dir': 'desc'}])

values = []
widget.on_edit(lambda e: values.append((e.column, e.row, e.old, e.value)))

serve(widget, port=port, threaded=True, show=False)

time.sleep(0.2)

page.goto(f"http://localhost:{port}")

expected_vals = list(df_mixed['str'].sort_values(ascending=False))

wait_until(page, lambda: tabulator_column_values(page, 'str') == expected_vals)

# Chankge the cell that contains B to BB
cell = page.locator('text="B"')
cell.click()
editable_cell = page.locator('input[type="text"]')
editable_cell.fill("Z")
editable_cell.press('Enter')

wait_until(page, lambda: len(values) == 1)

expected_vals = [item if item != 'B' else 'Z' for item in expected_vals]
wait_until(page, lambda: tabulator_column_values(page, 'str') == expected_vals)


@pytest.mark.xfail(reason='See https://github.com/holoviz/panel/issues/3660')
def test_tabulator_edit_event_and_header_filters(page, port):
df = pd.DataFrame({
Expand Down