How to use tables
This guide shows you how to visualize tables in Vizro.
When to use this
Use Table to display tabular data. For Plotly charts use Graph, for KPI tiles use a kpi_card figure, and for any other reactive Dash component use Figure.
API reference: Table
Vizro visualizes tabular data using AG Grid, via the Table model with a dash_ag_grid figure.
Migrating from earlier versions
Table now supports only a dash_ag_grid figure. The separate AgGrid model and the Dash DataTable backing (dash_data_table) have been removed: replace vm.AgGrid(figure=dash_ag_grid(...)) with vm.Table(figure=dash_ag_grid(...)), and any dash_data_table figure with dash_ag_grid. See the migration guide.
AG Grid
AG Grid is an interactive table/grid component designed for viewing, editing, and exploring large datasets. It is Vizro's recommended table implementation.
The Vizro Table model, with a dash_ag_grid figure, is based on the Dash AG Grid, which is in turn based on the original Javascript implementation.
More examples of AG Grid
If you would like to see more examples on what can be done with AG Grid, head to the Dash AG Grid documentation. Almost anything you see there is possible in Vizro by creating a custom AG Grid callable.
Basic usage
To add a Table with a dash_ag_grid figure to your page, do the following:
- Insert the
Tablemodel into thecomponentsargument of thePagemodel. - Enter the
dash_ag_gridfunction under thefigureargument (imported viafrom vizro.tables import dash_ag_grid).
The Vizro version of this AG Grid differs in one way from the original Dash AG Grid: it requires the user to pass a pandas DataFrame as the source of data. As explained in our guide to using data in Vizro, this must be entered under the argument data_frame. Most other parameters of the Dash AG Grid can be entered as keyword arguments. Note that some defaults are set for some arguments (for example, for columnDefs) to help with styling and usability. Sometimes a parameter may not work because it requires a callback to function. In that case you can try creating a custom AG Grid callable.
Basic Dash AG Grid
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
from vizro.tables import dash_ag_grid
df = px.data.gapminder()
page = vm.Page(
title="Default Dash AG Grid",
components=[vm.Table(figure=dash_ag_grid(data_frame=df))]
)
dashboard = vm.Dashboard(pages=[page])
Vizro().build(dashboard).run()
Run and edit this code in Py.Cafe
# Still requires a .py to add data to the data manager and parse YAML configuration
# See yaml_version example
pages:
- components:
- figure:
_target_: dash_ag_grid
data_frame: gapminder
type: table
title: Default Dash AG Grid
Interact with other graphs and tables
An AG Grid can act as a source for interactions with other components, for example to cross-filter another graph or table when the user clicks on a point.
Disable pagination
By default, pagination is enabled in AG Grid to improve performance and usability with large datasets. If you prefer to show all rows in a single scrollable table (for example, to allow users to scroll vertically through all data), you can disable pagination by setting dashGridOptions={"pagination": False}.
Dash AG Grid without pagination
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
from vizro.tables import dash_ag_grid
df = px.data.gapminder()
page = vm.Page(
title="Dash AG Grid without pagination",
components=[vm.Table(figure=dash_ag_grid(data_frame=df, dashGridOptions={"pagination": False}))]
)
dashboard = vm.Dashboard(pages=[page])
Vizro().build(dashboard).run()
Run and edit this code in Py.Cafe
# Still requires a .py to add data to the data manager and parse YAML configuration
# See yaml_version example
pages:
- components:
- figure:
_target_: dash_ag_grid
data_frame: gapminder
dashGridOptions:
pagination: false
type: table
title: Dash AG Grid with pagination
Formatting columns
Numbers
One of the most common tasks when working with tables is to format the columns so that displayed numbers are more readable. To do this, you can use the native functionality of value formatters or the Vizro custom cell data types as shown below.
The available custom cell types for Vizro are dollar, euro, percent and numeric.
To use these, define your desired <COLUMN> alongside the chosen cellDataType in the columnDefs argument of your dash_ag_grid function:
columnDefs = [{"field": "<COLUMN>", "cellDataType": "euro"}]
In the example below we select and format some columns of the gapminder data.
AG Grid with formatted columns
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
from vizro.tables import dash_ag_grid
df = px.data.gapminder()
columnDefs = [{"field": "country"}, {"field": "year"}, {"field": "lifeExp", "cellDataType": "numeric"},
{"field": "gdpPercap", "cellDataType": "dollar"}, {"field": "pop", "cellDataType": "numeric"}]
page = vm.Page(
title="Example of AG Grid with formatted columns",
components=[
vm.Table(
title="AG Grid with formatted columns",
figure=dash_ag_grid(
data_frame=df,
columnDefs=columnDefs,
),
)
],
)
dashboard = vm.Dashboard(pages=[page])
Vizro().build(dashboard).run()
Run and edit this code in Py.Cafe
# Still requires a .py to add data to the data manager and parse YAML configuration
# See yaml_version example
pages:
- components:
- figure:
_target_: dash_ag_grid
data_frame: gapminder
columnDefs:
- field: country
- field: year
- field: lifeExp
cellDataType: numeric
- field: gdpPercap
cellDataType: dollar
- field: pop
cellDataType: numeric
title: AG Grid with formatted columns
type: table
title: Example of AG Grid with formatted columns
Dates
For the Table model to sort and filter dates correctly, the date must either be of string format yyyy-mm-dd (see Dash AG Grid docs) or a pandas datetime object. Any pandas datetime column will be transformed into the yyyy-mm-dd format automatically.
Objects and strings
No specific formatting is available for custom objects and strings, however you can make use of Value Formatters to format displayed strings automatically.
Resizing columns
The Table model provides automatic column sizing options through the columnSize property. This feature allows you to control how columns are sized within the grid to optimize the display of your data.
You can configure column sizing by setting the columnSize parameter in your dash_ag_grid function call. By default, the columnSize is set to responsiveSizeToFit within the vm.Table. The available options are:
-
autoSize: Automatically adjusts column widths to fit their content. This is particularly useful when you have varying content lengths and want each column to be sized appropriately for readability. -
sizeToFit: Resizes all columns proportionally to fill the entire width of the grid container. This ensures no horizontal scrolling is needed and AG Grid uses all available space. -
responsiveSizeToFit: CombinessizeToFitwith automatic readjustment of the columns' widths when the grid container or columns change (such as when the browser window is resized or when filters are applied). -
None: Maintains the default column widths without automatic resizing.
For more advanced column sizing configurations, you can use the columnSizeOptions parameter in combination with columnSize.
AG Grid with column sizing
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
from vizro.tables import dash_ag_grid
df = px.data.gapminder()
page = vm.Page(
title="AG Grid with Column Sizing",
components=[vm.Table(id="ag-grid", figure=dash_ag_grid(data_frame=df, columnSize="responsiveSizeToFit"))],
controls=[
vm.Parameter(
targets=["ag-grid.columnSize"],
selector=vm.RadioItems(
title="Select ColumnSize",
options=[
{"value": "autoSize", "label": "autoSize"},
{"value": "responsiveSizeToFit", "label": "responsiveSizeToFit"},
{"value": "sizeToFit", "label": "sizeToFit"},
{"value": "NONE", "label": "None"},
],
value="responsiveSizeToFit"
),
)
],
)
dashboard = vm.Dashboard(pages=[page])
Vizro().build(dashboard).run()
Run and edit this code in Py.Cafe
# Still requires a .py to add data to the data manager and parse YAML configuration
# See yaml_version example
pages:
- components:
- figure:
_target_: dash_ag_grid
data_frame: gapminder
columnSize: responsiveSizeToFit
id: ag-grid
type: table
controls:
- selector:
options:
# Automatically adjusts column widths
- {value: autoSize, label: autoSize}
# Combines `sizeToFit` with automatic readjustment of the columns' widths
- {value: responsiveSizeToFit, label: responsiveSizeToFit}
# Resizes all columns proportionally
- {value: sizeToFit, label: sizeToFit}
# Maintains the default column widths
- {value: NONE, label: None}
value: responsiveSizeToFit
title: Select ColumnSize
type: radio_items
targets:
- ag-grid.columnSize
type: parameter
title: AG Grid with Column Sizing
For detailed information about column sizing options and advanced configurations, refer to the Dash AG Grid column sizing documentation.
Styling and changing the AG Grid
As mentioned above, all parameters of the Dash AG Grid can be entered as keyword arguments. Below you can find an example of a styled AG Grid where some conditional formatting is applied, and where the columns are editable, but not filterable or resizable. There are more ways to alter the grid beyond this showcase. AG Grid, like any other Vizro component, can be customized using custom CSS. You can find information in the guide to overwriting CSS properties.
Styled and modified Dash AG Grid
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
from vizro.tables import dash_ag_grid
df = px.data.gapminder()
cellStyle = {
"styleConditions": [
{
"condition": "params.value < 1045",
"style": {"backgroundColor": "#ff9222"},
},
{
"condition": "params.value >= 1045 && params.value <= 4095",
"style": {"backgroundColor": "#de9e75"},
},
{
"condition": "params.value > 4095 && params.value <= 12695",
"style": {"backgroundColor": "#aaa9ba"},
},
{
"condition": "params.value > 12695",
"style": {"backgroundColor": "#00b4ff"},
},
]
}
columnDefs = [
{"field": "country"},
{"field": "continent"},
{"field": "year"},
{
"field": "lifeExp",
"valueFormatter": {"function": "d3.format('.1f')(params.value)"},
},
{
"field": "gdpPercap",
"valueFormatter": {"function": "d3.format('$,.1f')(params.value)"},
"cellStyle": cellStyle,
},
{
"field": "pop",
"valueFormatter": {"function": "d3.format(',.0f')(params.value)"},
},
]
page = vm.Page(
title="Example of Modified Dash AG Grid",
components=[
vm.Table(
title="Modified Dash AG Grid",
figure=dash_ag_grid(
data_frame=df,
columnDefs=columnDefs,
defaultColDef={"resizable": False, "filter": False, "editable": True},
),
)
],
)
dashboard = vm.Dashboard(pages=[page])
Vizro().build(dashboard).run()
Run and edit this code in Py.Cafe
# Still requires a .py to add data to the data manager and parse YAML configuration
# See yaml_version example
pages:
- components:
- figure:
_target_: dash_ag_grid
data_frame: gapminder
columnDefs:
- field: country
- field: continent
- field: year
- field: lifeExp
valueFormatter:
function: d3.format('.1f')(params.value)
- field: gdpPercap
valueFormatter:
function: d3.format('$,.1f')(params.value)
cellStyle:
styleConditions:
- condition: params.value < 1045
style:
backgroundColor: '#ff9222'
- condition: params.value >= 1045 && params.value <= 4095
style:
backgroundColor: '#de9e75'
- condition: params.value > 4095 && params.value <= 12695
style:
backgroundColor: '#aaa9ba'
- condition: params.value > 12695
style:
backgroundColor: '#00b4ff'
- field: pop
type: rightAligned
valueFormatter:
function: d3.format(',.0f')(params.value)
defaultColDef:
resizable: false
filter: false
editable: true
title: Dash AG Grid
type: table
title: Example of a Dash AG Grid
If the available arguments are not sufficient, there is always the option to create a custom AG Grid callable.
Add sticky headers
To add sticky headers to your AG Grid, add the following CSS to your custom CSS file within your local assets folder.
.ag-header {
position: fixed !important;
z-index: 1;
}
.ag-body {
top: 40px;
}
If your dashboard contains multiple AG Grids, you can scope this CSS to a specific grid by assigning an ID to the corresponding vm.Table model and targeting it in your CSS. For example:
#my-aggrid .ag-header {
position: fixed !important;
z-index: 1;
}
#my-aggrid .ag-body {
top: 40px;
}
Note
This approach works reliably only when the Table is positioned in the non-scrollable page.
Add additional text
The Table model accepts title, header, footer and description arguments. These are useful for providing additional context on the table.
- title: Displayed as an H3 header, useful for summarizing the main topic or insight of the component.
- header: Accepts Markdown text, ideal for extra descriptions, subtitles, or detailed data insights.
- footer: Accepts Markdown text, commonly used for citing data sources, providing information on the last update, or adding disclaimers.
- description: Displayed as an icon that opens a tooltip containing Markdown text when hovered over. You can provide a string to use the default info icon or a
Tooltipmodel to use any icon from the Google Material Icons library.
Formatted AG Grid
Formatted AG Grid
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
from vizro.tables import dash_ag_grid
gapminder_2007 = px.data.gapminder().query("year == 2007")
page = vm.Page(
title="Formatted AG Grid",
components=[
vm.Table(
figure=dash_ag_grid(data_frame=gapminder_2007, dashGridOptions={"pagination": True}),
title="Gapminder Data Insights",
header="""#### An Interactive Exploration of Global Health, Wealth, and Population""",
footer="""SOURCE: **Plotly gapminder data set, 2024**""",
description="""
The Gapminder dataset tracks the development of countries over time using indicators like life expectancy, income per person, and population size.
It helps reveal broad global trends, such as how health and wealth have improved in many regions, although progress hasn’t been even across all countries.
""",
)
],
)
dashboard = vm.Dashboard(pages=[page])
Vizro().build(dashboard).run()
Run and edit this code in Py.Cafe
# Still requires a .py to add data to the data manager and parse YAML configuration
# See yaml_version example
pages:
- components:
- figure:
_target_: dash_ag_grid
data_frame: gapminder_2007
dashGridOptions:
pagination: true
title: Gapminder Data Insights
header: |
#### An Interactive Exploration of Global Health, Wealth, and Population
footer: |
SOURCE: **Plotly gapminder data set, 2024**
description: |
The Gapminder dataset tracks the development of countries over time using indicators like life expectancy, income per person, and population size.
It helps reveal broad global trends, such as how health and wealth have improved in many regions, although progress hasn’t been even across all countries.
type: table
title: Formatted AG Grid




