Skip to content

Table

The Table widget displays data in a structured, interactive tabular format. It supports column sorting (ascending/descending), quick filtering, and row selection for easier data exploration.

from mercury import Table

To use the Table widget, you only need to provide data. It works best with DataFrames (pandas or polars), but you can also pass lists of dict or dicts.

Example data

import pandas as pd
countries = ["Poland", "Germany", "France"]
df = pd.DataFrame({
"Country": [countries[i % 3] for i in range(100)],
"Year": [2020 + (i % 10) for i in range(100)],
"GDP": [500 + (i * 25) for i in range(100)],
})

Code

t = Table(df)

Preview

Simple Table

You can easily add more features to your table, such as row selection or filtering.

Code

t = Table(df, search=True, select_rows=True)

Preview

Table with features

After enabling row selection, you may want to access all selected rows in one place — this is very easy to do.

Code

# t is the variable that you assign the Table to
t.selected_rows

You can also customize the Table’s appearance by changing the page size (number of rows per page), width, or height.

Code

t = Table(
df,
search=True,
select_rows=True,
page_size=20,
width="700px",
height="360px",
)

Preview

Customized Table

By default, Table() displays the widget immediately. Set display_now=False when you want to create the widget first and display it later.

Code

from IPython.display import display
t = Table(df, display_now=False)
# display later
display(t)

type: DataFrame or list[dict] or dict

The dataset displayed in the table. Accepts pandas/polars DataFrames or standard Python structures like lists of dictionaries.

type: Integer

Sets how many rows are shown on a single page. Default is 50.

type: boolean

Enables selecting rows in the table. It’s off by default (False).

type: boolean

Enables the search bar and allows filtering table. It’s off by default (False).

type: string

Sets the width of the table component. Accepts CSS size values like 100%, 800px, 50vw, or 48rem. Default is 100%.

type: string | None

Sets the height of the scrollable table body. Accepts CSS size values like 360px, 50vh, or 24rem. When None, Mercury keeps the current automatic table height behavior. Default is None.

type: boolean

Controls whether the original DataFrame index is displayed as a table column. Default is False.

type: "sidebar" | "inline" | "bottom"

Controls where the table is rendered in the Mercury layout. Default is "inline".

type: boolean

Controls whether the table is displayed immediately after construction. Set to False when you want to return the widget and display it later yourself. Default is True.

type: string

Optional identifier used to distinguish tables with the same data and options. Use it when you intentionally want separate table widget instances for the same dataset.

  • Table widgets are cached based on the input data content and constructor options.
  • display_now is not part of the cache key. It only controls whether the widget is displayed immediately.
  • Use key to force separate table instances for the same data.