Skip to main content

Migration

From 1.x to 2.0​

2.0 moves the grid to TanStack Table 9. The grid's own API does not change: the same props, the same apiRef, the same column options, and saved layouts, saved views and persisted state carry over. What changes is the setup around it, and anything you do with the raw TanStack table.

Requirements​

1.x2.0
TanStack Table8, bundled with the grid9, a peer dependency you install
MUI5, 6, 7, 97, 9
Module formatESM + CommonJSESM only
Node18+20+
React18, 1918, 19
npm install @ackplus/mui-tanstack-data-grid@2 @tanstack/react-table@9

On MUI 5 or 6, stay on 1.x (@ackplus/mui-tanstack-data-grid@1) or upgrade MUI first. MUI 5 and 6 have no exports map, so Node's ESM loader can't load them from an ESM-only package.

ESM only. Bundlers (Vite, webpack, Next.js, Rollup, esbuild) need no change. Node 20.19+ and 22.12+ can still require() the package. A test runner that loads CommonJS only (Jest without ESM support) needs to transform the package or switch to its ESM mode.

Code changes​

Most apps need none. Check these:

  1. Import table types from the grid. TanStack 9 types take a "features" type first (Row<TFeatures, TData>). The grid exports versions bound to its own features, with the 1.x shapes:

    // ✅ the grid's ColumnDef includes its column options (type, align, valueGetter, …)
    import type { ColumnDef, Row } from '@ackplus/mui-tanstack-data-grid';
    const columns: ColumnDef<User>[] = [/* … */];

    ColumnDef from @tanstack/react-table itself no longer carries the grid's options.

  2. TanStack's aggregationFn takes a definition. The grid's own aggregation option is unchanged. If you set TanStack's aggregationFn to a function, wrap it:

    - aggregationFn: (columnId, leafRows) => leafRows.length,
    + aggregationFn: { aggregate: (context) => context.rows.length },
  3. The raw table is TanStack 9. apiRef.current.table.getTable() returns a v9 table. The grid adds getState() back (with column pinning as left / right), but TanStack's own APIs follow v9: for example getPaginatedRowModel() (was getPaginationRowModel()), and column.getIsPinned() returns 'start' / 'end'. See TanStack's migration guide.

  4. Column pinning stays left / right in the grid: initialState.columnPinning, onColumnPinningChange, api.columnPinning.pinColumnLeft() and saved layouts. TanStack 9 calls the sides start / end; the grid maps between them.

  5. Removed: the deprecated locale key columnMenuAutosize (autosize left the column menu in 1.13; double-click a resize handle instead). VisibilityState is now ColumnVisibilityState (the old name still works).

From @ackplus/react-tanstack-data-table​

This package is the successor to the deprecated @ackplus/react-tanstack-data-table. Same mental model and the same apiRef, but the grid now renders as <div> + CSS Grid (not an HTML <table>), theming is MUI-native + tokens, and some props are renamed. Old names keep working as deprecated aliases, so you can migrate gradually.

1. Install​

npm install @ackplus/mui-tanstack-data-grid @tanstack/react-table@9
npm uninstall @ackplus/react-tanstack-data-table
- import { DataTable } from '@ackplus/react-tanstack-data-table';
+ import { DataTable } from '@ackplus/mui-tanstack-data-grid';

2. Prop renames​

The v1 names still work (each maps to its new name, and the new name wins when both are set), but they're deprecated: your editor shows them struck through. Rename them when you can.

v1v2Notes
tableSize="small"density="compact"small→compact, medium→standard
enableTableSizeControlenableDensitySelector
enableStripesstriped
enableHoverhover
enableStickyHeaderOrFooterstickyHeader+ stickyFooter
enableColumnDraggingenableColumnReordering
onColumnDragEndonColumnOrderChangesame payload
enableExpandingenableRowExpansion
renderSubComponentrenderDetailPanelsame signature
bulkActionsrenderBulkActionssame signature
totalRowrowCountserver total
estimateRowHeightestimatedRowHeight
emptyMessagenoRowsMessage
onColumnFiltersChangeonColumnFilterChangesame signature
tablePropsslotProps.gridtyped, no more any
tableContainerPropsslotProps.scrollertyped

3. Behaviour changes​

  • The grid renders as <div>s with ARIA roles, not a <table>. CSS that targeted table/td/ .MuiTable-* should move to tokens, MuiTanstackDataGrid style overrides, or slotProps.
  • Column minSize/maxSize are now respected, and resizing no longer redistributes neighbouring columns.
  • Density names changed (small/medium → compact/standard/comfortable).
  • Excel export lazy-loads xlsx on first use; the API is unchanged.

4. Imperative handle: ref → apiRef​

The imperative API (its namespaces and method names) is unchanged — but how you obtain it changed. In v1, <DataTable> was a forwardRef component, so you read the handle off a React ref. In v2, <DataTable> is a plain function component that does not accept a ref; it exposes the handle through a dedicated apiRef prop instead.

- const ref = useRef<DataTableApi<Row>>(null);
- <DataTable ref={ref} columns={columns} data={rows} />;
+ const apiRef = useRef<DataTableApi<Row> | null>(null);
+ <DataTable apiRef={apiRef} columns={columns} data={rows} />;

Once wired, apiRef.current gives you the same API as before (apiRef.current?.selection.selectAll(), apiRef.current?.export.exportCSV(), etc.).

State persistence

v1's stateKey lived on the example app's DataGrid wrapper. Since 1.5.0 stateKey is a first-class <DataTable> prop — pass it directly and the grid persists view state for you (see State persistence). For v1's defaultHiddenColumns, map the hidden names into initialState.columnVisibility.