Tabulator#
This component is also available in the classic reference.
The Tabulator widget wraps the Tabulator js table to provide a full-featured, very powerful interactive table.
Use pn.ui.Tabulator to create this component.
API#
.. py:class:: Tabulator(value=None, **params) :module: panel.widgets.tables
The Tabulator widget wraps the Tabulator js
table to provide a full-featured, very powerful interactive table.
Reference: https://panel.holoviz.org/reference/widgets/Tabulator.html
:Example:
Tabulator(df, theme=’site’, pagination=’remote’, page_size=25)
:Attributes:
:obj:`current_view <.current_view>`
Returns the current view of the table after filtering and sorting are applied.
**header_filters**
..
**page_size**
..
**pagination**
..
**row_content**
..
**selectable_rows**
..
.. rubric:: Methods
.. autosummary::
download
download_menu
on_click
on_edit
stream
.. !! processed by numpydoc !!
Parameter Definitions
Parameters inherited from:
:class:`panel.widgets.base.WidgetBase`: label
:class:`panel.viewable.Layoutable`: align, aspect_ratio, css_classes, design, min_width, min_height, max_width, max_height, styles, stylesheets, tags, width_policy, height_policy, sizing_mode, visible
:class:`panel.viewable.Viewable`: loading
:class:`panel.widgets.base.Widget`: height, margin, width, disabled
:class:`panel.widgets.tables.BaseTable`: value, aggregators, editables, editors, formatters, hierarchical, show_index, sorters, text_align, titles, widths
selection = _ListValidateWithCallable(allow_refs=True, bounds=(0, None), default=[], item_type=<class 'int'>, label='Selection')
The currently selected rows of the table. It validates
its values against 'selectable_rows' if used.
row_height = Integer(allow_refs=True, default=30, inclusive_bounds=(True, True), label='Row height')
The height of each table row.
buttons = Dict(allow_refs=True, class_=<class 'dict'>, default={}, label='Buttons', nested_refs=True)
Dictionary mapping from column name to a HTML element
to use as the button icon.
container_popup = Boolean(allow_refs=True, default=True, label='Container popup')
If True, popups will appear within the table container, otherwise
popups will be appended to the body element of the DOM.
expanded = List(allow_refs=True, bounds=(0, None), default=[], item_type=<class 'int'>, label='Expanded', nested_refs=True)
List of expanded rows, only applicable if a row_content function
has been defined.
embed_content = Boolean(allow_refs=True, default=False, label='Embed content')
Whether to embed the row_content or render it dynamically
when a row is expanded.
filters = List(allow_refs=True, bounds=(0, None), default=[], item_type=<class 'dict'>, label='Filters')
List of client-side filters declared as dictionaries containing
'field', 'type' and 'value' keys.
frozen_columns = ClassSelector(allow_refs=True, class_=(<class 'list'>, <class 'dict'>), default=[], label='Frozen columns', nested_refs=True)
One of:
- List indicating the columns to freeze. The column(s) may be
selected by name or index.
- Dict indicating columns to freeze as keys and their freeze location
as values, freeze location is either 'right' or 'left'.
frozen_rows = List(allow_refs=True, bounds=(0, None), default=[], item_type=<class 'int'>, label='Frozen rows', nested_refs=True)
List indicating the rows to freeze. If set, the
first N rows will be frozen, which prevents them from scrolling
out of frame; if set to a negative value the last N rows will be
frozen.
groups = Dict(allow_refs=True, class_=<class 'dict'>, default={}, label='Groups', nested_refs=True)
Dictionary mapping defining the groups.
groupby = List(allow_refs=True, bounds=(0, None), default=[], item_type=<class 'str'>, label='Groupby', nested_refs=True)
Groups rows in the table by one or more columns.
header_align = ClassSelector(allow_refs=True, class_=(<class 'dict'>, <class 'str'>), default={}, label='Header align', nested_refs=True)
A mapping from column name to alignment or a fixed column
alignment, which should be one of 'left', 'center', 'right'.
header_filters = ClassSelector(allow_None=True, allow_refs=True, class_=(<class 'bool'>, <class 'dict'>), label='Header filters', nested_refs=True)
Whether to enable filters in the header or dictionary
configuring filters for each column.
header_tooltips = Dict(allow_refs=True, class_=<class 'dict'>, default={}, label='Header tooltips')
Dictionary mapping from column name to a tooltip to show when
hovering over the column header.
hidden_columns = List(allow_refs=True, bounds=(0, None), default=[], item_type=<class 'str'>, label='Hidden columns', nested_refs=True)
List of columns to hide.
movable_columns = Boolean(allow_refs=True, default=False, label='Movable columns')
Whether columns can be reordered by dragging their headers.
layout = Selector(allow_refs=True, default='fit_data_table', label='Layout', names={}, objects=['fit_data', 'fit_data_fill', 'fit_data_stretch', 'fit_data_table', 'fit_columns'])
Describes the column layout mode with one of the following options
'fit_columns', 'fit_data', 'fit_data_stretch', 'fit_data_fill',
'fit_data_table'.
initial_page_size = Integer(allow_refs=True, bounds=(1, None), default=20, inclusive_bounds=(True, True), label='Initial page size')
Initial page size if page_size is None and therefore automatically set.
pagination = Selector(allow_None=True, allow_refs=True, label='Pagination', names={}, objects=['local', 'remote'])
Defines the pagination mode of the Tabulator.
- None
No pagination is applied, all rows are rendered.
- 'local' (client-side)
Pagination is applied locally, i.e. the entire DataFrame
is loaded and then paginated.
- 'remote' (server-side)
Pagination is applied remotely, i.e. only the current page
is loaded from the server.
page = Integer(allow_refs=True, default=1, inclusive_bounds=(True, True), label='Page')
Currently selected page (indexed starting at 1), if pagination is enabled.
page_size = Integer(allow_None=True, allow_refs=True, bounds=(1, None), inclusive_bounds=(True, True), label='Page size')
Number of rows to render per page, if pagination is enabled.
row_content = Callable(allow_None=True, label='Row content')
A function which is given the DataFrame row and should return
a Panel object to render as additional detail below the row.
The function may also be asynchronous.
selectable = ClassSelector(allow_refs=True, class_=(<class 'bool'>, <class 'str'>, <class 'int'>), default=True, label='Selectable')
Defines the selection mode of the Tabulator.
- True
Selects rows on click. To select multiple use Ctrl-select,
to select a range use Shift-select
- False
Disables selection
- 'checkbox'
Adds a column of checkboxes to toggle selections
- 'checkbox-single'
Same as 'checkbox' but header does not allow select/deselect all
- 'toggle'
Selection toggles when clicked
- int
The maximum number of selectable rows.
selectable_rows = Callable(allow_None=True, allow_refs=True, label='Selectable rows')
A function which given a DataFrame should return a list of
rows by integer index, which are selectable.
sortable = ClassSelector(allow_refs=True, class_=(<class 'bool'>, <class 'dict'>), default=True, label='Sortable')
Whether the columns in the table should be sortable.
Can either be specified as a simple boolean toggling the behavior
on and off or as a dictionary specifying the option per column.
theme = Selector(allow_refs=True, default='simple', label='Theme', names={}, objects=['default', 'site', 'simple', 'midnight', 'modern', 'bootstrap', 'bootstrap4', 'materialize', 'bulma', 'semantic-ui', 'fast', 'bootstrap5'])
Tabulator CSS theme to apply to table.
theme_classes = List(allow_refs=True, bounds=(0, None), default=[], item_type=<class 'str'>, label='Theme classes', nested_refs=True)
List of extra CSS classes to apply to the Tabulator element
to customize the theme.
title_formatters = Dict(allow_refs=True, class_=<class 'dict'>, default={}, label='Title formatters', nested_refs=True)
Tabulator formatter specification to use for a particular column
header title.
.. py:property:: Tabulator.current_view :module: panel.widgets.tables :type: pd.DataFrame
Returns the current view of the table after filtering and
sorting are applied.
..
!! processed by numpydoc !!
.. py:method:: Tabulator.download(filename: str = ‘table.csv’) :module: panel.widgets.tables
Triggers downloading of the table as a CSV or JSON.
:Parameters:
**filename: str**
The filename to save the table as.
..
!! processed by numpydoc !!
.. py:method:: Tabulator.download_menu(text_kwargs={}, button_kwargs={}) :module: panel.widgets.tables
Returns a menu containing a TextInput and Button widget to set
the filename and trigger a client-side download of the data.
:Parameters:
**text_kwargs: dict**
Keyword arguments passed to the TextInput constructor
**button_kwargs: dict**
Keyword arguments passed to the Button constructor
:Returns:
filename: TextInput
The TextInput widget setting a filename.
button: Button
The Button that triggers a download.
..
!! processed by numpydoc !!
.. py:method:: Tabulator.on_click(callback: Callable[[CellClickEvent], None], column: str | None = None) :module: panel.widgets.tables
Register a callback to be executed when any cell is clicked.
The callback is given a CellClickEvent declaring the column
and row of the cell that was clicked.
:Parameters:
**callback: (callable)**
The callback to run on edit events.
**column: (str)**
Optional argument restricting the callback to a specific
column.
..
!! processed by numpydoc !!
.. py:method:: Tabulator.on_edit(callback: Callable[[TableEditEvent], None]) :module: panel.widgets.tables
Register a callback to be executed when a cell is edited.
Whenever a cell is edited on_edit callbacks are called with
a TableEditEvent as the first argument containing the column,
row and value of the edited cell.
:Parameters:
**callback: (callable)**
The callback to run on edit events.
..
!! processed by numpydoc !!
.. py:method:: Tabulator.stream(stream_value, rollover=None, reset_index=True, follow=True) :module: panel.widgets.tables
Streams (appends) the `stream_value` provided to the existing
value in an efficient manner.
:Parameters:
**stream_value: (pd.DataFrame | pd.Series | Dict)**
The new value(s) to append to the existing value.
**rollover: int**
A maximum column size, above which data from the start of
the column begins to be discarded. If None, then columns
will continue to grow unbounded.
**reset_index: (bool, default=True)**
If True and the stream_value is a DataFrame,
then its index is reset. Helps to keep the
index unique and named `index`
:Raises:
ValueError: Raised if the stream_value is not a supported type.
..
.. rubric:: Examples
Stream a Series to a DataFrame
>>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]})
>>> tabulator = Tabulator(value=value)
>>> stream_value = pd.Series({"x": 4, "y": "d"})
>>> tabulator.stream(stream_value)
>>> tabulator.value.to_dict("list")
{'x': [1, 2, 4], 'y': ['a', 'b', 'd']}
Stream a Dataframe to a Dataframe
>>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]})
>>> tabulator = Tabulator(value=value)
>>> stream_value = pd.DataFrame({"x": [3, 4], "y": ["c", "d"]})
>>> tabulator.stream(stream_value)
>>> tabulator.value.to_dict("list")
{'x': [1, 2, 3, 4], 'y': ['a', 'b', 'c', 'd']}
Stream a Dictionary row to a DataFrame
>>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]})
>>> tabulator = Tabulator(value=value)
>>> stream_value = {"x": 4, "y": "d"}
>>> tabulator.stream(stream_value)
>>> tabulator.value.to_dict("list")
{'x': [1, 2, 4], 'y': ['a', 'b', 'd']}
Stream a Dictionary of Columns to a Dataframe
>>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]})
>>> tabulator = Tabulator(value=value)
>>> stream_value = {"x": [3, 4], "y": ["c", "d"]}
>>> tabulator.stream(stream_value)
>>> tabulator.value.to_dict("list")
{'x': [1, 2, 3, 4], 'y': ['a', 'b', 'c', 'd']}
..
!! processed by numpydoc !!