@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,189 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: composable-components
|
|
3
|
+
description: >
|
|
4
|
+
Compose a custom Material React Table V4 layout from exported MRT_* components that all take the same table prop: MRT_TablePaper, MRT_TableContainer, MRT_Table, MRT_TopToolbar, MRT_TablePagination, MRT_GlobalFilterTextField, MRT_ToolbarInternalButtons, MRT_ShowHideColumnsButton, and MRT_TableBodyCellValue for fully custom markup. Load for tables inside cards or dialogs, toolbars placed outside the table, split layouts, or headless rendering with MRT state.
|
|
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/api/mrt-components.mdx'
|
|
14
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/examples/custom-headless/sandbox/src/TS.tsx'
|
|
15
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/examples/custom-top-toolbar/sandbox/src/TS.tsx'
|
|
16
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/examples/external-toolbar/sandbox/src/TS.tsx'
|
|
17
|
+
- 'lminii/material-react-table:packages/material-react-table/src/index.ts'
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
This skill builds on `getting-started`. `MaterialReactTable` is a thin composition of exported sub-components. Because every sub-component takes the same `table` instance as a prop, you can render any subset of them anywhere in your tree while MRT keeps managing state.
|
|
21
|
+
|
|
22
|
+
## Setup
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import {
|
|
26
|
+
MRT_GlobalFilterTextField,
|
|
27
|
+
MRT_TableContainer,
|
|
28
|
+
MRT_TablePagination,
|
|
29
|
+
MRT_ToggleFiltersButton,
|
|
30
|
+
useMaterialReactTable,
|
|
31
|
+
} from '@lminii/material-react-table'
|
|
32
|
+
|
|
33
|
+
const table = useMaterialReactTable({ columns, data, enableBottomToolbar: false })
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<Card>
|
|
37
|
+
<CardHeader
|
|
38
|
+
title="People"
|
|
39
|
+
action={
|
|
40
|
+
<Stack direction="row" gap={1}>
|
|
41
|
+
<MRT_GlobalFilterTextField table={table} />
|
|
42
|
+
<MRT_ToggleFiltersButton table={table} />
|
|
43
|
+
</Stack>
|
|
44
|
+
}
|
|
45
|
+
/>
|
|
46
|
+
<MRT_TableContainer table={table} />
|
|
47
|
+
<CardActions sx={{ justifyContent: 'flex-end' }}>
|
|
48
|
+
<MRT_TablePagination table={table} />
|
|
49
|
+
</CardActions>
|
|
50
|
+
</Card>
|
|
51
|
+
)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`MRT_TableContainer` renders the scroll container, the table, the loading overlay, the edit row modal, and the cell action menu. Turn off the built-in toolbars with `enableTopToolbar` and `enableBottomToolbar` when you place their pieces elsewhere.
|
|
55
|
+
|
|
56
|
+
## Core Patterns
|
|
57
|
+
|
|
58
|
+
### Layers of the default component
|
|
59
|
+
|
|
60
|
+
```text
|
|
61
|
+
MRT_TablePaper
|
|
62
|
+
MRT_TopToolbar
|
|
63
|
+
MRT_GlobalFilterTextField, MRT_ToolbarInternalButtons, MRT_ToolbarAlertBanner, MRT_TablePagination
|
|
64
|
+
MRT_TableContainer
|
|
65
|
+
MRT_Table
|
|
66
|
+
MRT_TableHead > MRT_TableHeadRow > MRT_TableHeadCell
|
|
67
|
+
MRT_TableBody > MRT_TableBodyRow > MRT_TableBodyCell, MRT_TableDetailPanel
|
|
68
|
+
MRT_TableFooter > MRT_TableFooterRow > MRT_TableFooterCell
|
|
69
|
+
MRT_BottomToolbar
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Start from the layer just above what you need to change. Replacing `MRT_TopToolbar` with your own component is the most common cut; replacing `MRT_TableBodyRow` is rarely worth it because `muiTableBodyRowProps` covers styling and events.
|
|
73
|
+
|
|
74
|
+
### Toolbar buttons are individual exports
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
import {
|
|
78
|
+
MRT_ShowHideColumnsButton,
|
|
79
|
+
MRT_ToggleDensePaddingButton,
|
|
80
|
+
MRT_ToggleFullScreenButton,
|
|
81
|
+
} from '@lminii/material-react-table'
|
|
82
|
+
|
|
83
|
+
<MRT_ShowHideColumnsButton table={table} />
|
|
84
|
+
<MRT_ToggleDensePaddingButton table={table} />
|
|
85
|
+
<MRT_ToggleFullScreenButton table={table} />
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Each button reads and writes MRT state on the shared instance, so it works from any position in the tree.
|
|
89
|
+
|
|
90
|
+
### Fully custom markup with MRT_TableBodyCellValue
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
import { MRT_TableBodyCellValue, flexRender } from '@lminii/material-react-table'
|
|
94
|
+
|
|
95
|
+
<Table>
|
|
96
|
+
<TableHead>
|
|
97
|
+
{table.getHeaderGroups().map((group) => (
|
|
98
|
+
<TableRow key={group.id}>
|
|
99
|
+
{group.headers.map((header) => (
|
|
100
|
+
<TableCell key={header.id}>
|
|
101
|
+
{header.isPlaceholder ? null : flexRender(header.column.columnDef.Header ?? header.column.columnDef.header, header.getContext())}
|
|
102
|
+
</TableCell>
|
|
103
|
+
))}
|
|
104
|
+
</TableRow>
|
|
105
|
+
))}
|
|
106
|
+
</TableHead>
|
|
107
|
+
<TableBody>
|
|
108
|
+
{table.getRowModel().rows.map((row, staticRowIndex) => (
|
|
109
|
+
<TableRow key={row.id} selected={row.getIsSelected()}>
|
|
110
|
+
{row.getVisibleCells().map((cell) => (
|
|
111
|
+
<TableCell key={cell.id}>
|
|
112
|
+
<MRT_TableBodyCellValue cell={cell} table={table} staticRowIndex={staticRowIndex} />
|
|
113
|
+
</TableCell>
|
|
114
|
+
))}
|
|
115
|
+
</TableRow>
|
|
116
|
+
))}
|
|
117
|
+
</TableBody>
|
|
118
|
+
</Table>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`MRT_TableBodyCellValue` applies the column's `Cell`, `AggregatedCell`, `GroupedCell`, filter match highlighting, and click to copy, so custom markup keeps MRT cell behaviour. `table.getRowModel()` is the final model after filtering, sorting, grouping, expanding, and pagination.
|
|
122
|
+
|
|
123
|
+
### Row virtualization in custom layouts
|
|
124
|
+
|
|
125
|
+
Render `MRT_TableContainer` rather than `MRT_Table` when `enableRowVirtualization` or `enableColumnVirtualization` is on. The container owns the scroll element the virtualizers measure.
|
|
126
|
+
|
|
127
|
+
## Common Mistakes
|
|
128
|
+
|
|
129
|
+
### HIGH Rendering MRT components without the table prop
|
|
130
|
+
|
|
131
|
+
Wrong:
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
<MRT_TablePagination />
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Correct:
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
<MRT_TablePagination table={table} />
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
MRT does not use React context. Every component requires the instance explicitly.
|
|
144
|
+
|
|
145
|
+
Source: `packages/material-react-table/src/components/toolbar/MRT_TablePagination.tsx`
|
|
146
|
+
|
|
147
|
+
### MEDIUM Duplicating the toolbar
|
|
148
|
+
|
|
149
|
+
Wrong:
|
|
150
|
+
|
|
151
|
+
```tsx
|
|
152
|
+
const table = useMaterialReactTable({ columns, data })
|
|
153
|
+
<MRT_GlobalFilterTextField table={table} />
|
|
154
|
+
<MaterialReactTable table={table} />
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Correct:
|
|
158
|
+
|
|
159
|
+
```tsx
|
|
160
|
+
const table = useMaterialReactTable({ columns, data, enableTopToolbar: false })
|
|
161
|
+
<MRT_GlobalFilterTextField table={table} />
|
|
162
|
+
<MaterialReactTable table={table} />
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The default top toolbar already contains the search field, so two inputs fight over `globalFilter`.
|
|
166
|
+
|
|
167
|
+
Source: `docs/api/mrt-components.mdx`
|
|
168
|
+
|
|
169
|
+
### MEDIUM Using a v8 header render
|
|
170
|
+
|
|
171
|
+
Wrong:
|
|
172
|
+
|
|
173
|
+
```tsx
|
|
174
|
+
flexRender(header.column.columnDef.header, header.getContext())
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Correct:
|
|
178
|
+
|
|
179
|
+
```tsx
|
|
180
|
+
flexRender(header.column.columnDef.Header ?? header.column.columnDef.header, header.getContext())
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
MRT columns carry both `header` (string) and `Header` (custom render). Falling back to the string alone drops custom header markup.
|
|
184
|
+
|
|
185
|
+
Source: `apps/material-react-table-docs/examples/custom-headless/sandbox/src/TS.tsx`
|
|
186
|
+
|
|
187
|
+
## API Discovery
|
|
188
|
+
|
|
189
|
+
`node_modules/@lminii/material-react-table/dist/index.d.ts` exports every `MRT_*` component with its props interface; all of them include `table: MRT_TableInstance<TData>`. The component tree with links to source is at `/docs/api/mrt-components`.
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: customization
|
|
3
|
+
description: >
|
|
4
|
+
Style and extend Material React Table V4 through mui*Props objects and callbacks, the sx prop, Material UI V9 slotProps on text fields, render* slots for toolbars, row actions, detail panels and empty states, displayColumnDefOptions, icons, and localization. Load for theming, conditional row or cell styling, custom toolbar buttons, or replacing built-in display columns.
|
|
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/customize-components.mdx'
|
|
14
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/guides/display-columns.mdx'
|
|
15
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/guides/toolbar-customization.mdx'
|
|
16
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/guides/row-actions.mdx'
|
|
17
|
+
- 'lminii/material-react-table:MIGRATION.md'
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
This skill builds on `getting-started`. MRT renders Material UI components and forwards props to each of them through a matching `mui<Component>Props` option, so customization means passing Material UI props, not overriding MRT internals.
|
|
21
|
+
|
|
22
|
+
## Setup
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
const table = useMaterialReactTable({
|
|
26
|
+
columns,
|
|
27
|
+
data,
|
|
28
|
+
muiTablePaperProps: { elevation: 0, sx: { borderRadius: 0 } },
|
|
29
|
+
muiTableBodyRowProps: ({ row }) => ({
|
|
30
|
+
sx: { backgroundColor: row.getIsSelected() ? 'action.selected' : undefined },
|
|
31
|
+
}),
|
|
32
|
+
muiTableBodyCellProps: ({ column }) => ({
|
|
33
|
+
align: column.id === 'amount' ? 'right' : 'left',
|
|
34
|
+
}),
|
|
35
|
+
})
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Every `mui*Props` option accepts a static object or a callback. The callback receives `table` plus whatever is in scope for that component: `row`, `cell`, `column`, `staticRowIndex`, `isDetailPanel`, and similar. Static objects are cheaper; use a callback only when the props depend on data.
|
|
39
|
+
|
|
40
|
+
## Core Patterns
|
|
41
|
+
|
|
42
|
+
### Text field options use Material UI V9 slotProps
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
muiSearchTextFieldProps: {
|
|
46
|
+
placeholder: 'Search people',
|
|
47
|
+
slotProps: {
|
|
48
|
+
input: { startAdornment: <SearchIcon /> },
|
|
49
|
+
htmlInput: { 'aria-label': 'Search people' },
|
|
50
|
+
inputLabel: { shrink: true },
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`muiEditTextFieldProps`, `muiFilterTextFieldProps`, and `muiSearchTextFieldProps` take `slotProps.input`, `slotProps.htmlInput`, `slotProps.select`, and `slotProps.inputLabel`. MRT merges the object form of each slot after its own defaults and composes `sx`. The function form `(ownerState) => props` is ignored.
|
|
56
|
+
|
|
57
|
+
### Column-level props override table-level props
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
const columns: MRT_ColumnDef<Person>[] = [
|
|
61
|
+
{
|
|
62
|
+
accessorKey: 'salary',
|
|
63
|
+
header: 'Salary',
|
|
64
|
+
muiTableHeadCellProps: { align: 'right' },
|
|
65
|
+
muiTableBodyCellProps: { align: 'right' },
|
|
66
|
+
Cell: ({ cell }) => cell.getValue<number>().toLocaleString('en-US', { style: 'currency', currency: 'USD' }),
|
|
67
|
+
},
|
|
68
|
+
]
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`muiTableHeadCellProps`, `muiTableBodyCellProps`, `muiTableFooterCellProps`, `muiFilter*Props`, `muiEditTextFieldProps`, `muiCopyButtonProps`, and `muiColumnActionsButtonProps` exist on both the table options and the column definition. The column value wins.
|
|
72
|
+
|
|
73
|
+
### render* slots add UI without replacing MRT components
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
const table = useMaterialReactTable({
|
|
77
|
+
columns,
|
|
78
|
+
data,
|
|
79
|
+
enableRowActions: true,
|
|
80
|
+
positionActionsColumn: 'last',
|
|
81
|
+
renderRowActionMenuItems: ({ row, closeMenu }) => [
|
|
82
|
+
<MenuItem key="edit" onClick={() => { edit(row.original); closeMenu() }}>Edit</MenuItem>,
|
|
83
|
+
],
|
|
84
|
+
renderTopToolbarCustomActions: ({ table }) => (
|
|
85
|
+
<Button onClick={() => exportRows(table.getPrePaginatedRowModel().rows)}>Export</Button>
|
|
86
|
+
),
|
|
87
|
+
renderDetailPanel: ({ row }) => <Address address={row.original.address} />,
|
|
88
|
+
renderEmptyRowsFallback: () => <Typography>No people match these filters</Typography>,
|
|
89
|
+
})
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`renderTopToolbar` and `renderBottomToolbar` replace the whole toolbar; `renderTopToolbarCustomActions`, `renderBottomToolbarCustomActions`, and `renderToolbarInternalActions` add to it. `renderRowActions` renders inline buttons; `renderRowActionMenuItems` fills the kebab menu. `renderDetailPanel` also makes every row expandable.
|
|
93
|
+
|
|
94
|
+
### Adjust built-in display columns
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
displayColumnDefOptions: {
|
|
98
|
+
'mrt-row-actions': { header: '', size: 80, muiTableHeadCellProps: { align: 'center' } },
|
|
99
|
+
'mrt-row-select': { enableColumnActions: false },
|
|
100
|
+
'mrt-row-expand': { size: 40 },
|
|
101
|
+
},
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Display column ids are `mrt-row-actions`, `mrt-row-drag`, `mrt-row-expand`, `mrt-row-numbers`, `mrt-row-pin`, `mrt-row-select`, and `mrt-row-spacer`. They exist only when the matching feature is enabled.
|
|
105
|
+
|
|
106
|
+
### Icons and localization
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import { MRT_Localization_DE } from '@lminii/material-react-table/locales/de'
|
|
110
|
+
|
|
111
|
+
const table = useMaterialReactTable({
|
|
112
|
+
columns,
|
|
113
|
+
data,
|
|
114
|
+
localization: MRT_Localization_DE,
|
|
115
|
+
icons: { SearchIcon: (props) => <TravelExploreIcon {...props} /> },
|
|
116
|
+
})
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`icons` accepts a partial `MRT_Icons` map; `localization` accepts a partial `MRT_Localization`, so overriding a few strings is fine.
|
|
120
|
+
|
|
121
|
+
## Common Mistakes
|
|
122
|
+
|
|
123
|
+
### HIGH Passing removed Material UI text field props
|
|
124
|
+
|
|
125
|
+
Wrong:
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
muiSearchTextFieldProps: {
|
|
129
|
+
InputProps: { startAdornment: <SearchIcon /> },
|
|
130
|
+
inputProps: { 'aria-label': 'Search' },
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Correct:
|
|
135
|
+
|
|
136
|
+
```tsx
|
|
137
|
+
muiSearchTextFieldProps: {
|
|
138
|
+
slotProps: {
|
|
139
|
+
input: { startAdornment: <SearchIcon /> },
|
|
140
|
+
htmlInput: { 'aria-label': 'Search' },
|
|
141
|
+
},
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Material UI V9 removed `InputProps`, `inputProps`, `SelectProps`, `InputLabelProps`, and `FormHelperTextProps` from `TextField`, so the old keys are type errors and are never applied.
|
|
146
|
+
|
|
147
|
+
Source: `MIGRATION.md`
|
|
148
|
+
|
|
149
|
+
### MEDIUM Styling with a class selector instead of the sx prop
|
|
150
|
+
|
|
151
|
+
Wrong:
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
muiTableBodyCellProps: { className: 'my-cell' }
|
|
155
|
+
// plus a global .my-cell rule fighting Material UI specificity
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Correct:
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
muiTableBodyCellProps: {
|
|
162
|
+
sx: (theme) => ({ borderRight: `1px solid ${theme.palette.divider}` }),
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
`sx` receives the Material UI theme and wins the specificity contest with Emotion styles that MRT already applies.
|
|
167
|
+
|
|
168
|
+
Source: `docs/guides/customize-components.mdx`
|
|
169
|
+
|
|
170
|
+
### MEDIUM Replacing the toolbar when only a button was needed
|
|
171
|
+
|
|
172
|
+
Wrong:
|
|
173
|
+
|
|
174
|
+
```tsx
|
|
175
|
+
renderTopToolbar: ({ table }) => <Button onClick={add}>Add</Button>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Correct:
|
|
179
|
+
|
|
180
|
+
```tsx
|
|
181
|
+
renderTopToolbarCustomActions: ({ table }) => <Button onClick={add}>Add</Button>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
`renderTopToolbar` removes the search box, filter toggle, density and full screen buttons, and the alert banner. The `*CustomActions` slot keeps them.
|
|
185
|
+
|
|
186
|
+
Source: `docs/guides/toolbar-customization.mdx`
|
|
187
|
+
|
|
188
|
+
## API Discovery
|
|
189
|
+
|
|
190
|
+
Search `node_modules/@lminii/material-react-table/dist/index.d.ts` for `mui` to see every prop option and its callback arguments, and for `render` to see every render slot. The Customize Components guide at `/docs/guides/customize-components` lists the options per component, and `/docs/api/column-options` marks which options also exist on columns.
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: drag-and-drop-ordering
|
|
3
|
+
description: >
|
|
4
|
+
Reorder columns and rows by drag and drop in Material React Table V4: enableColumnOrdering with the columnOrder state and mrt-row-* display column ids, enableRowOrdering with muiRowDragHandleProps onDragEnd reading draggingRow and hoveredRow, enableRowDragging for dropping rows onto other tables or UI, enableColumnDragging for column drags without reordering, and the draggingColumn, hoveredColumn, draggingRow, hoveredRow state. Load for user-arranged columns, sortable lists, moving rows between tables, or a drop that never fires.
|
|
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
|
+
- state-and-server-data
|
|
13
|
+
- '@tanstack/table-core#column-ordering'
|
|
14
|
+
sources:
|
|
15
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/guides/column-ordering-dnd.mdx'
|
|
16
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/guides/row-ordering-dnd.mdx'
|
|
17
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/examples/enable-row-ordering/sandbox/src/TS.tsx'
|
|
18
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/examples/enable-row-dragging/sandbox/src/TS.tsx'
|
|
19
|
+
- 'lminii/material-react-table:packages/material-react-table/src/components/body/MRT_TableBodyRowGrabHandle.tsx'
|
|
20
|
+
- 'lminii/material-react-table:packages/material-react-table/src/utils/column.utils.ts'
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
This skill builds on `getting-started`, `state-and-server-data`, and `@tanstack/table-core#column-ordering`. MRT uses native HTML drag events with a grab handle button. Column ordering is fully built in; row ordering exposes the drag state and leaves the reorder of `data` to you.
|
|
24
|
+
|
|
25
|
+
## Setup
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
const table = useMaterialReactTable({
|
|
29
|
+
columns,
|
|
30
|
+
data,
|
|
31
|
+
enableColumnOrdering: true, // drag handles in every header
|
|
32
|
+
enableRowOrdering: true, // adds the mrt-row-drag display column
|
|
33
|
+
enableSorting: false, // manual order and sorting fight each other
|
|
34
|
+
muiRowDragHandleProps: ({ table }) => ({
|
|
35
|
+
onDragEnd: () => {
|
|
36
|
+
const { draggingRow, hoveredRow } = table.getState()
|
|
37
|
+
if (draggingRow && hoveredRow) {
|
|
38
|
+
setData((old) => {
|
|
39
|
+
const next = [...old]
|
|
40
|
+
next.splice(hoveredRow.index!, 0, next.splice(draggingRow.index, 1)[0])
|
|
41
|
+
return next
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
}),
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Column-level `enableColumnOrdering: false` removes the handle from one column. `hoveredRow` and `hoveredColumn` are typed as partial objects because a drop target may be a placeholder; read `index` or `id` and guard for undefined.
|
|
50
|
+
|
|
51
|
+
## Core Patterns
|
|
52
|
+
|
|
53
|
+
### Set or persist the column order
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
const [columnOrder, setColumnOrder] = useState<MRT_ColumnOrderState>([
|
|
57
|
+
'mrt-row-select',
|
|
58
|
+
'name',
|
|
59
|
+
'email',
|
|
60
|
+
'mrt-row-actions',
|
|
61
|
+
])
|
|
62
|
+
|
|
63
|
+
const table = useMaterialReactTable({
|
|
64
|
+
columns,
|
|
65
|
+
data,
|
|
66
|
+
enableRowSelection: true,
|
|
67
|
+
enableRowActions: true,
|
|
68
|
+
enableColumnOrdering: true,
|
|
69
|
+
state: { columnOrder },
|
|
70
|
+
onColumnOrderChange: setColumnOrder,
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`columnOrder` is an array of column ids (`accessorKey` or `id`). Include the display column ids you enable (`mrt-row-select`, `mrt-row-actions`, `mrt-row-expand`, `mrt-row-numbers`, `mrt-row-drag`, `mrt-row-pin`) at the position you want; missing ones are appended at the start or end. If the array length does not match the column count MRT regenerates it, so `initialState.columnOrder` is enough when you only need a default. A dropped column is also pinned to the target column's pin position.
|
|
75
|
+
|
|
76
|
+
### Move rows between tables
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
const [draggingRow, setDraggingRow] = useState<MRT_Row<Person> | null>(null)
|
|
80
|
+
const [hoveredTable, setHoveredTable] = useState<string | null>(null)
|
|
81
|
+
|
|
82
|
+
const common = {
|
|
83
|
+
columns,
|
|
84
|
+
enableRowDragging: true, // handle only; no in-table reorder
|
|
85
|
+
onDraggingRowChange: setDraggingRow,
|
|
86
|
+
state: { draggingRow },
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const table1 = useMaterialReactTable({
|
|
90
|
+
...common,
|
|
91
|
+
data: data1,
|
|
92
|
+
getRowId: (row) => `t1-${row.id}`,
|
|
93
|
+
muiRowDragHandleProps: {
|
|
94
|
+
onDragEnd: () => {
|
|
95
|
+
if (hoveredTable === 'table-2' && draggingRow) {
|
|
96
|
+
setData2((rows) => [...rows, draggingRow.original])
|
|
97
|
+
setData1((rows) => rows.filter((r) => r !== draggingRow.original))
|
|
98
|
+
}
|
|
99
|
+
setHoveredTable(null)
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
muiTablePaperProps: {
|
|
103
|
+
onDragEnter: () => setHoveredTable('table-1'),
|
|
104
|
+
sx: { outline: hoveredTable === 'table-1' ? '2px dashed' : undefined },
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`enableRowDragging` shows the handle and maintains `draggingRow` without the in-table hover targets that `enableRowOrdering` adds. Any element can be a drop target through its own `onDragEnter`. Share `draggingRow` across tables by controlling it. Use `enableColumnDragging` the same way for columns that should be draggable onto external targets, for example a group-by drop zone.
|
|
110
|
+
|
|
111
|
+
### Style the drag interaction
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
muiRowDragHandleProps: ({ row }) => ({
|
|
115
|
+
'aria-label': `Move ${row.original.name}`,
|
|
116
|
+
sx: { cursor: 'grab' },
|
|
117
|
+
}),
|
|
118
|
+
muiTableBodyRowProps: ({ row, table }) => ({
|
|
119
|
+
sx: {
|
|
120
|
+
opacity: table.getState().draggingRow?.id === row.id ? 0.5 : 1,
|
|
121
|
+
outline: table.getState().hoveredRow?.id === row.id ? '2px dashed' : undefined,
|
|
122
|
+
},
|
|
123
|
+
}),
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
`muiRowDragHandleProps` takes `IconButtonProps`; your `onDragStart` and `onDragEnd` run before MRT sets or clears `draggingRow`. `muiColumnDragHandleProps` is the column counterpart, and `hoveredColumn` / `draggingColumn` drive header styling. Replace the handle icon through `icons.DragHandleIcon`.
|
|
127
|
+
|
|
128
|
+
### Combine with virtualization
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
enableRowOrdering: true,
|
|
132
|
+
enableRowVirtualization: true,
|
|
133
|
+
enablePagination: false,
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The row virtualizer keeps the dragging row mounted while it is scrolled out of view, so drops still resolve. Keep `autoResetPageIndex: false` when paginated so a drop does not jump back to page one.
|
|
137
|
+
|
|
138
|
+
## Common Mistakes
|
|
139
|
+
|
|
140
|
+
### HIGH Reordering with the wrong row index
|
|
141
|
+
|
|
142
|
+
Wrong:
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
onDragEnd: () => {
|
|
146
|
+
const { draggingRow, hoveredRow } = table.getState()
|
|
147
|
+
data.splice(hoveredRow.index, 0, data.splice(draggingRow.index, 1)[0])
|
|
148
|
+
setData(data) // same array reference, no re-render
|
|
149
|
+
},
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Correct:
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
onDragEnd: () => {
|
|
156
|
+
const { draggingRow, hoveredRow } = table.getState()
|
|
157
|
+
if (!draggingRow || hoveredRow?.index === undefined) return
|
|
158
|
+
setData((old) => {
|
|
159
|
+
const next = [...old]
|
|
160
|
+
next.splice(hoveredRow.index!, 0, next.splice(draggingRow.index, 1)[0])
|
|
161
|
+
return next
|
|
162
|
+
})
|
|
163
|
+
},
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
`row.index` is the index in the original `data` array, so it is only meaningful when no client-side sort or filter is applied; and a mutated array with the same reference does not trigger a render.
|
|
167
|
+
|
|
168
|
+
Source: `docs/examples/enable-row-ordering`
|
|
169
|
+
|
|
170
|
+
### HIGH Expecting a drop callback
|
|
171
|
+
|
|
172
|
+
Wrong:
|
|
173
|
+
|
|
174
|
+
```tsx
|
|
175
|
+
onHoveredRowChange: (row) => moveRow(row), // fires on every hover, not on drop
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Correct:
|
|
179
|
+
|
|
180
|
+
```tsx
|
|
181
|
+
muiRowDragHandleProps: { onDragEnd: () => moveRow(table.getState().hoveredRow) },
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
There is no `onRowDrop`; the drop point is the handle's `onDragEnd`, after which MRT clears `draggingRow` and `hoveredRow`.
|
|
185
|
+
|
|
186
|
+
Source: `packages/material-react-table/src/components/body/MRT_TableBodyRowGrabHandle.tsx`
|
|
187
|
+
|
|
188
|
+
### MEDIUM Leaving sorting on with row ordering
|
|
189
|
+
|
|
190
|
+
Wrong:
|
|
191
|
+
|
|
192
|
+
```tsx
|
|
193
|
+
enableRowOrdering: true,
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Correct:
|
|
197
|
+
|
|
198
|
+
```tsx
|
|
199
|
+
enableRowOrdering: true,
|
|
200
|
+
enableSorting: false,
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
A sorted view re-sorts after every drop, so the user's arrangement disappears and `row.index` no longer maps to the visible position.
|
|
204
|
+
|
|
205
|
+
Source: `docs/guides/row-ordering-dnd.mdx`
|
|
206
|
+
|
|
207
|
+
### MEDIUM Column order array that ignores display columns
|
|
208
|
+
|
|
209
|
+
Wrong:
|
|
210
|
+
|
|
211
|
+
```tsx
|
|
212
|
+
initialState: { columnOrder: ['name', 'email'] }, // with enableRowSelection: true
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Correct:
|
|
216
|
+
|
|
217
|
+
```tsx
|
|
218
|
+
initialState: { columnOrder: ['mrt-row-select', 'name', 'email'] },
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
The length mismatch makes MRT regenerate the order from the column definitions, discarding the custom arrangement.
|
|
222
|
+
|
|
223
|
+
Source: `docs/guides/column-ordering-dnd.mdx`
|
|
224
|
+
|
|
225
|
+
## API Discovery
|
|
226
|
+
|
|
227
|
+
Search `node_modules/@lminii/material-react-table/dist/index.d.ts` for `enableRowOrdering`, `enableRowDragging`, `muiRowDragHandleProps`, `muiColumnDragHandleProps`, `draggingRow`, and `hoveredColumn`. The Column Ordering and Row Ordering guides at `/docs/guides/column-ordering-dnd` and `/docs/guides/row-ordering-dnd` list the related options, and `/docs/examples/enable-column-ordering`, `enable-row-ordering`, and `enable-row-dragging` are runnable examples.
|