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

Add header_tooltips parameter to Tabulator #7241

Merged
merged 6 commits into from
Sep 9, 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
1 change: 1 addition & 0 deletions examples/reference/widgets/Tabulator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"* **`groupby`** (`list`): Groups rows in the table by one or more columns.\n",
"* **`header_align`** (`dict` or `str`): A mapping from column name to header alignment or a fixed header alignment, which should be one of `'left'`, `'center'`, `'right'`.\n",
"* **`header_filters`** (`boolean`/`dict`): A boolean enabling filters in the column headers or a dictionary providing filter definitions for specific columns.\n",
"* **`header_tooltips`** (`dict`): Dictionary mapping from column name to a tooltip to show when hovering over the column header. \n",
"* **`hidden_columns`** (`list`): List of columns to hide.\n",
"* **`hierarchical`** (boolean, default=False): Whether to render multi-indexes as hierarchical index (note hierarchical must be enabled during instantiation and cannot be modified later)\n",
"* **`initial_page_size`** (`int`, `default=20`): If pagination is enabled and `page_size` this determines the initial size of each page before rendering.\n",
Expand Down
15 changes: 15 additions & 0 deletions panel/tests/ui/widgets/test_tabulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3396,7 +3396,7 @@
assert table_values == list(df2['x'].sort_values(ascending=False))
else:
return False
wait_until(x_values, page)

Check failure on line 3399 in panel/tests/ui/widgets/test_tabulator.py

View workflow job for this annotation

GitHub Actions / ui:test-ui:ubuntu-latest

test_tabulator_sorter_default_number TimeoutError: wait_until timed out in 5000 milliseconds


def test_tabulator_update_hidden_columns(page):
Expand Down Expand Up @@ -3954,3 +3954,18 @@
self.set_filtering(page, n)
self.check_selected(page, list(range(10)), 0)
expect(page.locator('.tabulator')).to_have_count(1)


def test_tabulator_header_tooltips(page):
df = pd.DataFrame({"header": [True, False, True]})
widget = Tabulator(df, header_tooltips={"header": "Test"})

serve_component(page, widget)

header = page.locator('.tabulator-col-title', has_text="header")
expect(header).to_have_count(1)
header.hover()

page.wait_for_timeout(200)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this actually needed, expect should wait.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is for the hover part not the expect part. The mouse is moved to the header with hover.


expect(page.locator('.tabulator-tooltip')).to_have_text("Test")
10 changes: 10 additions & 0 deletions panel/tests/widgets/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2597,3 +2597,13 @@ def test_selection_cleared_remote_pagination_new_values(document, comm):

table.value = df.copy()
assert table.selection == []


def test_save_user_columns_configuration(document, comm):
df = pd.DataFrame({"header": [True, False, True]})
configuration={"columns": [{"field": "header", "headerTooltip": True}]}
tabulator = Tabulator(df, configuration=configuration, show_index=False)

expected = [{'field': 'header', 'sorter': 'boolean', 'headerTooltip': True}]
model = tabulator.get_root(document, comm)
assert model.configuration["columns"] == expected
15 changes: 13 additions & 2 deletions panel/widgets/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,10 @@ class Tabulator(BaseTable):
Whether to enable filters in the header or dictionary
configuring filters for each column.""")

header_tooltips = param.Dict(default={}, doc="""
Dictionary mapping from column name to a tooltip to show when
hovering over the column header.""")

hidden_columns = param.List(default=[], nested_refs=True, doc="""
List of columns to hide.""")

Expand Down Expand Up @@ -1220,7 +1224,7 @@ class Tabulator(BaseTable):
_rename: ClassVar[Mapping[str, str | None]] = {
'selection': None, 'row_content': None, 'row_height': None,
'text_align': None, 'embed_content': None, 'header_align': None,
'header_filters': None, 'styles': 'cell_styles',
'header_filters': None, 'header_tooltips': None, 'styles': 'cell_styles',
'title_formatters': None, 'sortable': None, 'initial_page_size': None
}

Expand Down Expand Up @@ -1985,6 +1989,9 @@ def _config_columns(self, column_objs: list[TableColumn]) -> list[dict[str, Any]
col_dict['width'] = self.widths[field]
col_dict.update(self._get_filter_spec(column))

if field in self.header_tooltips:
col_dict["headerTooltip"] = self.header_tooltips[field]

if isinstance(index, tuple):
if columns:
children = columns
Expand Down Expand Up @@ -2029,7 +2036,11 @@ def _get_configuration(self, columns: list[dict[str, Any]]) -> dict[str, Any]:
if self.groups and 'columns' in configuration:
raise ValueError("Groups must be defined either explicitly "
"or via the configuration, not both.")
configuration['columns'] = self._config_columns(columns)
user_columns = {v["field"]: v for v in configuration.get('columns', {})}
configuration["columns"] = self._config_columns(columns)
for idx, col in enumerate(columns):
if (name := col.field) in user_columns:
configuration["columns"][idx] |= user_columns[name]
configuration['dataTree'] = self.hierarchical
if self.sizing_mode in ('stretch_height', 'stretch_both'):
configuration['maxHeight'] = '100%'
Expand Down
Loading