Data Grid - Getting started
Get started with the last React Data Grid you will need. Install the package, configure the columns, provide rows, and you are set.
Installation
Using your favorite package manager, install @mui/x-data-grid-pro
or @mui/x-data-grid-premium
for the commercial version, or @mui/x-data-grid
for the free community version.
Plan
npm install @mui/x-data-grid@next
The Data Grid package has a peer dependency on @mui/material
.
If you are not already using it in your project, you can install it with:
npm install @mui/material @emotion/react @emotion/styled
Please note that react and react-dom are peer dependencies too:
"peerDependencies": {
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
},
Style engine
Material UI is using Emotion as a styling engine by default. If you want to use styled-components
instead, run:
npm install @mui/styled-engine-sc styled-components
Quickstart
First, you have to import the component as below. To avoid name conflicts the component is named Data Grid Pro for the full-featured enterprise grid, and Data Grid for the free community version.
import { DataGrid } from '@mui/x-data-grid';
Define rows
Rows are key-value pair objects, mapping column names as keys with their values.
You should also provide an id
property on each row to allow delta updates and better performance.
Here is an example
const rows: GridRowsProp = [
{ id: 1, col1: 'Hello', col2: 'World' },
{ id: 2, col1: 'DataGridPro', col2: 'is Awesome' },
{ id: 3, col1: 'MUI', col2: 'is Amazing' },
];
Define columns
Comparable to rows, columns are objects defined with a set of attributes of the GridColDef
interface.
They are mapped to the rows through their field
property.
const columns: GridColDef[] = [
{ field: 'col1', headerName: 'Column 1', width: 150 },
{ field: 'col2', headerName: 'Column 2', width: 150 },
];
You can import GridColDef
to see all column properties.
Demo
Putting it together, this is all you need to get started, as you can see in this live and interactive demo:
import * as React from 'react';
import { DataGrid, GridRowsProp, GridColDef } from '@mui/x-data-grid';
const rows: GridRowsProp = [
{ id: 1, col1: 'Hello', col2: 'World' },
{ id: 2, col1: 'DataGridPro', col2: 'is Awesome' },
{ id: 3, col1: 'MUI', col2: 'is Amazing' },
];
const columns: GridColDef[] = [
{ field: 'col1', headerName: 'Column 1', width: 150 },
{ field: 'col2', headerName: 'Column 2', width: 150 },
];
export default function App() {
return (
<div style={{ height: 300, width: '100%' }}>
<DataGrid rows={rows} columns={columns} />
</div>
);
}
TypeScript
In order to benefit from the CSS overrides and default prop customization with the theme, TypeScript users need to import the following types. Internally, it uses module augmentation to extend the default theme structure.
import type {} from '@mui/x-data-grid/themeAugmentation';
import type {} from '@mui/x-data-grid-pro/themeAugmentation';
import type {} from '@mui/x-data-grid-premium/themeAugmentation';
const theme = createTheme({
components: {
// Use `MuiDataGrid` on DataGrid, DataGridPro and DataGridPremium
MuiDataGrid: {
styleOverrides: {
root: {
backgroundColor: 'red',
},
},
},
},
});
Licenses
While MUI Core is entirely licensed under MIT, MUI X serves a part of its components under a commercial license. Please pay attention to the license.
Plans
The component comes in different plans:
- Community Plan:
@mui/x-data-grid
, published under the MIT license and free forever. - Pro Plan:
@mui/x-data-grid-pro
published under a Commercial license. - Premium Plan:
@mui/x-data-grid-premium
published under a Commercial license.
You can find more information about the plans in the Licensing page.
Feature comparison
The following table summarizes the features available in the community Data Grid and enterprise Data Grid Pro components. All the features of the community version are available in the enterprise one. The enterprise components come in two plans: Pro and Premium.