|
…
|
History | |
|---|---|---|
| .. | ||
| src | ||
| .gitignore | ||
| index.html | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
| vite.config.js | ||
Material React Table — TanStack Table v9 example
This example is a downloadable, self-contained adaptation of material-react-table v3 ported to TanStack Table v9 + Material UI v9.
The full MRT source lives under src/material-react-table/ — it is a 1:1 mirror of the upstream package's src/ (components, hooks, utils, fns, locales). The demo entry point in src/main.tsx shows how to wire it up.
Differences from upstream MRT v3
The upstream package targets TanStack Table v8 + MUI v6. This example has been migrated:
useReactTable→useTable(TanStack Table v9 hook).- Row models:
getCoreRowModel/getSortedRowModel/etc. options replaced withfeatures: stockFeaturesandrowModels: { sortedRowModel: createSortedRowModel(sortFns), … }. createRow→constructRow(renamed v9 export).sortingFn→sortFnon column defs and theMRT_SortFntype.columnSizingInfostate →columnResizing(andsetColumnSizingInfo→setColumnResizing).table.getState()→table.stateacross all ~48 consumer sites.- Type generics: every
MRT_*type now bindsTFeatures = StockFeaturesso consumers don't need to specify it. - MUI v9:
componentsProps→slotProps(one site).
The example uses the v9 escape-hatch useTable(opts, state => state) — every state change re-renders the consumer, matching v8 semantics. If you'd prefer fine-grained re-renders, swap the selector for narrower projections or use table.Subscribe/per-slice table.atoms.
Running
pnpm install
pnpm dev
Then open http://localhost:5173.
Caveats
@mui/x-date-pickersis pinned to^8inpackage.jsonbecause there is no v9 release. The MRT date-picker filter variant is therefore wired up but not exercised by the demo (no date columns). If install fails because of a peer-dep mismatch with@mui/material@^9, either add an override in your localpnpm-workspace.yamlor remove@mui/x-date-pickersfrompackage.jsonand delete the date-picker imports insrc/material-react-table/components/inputs/MRT_FilterTextField.tsxandsrc/material-react-table/types.ts.
Credits
Original library by Kevin Vandy — https://github.com/KevinVandy/material-react-table.