@lminii/material-react-table 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +234 -0
- package/dist/index.d.mts +2408 -0
- package/dist/index.d.ts +2408 -0
- package/dist/index.js +4825 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4631 -0
- package/dist/index.mjs.map +1 -0
- package/locales/ar/index.d.mts +3 -0
- package/locales/ar/index.d.ts +3 -0
- package/locales/ar/index.js +100 -0
- package/locales/ar/index.mjs +96 -0
- package/locales/ar/package.json +6 -0
- package/locales/az/index.d.mts +3 -0
- package/locales/az/index.d.ts +3 -0
- package/locales/az/index.js +100 -0
- package/locales/az/index.mjs +96 -0
- package/locales/az/package.json +6 -0
- package/locales/bg/index.d.mts +3 -0
- package/locales/bg/index.d.ts +3 -0
- package/locales/bg/index.js +100 -0
- package/locales/bg/index.mjs +96 -0
- package/locales/bg/package.json +6 -0
- package/locales/cs/index.d.mts +3 -0
- package/locales/cs/index.d.ts +3 -0
- package/locales/cs/index.js +100 -0
- package/locales/cs/index.mjs +96 -0
- package/locales/cs/package.json +6 -0
- package/locales/da/index.d.mts +3 -0
- package/locales/da/index.d.ts +3 -0
- package/locales/da/index.js +100 -0
- package/locales/da/index.mjs +96 -0
- package/locales/da/package.json +6 -0
- package/locales/de/index.d.mts +3 -0
- package/locales/de/index.d.ts +3 -0
- package/locales/de/index.js +100 -0
- package/locales/de/index.mjs +96 -0
- package/locales/de/package.json +6 -0
- package/locales/el/index.d.mts +3 -0
- package/locales/el/index.d.ts +3 -0
- package/locales/el/index.js +100 -0
- package/locales/el/index.mjs +96 -0
- package/locales/el/package.json +6 -0
- package/locales/en/index.d.mts +3 -0
- package/locales/en/index.d.ts +3 -0
- package/locales/en/index.js +100 -0
- package/locales/en/index.mjs +96 -0
- package/locales/en/package.json +6 -0
- package/locales/es/index.d.mts +3 -0
- package/locales/es/index.d.ts +3 -0
- package/locales/es/index.js +100 -0
- package/locales/es/index.mjs +96 -0
- package/locales/es/package.json +6 -0
- package/locales/et/index.d.mts +3 -0
- package/locales/et/index.d.ts +3 -0
- package/locales/et/index.js +100 -0
- package/locales/et/index.mjs +96 -0
- package/locales/et/package.json +6 -0
- package/locales/fa/index.d.mts +3 -0
- package/locales/fa/index.d.ts +3 -0
- package/locales/fa/index.js +100 -0
- package/locales/fa/index.mjs +96 -0
- package/locales/fa/package.json +6 -0
- package/locales/fi/index.d.mts +3 -0
- package/locales/fi/index.d.ts +3 -0
- package/locales/fi/index.js +100 -0
- package/locales/fi/index.mjs +96 -0
- package/locales/fi/package.json +6 -0
- package/locales/fr/index.d.mts +3 -0
- package/locales/fr/index.d.ts +3 -0
- package/locales/fr/index.js +100 -0
- package/locales/fr/index.mjs +96 -0
- package/locales/fr/package.json +6 -0
- package/locales/he/index.d.mts +3 -0
- package/locales/he/index.d.ts +3 -0
- package/locales/he/index.js +100 -0
- package/locales/he/index.mjs +96 -0
- package/locales/he/package.json +6 -0
- package/locales/hr/index.d.mts +3 -0
- package/locales/hr/index.d.ts +3 -0
- package/locales/hr/index.js +100 -0
- package/locales/hr/index.mjs +96 -0
- package/locales/hr/package.json +6 -0
- package/locales/hu/index.d.mts +3 -0
- package/locales/hu/index.d.ts +3 -0
- package/locales/hu/index.js +100 -0
- package/locales/hu/index.mjs +96 -0
- package/locales/hu/package.json +6 -0
- package/locales/hy/index.d.mts +3 -0
- package/locales/hy/index.d.ts +3 -0
- package/locales/hy/index.js +100 -0
- package/locales/hy/index.mjs +96 -0
- package/locales/hy/package.json +6 -0
- package/locales/id/index.d.mts +3 -0
- package/locales/id/index.d.ts +3 -0
- package/locales/id/index.js +100 -0
- package/locales/id/index.mjs +96 -0
- package/locales/id/package.json +6 -0
- package/locales/it/index.d.mts +3 -0
- package/locales/it/index.d.ts +3 -0
- package/locales/it/index.js +100 -0
- package/locales/it/index.mjs +96 -0
- package/locales/it/package.json +6 -0
- package/locales/ja/index.d.mts +3 -0
- package/locales/ja/index.d.ts +3 -0
- package/locales/ja/index.js +100 -0
- package/locales/ja/index.mjs +96 -0
- package/locales/ja/package.json +6 -0
- package/locales/ko/index.d.mts +3 -0
- package/locales/ko/index.d.ts +3 -0
- package/locales/ko/index.js +100 -0
- package/locales/ko/index.mjs +96 -0
- package/locales/ko/package.json +6 -0
- package/locales/nl/index.d.mts +3 -0
- package/locales/nl/index.d.ts +3 -0
- package/locales/nl/index.js +100 -0
- package/locales/nl/index.mjs +96 -0
- package/locales/nl/package.json +6 -0
- package/locales/no/index.d.mts +3 -0
- package/locales/no/index.d.ts +3 -0
- package/locales/no/index.js +100 -0
- package/locales/no/index.mjs +96 -0
- package/locales/no/package.json +6 -0
- package/locales/np/index.d.mts +3 -0
- package/locales/np/index.d.ts +3 -0
- package/locales/np/index.js +100 -0
- package/locales/np/index.mjs +96 -0
- package/locales/np/package.json +6 -0
- package/locales/pl/index.d.mts +3 -0
- package/locales/pl/index.d.ts +3 -0
- package/locales/pl/index.js +100 -0
- package/locales/pl/index.mjs +96 -0
- package/locales/pl/package.json +6 -0
- package/locales/pt/index.d.mts +3 -0
- package/locales/pt/index.d.ts +3 -0
- package/locales/pt/index.js +100 -0
- package/locales/pt/index.mjs +96 -0
- package/locales/pt/package.json +6 -0
- package/locales/pt-BR/index.d.mts +3 -0
- package/locales/pt-BR/index.d.ts +3 -0
- package/locales/pt-BR/index.js +100 -0
- package/locales/pt-BR/index.mjs +96 -0
- package/locales/pt-BR/package.json +6 -0
- package/locales/ro/index.d.mts +3 -0
- package/locales/ro/index.d.ts +3 -0
- package/locales/ro/index.js +100 -0
- package/locales/ro/index.mjs +96 -0
- package/locales/ro/package.json +6 -0
- package/locales/ru/index.d.mts +3 -0
- package/locales/ru/index.d.ts +3 -0
- package/locales/ru/index.js +100 -0
- package/locales/ru/index.mjs +96 -0
- package/locales/ru/package.json +6 -0
- package/locales/sk/index.d.mts +3 -0
- package/locales/sk/index.d.ts +3 -0
- package/locales/sk/index.js +100 -0
- package/locales/sk/index.mjs +96 -0
- package/locales/sk/package.json +6 -0
- package/locales/sr-Cyrl-RS/index.d.mts +3 -0
- package/locales/sr-Cyrl-RS/index.d.ts +3 -0
- package/locales/sr-Cyrl-RS/index.js +100 -0
- package/locales/sr-Cyrl-RS/index.mjs +96 -0
- package/locales/sr-Cyrl-RS/package.json +6 -0
- package/locales/sr-Latn-RS/index.d.mts +3 -0
- package/locales/sr-Latn-RS/index.d.ts +3 -0
- package/locales/sr-Latn-RS/index.js +100 -0
- package/locales/sr-Latn-RS/index.mjs +96 -0
- package/locales/sr-Latn-RS/package.json +6 -0
- package/locales/sv/index.d.mts +3 -0
- package/locales/sv/index.d.ts +3 -0
- package/locales/sv/index.js +100 -0
- package/locales/sv/index.mjs +96 -0
- package/locales/sv/package.json +6 -0
- package/locales/tr/index.d.mts +3 -0
- package/locales/tr/index.d.ts +3 -0
- package/locales/tr/index.js +100 -0
- package/locales/tr/index.mjs +96 -0
- package/locales/tr/package.json +6 -0
- package/locales/uk/index.d.mts +3 -0
- package/locales/uk/index.d.ts +3 -0
- package/locales/uk/index.js +100 -0
- package/locales/uk/index.mjs +96 -0
- package/locales/uk/package.json +6 -0
- package/locales/vi/index.d.mts +3 -0
- package/locales/vi/index.d.ts +3 -0
- package/locales/vi/index.js +100 -0
- package/locales/vi/index.mjs +96 -0
- package/locales/vi/package.json +6 -0
- package/locales/zh-Hans/index.d.mts +3 -0
- package/locales/zh-Hans/index.d.ts +3 -0
- package/locales/zh-Hans/index.js +100 -0
- package/locales/zh-Hans/index.mjs +96 -0
- package/locales/zh-Hans/package.json +6 -0
- package/locales/zh-Hant/index.d.mts +3 -0
- package/locales/zh-Hant/index.d.ts +3 -0
- package/locales/zh-Hant/index.js +100 -0
- package/locales/zh-Hant/index.mjs +96 -0
- package/locales/zh-Hant/package.json +6 -0
- package/package.json +147 -0
- package/skills/README.md +81 -0
- package/skills/composable-components/SKILL.md +189 -0
- package/skills/customization/SKILL.md +190 -0
- package/skills/drag-and-drop-ordering/SKILL.md +227 -0
- package/skills/editing/SKILL.md +243 -0
- package/skills/filtering/SKILL.md +213 -0
- package/skills/getting-started/SKILL.md +213 -0
- package/skills/localization/SKILL.md +182 -0
- package/skills/migrate-v3-to-v4/SKILL.md +161 -0
- package/skills/state-and-server-data/SKILL.md +200 -0
- package/skills/virtualization/SKILL.md +203 -0
- package/src/components/MaterialReactTable.tsx +36 -0
- package/src/components/body/MRT_TableBody.tsx +221 -0
- package/src/components/body/MRT_TableBodyCell.tsx +351 -0
- package/src/components/body/MRT_TableBodyCellValue.tsx +130 -0
- package/src/components/body/MRT_TableBodyRow.tsx +288 -0
- package/src/components/body/MRT_TableBodyRowGrabHandle.tsx +61 -0
- package/src/components/body/MRT_TableBodyRowPinButton.tsx +58 -0
- package/src/components/body/MRT_TableDetailPanel.tsx +110 -0
- package/src/components/buttons/MRT_ColumnPinningButtons.tsx +72 -0
- package/src/components/buttons/MRT_CopyButton.tsx +87 -0
- package/src/components/buttons/MRT_EditActionButtons.tsx +134 -0
- package/src/components/buttons/MRT_ExpandAllButton.tsx +78 -0
- package/src/components/buttons/MRT_ExpandButton.tsx +102 -0
- package/src/components/buttons/MRT_GrabHandleButton.tsx +65 -0
- package/src/components/buttons/MRT_RowPinButton.tsx +84 -0
- package/src/components/buttons/MRT_ShowHideColumnsButton.tsx +50 -0
- package/src/components/buttons/MRT_ToggleDensePaddingButton.tsx +52 -0
- package/src/components/buttons/MRT_ToggleFiltersButton.tsx +40 -0
- package/src/components/buttons/MRT_ToggleFullScreenButton.tsx +51 -0
- package/src/components/buttons/MRT_ToggleGlobalFilterButton.tsx +46 -0
- package/src/components/buttons/MRT_ToggleRowActionMenuButton.tsx +126 -0
- package/src/components/footer/MRT_TableFooter.tsx +88 -0
- package/src/components/footer/MRT_TableFooterCell.tsx +107 -0
- package/src/components/footer/MRT_TableFooterRow.tsx +95 -0
- package/src/components/head/MRT_TableHead.tsx +91 -0
- package/src/components/head/MRT_TableHeadCell.tsx +351 -0
- package/src/components/head/MRT_TableHeadCellColumnActionsButton.tsx +96 -0
- package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +52 -0
- package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +178 -0
- package/src/components/head/MRT_TableHeadCellGrabHandle.tsx +91 -0
- package/src/components/head/MRT_TableHeadCellResizeHandle.tsx +96 -0
- package/src/components/head/MRT_TableHeadCellSortLabel.tsx +101 -0
- package/src/components/head/MRT_TableHeadRow.tsx +90 -0
- package/src/components/inputs/MRT_EditCellTextField.tsx +202 -0
- package/src/components/inputs/MRT_FilterCheckbox.tsx +90 -0
- package/src/components/inputs/MRT_FilterRangeFields.tsx +41 -0
- package/src/components/inputs/MRT_FilterRangeSlider.tsx +143 -0
- package/src/components/inputs/MRT_FilterTextField.tsx +592 -0
- package/src/components/inputs/MRT_GlobalFilterTextField.tsx +167 -0
- package/src/components/inputs/MRT_SelectCheckbox.tsx +135 -0
- package/src/components/menus/MRT_ActionMenuItem.tsx +62 -0
- package/src/components/menus/MRT_CellActionMenu.tsx +107 -0
- package/src/components/menus/MRT_ColumnActionMenu.tsx +352 -0
- package/src/components/menus/MRT_FilterOptionMenu.tsx +292 -0
- package/src/components/menus/MRT_RowActionMenu.tsx +88 -0
- package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +181 -0
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +203 -0
- package/src/components/modals/MRT_EditRowModal.tsx +114 -0
- package/src/components/table/MRT_Table.tsx +84 -0
- package/src/components/table/MRT_TableContainer.tsx +111 -0
- package/src/components/table/MRT_TableLoadingOverlay.tsx +58 -0
- package/src/components/table/MRT_TablePaper.tsx +89 -0
- package/src/components/toolbar/MRT_BottomToolbar.tsx +111 -0
- package/src/components/toolbar/MRT_LinearProgressBar.tsx +53 -0
- package/src/components/toolbar/MRT_TablePagination.tsx +241 -0
- package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +184 -0
- package/src/components/toolbar/MRT_ToolbarDropZone.tsx +83 -0
- package/src/components/toolbar/MRT_ToolbarInternalButtons.tsx +72 -0
- package/src/components/toolbar/MRT_TopToolbar.tsx +130 -0
- package/src/features/mrtCellActionsFeature.ts +67 -0
- package/src/features/mrtColumnDraggingFeature.ts +83 -0
- package/src/features/mrtDensityFeature.ts +64 -0
- package/src/features/mrtEditingFeature.ts +102 -0
- package/src/features/mrtFeatures.ts +103 -0
- package/src/features/mrtFilterModesFeature.ts +99 -0
- package/src/features/mrtFnsFeature.ts +46 -0
- package/src/features/mrtFullScreenFeature.ts +63 -0
- package/src/features/mrtLoadingFeature.ts +35 -0
- package/src/features/mrtRefsFeature.ts +60 -0
- package/src/features/mrtRowDraggingFeature.ts +81 -0
- package/src/features/mrtStateCompatFeature.ts +43 -0
- package/src/features/mrtToolbarsFeature.ts +76 -0
- package/src/fns/aggregationFns.ts +3 -0
- package/src/fns/filterFns.ts +196 -0
- package/src/fns/sortingFns.ts +31 -0
- package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +28 -0
- package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +29 -0
- package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +97 -0
- package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +30 -0
- package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +24 -0
- package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +34 -0
- package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +33 -0
- package/src/hooks/useMRT_ColumnVirtualizer.ts +124 -0
- package/src/hooks/useMRT_Effects.ts +108 -0
- package/src/hooks/useMRT_RowVirtualizer.ts +88 -0
- package/src/hooks/useMRT_Rows.ts +44 -0
- package/src/hooks/useMRT_TableInstance.ts +181 -0
- package/src/hooks/useMRT_TableOptions.ts +241 -0
- package/src/hooks/useMaterialReactTable.ts +12 -0
- package/src/icons.ts +73 -0
- package/src/index.ts +91 -0
- package/src/locales/ar.ts +97 -0
- package/src/locales/az.ts +97 -0
- package/src/locales/bg.ts +97 -0
- package/src/locales/cs.ts +98 -0
- package/src/locales/da.ts +97 -0
- package/src/locales/de.ts +97 -0
- package/src/locales/el.ts +97 -0
- package/src/locales/en.ts +97 -0
- package/src/locales/es.ts +97 -0
- package/src/locales/et.ts +98 -0
- package/src/locales/fa.ts +97 -0
- package/src/locales/fi.ts +98 -0
- package/src/locales/fr.ts +97 -0
- package/src/locales/he.ts +97 -0
- package/src/locales/hr.ts +97 -0
- package/src/locales/hu.ts +97 -0
- package/src/locales/hy.ts +97 -0
- package/src/locales/id.ts +98 -0
- package/src/locales/it.ts +97 -0
- package/src/locales/ja.ts +97 -0
- package/src/locales/ko.ts +97 -0
- package/src/locales/mk.ts +96 -0
- package/src/locales/nl.ts +97 -0
- package/src/locales/no.ts +99 -0
- package/src/locales/np.ts +98 -0
- package/src/locales/pl.ts +97 -0
- package/src/locales/pt-BR.ts +97 -0
- package/src/locales/pt.ts +97 -0
- package/src/locales/ro.ts +97 -0
- package/src/locales/ru.ts +97 -0
- package/src/locales/sk.ts +98 -0
- package/src/locales/sr-Cyrl-RS.ts +97 -0
- package/src/locales/sr-Latn-RS.ts +97 -0
- package/src/locales/sv.ts +97 -0
- package/src/locales/tr.ts +97 -0
- package/src/locales/uk.ts +97 -0
- package/src/locales/vi.ts +97 -0
- package/src/locales/zh-Hans.ts +96 -0
- package/src/locales/zh-Hant.ts +96 -0
- package/src/types.ts +1314 -0
- package/src/utils/cell.utils.ts +234 -0
- package/src/utils/column.utils.ts +204 -0
- package/src/utils/displayColumn.utils.ts +152 -0
- package/src/utils/row.utils.ts +258 -0
- package/src/utils/style.utils.ts +211 -0
- package/src/utils/tanstack.helpers.ts +64 -0
- package/src/utils/utils.ts +34 -0
- package/src/utils/virtualization.utils.ts +24 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: localization
|
|
3
|
+
description: >
|
|
4
|
+
Translate Material React Table V4 with the localization option: import a built-in locale from @lminii/material-react-table/locales/<code>, override individual MRT_Localization strings, write a full custom locale with the language BCP 47 tag, keep {column} placeholders, and pair it with Material UI theme locales and the date pickers adapterLocale. Load for i18n, translating toolbar and menu text, number formatting in pagination, or a locale import that fails to resolve.
|
|
5
|
+
metadata:
|
|
6
|
+
type: framework
|
|
7
|
+
library: '@lminii/material-react-table'
|
|
8
|
+
library_version: '4.0.0'
|
|
9
|
+
framework: react
|
|
10
|
+
requires:
|
|
11
|
+
- getting-started
|
|
12
|
+
sources:
|
|
13
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/guides/localization.mdx'
|
|
14
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/examples/localization-i18n-de/sandbox/src/TS.tsx'
|
|
15
|
+
- 'lminii/material-react-table:packages/material-react-table/src/locales/en.ts'
|
|
16
|
+
- 'lminii/material-react-table:packages/material-react-table/src/hooks/useMRT_TableOptions.ts'
|
|
17
|
+
- 'lminii/material-react-table:packages/material-react-table/src/types.ts'
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
This skill builds on `getting-started`. Every user-facing string MRT renders comes from one `MRT_Localization` object. The `localization` option takes a partial object that is merged over the English defaults, so a locale file or a handful of overrides both work.
|
|
21
|
+
|
|
22
|
+
## Setup
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { MRT_Localization_DE } from '@lminii/material-react-table/locales/de'
|
|
26
|
+
|
|
27
|
+
const table = useMaterialReactTable({
|
|
28
|
+
columns,
|
|
29
|
+
data,
|
|
30
|
+
localization: MRT_Localization_DE,
|
|
31
|
+
})
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Built-in locales, imported from `@lminii/material-react-table/locales/<code>`: `ar`, `az`, `bg`, `cs`, `da`, `de`, `el`, `en`, `es`, `et`, `fa`, `fi`, `fr`, `he`, `hr`, `hu`, `hy`, `id`, `it`, `ja`, `ko`, `mk`, `nl`, `no`, `np`, `pl`, `pt`, `pt-BR`, `ro`, `ru`, `sk`, `sr-Cyrl-RS`, `sr-Latn-RS`, `sv`, `tr`, `uk`, `vi`, `zh-Hans`, `zh-Hant`. Each exports `MRT_Localization_<CODE>` with hyphens replaced by underscores, for example `MRT_Localization_PT_BR` and `MRT_Localization_ZH_HANS`. Column headers, cell content, and your own toolbar buttons are not translated by MRT; those come from your column definitions and render slots.
|
|
35
|
+
|
|
36
|
+
## Core Patterns
|
|
37
|
+
|
|
38
|
+
### Override a few strings
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
const table = useMaterialReactTable({
|
|
42
|
+
columns,
|
|
43
|
+
data,
|
|
44
|
+
localization: {
|
|
45
|
+
...MRT_Localization_DE,
|
|
46
|
+
noRecordsToDisplay: 'Keine Personen gefunden',
|
|
47
|
+
rowsPerPage: 'Personen pro Seite',
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Partial objects are merged over English, so an override object without a base locale still renders every other string. Keep the `localization` object stable (module scope or `useMemo`); MRT memoizes the merge on its identity.
|
|
53
|
+
|
|
54
|
+
### Write a custom locale
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { type MRT_Localization } from '@lminii/material-react-table'
|
|
58
|
+
|
|
59
|
+
export const MRT_Localization_GA: MRT_Localization = {
|
|
60
|
+
...MRT_Localization_EN, // start from English so nothing is missing
|
|
61
|
+
language: 'ga', // BCP 47 tag used for number formatting
|
|
62
|
+
actions: 'Gníomhartha',
|
|
63
|
+
filterByColumn: 'Scag de réir {column}',
|
|
64
|
+
sortByColumnAsc: 'Sórtáil de réir {column} in ord ardaitheach',
|
|
65
|
+
noRecordsToDisplay: 'Níl aon taifid le taispeáint',
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`MRT_Localization` has around 90 keys; `language` is required on the type and feeds `toLocaleString` for the row counts in pagination and the selection banner. Strings such as `filterByColumn`, `sortByColumnAsc`, `dropToGroupBy`, and `filteringByColumn` contain `{column}` placeholders that MRT replaces with the column header, so keep the token verbatim. Fully translated locales are welcome as pull requests to `packages/material-react-table/src/locales`.
|
|
70
|
+
|
|
71
|
+
### Pair with Material UI and the date pickers
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
import { createTheme, ThemeProvider, useTheme } from '@mui/material'
|
|
75
|
+
import { deDE } from '@mui/material/locale'
|
|
76
|
+
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'
|
|
77
|
+
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'
|
|
78
|
+
import { deDE as pickersDeDE } from '@mui/x-date-pickers/locales'
|
|
79
|
+
import 'dayjs/locale/de'
|
|
80
|
+
|
|
81
|
+
const theme = useTheme()
|
|
82
|
+
|
|
83
|
+
<ThemeProvider theme={createTheme(theme, deDE, pickersDeDE)}>
|
|
84
|
+
<LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale="de">
|
|
85
|
+
<MaterialReactTable table={table} />
|
|
86
|
+
</LocalizationProvider>
|
|
87
|
+
</ThemeProvider>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
MRT's `localization` covers MRT strings only. Material UI's own component text (pagination select labels, accessibility labels) comes from the theme locale, and the date and time filter pickers take their month names and formats from the pickers locale and `adapterLocale`.
|
|
91
|
+
|
|
92
|
+
### Switch locales at runtime
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
const locales = { en: MRT_Localization_EN, de: MRT_Localization_DE, ja: MRT_Localization_JA }
|
|
96
|
+
|
|
97
|
+
const table = useMaterialReactTable({
|
|
98
|
+
columns,
|
|
99
|
+
data,
|
|
100
|
+
localization: locales[currentLanguage],
|
|
101
|
+
})
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The table re-renders with the new strings; no state is reset.
|
|
105
|
+
|
|
106
|
+
## Common Mistakes
|
|
107
|
+
|
|
108
|
+
### HIGH Importing a locale from the upstream package name
|
|
109
|
+
|
|
110
|
+
Wrong:
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
import { MRT_Localization_ES } from 'material-react-table/locales/es'
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Correct:
|
|
117
|
+
|
|
118
|
+
```tsx
|
|
119
|
+
import { MRT_Localization_ES } from '@lminii/material-react-table/locales/es'
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The fork publishes locales under its own `exports` map. The upstream path resolves only if the upstream package is also installed, which produces two copies of MRT.
|
|
123
|
+
|
|
124
|
+
Source: `MIGRATION.md`
|
|
125
|
+
|
|
126
|
+
### MEDIUM Custom locale without the language tag
|
|
127
|
+
|
|
128
|
+
Wrong:
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
localization: { actions: 'Ações', cancel: 'Cancelar', rowsPerPage: 'Linhas por página' }
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Correct:
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
localization: { language: 'pt', actions: 'Ações', cancel: 'Cancelar', rowsPerPage: 'Linhas por página' }
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Without `language`, the English `en` tag from the merged defaults formats row counts, so `1.234` renders as `1,234`.
|
|
141
|
+
|
|
142
|
+
Source: `packages/material-react-table/src/locales/en.ts`
|
|
143
|
+
|
|
144
|
+
### MEDIUM Dropping the {column} placeholder
|
|
145
|
+
|
|
146
|
+
Wrong:
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
localization: { filterByColumn: 'Filtrer' }
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Correct:
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
localization: { filterByColumn: 'Filtrer par {column}' }
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
MRT substitutes the header into `{column}`; without it the tooltip and placeholder no longer say which column they apply to.
|
|
159
|
+
|
|
160
|
+
Source: `packages/material-react-table/src/locales/en.ts`
|
|
161
|
+
|
|
162
|
+
### LOW Passing an unstable localization object
|
|
163
|
+
|
|
164
|
+
Wrong:
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
localization: { ...MRT_Localization_FR, noRecordsToDisplay: t('empty') }, // new object each render
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Correct:
|
|
171
|
+
|
|
172
|
+
```tsx
|
|
173
|
+
const localization = useMemo(() => ({ ...MRT_Localization_FR, noRecordsToDisplay: t('empty') }), [t])
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
A fresh object every render re-runs the merge and invalidates the memoized table options.
|
|
177
|
+
|
|
178
|
+
Source: `packages/material-react-table/src/hooks/useMRT_TableOptions.ts`
|
|
179
|
+
|
|
180
|
+
## API Discovery
|
|
181
|
+
|
|
182
|
+
`MRT_Localization` in `node_modules/@lminii/material-react-table/dist/index.d.ts` lists every key; `en.ts` in `packages/material-react-table/src/locales` is the reference translation. `ls node_modules/@lminii/material-react-table/locales` shows the shipped locale folders. The Localization guide at `/docs/guides/localization` renders an example per locale.
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: migrate-v3-to-v4
|
|
3
|
+
description: >
|
|
4
|
+
Migrate an application from material-react-table V3 to @lminii/material-react-table V4: switch the package and imports, upgrade Material UI and X Date Pickers to V9, move text field props to slotProps, and apply every TanStack Table V9 rename and behaviour change (column pinning start/end, columnResizing, sortFn, getPaginatedRowModel, rowSelection true values, removed getCoreRowModel options and onStateChange). Load for migration plans, implementation, or audits of a V3 codebase.
|
|
5
|
+
metadata:
|
|
6
|
+
type: lifecycle
|
|
7
|
+
library: '@lminii/material-react-table'
|
|
8
|
+
library_version: '4.0.0'
|
|
9
|
+
framework: react
|
|
10
|
+
requires:
|
|
11
|
+
- getting-started
|
|
12
|
+
sources:
|
|
13
|
+
- 'lminii/material-react-table:MIGRATION.md'
|
|
14
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/getting-started/migrating-to-v4.mdx'
|
|
15
|
+
- 'lminii/material-react-table:packages/material-react-table/src/types.ts'
|
|
16
|
+
- 'lminii/material-react-table:packages/material-react-table/src/hooks/useMRT_TableOptions.ts'
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
This skill builds on `getting-started`. V4 keeps the V3 API: `useMaterialReactTable`, the `table` prop, every `mui*Props`, `render*`, and `enable*` option. Breaking changes come from three sources only: the package rename, Material UI V9, and TanStack Table V9. Do them in that order.
|
|
20
|
+
|
|
21
|
+
## Setup
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npx @mui/codemod@latest v9.0.0/system-props src
|
|
25
|
+
npx @mui/codemod@latest deprecations/all src
|
|
26
|
+
npm uninstall material-react-table
|
|
27
|
+
npm install @lminii/material-react-table @mui/material@^9 @mui/icons-material@^9 @mui/x-date-pickers@^9
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Then rewrite imports:
|
|
31
|
+
|
|
32
|
+
```diff
|
|
33
|
+
-import { MaterialReactTable } from 'material-react-table';
|
|
34
|
+
-import { MRT_Localization_DE } from 'material-react-table/locales/de';
|
|
35
|
+
+import { MaterialReactTable } from '@lminii/material-react-table';
|
|
36
|
+
+import { MRT_Localization_DE } from '@lminii/material-react-table/locales/de';
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Peer floors are `@mui/material`, `@mui/icons-material`, and `@mui/x-date-pickers` at 9.0 or newer; React 18 and Emotion 11.13 are unchanged. Node 22.12 or newer is required for the CommonJS build.
|
|
40
|
+
|
|
41
|
+
## Core Patterns
|
|
42
|
+
|
|
43
|
+
### Renames from TanStack Table V9
|
|
44
|
+
|
|
45
|
+
Each of these is a find and replace across the codebase:
|
|
46
|
+
|
|
47
|
+
| V3 | V4 |
|
|
48
|
+
| --- | --- |
|
|
49
|
+
| `columnPinning: { left, right }` | `columnPinning: { start, end }` |
|
|
50
|
+
| `column.pin('left')`, `getIsPinned() === 'left'` | `column.pin('start')`, `getIsPinned() === 'start'` |
|
|
51
|
+
| `table.getLeftLeafColumns()`, `getRight*`, `row.getLeftVisibleCells()` | `getStartLeafColumns()`, `getEnd*`, `row.getStartVisibleCells()` |
|
|
52
|
+
| `columnSizingInfo`, `onColumnSizingInfoChange`, `setColumnSizingInfo` | `columnResizing`, `onColumnResizingChange`, `setColumnResizing` |
|
|
53
|
+
| `sortingFn`, `sortingFns`, `column.getSortingFn()` | `sortFn`, `sortFns`, `column.getSortFn()` |
|
|
54
|
+
| `table.getPrePaginationRowModel()`, `getPaginationRowModel()` | `getPrePaginatedRowModel()`, `getPaginatedRowModel()` |
|
|
55
|
+
| `column.getAggregationFn()` | `column.getAggregationFns()` |
|
|
56
|
+
| `MRT_SortingFn`, `MRT_ColumnSizingInfoState` | `MRT_SortFn`, `MRT_ColumnResizingState` (old names remain as deprecated aliases) |
|
|
57
|
+
|
|
58
|
+
### Behaviour changes to audit
|
|
59
|
+
|
|
60
|
+
- `rowSelection` values are `true`, never `false`. Deselect by deleting the key.
|
|
61
|
+
- `rowPinning` needs both `top` and `bottom`; `columnPinning` needs both `start` and `end` when passed through `initialState` or `state`.
|
|
62
|
+
- `table.getIsSomeRowsSelected()` is `true` when all rows are selected. Indeterminate is `getIsSomeRowsSelected() && !getIsAllRowsSelected()`.
|
|
63
|
+
- A custom `aggregationFn` is `{ aggregate: (context) => value }`, not a callable. Built-in names still work.
|
|
64
|
+
- `getCoreRowModel`, `getFilteredRowModel`, `getSortedRowModel`, `getPaginationRowModel`, `getExpandedRowModel`, `getGroupedRowModel`, and `getFaceted*` options are gone; the models are always registered. Use `manual*` to take over a stage.
|
|
65
|
+
- Rows with `renderDetailPanel` report `row.getCanExpand()` as `true`. Pass `getRowCanExpand` to restrict it.
|
|
66
|
+
- `onStateChange` and `table.setState()` are gone. Control slices individually.
|
|
67
|
+
- `table.getState()` still returns the full state; `table.state` is reactive in render code.
|
|
68
|
+
- Pinned cells use `insetInlineStart` and `insetInlineEnd`, so RTL pins to the logical start and end.
|
|
69
|
+
|
|
70
|
+
### Material UI V9 changes inside MRT options
|
|
71
|
+
|
|
72
|
+
```diff
|
|
73
|
+
muiFilterTextFieldProps: {
|
|
74
|
+
- InputProps: { sx: { minWidth: 120 } },
|
|
75
|
+
+ slotProps: { input: { sx: { minWidth: 120 } } },
|
|
76
|
+
},
|
|
77
|
+
-const pickerProps: DatePickerProps<Dayjs> = { ... };
|
|
78
|
+
+const pickerProps: DatePickerProps = { ... };
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`muiFilterDatePickerProps`, `muiFilterDateTimePickerProps`, and `muiFilterTimePickerProps` are no longer generic, and the filter pickers render `PickersTextField`, so a custom `slots.textField` must accept `PickersTextFieldProps`. Everything else in `mui*Props` passes straight to Material UI, so Material UI's own V7 and V9 notes apply.
|
|
82
|
+
|
|
83
|
+
### Package entry points
|
|
84
|
+
|
|
85
|
+
The package ships an `exports` map with `.mjs` and `.js` builds. Only `@lminii/material-react-table`, `@lminii/material-react-table/locales/<code>`, and `@lminii/material-react-table/package.json` resolve; deep imports into `dist/` or `src/` fail at build time and must be replaced with root exports.
|
|
86
|
+
|
|
87
|
+
## Common Mistakes
|
|
88
|
+
|
|
89
|
+
### HIGH Keeping v8 pinning literals
|
|
90
|
+
|
|
91
|
+
Wrong:
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
initialState: { columnPinning: { left: ['mrt-row-select'], right: ['mrt-row-actions'] } }
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Correct:
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
initialState: { columnPinning: { start: ['mrt-row-select'], end: ['mrt-row-actions'] } }
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`left` and `right` are no longer valid keys, so the pinning state is silently empty.
|
|
104
|
+
|
|
105
|
+
Source: `MIGRATION.md`
|
|
106
|
+
|
|
107
|
+
### HIGH Passing row model factories
|
|
108
|
+
|
|
109
|
+
Wrong:
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
useMaterialReactTable({ columns, data, getSortedRowModel: getSortedRowModel() })
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Correct:
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
useMaterialReactTable({ columns, data })
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The options no longer exist in `MRT_TableOptions`; MRT registers every row model itself.
|
|
122
|
+
|
|
123
|
+
Source: `packages/material-react-table/src/features/mrtFeatures.ts`
|
|
124
|
+
|
|
125
|
+
### MEDIUM Treating the migration as a TanStack useTable rewrite
|
|
126
|
+
|
|
127
|
+
Wrong:
|
|
128
|
+
|
|
129
|
+
```tsx
|
|
130
|
+
const table = useTable({ features: tableFeatures({ rowSortingFeature }), columns, data })
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Correct:
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
const table = useMaterialReactTable({ columns, data })
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
The `@tanstack/react-table#migrate-v8-to-v9` skill describes migrating a headless table. MRT applications stay on `useMaterialReactTable`; only the renamed instance methods and state shapes from that skill apply.
|
|
140
|
+
|
|
141
|
+
Source: `MIGRATION.md`
|
|
142
|
+
|
|
143
|
+
### LOW Deep-importing a locale file
|
|
144
|
+
|
|
145
|
+
Wrong:
|
|
146
|
+
|
|
147
|
+
```tsx
|
|
148
|
+
import { MRT_Localization_FR } from '@lminii/material-react-table/dist/locales/fr'
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Correct:
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
import { MRT_Localization_FR } from '@lminii/material-react-table/locales/fr'
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Source: `packages/material-react-table/package.json` exports map
|
|
158
|
+
|
|
159
|
+
## API Discovery
|
|
160
|
+
|
|
161
|
+
Compare `node_modules/@lminii/material-react-table/dist/index.d.ts` against the V3 declarations for renamed members; the deprecated `MRT_SortingFn` and `MRT_ColumnSizingInfoState` aliases carry JSDoc pointing to the new names. The full guide with tables is at `/docs/getting-started/migrating-to-v4`.
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: state-and-server-data
|
|
3
|
+
description: >
|
|
4
|
+
Control Material React Table V4 state with initialState, the state option plus on*Change callbacks, MRT_Updater handlers, table.getState and table.state, and move filtering, sorting, pagination, grouping, or expanding to the server with manual* options and rowCount. Load for controlled tables, persisted state, side effects on state change, TanStack Query integration, or infinite scrolling.
|
|
5
|
+
metadata:
|
|
6
|
+
type: framework
|
|
7
|
+
library: '@lminii/material-react-table'
|
|
8
|
+
library_version: '4.0.0'
|
|
9
|
+
framework: react
|
|
10
|
+
requires:
|
|
11
|
+
- getting-started
|
|
12
|
+
- '@tanstack/table-core#client-vs-server'
|
|
13
|
+
sources:
|
|
14
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/guides/state-management.mdx'
|
|
15
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/guides/pagination.mdx'
|
|
16
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/guides/async-loading.mdx'
|
|
17
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/examples/react-query/sandbox/src/TS.tsx'
|
|
18
|
+
- 'lminii/material-react-table:packages/material-react-table/src/types.ts'
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
This skill builds on `getting-started` and `@tanstack/table-core#client-vs-server`. MRT manages every state slice internally by default. Take over only the slices you need to read or persist, and only through the `state` option paired with the matching `on*Change` callback.
|
|
22
|
+
|
|
23
|
+
## Setup
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
const [pagination, setPagination] = useState<MRT_PaginationState>({ pageIndex: 0, pageSize: 25 })
|
|
27
|
+
const [sorting, setSorting] = useState<MRT_SortingState>([])
|
|
28
|
+
|
|
29
|
+
const table = useMaterialReactTable({
|
|
30
|
+
columns,
|
|
31
|
+
data,
|
|
32
|
+
initialState: { density: 'compact', showColumnFilters: true },
|
|
33
|
+
state: { pagination, sorting },
|
|
34
|
+
onPaginationChange: setPagination,
|
|
35
|
+
onSortingChange: setSorting,
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`initialState` seeds slices MRT keeps managing. `state` hands a slice over to you; from then on MRT calls `on<Slice>Change` and reads only what you pass back. Do not put the same slice in both.
|
|
40
|
+
|
|
41
|
+
## Core Patterns
|
|
42
|
+
|
|
43
|
+
### Handle updaters like React setState
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
import { type MRT_Updater, type MRT_RowSelectionState } from '@lminii/material-react-table'
|
|
47
|
+
|
|
48
|
+
const handleRowSelectionChange = (updater: MRT_Updater<MRT_RowSelectionState>) => {
|
|
49
|
+
setRowSelection((previous) => {
|
|
50
|
+
const next = updater instanceof Function ? updater(previous) : updater
|
|
51
|
+
onSelectionChanged(Object.keys(next)) // side effect runs once, even in Strict Mode
|
|
52
|
+
return next
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Callbacks receive either a value or an updater function, exactly like `useState`. Use `getRowId` so selection keys are stable ids instead of row indexes.
|
|
58
|
+
|
|
59
|
+
### Server-side data with manual* options
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
const { data: page, isLoading, isError, isRefetching } = useQuery({
|
|
63
|
+
queryKey: ['people', pagination, sorting, columnFilters, globalFilter],
|
|
64
|
+
queryFn: () => fetchPeople({ pagination, sorting, columnFilters, globalFilter }),
|
|
65
|
+
placeholderData: keepPreviousData,
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const table = useMaterialReactTable({
|
|
69
|
+
columns,
|
|
70
|
+
data: page?.rows ?? EMPTY,
|
|
71
|
+
rowCount: page?.total ?? 0,
|
|
72
|
+
manualFiltering: true,
|
|
73
|
+
manualPagination: true,
|
|
74
|
+
manualSorting: true,
|
|
75
|
+
state: { pagination, sorting, columnFilters, globalFilter, isLoading, showAlertBanner: isError, showProgressBars: isRefetching },
|
|
76
|
+
onPaginationChange: setPagination,
|
|
77
|
+
onSortingChange: setSorting,
|
|
78
|
+
onColumnFiltersChange: setColumnFilters,
|
|
79
|
+
onGlobalFilterChange: setGlobalFilter,
|
|
80
|
+
muiToolbarAlertBannerProps: isError ? { color: 'error', children: 'Error loading data' } : undefined,
|
|
81
|
+
})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Each `manual*` option tells MRT that stage already happened on the server, so the client row model passes rows through. `rowCount` (or `pageCount`) drives the pagination controls. `isLoading`, `showProgressBars`, `showSkeletons`, and `showLoadingOverlay` are MRT state slices meant to be set from fetch status.
|
|
85
|
+
|
|
86
|
+
### Read state without controlling it
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
const table = useMaterialReactTable({ columns, data })
|
|
90
|
+
|
|
91
|
+
<Button onClick={() => save(table.getState().columnVisibility)}>Save layout</Button>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`table.getState()` returns the complete state, including MRT-only slices such as `density`, `isFullScreen`, `showColumnFilters`, `editingRow`, and `creatingRow`. In render code `table.state` is reactive. Setters such as `table.setPagination`, `table.resetSorting`, `table.setShowColumnFilters`, and `table.setDensity` exist for every slice.
|
|
95
|
+
|
|
96
|
+
### Persist state
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
const [columnVisibility, setColumnVisibility] = useState<MRT_VisibilityState>(
|
|
100
|
+
() => JSON.parse(localStorage.getItem('people-columns') ?? '{}'),
|
|
101
|
+
)
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
localStorage.setItem('people-columns', JSON.stringify(columnVisibility))
|
|
104
|
+
}, [columnVisibility])
|
|
105
|
+
|
|
106
|
+
const table = useMaterialReactTable({
|
|
107
|
+
columns,
|
|
108
|
+
data,
|
|
109
|
+
state: { columnVisibility },
|
|
110
|
+
onColumnVisibilityChange: setColumnVisibility,
|
|
111
|
+
})
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Common Mistakes
|
|
115
|
+
|
|
116
|
+
### HIGH Passing on*Change without state
|
|
117
|
+
|
|
118
|
+
Wrong:
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
const table = useMaterialReactTable({ columns, data, onSortingChange: setSorting })
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Correct:
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
const table = useMaterialReactTable({
|
|
128
|
+
columns,
|
|
129
|
+
data,
|
|
130
|
+
state: { sorting },
|
|
131
|
+
onSortingChange: setSorting,
|
|
132
|
+
})
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Once a callback is supplied, MRT stops updating that slice itself. Without `state`, the table never sorts.
|
|
136
|
+
|
|
137
|
+
Source: `docs/guides/state-management.mdx`
|
|
138
|
+
|
|
139
|
+
### HIGH Toggling row selection with false
|
|
140
|
+
|
|
141
|
+
Wrong:
|
|
142
|
+
|
|
143
|
+
```tsx
|
|
144
|
+
setRowSelection((old) => ({ ...old, [id]: false }))
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Correct:
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
setRowSelection(({ [id]: _removed, ...rest }) => rest)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
TanStack Table V9 types `rowSelection` as `Record<string, true>`, so a `false` entry is a type error; absence of the key is the only deselected state.
|
|
154
|
+
|
|
155
|
+
Source: `MIGRATION.md`
|
|
156
|
+
|
|
157
|
+
### MEDIUM Using onStateChange or table.setState
|
|
158
|
+
|
|
159
|
+
Wrong:
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
onStateChange: (updater) => setTableState(updater)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Correct:
|
|
166
|
+
|
|
167
|
+
```tsx
|
|
168
|
+
state: { pagination, sorting },
|
|
169
|
+
onPaginationChange: setPagination,
|
|
170
|
+
onSortingChange: setSorting,
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
`onStateChange` and `table.setState` were removed with TanStack Table V9. Control slices individually.
|
|
174
|
+
|
|
175
|
+
Source: `MIGRATION.md`
|
|
176
|
+
|
|
177
|
+
### MEDIUM Forgetting rowCount with manualPagination
|
|
178
|
+
|
|
179
|
+
Wrong:
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
manualPagination: true,
|
|
183
|
+
data: page.rows,
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Correct:
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
manualPagination: true,
|
|
190
|
+
data: page.rows,
|
|
191
|
+
rowCount: page.total,
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Without a total, MRT assumes the current page is all the data and disables the next page button.
|
|
195
|
+
|
|
196
|
+
Source: `docs/guides/pagination.mdx`
|
|
197
|
+
|
|
198
|
+
## API Discovery
|
|
199
|
+
|
|
200
|
+
`MRT_TableState` in `node_modules/@lminii/material-react-table/dist/index.d.ts` lists every slice; each has an `on<Slice>Change` option and `table.set<Slice>` method. The State Options table at `/docs/api/state-options` shows defaults, and the `manual*` and `rowCount` options are in `/docs/api/table-options`.
|