diff --git a/examples/reference/widgets/Tabulator.ipynb b/examples/reference/widgets/Tabulator.ipynb index fdae2c25f1..cc26c2d217 100644 --- a/examples/reference/widgets/Tabulator.ipynb +++ b/examples/reference/widgets/Tabulator.ipynb @@ -69,6 +69,7 @@ "* **``text_align``** (``dict`` or ``str``): A mapping from column name to alignment or a fixed column alignment, which should be one of `'left'`, `'center'`, `'right'`.\n", "* **`theme`** (``str``, `default='simple'`): The CSS theme to apply (note that changing the theme will restyle all tables on the page), which should be one of `'default'`, `'site'`, `'simple'`, `'midnight'`, `'modern'`, `'bootstrap'`, `'bootstrap4'`, `'materialize'`, `'bulma'`, `'semantic-ui'`, or `'fast'`.\n", "* **`theme_classes`** (`list[str]`): List of extra CSS classes to apply to the Tabulator element to customize the theme.\n", + "* **``title_formatters``** (``dict``): A dictionary mapping from column name to a *Tabulator* formatter specification.\n", "* **``titles``** (``dict``): A mapping from column name to a title to override the name with.\n", "* **``value``** (``pd.DataFrame``): The pandas DataFrame to display and edit\n", "* **``widths``** (``dict``): A dictionary mapping from column name to column width in the rendered table.\n", @@ -176,7 +177,15 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The list of valid *Tabulator* formatters can be found in the [Tabulator documentation](https://tabulator.info/docs/5.4/format#format-builtin).\n", + "The list of valid *Tabulator* formatters can be found in the [Tabulator documentation](https://tabulator.info/docs/5.5/format#format-builtin).\n", + "\n", + "Note that the equivalent specification may also be applied for column titles using the `title_formatters` parameter (but does not support Bokeh `CellFormatter` types)." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "\n", "## Editors/Editing\n", "\n", @@ -204,7 +213,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Therefore it is often preferable to use one of the [*Tabulator* editors](https://tabulator.info/docs/5.4/edit#edit) directly. Setting the editor of a column to `None` makes that column non-editable. Note that in addition to the standard *Tabulator* editors the `Tabulator` widget also supports `'date'` and `'datetime'` editors:" + "Therefore it is often preferable to use one of the [*Tabulator* editors](https://tabulator.info/docs/5.5/edit#edit) directly. Setting the editor of a column to `None` makes that column non-editable. Note that in addition to the standard *Tabulator* editors the `Tabulator` widget also supports `'date'` and `'datetime'` editors:" ] }, { diff --git a/panel/widgets/tables.py b/panel/widgets/tables.py index cba5d20863..19ae7c08fb 100644 --- a/panel/widgets/tables.py +++ b/panel/widgets/tables.py @@ -1095,6 +1095,10 @@ class Tabulator(BaseTable): List of extra CSS classes to apply to the Tabulator element to customize the theme.""") + title_formatters = param.Dict(default={}, doc=""" + Tabulator formatter specification to use for a particular column + header title.""") + _data_params: ClassVar[List[str]] = [ 'value', 'page', 'page_size', 'pagination', 'sorters', 'filters' ] @@ -1112,7 +1116,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, 'styles': 'cell_styles', 'title_formatters': None } # Determines the maximum size limits beyond which (local, remote) @@ -1718,6 +1722,13 @@ def _config_columns(self, column_objs: List[TableColumn]) -> List[Dict[str, Any] formatter = dict(formatter) col_dict['formatter'] = formatter.pop('type') col_dict['formatterParams'] = formatter + title_formatter = self.title_formatters.get(column.field) + if title_formatter: + col_dict['titleFormatter'] = title_formatter + elif isinstance(title_formatter, dict): + formatter = dict(title_formatter) + col_dict['titleFormatter'] = title_formatter.pop('type') + col_dict['titleFormatterParams'] = title_formatter col_name = self._renamed_cols[column.field] if column.field in self.indexes: if len(self.indexes) == 1: