Skip to main content

DataGrid

The DataGrid component is a flexible and feature-rich table implementation designed for large datasets, supporting advanced features like sorting, filtering, pagination, and customization.


Python Dash Example

Below is an example of how to use the DataGrid component in a Python Dash application.

import dash
from dash import html
import yipit_dash_mui_components as dmc

dash._dash_renderer._set_react_version('18.2.0')

app = dash.Dash(__name__)

app.layout = dmc.YipitMUIProvider(
children=[
html.Div([
dmc.DataGrid(
id="example-grid",
initialState={
"pagination": {
"paginationModel": { "pageSize": 5, "page": 0 }
}
},
pageSizeOptions=[5, 10, 50],
checkboxSelection=True,
rows=[
{"id": 1, "col1": "Hello", "col2": "World"},
{"id": 2, "col1": "Dash", "col2": "MUI"},
{"id": 3, "col1": "React", "col2": "MUI"},
{"id": 4, "col1": "Hello", "col2": "World"},
{"id": 5, "col1": "Dash", "col2": "MUI"},
{"id": 6, "col1": "React", "col2": "MUI"},
],
columns=[
{"field": "col1", "headerName": "Column 1", "width": 150},
{"field": "col2", "headerName": "Column 2", "width": 150},
],
autoHeight=True,
disableColumnMenu=True,
checkboxSelection=True,
)
])
]
)

if __name__ == "__main__":
app.run_server(debug=True)

Customized Example

Below is a customized example with additional features such as dynamic styling and column-based rendering.

React Example

Python Dash Example

Below is a Python Dash example using similar customizations.

import dash
from dash import html
import yipit_dash_mui_components as dmc

dash._dash_renderer._set_react_version('18.2.0')

app = dash.Dash(__name__)

app.layout = dmc.YipitMUIProvider(
children=[
html.Div([
dmc.DataGrid(
id="customized-grid",
rows=[
{"id": 1, "col1": "Dynamic", "col2": "Styling"},
{"id": 2, "col1": "Custom", "col2": "Rendering"},
],
columns=[
{
"field": "col1",
"headerName": "Column 1",
"width": 150,
"align": "center",
"headerAlign": "center",
},
{
"field": "col2",
"headerName": "Column 2",
"width": 150,
"align": "right",
"headerSx": {"color": "blue"},
"cellSx": {"color": "blue"}
},
],
autoHeight=True,
disableColumnMenu=True,
checkboxSelection=True,
)
])
]
)

if __name__ == "__main__":
app.run_server(debug=True)

Props Table

Below are the updated props for the DataGrid component:

PropTypeDefaultDescription
idstringNoneUnique identifier for the grid.
rowsarray[]Array of data rows to be displayed.
columnsarray[]Array of column definitions. Each column object can include headerSx and cellSx for custom styling of headers and cells.
autoHeightbooleanfalseIf true, the grid adjusts height based on its content.
disableColumnMenubooleanfalseDisables the column menu.
checkboxSelectionbooleanfalseEnables checkboxes for row selection.
sortingMode'client' or 'server''client'Defines sorting mode.
selectedRowsarray[]Array of selected row IDs.
initialStateobjectInitial state of the grid.
pageSizeOptionsarray[5, 10, 20]Array of page size options.
showToolbarbooleanfalseShows the grid toolbar with additional features.
showQuickFilterbooleanfalseShows a quick filter input in the toolbar.
disableColumnFilterbooleantrueDisables column filtering functionality.
disableColumnSortingbooleantrueDisables column sorting functionality.
disableColumnSelectorbooleanfalseDisables column selector in toolbar.
disableColumnGroupingbooleantrueDisables column grouping functionality.
disableDensitySelectorbooleanfalseDisables density selector in toolbar.
rowSelectionbooleanfalseEnables row selection functionality.
cellSelectionbooleanfalseEnables cell selection functionality.
cellSelectionModelobjectnullControl which cells are selected.
clipboardCopyCellDelimiterstring'\t'The character used to separate cell values when copying to the clipboard.
splitClipboardPastedTextstringnullJavaScript function as string to customize clipboard paste behavior.
getCellClassNamestringnullJavaScript function as string to define cell class names dynamically.
densitystring'standard'Controls the density of the grid. Options: 'compact', 'standard', 'comfortable'.
rowHeightnumber52Height of each row in pixels.
loadingbooleanfalseShows a loading indicator.
filterMode'client' or 'server''client'Defines filtering mode.
disableExportButtonbooleanfalseDisables the export button for all export options (CSV, Excel).
rowCountnumbernullControls the number of rows shown in server-side pagination.
totalRowCountnumbernullShows the total row count (read-only, updated by the component).
paginationMode'client' or 'server''client'Defines pagination mode.
pageSizenumbernullControls the page size.
hideFooterbooleanfalseHides the footer with pagination controls.

Premium Features

