@lminii/material-react-table-mcp 4.0.1
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/README.md +68 -0
- package/data/MIGRATION.md +136 -0
- package/data/api.json +5379 -0
- package/data/examples/advanced.js +215 -0
- package/data/examples/advanced.tsx +309 -0
- package/data/examples/aggregation-and-grouping.js +116 -0
- package/data/examples/aggregation-and-grouping.tsx +153 -0
- package/data/examples/aggregation-multi.js +89 -0
- package/data/examples/aggregation-multi.tsx +105 -0
- package/data/examples/alternate-column-filtering.js +38 -0
- package/data/examples/alternate-column-filtering.tsx +49 -0
- package/data/examples/alternate-detail-panel.js +65 -0
- package/data/examples/alternate-detail-panel.tsx +81 -0
- package/data/examples/alternate-pagination.js +17 -0
- package/data/examples/alternate-pagination.tsx +23 -0
- package/data/examples/basic.js +86 -0
- package/data/examples/basic.tsx +109 -0
- package/data/examples/chart-detail-panel.js +69 -0
- package/data/examples/chart-detail-panel.tsx +89 -0
- package/data/examples/column-actions-space.js +34 -0
- package/data/examples/column-actions-space.tsx +44 -0
- package/data/examples/column-alignment.js +58 -0
- package/data/examples/column-alignment.tsx +70 -0
- package/data/examples/custom-column-actions.js +74 -0
- package/data/examples/custom-column-actions.tsx +109 -0
- package/data/examples/custom-column-filtering-ui.js +59 -0
- package/data/examples/custom-column-filtering-ui.tsx +89 -0
- package/data/examples/custom-headless.js +85 -0
- package/data/examples/custom-headless.tsx +125 -0
- package/data/examples/custom-top-toolbar.js +60 -0
- package/data/examples/custom-top-toolbar.tsx +88 -0
- package/data/examples/customize-display-columns.js +72 -0
- package/data/examples/customize-display-columns.tsx +85 -0
- package/data/examples/customize-filter-components.js +78 -0
- package/data/examples/customize-filter-components.tsx +101 -0
- package/data/examples/customize-filter-modes.js +59 -0
- package/data/examples/customize-filter-modes.tsx +73 -0
- package/data/examples/customize-filter-variants.js +98 -0
- package/data/examples/customize-filter-variants.tsx +116 -0
- package/data/examples/customize-global-filter-component.js +37 -0
- package/data/examples/customize-global-filter-component.tsx +52 -0
- package/data/examples/customize-remove-column-grouping.js +75 -0
- package/data/examples/customize-remove-column-grouping.tsx +94 -0
- package/data/examples/customize-row-selection.js +43 -0
- package/data/examples/customize-row-selection.tsx +54 -0
- package/data/examples/customize-table-styles.js +81 -0
- package/data/examples/customize-table-styles.tsx +100 -0
- package/data/examples/disable-column-actions.js +26 -0
- package/data/examples/disable-column-actions.tsx +37 -0
- package/data/examples/disable-column-hiding.js +74 -0
- package/data/examples/disable-column-hiding.tsx +90 -0
- package/data/examples/disable-density-toggle.js +37 -0
- package/data/examples/disable-density-toggle.tsx +49 -0
- package/data/examples/dynamic-columns.js +124 -0
- package/data/examples/dynamic-columns.tsx +189 -0
- package/data/examples/editing-crud-cell.js +288 -0
- package/data/examples/editing-crud-cell.tsx +377 -0
- package/data/examples/editing-crud-modal.js +275 -0
- package/data/examples/editing-crud-modal.tsx +370 -0
- package/data/examples/editing-crud-row.js +255 -0
- package/data/examples/editing-crud-row.tsx +333 -0
- package/data/examples/editing-crud-table.js +280 -0
- package/data/examples/editing-crud-table.tsx +369 -0
- package/data/examples/editing-crud-tree.js +328 -0
- package/data/examples/editing-crud-tree.tsx +416 -0
- package/data/examples/enable-cell-actions.js +52 -0
- package/data/examples/enable-cell-actions.tsx +76 -0
- package/data/examples/enable-click-to-copy.js +33 -0
- package/data/examples/enable-click-to-copy.tsx +39 -0
- package/data/examples/enable-column-grouping.js +69 -0
- package/data/examples/enable-column-grouping.tsx +120 -0
- package/data/examples/enable-column-ordering.js +37 -0
- package/data/examples/enable-column-ordering.tsx +48 -0
- package/data/examples/enable-column-pinning.js +58 -0
- package/data/examples/enable-column-pinning.tsx +69 -0
- package/data/examples/enable-column-resizing.js +45 -0
- package/data/examples/enable-column-resizing.tsx +56 -0
- package/data/examples/enable-column-virtualization.js +19 -0
- package/data/examples/enable-column-virtualization.tsx +27 -0
- package/data/examples/enable-detail-panel-conditionally.js +61 -0
- package/data/examples/enable-detail-panel-conditionally.tsx +78 -0
- package/data/examples/enable-detail-panel-virtualized.js +64 -0
- package/data/examples/enable-detail-panel-virtualized.tsx +80 -0
- package/data/examples/enable-expanding-tree.js +87 -0
- package/data/examples/enable-expanding-tree.tsx +110 -0
- package/data/examples/enable-filter-facet-values.js +52 -0
- package/data/examples/enable-filter-facet-values.tsx +65 -0
- package/data/examples/enable-row-dragging.js +102 -0
- package/data/examples/enable-row-dragging.tsx +137 -0
- package/data/examples/enable-row-numbers-original.js +37 -0
- package/data/examples/enable-row-numbers-original.tsx +48 -0
- package/data/examples/enable-row-numbers-static.js +37 -0
- package/data/examples/enable-row-numbers-static.tsx +48 -0
- package/data/examples/enable-row-ordering.js +40 -0
- package/data/examples/enable-row-ordering.tsx +57 -0
- package/data/examples/enable-row-pinning-select.js +64 -0
- package/data/examples/enable-row-pinning-select.tsx +76 -0
- package/data/examples/enable-row-pinning-static.js +39 -0
- package/data/examples/enable-row-pinning-static.tsx +50 -0
- package/data/examples/enable-row-pinning-sticky.js +57 -0
- package/data/examples/enable-row-pinning-sticky.tsx +69 -0
- package/data/examples/enable-row-selection.js +71 -0
- package/data/examples/enable-row-selection.tsx +96 -0
- package/data/examples/enable-row-virtualization.js +85 -0
- package/data/examples/enable-row-virtualization.tsx +101 -0
- package/data/examples/enable-sticky-header.js +47 -0
- package/data/examples/enable-sticky-header.tsx +59 -0
- package/data/examples/expanding-tree-expanded.js +98 -0
- package/data/examples/expanding-tree-expanded.tsx +121 -0
- package/data/examples/expanding-tree-flat-parse.js +102 -0
- package/data/examples/expanding-tree-flat-parse.tsx +125 -0
- package/data/examples/expanding-tree-root-expanded.js +120 -0
- package/data/examples/expanding-tree-root-expanded.tsx +151 -0
- package/data/examples/export-to-csv.js +84 -0
- package/data/examples/export-to-csv.tsx +114 -0
- package/data/examples/export-to-pdf.js +76 -0
- package/data/examples/export-to-pdf.tsx +104 -0
- package/data/examples/external-toolbar.js +82 -0
- package/data/examples/external-toolbar.tsx +108 -0
- package/data/examples/font-awesome-icons.js +62 -0
- package/data/examples/font-awesome-icons.tsx +106 -0
- package/data/examples/infinite-scrolling.js +137 -0
- package/data/examples/infinite-scrolling.tsx +208 -0
- package/data/examples/lazy-detail-panel.js +164 -0
- package/data/examples/lazy-detail-panel.tsx +262 -0
- package/data/examples/lazy-sub-rows.js +118 -0
- package/data/examples/lazy-sub-rows.tsx +190 -0
- package/data/examples/linear-progress.js +48 -0
- package/data/examples/linear-progress.tsx +66 -0
- package/data/examples/loading.js +34 -0
- package/data/examples/loading.tsx +50 -0
- package/data/examples/localization-i18n-ar.js +40 -0
- package/data/examples/localization-i18n-ar.tsx +65 -0
- package/data/examples/localization-i18n-az.js +38 -0
- package/data/examples/localization-i18n-az.tsx +60 -0
- package/data/examples/localization-i18n-bg.js +38 -0
- package/data/examples/localization-i18n-bg.tsx +60 -0
- package/data/examples/localization-i18n-cs.js +38 -0
- package/data/examples/localization-i18n-cs.tsx +60 -0
- package/data/examples/localization-i18n-da.js +38 -0
- package/data/examples/localization-i18n-da.tsx +60 -0
- package/data/examples/localization-i18n-de.js +38 -0
- package/data/examples/localization-i18n-de.tsx +60 -0
- package/data/examples/localization-i18n-el.js +38 -0
- package/data/examples/localization-i18n-el.tsx +60 -0
- package/data/examples/localization-i18n-en.js +38 -0
- package/data/examples/localization-i18n-en.tsx +60 -0
- package/data/examples/localization-i18n-es.js +38 -0
- package/data/examples/localization-i18n-es.tsx +60 -0
- package/data/examples/localization-i18n-et.js +38 -0
- package/data/examples/localization-i18n-et.tsx +60 -0
- package/data/examples/localization-i18n-fa.js +40 -0
- package/data/examples/localization-i18n-fa.tsx +66 -0
- package/data/examples/localization-i18n-fi.js +38 -0
- package/data/examples/localization-i18n-fi.tsx +60 -0
- package/data/examples/localization-i18n-fr.js +38 -0
- package/data/examples/localization-i18n-fr.tsx +60 -0
- package/data/examples/localization-i18n-he.js +40 -0
- package/data/examples/localization-i18n-he.tsx +66 -0
- package/data/examples/localization-i18n-hr.js +38 -0
- package/data/examples/localization-i18n-hr.tsx +60 -0
- package/data/examples/localization-i18n-hu.js +38 -0
- package/data/examples/localization-i18n-hu.tsx +60 -0
- package/data/examples/localization-i18n-hy.js +40 -0
- package/data/examples/localization-i18n-hy.tsx +65 -0
- package/data/examples/localization-i18n-id.js +38 -0
- package/data/examples/localization-i18n-id.tsx +60 -0
- package/data/examples/localization-i18n-it.js +38 -0
- package/data/examples/localization-i18n-it.tsx +60 -0
- package/data/examples/localization-i18n-ja.js +38 -0
- package/data/examples/localization-i18n-ja.tsx +60 -0
- package/data/examples/localization-i18n-ko.js +38 -0
- package/data/examples/localization-i18n-ko.tsx +60 -0
- package/data/examples/localization-i18n-nl.js +38 -0
- package/data/examples/localization-i18n-nl.tsx +60 -0
- package/data/examples/localization-i18n-no.js +38 -0
- package/data/examples/localization-i18n-no.tsx +60 -0
- package/data/examples/localization-i18n-np.js +38 -0
- package/data/examples/localization-i18n-np.tsx +60 -0
- package/data/examples/localization-i18n-pl.js +38 -0
- package/data/examples/localization-i18n-pl.tsx +60 -0
- package/data/examples/localization-i18n-pt-BR.js +38 -0
- package/data/examples/localization-i18n-pt-BR.tsx +60 -0
- package/data/examples/localization-i18n-pt.js +38 -0
- package/data/examples/localization-i18n-pt.tsx +60 -0
- package/data/examples/localization-i18n-ro.js +38 -0
- package/data/examples/localization-i18n-ro.tsx +60 -0
- package/data/examples/localization-i18n-ru.js +38 -0
- package/data/examples/localization-i18n-ru.tsx +60 -0
- package/data/examples/localization-i18n-sk.js +38 -0
- package/data/examples/localization-i18n-sk.tsx +60 -0
- package/data/examples/localization-i18n-sr-Cyrl-RS.js +38 -0
- package/data/examples/localization-i18n-sr-Cyrl-RS.tsx +60 -0
- package/data/examples/localization-i18n-sr-Latn-RS.js +38 -0
- package/data/examples/localization-i18n-sr-Latn-RS.tsx +60 -0
- package/data/examples/localization-i18n-sv.js +38 -0
- package/data/examples/localization-i18n-sv.tsx +60 -0
- package/data/examples/localization-i18n-tr.js +38 -0
- package/data/examples/localization-i18n-tr.tsx +60 -0
- package/data/examples/localization-i18n-uk.js +38 -0
- package/data/examples/localization-i18n-uk.tsx +60 -0
- package/data/examples/localization-i18n-vi.js +38 -0
- package/data/examples/localization-i18n-vi.tsx +60 -0
- package/data/examples/localization-i18n-zh-hans.js +38 -0
- package/data/examples/localization-i18n-zh-hans.tsx +60 -0
- package/data/examples/localization-i18n-zh-hant.js +38 -0
- package/data/examples/localization-i18n-zh-hant.tsx +60 -0
- package/data/examples/manual-selection.js +81 -0
- package/data/examples/manual-selection.tsx +105 -0
- package/data/examples/minimal.js +66 -0
- package/data/examples/minimal.tsx +78 -0
- package/data/examples/mui-theme.js +109 -0
- package/data/examples/mui-theme.tsx +136 -0
- package/data/examples/multi-sorting.js +48 -0
- package/data/examples/multi-sorting.tsx +58 -0
- package/data/examples/persistent-state.js +126 -0
- package/data/examples/persistent-state.tsx +184 -0
- package/data/examples/react-query.js +122 -0
- package/data/examples/react-query.tsx +182 -0
- package/data/examples/remote.js +113 -0
- package/data/examples/remote.tsx +150 -0
- package/data/examples/row-actions-buttons.js +54 -0
- package/data/examples/row-actions-buttons.tsx +89 -0
- package/data/examples/row-actions-menu-items.js +36 -0
- package/data/examples/row-actions-menu-items.tsx +64 -0
- package/data/examples/single-row-selection.js +74 -0
- package/data/examples/single-row-selection.tsx +98 -0
- package/data/examples/virtualized.js +122 -0
- package/data/examples/virtualized.tsx +138 -0
- package/data/guides/accessibility.md +119 -0
- package/data/guides/aggregation.md +210 -0
- package/data/guides/async-loading.md +132 -0
- package/data/guides/best-practices.md +363 -0
- package/data/guides/cell-actions.md +139 -0
- package/data/guides/click-to-copy.md +67 -0
- package/data/guides/column-actions.md +69 -0
- package/data/guides/column-filtering.md +366 -0
- package/data/guides/column-grouping.md +192 -0
- package/data/guides/column-hiding.md +133 -0
- package/data/guides/column-ordering-dnd.md +99 -0
- package/data/guides/column-pinning.md +72 -0
- package/data/guides/column-resizing.md +157 -0
- package/data/guides/column-size.md +162 -0
- package/data/guides/customize-components.md +395 -0
- package/data/guides/customize-icons.md +35 -0
- package/data/guides/data-columns.md +292 -0
- package/data/guides/density-toggle.md +46 -0
- package/data/guides/detail-panel.md +195 -0
- package/data/guides/display-columns.md +135 -0
- package/data/guides/editing.md +367 -0
- package/data/guides/expanding-sub-rows.md +194 -0
- package/data/guides/full-screen-toggle.md +63 -0
- package/data/guides/global-filtering.md +237 -0
- package/data/guides/localization.md +57 -0
- package/data/guides/memoization.md +157 -0
- package/data/guides/pagination.md +171 -0
- package/data/guides/row-actions.md +116 -0
- package/data/guides/row-numbers.md +24 -0
- package/data/guides/row-ordering-dnd.md +51 -0
- package/data/guides/row-pinning.md +96 -0
- package/data/guides/row-selection.md +237 -0
- package/data/guides/sorting.md +190 -0
- package/data/guides/state-management.md +165 -0
- package/data/guides/sticky-header.md +41 -0
- package/data/guides/table-event-listeners.md +103 -0
- package/data/guides/toolbar-customization.md +251 -0
- package/data/guides/virtualization.md +183 -0
- package/data/index.json +1930 -0
- package/data/reference/mrt-components.md +183 -0
- package/data/reference/mrt-hooks.md +125 -0
- package/data/skills/README.md +81 -0
- package/data/skills/composable-components/SKILL.md +189 -0
- package/data/skills/customization/SKILL.md +190 -0
- package/data/skills/drag-and-drop-ordering/SKILL.md +227 -0
- package/data/skills/editing/SKILL.md +243 -0
- package/data/skills/filtering/SKILL.md +213 -0
- package/data/skills/getting-started/SKILL.md +213 -0
- package/data/skills/localization/SKILL.md +182 -0
- package/data/skills/migrate-v3-to-v4/SKILL.md +161 -0
- package/data/skills/state-and-server-data/SKILL.md +200 -0
- package/data/skills/virtualization/SKILL.md +203 -0
- package/dist/data.js +159 -0
- package/dist/index.js +244 -0
- package/package.json +50 -0
|
@@ -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.
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: editing
|
|
3
|
+
description: >
|
|
4
|
+
Add create, update, and inline editing to Material React Table V4 with enableEditing, editDisplayMode (modal, row, cell, table, custom), createDisplayMode, onEditingRowSave and onCreatingRowSave with exitEditingMode, table.setEditingRow, table.setCreatingRow, muiEditTextFieldProps validation, editVariant select, and the Edit column slot. Load for CRUD tables, editable cells, row forms in a dialog, or when saved values never reach the callback.
|
|
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
|
+
- customization
|
|
13
|
+
sources:
|
|
14
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/guides/editing.mdx'
|
|
15
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/examples/editing-crud-modal/sandbox/src/TS.tsx'
|
|
16
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/examples/editing-crud-cell/sandbox/src/TS.tsx'
|
|
17
|
+
- 'lminii/material-react-table:packages/material-react-table/src/components/inputs/MRT_EditCellTextField.tsx'
|
|
18
|
+
- 'lminii/material-react-table:packages/material-react-table/src/types.ts'
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
This skill builds on `getting-started` and `customization`. MRT renders the editing inputs and tracks which row or cell is being edited; persisting the values is always application code, wired through the save callbacks or the text field events.
|
|
22
|
+
|
|
23
|
+
## Setup
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
const table = useMaterialReactTable({
|
|
27
|
+
columns,
|
|
28
|
+
data,
|
|
29
|
+
enableEditing: true,
|
|
30
|
+
editDisplayMode: 'modal', // default; also 'row' | 'cell' | 'table' | 'custom'
|
|
31
|
+
createDisplayMode: 'modal', // default; also 'row' | 'custom'
|
|
32
|
+
getRowId: (row) => row.id,
|
|
33
|
+
onEditingRowSave: async ({ values, table }) => {
|
|
34
|
+
await updateUser(values)
|
|
35
|
+
table.setEditingRow(null) // exit editing mode
|
|
36
|
+
},
|
|
37
|
+
onCreatingRowSave: async ({ values, table }) => {
|
|
38
|
+
await createUser(values)
|
|
39
|
+
table.setCreatingRow(null) // exit creating mode
|
|
40
|
+
},
|
|
41
|
+
renderRowActions: ({ row, table }) => (
|
|
42
|
+
<IconButton onClick={() => table.setEditingRow(row)}><EditIcon /></IconButton>
|
|
43
|
+
),
|
|
44
|
+
renderTopToolbarCustomActions: ({ table }) => (
|
|
45
|
+
<Button onClick={() => table.setCreatingRow(true)}>Create</Button>
|
|
46
|
+
),
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`enableEditing` accepts a boolean or `(row) => boolean`, on the table and on each column. Column-level `enableEditing: false` renders a disabled field in the modal and the plain cell value in the other modes. The `editingRow`, `creatingRow`, and `editingCell` state slices hold the active row or cell; `table.setEditingRow`, `table.setCreatingRow`, and `table.setEditingCell` change them.
|
|
51
|
+
|
|
52
|
+
## Core Patterns
|
|
53
|
+
|
|
54
|
+
### Modal and row modes save through onEditingRowSave
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
const handleSave: MRT_TableOptions<User>['onEditingRowSave'] = async ({ values, row, table, exitEditingMode }) => {
|
|
58
|
+
const errors = validateUser(values)
|
|
59
|
+
if (Object.values(errors).some(Boolean)) {
|
|
60
|
+
setValidationErrors(errors)
|
|
61
|
+
return // stay in editing mode
|
|
62
|
+
}
|
|
63
|
+
setValidationErrors({})
|
|
64
|
+
await updateUser({ ...row.original, ...values })
|
|
65
|
+
exitEditingMode() // same as table.setEditingRow(null)
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`values` is a record keyed by column id, holding the edited text of every editable column. Nothing is written to `data`; the callback owns persistence. The callback may return a promise, and the `isSaving` state slice disables the save button and shows a spinner while it is true. `onEditingRowCancel` and `onCreatingRowCancel` fire when the user closes without saving, which is where validation errors get cleared.
|
|
70
|
+
|
|
71
|
+
### Cell and table modes save through the text field events
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
const columns: MRT_ColumnDef<User>[] = [
|
|
75
|
+
{
|
|
76
|
+
accessorKey: 'email',
|
|
77
|
+
header: 'Email',
|
|
78
|
+
muiEditTextFieldProps: ({ cell, row }) => ({
|
|
79
|
+
type: 'email',
|
|
80
|
+
required: true,
|
|
81
|
+
error: !!validationErrors[cell.id],
|
|
82
|
+
helperText: validationErrors[cell.id],
|
|
83
|
+
onBlur: (event) => {
|
|
84
|
+
const value = event.currentTarget.value
|
|
85
|
+
setValidationErrors((prev) => ({ ...prev, [cell.id]: validateEmail(value) ? undefined : 'Invalid email' }))
|
|
86
|
+
setEditedUsers((prev) => ({ ...prev, [row.id]: { ...row.original, email: value } }))
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
},
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
const table = useMaterialReactTable({
|
|
93
|
+
columns,
|
|
94
|
+
data,
|
|
95
|
+
enableEditing: true,
|
|
96
|
+
editDisplayMode: 'cell', // double-click a cell to edit it
|
|
97
|
+
})
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
In `'cell'` mode a double-click opens the field for that cell; in `'table'` mode every editable cell is a field at once. `onEditingRowSave` never fires in these modes. MRT calls your `onBlur` first, then stores the value in `row._valuesCache` and clears `editingCell`, so read `event.currentTarget.value` rather than `cell.getValue()`. Enter blurs the field. For single-click editing set `muiTableBodyCellProps` with an `onClick` that calls `table.setEditingCell(cell)` and focuses `table.refs.editInputRefs.current?.[column.id]`.
|
|
101
|
+
|
|
102
|
+
### Select inputs and custom Edit components
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
{
|
|
106
|
+
accessorKey: 'state',
|
|
107
|
+
header: 'State',
|
|
108
|
+
editVariant: 'select',
|
|
109
|
+
editSelectOptions: usStates, // string[] or { label, value }[]
|
|
110
|
+
muiEditTextFieldProps: { select: true, required: true },
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
accessorKey: 'birthday',
|
|
114
|
+
header: 'Birthday',
|
|
115
|
+
Edit: ({ cell, column, row, table }) => (
|
|
116
|
+
<DatePicker
|
|
117
|
+
value={dayjs(cell.getValue<string>())}
|
|
118
|
+
onChange={(date) => {
|
|
119
|
+
row._valuesCache[column.id] = date?.toISOString()
|
|
120
|
+
if (table.getState().creatingRow?.id === row.id) table.setCreatingRow(row)
|
|
121
|
+
else table.setEditingRow(row)
|
|
122
|
+
}}
|
|
123
|
+
/>
|
|
124
|
+
),
|
|
125
|
+
},
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
`editSelectOptions` also accepts a callback receiving `cell`, `column`, `row`, and `table`. Select values save on change; text values save on blur. A custom `Edit` slot replaces the text field entirely, so it must write to `row._valuesCache[column.id]` and re-set the editing or creating row, otherwise the value never reaches `values` in the save callback.
|
|
129
|
+
|
|
130
|
+
### Customize the dialog and the create row
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
import { MRT_EditActionButtons, createRow } from '@lminii/material-react-table'
|
|
134
|
+
|
|
135
|
+
const table = useMaterialReactTable({
|
|
136
|
+
columns,
|
|
137
|
+
data,
|
|
138
|
+
enableEditing: true,
|
|
139
|
+
positionCreatingRow: 'bottom', // 'top' (default), 'bottom', or a row index
|
|
140
|
+
renderEditRowDialogContent: ({ internalEditComponents, row, table }) => (
|
|
141
|
+
<>
|
|
142
|
+
<DialogTitle>Edit user</DialogTitle>
|
|
143
|
+
<DialogContent sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>{internalEditComponents}</DialogContent>
|
|
144
|
+
<DialogActions><MRT_EditActionButtons table={table} row={row} variant="text" /></DialogActions>
|
|
145
|
+
</>
|
|
146
|
+
),
|
|
147
|
+
renderTopToolbarCustomActions: ({ table }) => (
|
|
148
|
+
<Button onClick={() => table.setCreatingRow(createRow(table, { id: crypto.randomUUID(), role: 'viewer' }))}>
|
|
149
|
+
Create with defaults
|
|
150
|
+
</Button>
|
|
151
|
+
),
|
|
152
|
+
})
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
`internalEditComponents` is the array of generated fields, one per column, so custom dialog content can reorder them or mix in other inputs. `renderCreateRowDialogContent` is the create counterpart. `table.setCreatingRow(true)` opens a blank row; `createRow(table, defaults)` seeds it. `muiEditRowDialogProps` reaches the Material UI `Dialog` itself. `editDisplayMode: 'custom'` and `createDisplayMode: 'custom'` keep the state slices and callbacks but render no MRT editing UI, for forms in a sidebar.
|
|
156
|
+
|
|
157
|
+
## Common Mistakes
|
|
158
|
+
|
|
159
|
+
### HIGH Forgetting to exit editing mode after saving
|
|
160
|
+
|
|
161
|
+
Wrong:
|
|
162
|
+
|
|
163
|
+
```tsx
|
|
164
|
+
onEditingRowSave: async ({ values }) => {
|
|
165
|
+
await updateUser(values)
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Correct:
|
|
170
|
+
|
|
171
|
+
```tsx
|
|
172
|
+
onEditingRowSave: async ({ values, table }) => {
|
|
173
|
+
await updateUser(values)
|
|
174
|
+
table.setEditingRow(null)
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
MRT does not close the dialog or row on its own, so validation can keep it open. Call `exitEditingMode()` or `table.setEditingRow(null)` once the save succeeds, and the create counterpart `table.setCreatingRow(null)`.
|
|
179
|
+
|
|
180
|
+
Source: `docs/guides/editing.mdx`
|
|
181
|
+
|
|
182
|
+
### HIGH Expecting the data array to update itself
|
|
183
|
+
|
|
184
|
+
Wrong:
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
editDisplayMode: 'cell',
|
|
188
|
+
// no muiEditTextFieldProps handlers; edits vanish after blur
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Correct:
|
|
192
|
+
|
|
193
|
+
```tsx
|
|
194
|
+
muiEditTextFieldProps: ({ cell, row }) => ({
|
|
195
|
+
onBlur: (event) => saveCell(row.id, cell.column.id, event.currentTarget.value),
|
|
196
|
+
}),
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Edited text lives only in `row._valuesCache` until your code writes it to state or a server and the `data` prop changes.
|
|
200
|
+
|
|
201
|
+
Source: `packages/material-react-table/src/components/inputs/MRT_EditCellTextField.tsx`
|
|
202
|
+
|
|
203
|
+
### MEDIUM Passing removed Material UI text field props to the editor
|
|
204
|
+
|
|
205
|
+
Wrong:
|
|
206
|
+
|
|
207
|
+
```tsx
|
|
208
|
+
muiEditTextFieldProps: { InputProps: { startAdornment: <EuroIcon /> }, inputProps: { maxLength: 40 } }
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Correct:
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
muiEditTextFieldProps: {
|
|
215
|
+
slotProps: { input: { startAdornment: <EuroIcon /> }, htmlInput: { maxLength: 40 } },
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Material UI V9 removed `InputProps` and `inputProps` from `TextField`; MRT merges `slotProps.input`, `slotProps.htmlInput`, and `slotProps.select` with its own.
|
|
220
|
+
|
|
221
|
+
Source: `MIGRATION.md`
|
|
222
|
+
|
|
223
|
+
### MEDIUM Editing without a stable row id
|
|
224
|
+
|
|
225
|
+
Wrong:
|
|
226
|
+
|
|
227
|
+
```tsx
|
|
228
|
+
useMaterialReactTable({ columns, data, enableEditing: true })
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Correct:
|
|
232
|
+
|
|
233
|
+
```tsx
|
|
234
|
+
useMaterialReactTable({ columns, data, enableEditing: true, getRowId: (row) => row.id })
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Without `getRowId` rows are keyed by index, so `editingRow` and `creatingRow` can point at a different record after sorting, filtering, or an optimistic insert.
|
|
238
|
+
|
|
239
|
+
Source: `docs/examples/editing-crud-modal`
|
|
240
|
+
|
|
241
|
+
## API Discovery
|
|
242
|
+
|
|
243
|
+
Search `node_modules/@lminii/material-react-table/dist/index.d.ts` for `editDisplayMode`, `onEditingRowSave`, `onCreatingRowSave`, `_valuesCache`, and `editInputRefs` to see the exact signatures. The Editing guide at `/docs/guides/editing` lists the related table, column, and state options, and `/docs/examples/editing-crud`, `editing-crud-row`, `editing-crud-cell`, `editing-crud-table`, and `editing-crud-tree` are complete TanStack Query CRUD examples.
|