Skip to content

DataGrid API

The API documentation of the DataGrid React component. Learn more about the props and the CSS customization points.

Import

import DataGrid from '@material-ui/lab/DataGrid';
// or
import { DataGrid } from '@material-ui/lab';

You can learn more about the difference by reading this guide.

Props

Name Type Default Description
children node The content of the component.
classes object Override or extend the styles applied to the component. See CSS API below for more details.
columns Array<{ children?: Array<object>, field: string, label?: string, resizable?: bool, sortable?: bool, sortingComparator?: func, sortingOrder?: Array<'asc'
| 'desc'
| null> }>
[] The columns configuration.
dataProvider { getList: func } Manage the communication with the data store.
defaultColumnOptions { resizable?: bool, sortable?: bool, sortingComparator?: func, sortingOrder?: Array<'asc'
| 'desc'
| null> }
{ resizable: false, sortable: false, sortingOrder: ['asc', 'desc', null],} The default options that get applied to each column.
defaultPage number 0 The initial page to be displayed.
defaultRowsPerPage number 50 The initial rows per page size. Must be one of the paginationPageSize options.
defaultSorting Array<{ field: string, sort: 'asc'
| 'desc' }>
[] The default sorting state. (Uncontrolled)
loading bool false If true, the loading state is displayed. If false the component shows the loading state, while it waits for new data being loaded.
onSortingChange func Callback fired when the user change the column sort.

Signature:
function(event: object, value: SortingType) => void
event: The event source of the callback.
value: The new sorting value.
pagination bool false If true, the pagination is enabled.
paginationRowsPerPageOptions Array<number
| { label: string, value: number }>
[10, 25, 50, 100, 250, 500] The possible pagination size options to be selected by the user.
rowsData array [] The data record array to be rendered.
sorting Array<{ field: string, sort: 'asc'
| 'desc' }>
Sorting state. (Controlled)
text any { loading: 'Loading', reload: 'Reload',} The localization strings.

The ref is forwarded to the root element.

Any other props supplied will be provided to the root element (native element).

CSS

  • Style sheet name: MuiDataGrid.
  • Style sheet details:
Rule name Global class Description
root .MuiDataGrid-root Styles applied to the root element.
bodyContainer .MuiDataGrid-bodyContainer
headerLabel .MuiDataGrid-headerLabel
resize .MuiDataGrid-resize

You can override the style of the component thanks to one of these customization points:

If that's not sufficient, you can check the implementation of the component for more detail.

Demos