Migration from v5 to v6
This guide describes the changes needed to migrate the Data Grid from v5 to v6.
Introduction
To get started, check out the blog post about the release of MUI X v6.
Start using the new release
In package.json, change the version of the Data Grid package to ^6.0.0.
-"@mui/x-data-grid": "^5.0.0",
+"@mui/x-data-grid": "^6.0.0",
Since v6 is a major release, it contains changes that affect the public API. These changes were done for consistency, improved stability and to make room for new features. Described below are the steps needed to migrate from v5 to v6.
Run codemods
The preset-safe codemod will automatically adjust the bulk of your code to account for breaking changes in v6. You can run v6.0.0/data-grid/preset-safe targeting only Data Grid or v6.0.0/preset-safe to target Date and Time pickers as well.
You can either run it on a specific file, folder, or your entire codebase when choosing the <path> argument.
# Data Grid specific
npx @mui/x-codemod@latest v6.0.0/data-grid/preset-safe <path>
# Target Date and Time Pickers as well
npx @mui/x-codemod@latest v6.0.0/preset-safe <path>
Breaking changes that are handled by preset-safe codemod are denoted by a ✅ emoji in the table of contents on the right side of the screen or next to the specific point that is handled by it.
If you have already applied the v6.0.0/data-grid/preset-safe (or v6.0.0/preset-safe) codemod, then you should not need to take any further action on these items. If there's a specific part of the breaking change that is not part of the codemod or needs some manual work, it will be listed in the end of each section.
All other changes must be handled manually.
Breaking changes
Since v6 is a major release, it contains some changes that affect the public API. These changes were done for consistency, improve stability and make room for new features. Below are described the steps you need to make to migrate from v5 to v6.
✅ Renamed props
To avoid confusion with the props that will be added for the cell selection feature, some props related to row selection were renamed to have "row" in their name. The renamed props are the following:
Old name New name selectionModelrowSelectionModelonSelectionModelChangeonRowSelectionModelChangedisableSelectionOnClickdisableRowSelectionOnClickdisableMultipleSelectiondisableMultipleRowSelectionshowCellRightBordershowCellVerticalBordershowColumnRightBordershowColumnVerticalBorderheaderHeightcolumnHeaderHeightThe corresponding type for
rowSelectionModel(previouslyselectionModel) was renamed fromGridSelectionModeltoGridRowSelectionModel.
Removed props
- The
disableIgnoreModificationsIfProcessingPropsprop was removed and its behavior whentruewas incorporated as the default behavior. The old behavior can be restored by usingapiRef.current.stopRowEditMode({ ignoreModifications: true })orapiRef.current.stopCellEditMode({ ignoreModifications: true }). - The
onColumnVisibilityChangeprop was removed. UseonColumnVisibilityModelChangeinstead. - The
components.Headerslot was removed. Usecomponents.Toolbarorslots.toolbarslot instead. - ✅ The
disableExtendRowFullWidthprop was removed. UseshowCellVerticalBorderorshowColumnVerticalBorderprop to show or hide right border for cells and header cells respectively. - The
columnTypesprop was removed. For custom column types see Custom column types docs. - ✅ The
onCellFocusOutprop was removed. UseslotProps.cell.onBlurinstead:<DataGrid slotProps={{ cell: { onBlur: (event) => { const cellElement = event.currentTarget; const field = cellElement.getAttribute('data-field'); const rowId = cell.parentElement.getAttribute('data-id'); }, }, }} /> - The
errorandonErrorprops were removed - the grid no longer catches errors during rendering. To catch errors that happen during rendering use the error boundary. Thecomponents.ErrorOverlayslot was also removed.
State access
- ✅ The
gridSelectionStateSelectorselector was renamed togridRowSelectionStateSelector. - ✅ The
allGridColumnsFieldsSelectorselector was removed. UsegridColumnFieldsSelectorinstead. - ✅ The
allGridColumnsSelectorselector was removed. UsegridColumnDefinitionsSelectorinstead. - ✅ The
visibleGridColumnsSelectorselector was removed. UsegridVisibleColumnDefinitionsSelectorinstead. - ✅ The
filterableGridColumnsSelectorselector was removed. UsegridFilterableColumnDefinitionsSelectorinstead. - ✅ The
gridVisibleSortedRowIdsSelectorselector was renamed togridExpandedSortedRowIdsSelector - ✅ The
gridVisibleSortedRowEntriesSelectorselector was renamed togridExpandedSortedRowEntriesSelector. - ✅ The
gridVisibleRowCountSelectorselector was renamed togridExpandedRowCountSelector. - ✅ The
gridVisibleSortedTopLevelRowEntriesSelectorselector was renamed togridFilteredSortedTopLevelRowEntriesSelector. - ✅ The
gridVisibleTopLevelRowCountSelectorselector was renamed togridFilteredTopLevelRowCountSelector. - ✅ The
getGridNumericColumnOperatorsselector was removed. UsegetGridNumericOperatorsinstead. - The
gridVisibleRowsSelectorselector was removed. UsegridExpandedSortedRowIdsSelectorinstead. - The
gridColumnsSelectorselector was removed. Use more specific grid columns selectors instead.-const { all, lookup, columnVisibilityModel } = gridColumnsSelector(apiRef); +const all = gridColumnFieldsSelector(apiRef); +const lookup = gridColumnLookupSelector(apiRef); +const columnVisibilityModel = gridColumnVisibilityModelSelector(apiRef); - The
filterableGridColumnsIdsSelectorselector was removed. UsegridFilterableColumnLookupSelectorinstead.-const filterableFields = filterableGridColumnsIdsSelector(apiRef); +const lookup = gridFilterableColumnLookupSelector(apiRef); +const filterableFields = gridColumnFieldsSelector(apiRef).filter(field => lookup[field]); - The
visibleGridColumnsLengthSelectorselector was removed. UsegridVisibleColumnDefinitionsSelectorinstead.-const visibleColumnsLength = visibleGridColumnsLengthSelector(apiRef); +const visibleColumnsLength = gridVisibleColumnDefinitionsSelector(apiRef).length; - The
gridColumnsMetaSelectorselector was removed. UsegridColumnsTotalWidthSelectororgridColumnPositionsSelectorinstead.-const { totalWidth, positions } = gridColumnsMetaSelector(apiRef); +const totalWidth = gridColumnsTotalWidthSelector(apiRef); +const positions = gridColumnPositionsSelector(apiRef); - The
gridRowGroupingStateSelectorselector was removed. - The
gridFilterStateSelectorselector was removed. - The
gridRowsStateSelectorselector was removed. - The
gridSortingStateSelectorselector was removed. - The
gridTotalHeaderHeightSelectorselector was removed. - The
gridDensityRowHeightSelectorselector was removed. - The
gridDensityHeaderHeightSelectorselector was removed. - The
gridEditRowsStateSelectorselector was removed. - The
apiRef.current.state.density.headerHeightproperty was removed. - The
apiRef.current.state.density.rowHeightproperty was removed.
Events
- ✅ The
selectionChangeevent was renamed torowSelectionChange. - ✅ The
rowsScrollevent was renamed toscrollPositionChange. - The
columnVisibilityChangeevent was removed. UsecolumnVisibilityModelChangeinstead. - The
cellNavigationKeyDownevent was removed. UsecellKeyDownand check the key provided in the event argument. - The
columnHeaderNavigationKeyDownevent was removed. UsecolumnHeaderKeyDownand check the key provided in the event argument. - The
cellKeyDownevent will also be fired for keyboard events that occur inside components that use Portals. This affects specially custom edit components, where pressing a shortcut key will trigger the stop editing routine. For instance, pressing Enter inside the Portal will cause the change to be saved. TheonCellEditStop(oronRowEditStop) prop can be used to restore the old behavior.<DataGrid onCellEditStop={(params, event) => { if (params.reason !== GridCellEditStopReasons.enterKeyDown) { return; } // Check if the target is inside a Portal if ( (event.target as any).nodeType === 1 && !event.currentTarget.contains(event.target) ) { event.defaultMuiPrevented = true; } }} /> - The
componentErrorevent was removed. Use the error boundary to catch errors thrown during rendering. - The
GridCallbackDetails['api']was removed from event details. Use theapiRefreturned byuseGridApiContextoruseGridApiRefinstead. - The
cellFocusInandcellFocusOutevents are internal now. UseslotProps.cell.onFocusandslotProps.cell.onBlurprops instead.
Columns
The
GridColDef['hide']property was removed. UsecolumnVisibilityModelinstead.Returning
nullincolumn.renderCellorcolumn.renderEditCellnow renders an empty cell instead of the default formatted value. To fall back to the default formatted value, returnundefinedinstead ofnull.const renderCell = () => { if (condition) { return <CustomComponent />; } - return null; + return undefined; }The
onColumnOrderChangeprop callback now is called only when a column, that is being reordered, is dropped in another position.The
singleSelectcolumn type now has a default value formatter that returns thelabelcorresponding to the selected value whenvalueOptionsis an array of objects. As a consequence, any existing value formatter will not be applied to the individual options anymore, but only to the text of the cell. It is recommended to migratevalueOptionsto an array of objects to be able to add a custom label for each value. To override the label used for each option when the cell is in edit mode or in the filter panel, the following components now support agetOptionLabelprop:GridEditSingleSelectCellGridFilterInputSingleSelectGridFilterInputMultipleSingleSelect
This prop accepts a callback that is called with the item from
valueOptionsand must return the string to use as new label.The
dateanddateTimecolumns now only supportDateobjects as values. To parse a string value, use thevalueGetter:<DataGrid columns={[ { field: 'date', type: 'date', valueGetter: (params) => new Date(params.value), }, ]} />
✅ Column menu
The column menu components have been renamed or merged with the new design for consistency and API improvement, the new components are following:
Old name New name GridFilterMenuItemGridColumnMenuFilterItemHideGridColMenuItemGridColumnMenuHideItemGridColumnsMenuItemGridColumnMenuColumnsItemSortGridMenuItemsGridColumnMenuSortItemGridColumnPinningMenuItemsGridColumnMenuPinningItemGridAggregationColumnMenuItemGridColumnMenuAggregationItemGridRowGroupingColumnMenuItems,GridRowGroupableColumnMenuItemsGridColumnMenuGroupingItemThe
GridFilterItemPropstype has been renamed toGridColumnMenuItemProps.Props
columnandcurrentColumnpassed toGridColumnMenuand column menu items have been renamed tocolDef-function CustomColumnMenu({ column }) { - if (column.field === 'name') { +function CustomColumnMenu({ colDef }) { + if (colDef.field === 'name') { return <div>Custom column menu for name field</div>; } return ( <div> <GridFilterMenuItem colDef={colDef} /> <GridColumnMenuColumnsItem colDef={colDef} /> </div> ); }
Rows
- The
GridRowParams['getValue']property was removed. Useparams.rowinstead. - The
GridCellParams['getValue']property was removed. Useparams.rowinstead. - The default type of
GridCellParams['value']was changed fromanytounknown. - The
GridActionsCellProps['api']property was removed. UseuseGridApiContexthook instead to getapiRef. - The
GridActionsCellProps['getValue']property was removed. Useparams.rowinstead. - The
GridFooterCellProps['getValue']property was removed. Useparams.rowinstead. - The
cellFocus,cellTabIndexandeditRowsStateprops are not passed to theRowslot anymore. Use thefocusedCellandtabbableCellprops instead. For the editing state, use the API methods.function CustomRow(props) { - const focusedField = props.cellFocus.field; - const tabIndex = props.cellTabIndex.field && cellMode === 'view' ? 0 : 1; + const focusedField = props.focusedCell; + const tabIndex = props.tabbableCell === column.field ? 0 : 1; - Updating the
rowsprop or callingapiRef.current.setRows()will now remove the expansion state of the grid as these methods are meant to replace the rows. For partial row updates, use theapiRef.current.updateRows()method instead.
Pagination
The
pageandpageSizeprops and their respective event handlersonPageChangeandonPageSizeChangewere removed. UsepaginationModelandonPaginationModelChangeinstead.<DataGrid - page={page} - pageSize={pageSize} - onPageChange={handlePageChange} - onPageSizeChange={handlePageSizeChange} + paginationModel={{ page, pageSize }} + onPaginationModelChange={(paginationModel) => handlePaginationModelChange(paginationModel)} />The properties
initialState.pagination.pageandinitialState.pagination.pageSizewere also removed. UseinitialState.pagination.paginationModelinstead.-initialState={{ pagination: { page: 1, pageSize: 10 } }} +initialState={{ pagination: { paginationModel: { page: 1, pageSize: 10 } } }}✅ The
rowsPerPageOptionsprop was renamed topageSizeOptions.-<DataGrid rowsPerPageOptions={[10, 20, 50]} /> +<DataGrid pageSizeOptions={[10, 20, 50]} />
apiRef methods
✅ The
apiRef.current.getRowIndexmethod was removed. UseapiRef.current.getRowIndexRelativeToVisibleRowsinstead.✅ The
apiRef.current.setFilterLinkOperatormethod was renamed toapiRef.current.setFilterLogicOperator.The
apiRef.current.updateColumnmethod was removed. UseapiRef.current.updateColumnsinstead.-apiRef.current.updateColumn({ field: 'name', width: 100 }); +apiRef.current.updateColumns([{ field: 'name', width: 100 }]);The
apiRef.current.getColumnsMetamethod was removed. UsegridColumnsTotalWidthSelectororgridColumnPositionsSelectorselectors instead.-const { totalWidth, positions } = apiRef.current.getColumnsMeta(); +const totalWidth = gridColumnsTotalWidthSelector(apiRef); +const positions = gridColumnPositionsSelector(apiRef);The
apiRef.current.setDensitysignature was changed. It only acceptsdensity: GridDensityas a single parameter.The
apiRef.current.getVisibleRowModelsmethod was removed. UsegridExpandedSortedRowEntriesSelectorselector instead.The
apiRef.current.showErrormethod was removed. The UI for errors is no longer handled by the grid.Some internal undocumented
apiRefmethods and properties were removed.If you don't use undocumented properties - you can skip the list below. Otherwise, please check the list and open an issue if there's something missing in the
apiRef.List of removed undocumented methods and properties
getLoggerwindowReffooterRefheaderRefcolumnHeadersElementRefcolumnHeadersContainerElementRefunstable_cachesunstable_eventManagerunstable_requestPipeProcessorsApplicationunstable_registerPipeProcessorunstable_registerPipeApplierunstable_storeDetailPanelHeightunstable_detailPanelHasAutoHeightunstable_calculateColSpanunstable_rowHasAutoHeightunstable_getLastMeasuredRowIndexunstable_getViewportPageSizeunstable_updateGridDimensionsRefunstable_getRenderContextunstable_registerStrategyProcessorunstable_applyStrategyProcessorunstable_getActiveStrategyunstable_setStrategyAvailabilityunstable_setCellEditingEditCellValueunstable_getRowWithUpdatedValuesFromCellEditingunstable_setRowEditingEditCellValueunstable_getRowWithUpdatedValuesFromRowEditingunstable_runPendingEditCellValueMutationunstable_moveFocusToRelativeCellunstable_updateControlStateunstable_registerControlState
Filtering
- ✅ The
GridFilterItem['columnField']was renamed toGridFilterItem['field'] - ✅ The
GridFilterItem['operatorValue']was renamed toGridFilterItem['operator'] - The
GridFilterItem['operator']is now required. - The
GridFilterInputValuecomponent cannot be used withsingleSelectcolumns anymore. UseGridFilterInputSingleSelectinstead. - ✅ The
GridLinkOperatorenum was renamed toGridLogicOperator. - The
GridFilterModel['linkOperator']type was renamed toGridFilterModel['logicOperator']. - ✅ The
linkOperatorsprop ofGridFilterFormandGridFilterPanelcomponents was renamed tologicOperators. - ✅ The
linkOperatorInputPropsprop ofGridFilterFormcomponent was renamed tologicOperatorInputProps. - ✅ The
filterFormProps.linkOperatorInputPropsprop inGridFilterFormcomponent was renamed tofilterFormProps.logicOperatorInputProps. - ✅ The
GridLocaleText['filterPanelLinkOperator']property was renamed toGridLocaleText['filterPanelLogicOperator'].
Editing
- ✅ The editing API that is enabled by default was replaced with a new API that contains better support for server-side persistence, validation and customization. This new editing feature was already available in v5 under the
newEditingApiexperimental flag. In v6, this flag can be removed.<DataGrid - experimentalFeatures={{ newEditingApi: true }} /> - ✅ The aggregation and row pinning are no longer experimental features. The flags
experimentalFeatures.aggregationandexperimentalFeatures.rowPinningcan be removed now.<DataGridPremium - experimentalFeatures={{ - aggregation: true, - rowPinning: true, - }} /> - The
editCellPropsChangeevent was removed. If you still need it please file a new issue so we can propose an alternative. - The
cellEditCommitevent was removed and theprocessRowUpdateprop can be used in place. More information, check the docs section about the topic. - The
editRowsModelandonEditRowsModelChangeprops were removed. ThecellModesModelorrowModesModelprops can be used to achieve the same goal. - The
GridEditRowsModeltype was removed. - The following API methods were removed:
- Use
apiRef.current.stopCellEditModeto replaceapiRef.current.commitCellChange - Use
apiRef.current.startCellEditModeto replaceapiRef.current.setCellMode(id, field, 'edit') - Use
apiRef.current.stopRowEditModeto replaceapiRef.current.commitRowChange - Use
apiRef.current.startRowModeto replaceapiRef.current.setRowMode(id, 'edit') - Use the
cellModesModelorrowModesModelprops to replaceapiRef.current.setEditRowsModel.
- Use
Other exports
The
useGridApihook was removed. UseapiRef.currentinstead.The
useGridStatehook was removed. UseapiRef.current.state,apiRef.current.setStateandapiRef.current.forceUpdateinstead.The
getGridColDefutility function was removed.The
GridColumnstype was removed. UseGridColDef[]instead.The
GridActionsColDefinterface was removed. UseGridColDefinstead.The
GridEnrichedColDeftype was removed. UseGridColDefinstead.The
GridStateColDeftype was removed.The
GridDensityTypesenum was removed. UseGridDensitytype instead.If you use it to type
searchPredicate- useGridColumnsPanelProps['searchPredicate']instead.If you use it to type
getApplyFilterFn- useGridFilterOperator['getApplyFilterFn']instead.The
GridHeaderPlaceholdercomponent was removed.The
GridValueGetterFullParamstype was removed.The
GridSortModelParamsinterface was removed.The
GridApiReftype was removed. UseReact.MutableRefObject<GridApi>instead.The
GridCellValuetype was removed. Useanyor theVgeneric passed to most interfaces.The
GridRowDatatype was removed. UseGridRowModelinstead.The
filterPanelOperatorstranslation key was renamed tofilterPanelOperatorThe
MAX_PAGE_SIZEconstant was removed.The
DATA_GRID_DEFAULT_SLOTS_COMPONENTSexport was removed.The
useGridScrollFnhook was removed.The
GridCellParamsinterface was changed. The row generic is now before the cell generic.-extends GridCellParams<V, R, F, N> { +extends GridCellParams<R, V, F, N> {This means that values for 2 generic arguments needs to be provided before the argument that you already have.
-renderCell: (params: GridRenderCellParams<number>) => { +renderCell: (params: GridRenderCellParams<any, number>) => {The
GridErrorOverlaycomponent was removed.The
GridRowScrollEndParams["virtualRowsCount"]param was renamed toGridRowScrollEndParams["visibleRowsCount"].The
GridCellIdentifiertype was removed. UseGridCellCoordinatesinstead.
✅ CSS classes
Some CSS classes were removed or renamed
MUI X v5 classes MUI X v6 classes Note .MuiDataGrid-withBorder.MuiDataGrid-withBorderColorThe class only sets border-colorCSS property.MuiDataGrid-filterFormLinkOperatorInput.MuiDataGrid-filterFormLogicOperatorInput
Removals from the public API
- The
getGridSingleSelectQuickFilterFnfunction was removed. You can copy the old function and pass it to thegetApplyQuickFilterFnproperty of thesingleSelectcolumn definition.
Rename components to slots (optional)
The components and componentsProps props are being renamed to slots and slotProps props respectively.
This is a slow and ongoing effort between all the different libraries maintained by MUI.
To smooth the transition, Data Grid support both the components props which are deprecated, and the new slots props.
If you would like to use the new API and do not want to see deprecated prop usage, consider running rename-components-to-slots codemod handling the prop renaming.
npx @mui/x-codemod@latest v6.0.0/data-grid/rename-components-to-slots <path>
Take a look at the RFC for more information.