Migrating from MUI X Data Grid
Map MUI X DataGrid, DataGridPro and DataGridPremium props, column definitions, apiRef calls and models to Birch UI Grid.
MUI X Data Grid and Birch UI Grid share a lot of vocabulary: rows, columns, field, getRowId, checkboxSelection, density. The biggest differences are that Birch UI works in every framework, cell renderers return DOM content instead of React elements, and models such as sorting and filtering use slightly different shapes.
Pinned columns, column reordering and the set filter, which are Pro features in MUI X, are free in Birch UI Grid. MUI X Premium features such as row grouping, aggregation, Excel export and cell selection map to Grid Pro.
To convert a codebase automatically, run the migration tool, which applies these mappings and lists what is left to do by hand.
Before and after#
import { DataGrid, type GridColDef } from '@mui/x-data-grid';
const columns: GridColDef<Order>[] = [
{ field: 'id', headerName: 'Order', width: 120 },
{ field: 'customer', headerName: 'Customer', flex: 1, editable: true },
{
field: 'total',
headerName: 'Total',
type: 'number',
valueFormatter: (value) => usd.format(value),
},
];
export function OrdersGrid({ orders }: { orders: Order[] }) {
return (
<div style={{ height: 480 }}>
<DataGrid
rows={orders}
columns={columns}
getRowId={(row) => row.id}
checkboxSelection
initialState={{ pagination: { paginationModel: { pageSize: 50 } } }}
pageSizeOptions={[50]}
processRowUpdate={(updated) => saveOrder(updated)}
/>
</div>
);
}'use client';
import { BirchGrid } from '@birchui/react';
import type { CellValueChangedEvent, ColumnDef } from '@birchui/core';
const columns: ColumnDef<Order>[] = [
{ field: 'id', header: 'Order', width: 120 },
{ field: 'customer', header: 'Customer', flex: 1, editable: true },
{
field: 'total',
header: 'Total',
type: 'number',
format: (value) => usd.format(Number(value)),
},
];
const getRowId = (order: Order) => order.id;
const pagination = { pageSize: 50 };
export function OrdersGrid({ orders }: { orders: Order[] }) {
return (
<BirchGrid<Order>
style={{ height: 480 }}
rows={orders}
columns={columns}
getRowId={getRowId}
rowSelection="multiple"
checkboxSelection
pagination={pagination}
onCellValueChanged={(event: CellValueChangedEvent<Order>) => saveOrder(event.row)}
/>
);
}Things to notice:
headerNamebecomesheader, andvalueFormatterbecomesformat.- Number columns are right-aligned and boolean columns centered by default; override with
align. checkboxSelectionneedsrowSelection: 'multiple'(or'single').- There is no
processRowUpdate. The grid applies the edit to your row, then emitscellValueChanged. - The grid fills the element you size with
styleorclassName; there is no wrapperdivto add. - Keep
columns,getRowIdand other option props stable between renders. See Props and updates.
Props#
| MUI X | Birch UI | Notes |
|---|---|---|
rows |
rows |
|
columns |
columns |
|
getRowId={(row) => row.sku} |
getRowId={(row, index) => row.sku} |
|
apiRef={useGridApiRef()} |
ref={useRef<GridApi<Order>>(null)} |
The ref is the full GridApi |
rowHeight={52} |
rowHeight={52} |
|
getRowHeight |
rowHeight as a function |
|
columnHeaderHeight |
headerHeight |
|
density="compact" | "standard" | "comfortable" |
density="compact" | "normal" | "comfortable" |
|
checkboxSelection |
checkboxSelection |
Together with rowSelection |
disableMultipleRowSelection |
rowSelection="single" |
|
rowSelectionModel, onRowSelectionModelChange |
api.setRowSelected(id, selected), onSelectionChanged |
onSelectionChanged receives { selected } rows |
sortModel={[{ field, sort: 'asc' }]} |
sort={[{ colId, dir: 'asc' }]} |
|
onSortModelChange |
onSortChanged |
Receives { sort }. Also fires when you change sort through props or the API |
filterModel={{ items: [...] }} |
filterModel={{ [colId]: model }} |
See Filter models |
filterModel.quickFilterValues |
quickFilter |
A single string. Every word must match, and hidden columns are searched too |
onFilterModelChange |
onFilterChanged |
Receives { filterModel, quickFilter }. Also fires when you change filters through props or the API |
pagination, paginationModel={{ page, pageSize }} |
pagination={{ page, pageSize }} |
page is zero-based in both |
onPaginationModelChange |
onPageChanged |
Receives { page, pageCount } |
pinnedColumns={{ left: ['id'] }} (Pro) |
pinned: 'left' on the column |
Free in Birch UI |
columnVisibilityModel |
hidden on the column, or api.applyColumnState |
|
slots.noRowsOverlay |
emptyMessage |
Plain text |
slots.toolbar with GridToolbarQuickFilter |
Your own toolbar calling api.setQuickFilter |
|
slots.toolbar with GridToolbarExport |
Your own button calling api.downloadCsv() |
|
showCellVerticalBorder, getRowClassName |
--lq-border and rowClass |
|
rowGroupingModel={['region']} (Premium) |
groupBy={['region']} |
Pro |
groupingColDef (Premium) |
groupColumn |
Pro |
defaultGroupingExpansionDepth (Premium) |
groupDefaultExpanded |
Pro |
aggregationModel={{ revenue: 'sum' }} (Premium) |
aggFunc: 'sum' on the column |
Pro |
treeData, getTreeDataPath (Pro) |
treeData, getDataPath |
Pro |
getDetailPanelContent, getDetailPanelHeight (Pro) |
masterDetail={{ render, height }} |
Pro |
cellSelection (Premium) |
rangeSelection |
Pro |
| Clipboard paste (Premium) | clipboard |
Pro |
| Excel export (Premium) | api.exportExcel?.() with ExcelModule |
Pro. Exports every page; allRows: true adds rows inside collapsed groups as hidden outline rows |
| Pivoting (Premium) | pivot={{ enabled: true, rows, columns, values }} |
Pro |
Column definitions#
MUI X GridColDef |
Birch UI ColumnDef |
Notes |
|---|---|---|
field |
field |
|
headerName |
header |
|
description |
headerTooltip |
|
width, minWidth, maxWidth, flex |
same names | |
type: 'number' |
type: 'number' |
Right-aligned by default |
type: 'date', 'dateTime' |
type: 'date' |
|
type: 'boolean' |
type: 'boolean' |
|
type: 'singleSelect', valueOptions |
editor: 'select', options |
Add filter: 'set' for a set filter |
type: 'actions', getActions |
cell returning buttons |
|
editable |
editable |
Or a function of the cell context |
sortable, resizable |
same names | |
filterable |
filter |
true or 'text' | 'number' | 'date' | 'set' | 'boolean' |
disableReorder: true |
reorderable: false |
|
hideable |
No column-level switch | Hide columns with hidden or api.setColumnHidden |
align, headerAlign |
align |
|
valueGetter: (value, row) => ... |
valueGetter: (row) => ... |
|
valueSetter: (value, row) => ({ ...row, x: value }) |
valueSetter: (row, value) => { row.x = value } |
Birch UI updates the row in place |
valueParser: (value, row) => ... |
valueParser: (input, row) => ... |
|
valueFormatter: (value, row) => ... |
format: (value, row) => string |
|
renderCell: (params) => <Chip /> |
cell: (ctx) => string | Node |
Returns text or a DOM node |
renderEditCell |
editor: (params) => CellEditor |
|
cellClassName |
cellClass |
String or function |
headerClassName |
headerClass |
|
sortComparator: (v1, v2, p1, p2) |
comparator: (a, b, rowA, rowB) |
|
aggregable, availableAggregationFunctions (Premium) |
aggFunc |
Pro |
groupable (Premium) |
rowGroup |
Pro |
apiRef calls#
MUI X apiRef.current |
Birch UI GridApi |
|---|---|
updateRows([{ id, ...changes }]) |
applyTransaction({ update: [row] }) |
updateRows([{ id, _action: 'delete' }]) |
applyTransaction({ remove: [id] }) |
setRows(rows) |
setRows(rows) |
getRow(id) |
getRowById(id) |
getAllRowIds() |
getRows().map((row) => grid.getRowId(row)) |
gridFilteredSortedRowEntriesSelector(apiRef) |
getAllDisplayRows(), the rows after filtering, sorting and grouping on every page |
setRowChildrenExpansion(id, true) |
setExpanded(id, true), which also takes an array of ids |
setRowGroupingModel(['region']) (Premium) |
setGroupBy?.(['region']) (Pro) |
setAggregationModel(model) (Premium) |
aggFunc on the column; read a total with getColumnAggregate?.(colId, 'sum') (Pro) |
setPivotModel(model) (Premium) |
setPivot?.({ enabled: true, rows, columns, values }) (Pro) |
getSelectedRows() |
getSelectedRows(), which returns an array |
selectRow(id, true) |
setRowSelected(id, true) |
setSortModel(model) |
setSort(sort) |
setFilterModel(model) |
setFilterModel(model) |
setQuickFilterValues(['north']) |
setQuickFilter('north') |
setPage(n) |
setPage(n) |
setColumnVisibility(field, false) |
setColumnHidden(colId, true) |
setColumnWidth(field, width) |
setColumnWidth(colId, width) |
setColumnIndex(field, index) |
moveColumn(colId, index) |
pinColumn(field, 'left') |
setColumnPinned(colId, 'left') |
autosizeColumns() |
autosizeColumns() |
exportState(), restoreState() |
getColumnState(), applyColumnState() plus getSort() and getFilterModel() |
scrollToIndexes({ rowIndex, colIndex }) |
scrollToRow(rowIndex), scrollToColumn(colId) |
setCellFocus(id, field) |
focusCell(rowIndex, colId) |
startCellEditMode({ id, field }) |
startEdit(rowIndex, colId) |
stopCellEditMode({ id, field }) |
stopEdit() |
exportDataAsCsv() |
downloadCsv() |
exportDataAsExcel() (Premium) |
exportExcel?.() (Pro, with ExcelModule) |
subscribeEvent('cellClick', fn) |
on('cellClick', fn) |
Methods that Grid Pro modules add, such as setGroupBy, setPivot, getColumnAggregate and exportExcel, are optional in the GridApi type, so call them with ?..
Filter models#
MUI X keeps a list of filter items. Birch UI keeps one model per column id:
const filterModel = {
items: [
{ field: 'customer', operator: 'contains', value: 'traders' },
{ field: 'total', operator: '>', value: 1000 },
{ field: 'region', operator: 'isAnyOf', value: ['EMEA', 'APAC'] },
],
quickFilterValues: ['priority'],
};const filterModel = {
customer: { type: 'text', op: 'contains', value: 'traders' },
total: { type: 'number', op: 'gt', value: 1000 },
region: { type: 'set', values: ['EMEA', 'APAC'] },
} satisfies Record<string, FilterModel>;
const quickFilter = 'priority';| MUI X operator | Birch UI |
|---|---|
contains, doesNotContain, equals, doesNotEqual, startsWith, endsWith |
text with contains, notContains, equals, notEquals, startsWith, endsWith |
isEmpty, isNotEmpty |
blank, notBlank |
isAnyOf |
{ type: 'set', values } |
=, !=, <, <=, >, >= |
number with eq, ne, lt, lte, gt, gte |
is, before, after (date) |
date with eq, before, after |
is (boolean) |
{ type: 'boolean', value: true } |
MUI X combines items with logicOperator. Birch UI combines columns with AND; for an OR across conditions in one column, use a custom filter. See Filtering.
Cell rendering#
MUI X renders React elements in cells. A Birch UI cell function returns a string or a DOM node, which keeps scrolling fast in every framework:
const columns: ColumnDef<Order>[] = [
{
field: 'status',
header: 'Status',
cell: ({ value }) => {
const chip = document.createElement('span');
chip.className = `status-chip status-chip-${String(value)}`;
chip.textContent = String(value);
return chip;
},
},
{
id: 'actions',
header: '',
width: 96,
sortable: false,
cell: ({ row }) => {
const button = document.createElement('button');
button.type = 'button';
button.textContent = 'Refund';
button.addEventListener('click', () => row && openRefundDialog(row));
return button;
},
},
];Strings are inserted as text, so values from your data cannot inject HTML.
Editing and persistence#
MUI X calls processRowUpdate and waits for it. In Birch UI, the edit is applied first, then cellValueChanged fires with the old and new values. Persist it there, and revert with setValue if the server rejects it:
async function handleChange({ row, colId, oldValue, newValue }: CellValueChangedEvent<Order>) {
try {
await saveOrder(row);
} catch {
grid.current?.setValue(row, colId, oldValue, 'api');
showToast(`Could not save ${colId} for ${row.id}; the previous value was restored.`);
}
}Use valueParser to convert input and editable: (ctx) => boolean to lock cells. See Editing.
Licensing differences#
| MUI X Pro and Premium | Birch UI Grid Pro | |
|---|---|---|
| Purchase | Annual subscription per developer | One-time purchase, free updates forever |
| Frameworks | React | React, Vue, Angular, Svelte, Solid, Web Components and plain JavaScript |
| Pinned columns, reordering, set filter | Pro | Free |
| Grouping, aggregation, Excel export, cell selection | Premium | Grid Pro |
| Without a key | Watermark and console message | Watermark on non-local hosts and one console warning; features keep working |
See Licensing and activation and Pricing.
Migration checklist#
- Install
@birchui/coreand@birchui/react(plus@birchui/grid-profor Premium features). - Rename props and column fields with the tables above.
- Convert
renderCellcomponents tocellfunctions that return text or DOM nodes. - Replace
apiRefwith a React ref typed asGridApi<Row>. - Convert sort, filter and pagination models.
- Replace
processRowUpdatewith anonCellValueChangedhandler. - Move styling from
sxand theme overrides to the--lq-*CSS variables. See Theming. - Read the React guide for Next.js and server rendering.