PropTypeDefaultDescription
pinnedColumnsobjectnullColumns to pin to left or right. Format: { left: ['id'], right: ['actions'] }
pinnedRowsobjectnullRows to pin to top or bottom. Format: { top: [row1], bottom: [row2] }
aggregationModelobjectnullModel for column aggregation (sum, average, etc.).
treeDatabooleanfalseEnables hierarchical data display in tree format.
getTreeDataPathstringnullJavaScript function as string to get the path for tree data display.
groupingColDefobjectnullConfiguration for the grouping column, supports headerSx and cellSx for styling.
getDetailPanelContentfunctionnullFunction to define content for row detail panels.
getDetailPanelHeightfunctionnullFunction to define height for row detail panels.
columnHeaderHeightnumbernullHeight of column headers in pixels.
rowBufferPxnumbernullExtra buffer space for rows (in pixels).
columnBufferPxnumbernullExtra buffer space for columns (in pixels).
autoSizebooleanfalseAuto-sizes columns based on content.
autosizeOptionsobjectnullOptions for autosize behavior: { columns, skipHeader, includeHeaders, includeOutliers }.
disableChildrenSortingbooleanfalseDisables sorting of children in tree data.
defaultGroupingExpansionDepthnumbernullDefault depth to which grouped rows are expanded.

Pivoting Features

PropTypeDefaultDescription
pivotActivebooleanfalseWhether pivot mode is active.
pivotModelobjectnullModel defining the pivot configuration.
pivotPanelOpenbooleanfalseWhether the pivot configuration panel is open.
disablePivotingbooleanfalseDisables pivoting functionality.
getPivotDerivedColumnsstringnullJavaScript function as string to get derived columns for pivot mode.
pivotDerivedColumnsConfigarraynullConfiguration for automatically derived columns in pivot mode.
customPivotTransformationsobjectnullCustom transformations for pivot mode.

Advanced Styling

PropTypeDefaultDescription
sxobjectnullMUI system prop for styling the grid container.
toolbarSlotPropsobjectnullAdditional props for the toolbar component.
columnGroupingModelarraynullModel for column grouping.
columnVisibilityModelobjectnullModel for column visibility.
filterModelobjectnullModel for filtering data.
sortModelarraynullModel for sorting data. Format: [{ field: 'col1', sort: 'asc' }]

Custom Column Options

PropTypeDescription
headerSxobjectMUI system props for styling column headers.
cellSxobjectMUI system props for styling cells.
descriptionstringAdds a tooltip with description to the column header.
d3FormatstringFormat string using d3-format for numerical data.
nullPlaceholderstringText to display for null/undefined values (default: "N/A").
valueFormatterstringJavaScript function as string for custom value formatting.

Advanced Example: Pivot Grid

Here's an example of using the DataGrid with pivoting capabilities:

import dash
from dash import html
import yipit_dash_mui_components as dmc

app = dash.Dash(__name__)

app.layout = dmc.YipitMUIProvider(
children=[
html.Div([
dmc.DataGrid(
id="pivot-grid",
rows=[
{"id": 1, "category": "Electronics", "date": "2023-01-15", "sales": 500},
{"id": 2, "category": "Clothing", "date": "2023-01-20", "sales": 300},
{"id": 3, "category": "Electronics", "date": "2023-02-10", "sales": 700},
{"id": 4, "category": "Clothing", "date": "2023-02-25", "sales": 400},
],
columns=[
{"field": "category", "headerName": "Category", "width": 150},
{"field": "date", "headerName": "Date", "width": 150, "type": "date"},
{"field": "sales", "headerName": "Sales", "width": 150, "type": "number"},
],
pivotActive=True,
showToolbar=True,
pivotPanelOpen=True,
pivotModel={
"dimensions": [
{"field": "category", "aggregationColumn": "sales"}
],
"aggregation": {
"sales": "sum"
}
},
pivotDerivedColumnsConfig=[
{
"match": {"type": "date"},
"derivedColumns": [
{
"suffix": "_year",
"headerSuffix": " (Year)",
"transformation": "date.year"
},
{
"suffix": "_quarter",
"headerSuffix": " (Quarter)",
"transformation": "date.quarter"
}
]
}
],
disablePivoting=False,
autoHeight=True,
)
])
]
)

if __name__ == "__main__":
app.run_server(debug=True)

Advanced Example: Tree Data

Here's an example of using the DataGrid with hierarchical tree data:

import dash
from dash import html
import yipit_dash_mui_components as dmc

app = dash.Dash(__name__)

app.layout = dmc.YipitMUIProvider(
children=[
html.Div([
dmc.DataGrid(
id="tree-grid",
rows=[
{"id": 1, "name": "Products", "path": ["Products"]},
{"id": 2, "name": "Electronics", "path": ["Products", "Electronics"]},
{"id": 3, "name": "Phones", "path": ["Products", "Electronics", "Phones"]},
{"id": 4, "name": "Laptops", "path": ["Products", "Electronics", "Laptops"]},
{"id": 5, "name": "Clothing", "path": ["Products", "Clothing"]},
{"id": 6, "name": "Shirts", "path": ["Products", "Clothing", "Shirts"]},
],
columns=[
{"field": "name", "headerName": "Category", "width": 200},
],
treeData=True,
autoHeight=True,
defaultGroupingExpansionDepth=2,
)
])
]
)

if __name__ == "__main__":
app.run_server(debug=True)

For the full list of props, refer to the official MUI documentation, as this component is based on MUI:

MUI DataGrid Documentation