@mini_7/material-react-table-mcp 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.
Files changed (170) hide show
  1. package/README.md +68 -0
  2. package/data/MIGRATION.md +136 -0
  3. package/data/api.json +5379 -0
  4. package/data/examples/advanced.tsx +309 -0
  5. package/data/examples/aggregation-and-grouping.tsx +153 -0
  6. package/data/examples/aggregation-multi.tsx +105 -0
  7. package/data/examples/alternate-column-filtering.tsx +49 -0
  8. package/data/examples/alternate-detail-panel.tsx +81 -0
  9. package/data/examples/alternate-pagination.tsx +23 -0
  10. package/data/examples/basic.tsx +109 -0
  11. package/data/examples/chart-detail-panel.tsx +89 -0
  12. package/data/examples/column-actions-space.tsx +44 -0
  13. package/data/examples/column-alignment.tsx +70 -0
  14. package/data/examples/custom-column-actions.tsx +109 -0
  15. package/data/examples/custom-column-filtering-ui.tsx +89 -0
  16. package/data/examples/custom-headless.tsx +125 -0
  17. package/data/examples/custom-top-toolbar.tsx +88 -0
  18. package/data/examples/customize-display-columns.tsx +85 -0
  19. package/data/examples/customize-filter-components.tsx +101 -0
  20. package/data/examples/customize-filter-modes.tsx +73 -0
  21. package/data/examples/customize-filter-variants.tsx +116 -0
  22. package/data/examples/customize-global-filter-component.tsx +52 -0
  23. package/data/examples/customize-remove-column-grouping.tsx +94 -0
  24. package/data/examples/customize-row-selection.tsx +54 -0
  25. package/data/examples/customize-table-styles.tsx +100 -0
  26. package/data/examples/disable-column-actions.tsx +37 -0
  27. package/data/examples/disable-column-hiding.tsx +90 -0
  28. package/data/examples/disable-density-toggle.tsx +49 -0
  29. package/data/examples/dynamic-columns.tsx +189 -0
  30. package/data/examples/editing-crud-cell.tsx +377 -0
  31. package/data/examples/editing-crud-modal.tsx +370 -0
  32. package/data/examples/editing-crud-row.tsx +333 -0
  33. package/data/examples/editing-crud-table.tsx +369 -0
  34. package/data/examples/editing-crud-tree.tsx +416 -0
  35. package/data/examples/enable-cell-actions.tsx +76 -0
  36. package/data/examples/enable-click-to-copy.tsx +39 -0
  37. package/data/examples/enable-column-grouping.tsx +120 -0
  38. package/data/examples/enable-column-ordering.tsx +48 -0
  39. package/data/examples/enable-column-pinning.tsx +69 -0
  40. package/data/examples/enable-column-resizing.tsx +56 -0
  41. package/data/examples/enable-column-virtualization.tsx +27 -0
  42. package/data/examples/enable-detail-panel-conditionally.tsx +78 -0
  43. package/data/examples/enable-detail-panel-virtualized.tsx +80 -0
  44. package/data/examples/enable-expanding-tree.tsx +110 -0
  45. package/data/examples/enable-filter-facet-values.tsx +65 -0
  46. package/data/examples/enable-row-dragging.tsx +137 -0
  47. package/data/examples/enable-row-numbers-original.tsx +48 -0
  48. package/data/examples/enable-row-numbers-static.tsx +48 -0
  49. package/data/examples/enable-row-ordering.tsx +57 -0
  50. package/data/examples/enable-row-pinning-select.tsx +76 -0
  51. package/data/examples/enable-row-pinning-static.tsx +50 -0
  52. package/data/examples/enable-row-pinning-sticky.tsx +69 -0
  53. package/data/examples/enable-row-selection.tsx +96 -0
  54. package/data/examples/enable-row-virtualization.tsx +101 -0
  55. package/data/examples/enable-sticky-header.tsx +59 -0
  56. package/data/examples/expanding-tree-expanded.tsx +121 -0
  57. package/data/examples/expanding-tree-flat-parse.tsx +125 -0
  58. package/data/examples/expanding-tree-root-expanded.tsx +151 -0
  59. package/data/examples/export-to-csv.tsx +114 -0
  60. package/data/examples/export-to-pdf.tsx +104 -0
  61. package/data/examples/external-toolbar.tsx +108 -0
  62. package/data/examples/font-awesome-icons.tsx +106 -0
  63. package/data/examples/infinite-scrolling.tsx +208 -0
  64. package/data/examples/lazy-detail-panel.tsx +262 -0
  65. package/data/examples/lazy-sub-rows.tsx +190 -0
  66. package/data/examples/linear-progress.tsx +66 -0
  67. package/data/examples/loading.tsx +50 -0
  68. package/data/examples/localization-i18n-ar.tsx +65 -0
  69. package/data/examples/localization-i18n-az.tsx +60 -0
  70. package/data/examples/localization-i18n-bg.tsx +60 -0
  71. package/data/examples/localization-i18n-cs.tsx +60 -0
  72. package/data/examples/localization-i18n-da.tsx +60 -0
  73. package/data/examples/localization-i18n-de.tsx +60 -0
  74. package/data/examples/localization-i18n-el.tsx +60 -0
  75. package/data/examples/localization-i18n-en.tsx +60 -0
  76. package/data/examples/localization-i18n-es.tsx +60 -0
  77. package/data/examples/localization-i18n-et.tsx +60 -0
  78. package/data/examples/localization-i18n-fa.tsx +66 -0
  79. package/data/examples/localization-i18n-fi.tsx +60 -0
  80. package/data/examples/localization-i18n-fr.tsx +60 -0
  81. package/data/examples/localization-i18n-he.tsx +66 -0
  82. package/data/examples/localization-i18n-hr.tsx +60 -0
  83. package/data/examples/localization-i18n-hu.tsx +60 -0
  84. package/data/examples/localization-i18n-hy.tsx +65 -0
  85. package/data/examples/localization-i18n-id.tsx +60 -0
  86. package/data/examples/localization-i18n-it.tsx +60 -0
  87. package/data/examples/localization-i18n-ja.tsx +60 -0
  88. package/data/examples/localization-i18n-ko.tsx +60 -0
  89. package/data/examples/localization-i18n-nl.tsx +60 -0
  90. package/data/examples/localization-i18n-no.tsx +60 -0
  91. package/data/examples/localization-i18n-np.tsx +60 -0
  92. package/data/examples/localization-i18n-pl.tsx +60 -0
  93. package/data/examples/localization-i18n-pt-BR.tsx +60 -0
  94. package/data/examples/localization-i18n-pt.tsx +60 -0
  95. package/data/examples/localization-i18n-ro.tsx +60 -0
  96. package/data/examples/localization-i18n-ru.tsx +60 -0
  97. package/data/examples/localization-i18n-sk.tsx +60 -0
  98. package/data/examples/localization-i18n-sr-Cyrl-RS.tsx +60 -0
  99. package/data/examples/localization-i18n-sr-Latn-RS.tsx +60 -0
  100. package/data/examples/localization-i18n-sv.tsx +60 -0
  101. package/data/examples/localization-i18n-tr.tsx +60 -0
  102. package/data/examples/localization-i18n-uk.tsx +60 -0
  103. package/data/examples/localization-i18n-vi.tsx +60 -0
  104. package/data/examples/localization-i18n-zh-hans.tsx +60 -0
  105. package/data/examples/localization-i18n-zh-hant.tsx +60 -0
  106. package/data/examples/manual-selection.tsx +105 -0
  107. package/data/examples/minimal.tsx +78 -0
  108. package/data/examples/mui-theme.tsx +136 -0
  109. package/data/examples/multi-sorting.tsx +58 -0
  110. package/data/examples/persistent-state.tsx +184 -0
  111. package/data/examples/react-query.tsx +182 -0
  112. package/data/examples/remote.tsx +150 -0
  113. package/data/examples/row-actions-buttons.tsx +89 -0
  114. package/data/examples/row-actions-menu-items.tsx +64 -0
  115. package/data/examples/single-row-selection.tsx +98 -0
  116. package/data/examples/virtualized.tsx +138 -0
  117. package/data/guides/accessibility.md +119 -0
  118. package/data/guides/aggregation.md +210 -0
  119. package/data/guides/async-loading.md +132 -0
  120. package/data/guides/best-practices.md +363 -0
  121. package/data/guides/cell-actions.md +139 -0
  122. package/data/guides/click-to-copy.md +67 -0
  123. package/data/guides/column-actions.md +69 -0
  124. package/data/guides/column-filtering.md +366 -0
  125. package/data/guides/column-grouping.md +192 -0
  126. package/data/guides/column-hiding.md +133 -0
  127. package/data/guides/column-ordering-dnd.md +99 -0
  128. package/data/guides/column-pinning.md +72 -0
  129. package/data/guides/column-resizing.md +157 -0
  130. package/data/guides/column-size.md +162 -0
  131. package/data/guides/customize-components.md +395 -0
  132. package/data/guides/customize-icons.md +35 -0
  133. package/data/guides/data-columns.md +292 -0
  134. package/data/guides/density-toggle.md +46 -0
  135. package/data/guides/detail-panel.md +195 -0
  136. package/data/guides/display-columns.md +135 -0
  137. package/data/guides/editing.md +367 -0
  138. package/data/guides/expanding-sub-rows.md +194 -0
  139. package/data/guides/full-screen-toggle.md +63 -0
  140. package/data/guides/global-filtering.md +237 -0
  141. package/data/guides/localization.md +57 -0
  142. package/data/guides/memoization.md +157 -0
  143. package/data/guides/pagination.md +171 -0
  144. package/data/guides/row-actions.md +116 -0
  145. package/data/guides/row-numbers.md +24 -0
  146. package/data/guides/row-ordering-dnd.md +51 -0
  147. package/data/guides/row-pinning.md +96 -0
  148. package/data/guides/row-selection.md +237 -0
  149. package/data/guides/sorting.md +190 -0
  150. package/data/guides/state-management.md +165 -0
  151. package/data/guides/sticky-header.md +41 -0
  152. package/data/guides/table-event-listeners.md +103 -0
  153. package/data/guides/toolbar-customization.md +251 -0
  154. package/data/guides/virtualization.md +183 -0
  155. package/data/index.json +1930 -0
  156. package/data/reference/mrt-components.md +183 -0
  157. package/data/reference/mrt-hooks.md +125 -0
  158. package/data/skills/composable-components/SKILL.md +189 -0
  159. package/data/skills/customization/SKILL.md +190 -0
  160. package/data/skills/drag-and-drop-ordering/SKILL.md +227 -0
  161. package/data/skills/editing/SKILL.md +243 -0
  162. package/data/skills/filtering/SKILL.md +213 -0
  163. package/data/skills/getting-started/SKILL.md +213 -0
  164. package/data/skills/localization/SKILL.md +182 -0
  165. package/data/skills/migrate-v3-to-v4/SKILL.md +161 -0
  166. package/data/skills/state-and-server-data/SKILL.md +200 -0
  167. package/data/skills/virtualization/SKILL.md +203 -0
  168. package/dist/data.js +137 -0
  169. package/dist/index.js +232 -0
  170. package/package.json +50 -0
@@ -0,0 +1,116 @@
1
+ ## Row Actions Feature Guide
2
+
3
+ The row actions feature is simply a pre-built [Display Column](/docs/guides/display-columns) feature that adds a column as a place to store either a row action menu or other row action buttons.
4
+
5
+ Using the built-in Row Actions column is optional, as you can simply create your own display columns, but this feature has some built-in conveniences that make it easy to add row actions to your table.
6
+
7
+ ### Relevant Table Options
8
+
9
+ Relevant table options (get_mrt_api has full details):
10
+
11
+ - `displayColumnDefOptions` - type `{ [key: string]: MRT_DisplayColumnDef<TData> }` - Customize and override the column definition options for the built-in display columns. (Select, Expand, Row Actions, etc.)
12
+ - `enableRowActions` - type `boolean`
13
+ - `positionActionsColumn` - type `'first' | 'last'`
14
+ - `renderRowActionMenuItems` - type `({ closeMenu, row, table }) => ReactNode[]`
15
+ - `renderRowActions` - type `({ cell, row, table }) => ReactNode`
16
+
17
+ ### Enable Row Actions
18
+
19
+ You can enable the row actions feature by setting the `enableRowActions` table option to `true`.
20
+
21
+ You can then add your row action components with either the `renderRowActions` or `renderRowActionMenuItems` props.
22
+
23
+ #### Add Row Actions Menu Items
24
+
25
+ If you want to embed all of your row actions into a single menu, you can use the `renderRowActionMenuItems` table option.
26
+
27
+ ```jsx
28
+ const table = useMaterialReactTable({
29
+ columns,
30
+ data,
31
+ enableRowActions: true,
32
+ renderRowActionMenuItems: ({ row }) => [
33
+ <MenuItem key="edit" onClick={() => console.info('Edit')}>
34
+ Edit
35
+ </MenuItem>,
36
+ <MenuItem key="delete" onClick={() => console.info('Delete')}>
37
+ Delete
38
+ </MenuItem>,
39
+ ],
40
+ });
41
+
42
+ return <MaterialReactTable table={table} />;
43
+ ```
44
+
45
+ > Live example: `row-actions-menu-items` (call get_mrt_example with that id).
46
+
47
+ #### Add Row Action Buttons
48
+
49
+ If you want to add row action buttons, you can use the `renderRowActions` table option.
50
+
51
+ ```jsx
52
+ const table = useMaterialReactTable({
53
+ columns,
54
+ data,
55
+ enableRowActions: true,
56
+ renderRowActions: ({ row }) => (
57
+ <Box>
58
+ <IconButton onClick={() => console.info('Edit')}>
59
+ <EditIcon />
60
+ </IconButton>
61
+ <IconButton onClick={() => console.info('Delete')}>
62
+ <DeleteIcon />
63
+ </IconButton>
64
+ </Box>
65
+ ),
66
+ });
67
+
68
+ return <MaterialReactTable table={table} />;
69
+ ```
70
+
71
+ > Live example: `row-actions-buttons` (call get_mrt_example with that id).
72
+
73
+ ### Customize Row Actions Column
74
+
75
+ #### Change Row Actions Display Column Options
76
+
77
+ You can customize all column def options for the row actions column, including the column width, header text, and more using the `displayColumnDefOptions` table option.
78
+
79
+ ```jsx
80
+ const table = useMaterialReactTable({
81
+ columns,
82
+ data,
83
+ enableRowActions: true,
84
+ displayColumnDefOptions: {
85
+ 'mrt-row-actions': {
86
+ header: 'Change Account Settings', //change header text
87
+ size: 300, //make actions column wider
88
+ },
89
+ },
90
+ renderRowActions: ({ table }) => (
91
+ <Box>
92
+ <Button>Button 1</Button>
93
+ <Button>Button 2</Button>
94
+ <Button>Button 3</Button>
95
+ </Box>
96
+ ),
97
+ });
98
+ ```
99
+
100
+ #### Position Row Actions Column
101
+
102
+ You can position the row actions column to the left or right (first or last column) of the table using the `positionActionsColumn` table option. The default is as the first column.
103
+
104
+ ```jsx
105
+ const table = useMaterialReactTable({
106
+ columns,
107
+ data,
108
+ enableRowActions: true,
109
+ positionActionsColumn: 'last',
110
+ renderRowActions: ({ table }) => (
111
+ //...
112
+ ),
113
+ })
114
+ ```
115
+
116
+ View Extra Storybook **[Examples](https://www.material-react-table.dev/?path=/story/features-row-actions-examples)**
@@ -0,0 +1,24 @@
1
+ ## Row Numbers Feature Guide
2
+
3
+ Material React Table has an easy to implement row number features. There are two row number modes that you can enable. You can have row numbers that are associated with the data in the table ([original mode](<#enable-row-numbers-(original-mode)>)), or you can have row numbers that are just statically part of the table ([static mode](<#enable-row-numbers-(static-mode)>)).
4
+
5
+ ### Relevant Table Options
6
+
7
+ Relevant table options (get_mrt_api has full details):
8
+
9
+ - `enableRowNumbers` - type `boolean`
10
+ - `rowNumberDisplayMode` - type `'original' | 'static'` - default `'original'`
11
+
12
+ ### Enable Row Numbers (Static Mode)
13
+
14
+ In the default rowNumberDisplayMode (`static`), row numbers are just a static part of the table in their own column. They act like the row numbers in an excel spreadsheet. Sorting and filtering will not affect the row numbers.
15
+
16
+ > Live example: `enable-row-numbers-static` (call get_mrt_example with that id).
17
+
18
+ ### Enable Row Numbers (Original Mode)
19
+
20
+ Alternatively, use the `"original"` rowNumberDisplayMode to have row numbers linked to the original index of the data array. This means that when you search or filter, the same row numbers will stay with the same rows as data is sorted and filtered.
21
+
22
+ > Live example: `enable-row-numbers-original` (call get_mrt_example with that id).
23
+
24
+ View Extra Storybook **[Examples](https://www.material-react-table.dev/?path=/story/features-row-number-examples)**
@@ -0,0 +1,51 @@
1
+ ## Row Ordering (DnD) Feature Guide
2
+
3
+ Material React Table has exposed all the APIs necessary to enable rich row drag-and-drop features that you can easily build to meet your needs. This includes the ability to reorder rows, drag rows to other tables, or drag rows to other UI in your application.
4
+
5
+ > This is not the [Sorting Guide](/docs/guides/sorting), which is a different feature.
6
+
7
+ ### Relevant Table Options
8
+
9
+ Relevant table options (get_mrt_api has full details):
10
+
11
+ - `enableRowOrdering` - type `boolean`
12
+ - `muiRowDragHandleProps` - type `IconButtonProps | ({ row, table }) => IconButtonProps`
13
+ - `onDraggingRowChange` - type `OnChangeFn<MRT_Row<TData> | null>`
14
+ - `onHoveredRowChange` - type `OnChangeFn<MRT_Row<TData> | null>`
15
+
16
+ ### Relevant State
17
+
18
+ Relevant state options (get_mrt_api has full details):
19
+
20
+ - `draggingRow` - type `MRT_Row | null` - a variable representing the currently dragged row
21
+ - `hoveredRow` - type `MRT_Row | null`
22
+
23
+ ### Enable Row Ordering
24
+
25
+ A common use for row drag and drop is to allow users to reorder rows in a table. This can be done by setting the `enableRowOrdering` table option to `true`, then setting up an `onDragEnd` event handler on the `muiRowDragHandleProps` table option.
26
+
27
+ ```jsx
28
+ const table = useMaterialReactTable({
29
+ columns,
30
+ data,
31
+ enableRowOrdering: true,
32
+ enableSorting: false, //usually you do not want to sort when re-ordering
33
+ muiRowDragHandleProps: {
34
+ onDragEnd: (event, data) => {
35
+ //data re-ordering logic here
36
+ },
37
+ },
38
+ });
39
+
40
+ return <MaterialReactTable table={table} />;
41
+ ```
42
+
43
+ > Live example: `enable-row-ordering` (call get_mrt_example with that id).
44
+
45
+ ### Drag and Drop Rows to Other UI or Tables
46
+
47
+ The drag-and-drop features are not limited to just internally within the same table. You can also use them to drag rows to other UI elements in your application or even to other tables. This can be done by setting the `enableRowDragging` table option to `true` and setting up an `onDragEnd` event handler on the `muiRowDragHandleProps` table option to perform whatever logic you want to happen when a row is dropped.
48
+
49
+ > Live example: `enable-row-dragging` (call get_mrt_example with that id).
50
+
51
+ View Extra Storybook **[Examples](https://www.material-react-table.dev/?path=/story/features-row-ordering-examples)**
@@ -0,0 +1,96 @@
1
+ ## Row Pinning Feature Guide
2
+
3
+ Material React Table has a powerful row pinning feature that allows you to either pin rows to the top and bottom of the table as a user scrolls, or pin rows to the top and bottom of the table regardless of scrolling.
4
+
5
+ ### Relevant Table Options
6
+
7
+ Relevant table options (get_mrt_api has full details):
8
+
9
+ - `enableRowSelection` - type `boolean | (row: MRT_Row) => boolean` - Enables row selection either for every row, or on a per-row basis using a function.
10
+ - `keepPinnedRows` - type `boolean` - default `true`
11
+ - `onRowPinningChange` - type `OnChangeFn<RowSelectionState>` - If provided, this function will be called with an updaterFn when state.rowPinning changes. This overrides the default internal state management, so you will need to persist the state change either fully or partially outside of the table.
12
+ - `rowPinningDisplayMode` - type `'sticky' | 'top' | 'bottom' | 'top-and-bottom' | 'select-sticky' | 'select-top' | 'select-bottom'` - default `'sticky'`
13
+
14
+ ### Relevant State
15
+
16
+ Relevant state options (get_mrt_api has full details):
17
+
18
+ - `rowPinning` - type `{ top: string[], bottom: string[] }` - default `{ top: [], bottom: [] }` - an object with top and bottom properties, each of which is an array of strings representing the rows that are pinned to the top or bottom of the table
19
+
20
+ ### Row Pinning Display Modes
21
+
22
+ You can enable the row pinning feature with the `enableRowPinning` table option. There are multiple display modes that you can choose from with the `rowPinningDisplayMode` table option.
23
+
24
+ ```jsx
25
+ const table = useMaterialReactTable({
26
+ columns,
27
+ data,
28
+ enableRowPinning: true,
29
+ rowPinningDisplayMode: 'sticky', // default
30
+ });
31
+ ```
32
+
33
+ - `sticky` - This is the default display mode. It will make rows stick to the top and bottom of the table as a user scrolls.
34
+ - `top` - This will statically pin rows to the top of the table upon pinning.
35
+ - `bottom` - This will statically pin rows to the bottom of the table upon pinning.
36
+ - `top-and-bottom` - This allows the user to statically pin rows to either the top or bottom of the table.
37
+ - `select-sticky` - This pins selected rows to the top and bottom of the table as a user scrolls. (alternative pinning UI)
38
+ - `select-top` - This statically pins selected rows to the top of the table upon pinning. (alternative pinning UI)
39
+ - `select-bottom` - This statically pins selected rows to the bottom of the table upon pinning. (alternative pinning UI)
40
+
41
+ ### Sticky Row Pinning
42
+
43
+ By default, the row pinning feature will add a position sticky style to the pinned rows. This means that the pinned rows will stay in place if the row is already in view. However, the rows will stay in view as the user scrolls up or down.
44
+
45
+ Sticky row pinning will work best if you give your rows a fixed height, or at least disable any kind of whitespace wrapping.
46
+
47
+ ```jsx
48
+ const table = useMaterialReactTable({
49
+ columns,
50
+ data,
51
+ enableRowPinning: true,
52
+ muiTableBodyRowProps: ({ row, table }) => {
53
+ const { density } = table.getState();
54
+ return {
55
+ sx: {
56
+ //Set a fixed height for pinned rows
57
+ height: row.getIsPinned()
58
+ ? `${
59
+ //Default mrt row height estimates. Adjust as needed.
60
+ density === 'compact' ? 37 : density === 'comfortable' ? 53 : 69
61
+ }px`
62
+ : undefined,
63
+ },
64
+ };
65
+ },
66
+ rowPinningDisplayMode: 'sticky', // default
67
+ });
68
+ ```
69
+
70
+ > Live example: `enable-row-pinning-sticky` (call get_mrt_example with that id).
71
+
72
+ > Note: Sticky Row Pinning is not currently compatible with row virtualization.
73
+
74
+ ### Static Row Pinning
75
+
76
+ Some of the other row pinning modes will show pinned rows at the top or bottom of the the table regardless of scrolling. This is a simpler implementation of the row pinning feature.
77
+
78
+ Static row pinning does not require set row heights, as they will render in a normal `<tbody>` element that itself is what is sticky.
79
+
80
+ > Live example: `enable-row-pinning-static` (call get_mrt_example with that id).
81
+
82
+ ### Alternative Selection Row Pinning UI
83
+
84
+ By default, the row pinning feature adds a pinning display column with pinning buttons for each row. However, you can instead combine the row pinning feature with the row selection feature to pin selected rows.
85
+
86
+ ```jsx
87
+ const table = useMaterialReactTable({
88
+ columns,
89
+ data,
90
+ enableRowPinning: true,
91
+ enableRowSelection: true,
92
+ rowPinningDisplayMode: 'select-sticky',
93
+ });
94
+ ```
95
+
96
+ > Live example: `enable-row-pinning-select` (call get_mrt_example with that id).
@@ -0,0 +1,237 @@
1
+ ## Row Selection Guide
2
+
3
+ Material React Table has a built-in row selection feature and makes it easy to manage the selection state yourself. This guide demonstrates how to enable row selection and customize the selection behavior.
4
+
5
+ ### Relevant Table Options
6
+
7
+ Relevant table options (get_mrt_api has full details):
8
+
9
+ - `enableBatchRowSelection` - type `boolean` - default `true` - If true, the user can select multiple rows at once by holding down the shift key while clicking.
10
+ - `enableMultiRowSelection` - type `boolean` - default `true` - If true, the user can select multiple rows at once with a checkbox. If false, the user can only select one row at a time with a radio button.
11
+ - `enableRowSelection` - type `boolean | (row: MRT_Row) => boolean` - Enables row selection either for every row, or on a per-row basis using a function.
12
+ - `enableSelectAll` - type `boolean` - default `true`
13
+ - `enableSubRowSelection` - type `boolean` - default `true`
14
+ - `getRowId` - type `(originalRow: TData, index: number, parent?: MRT_Row<TData>) => string` - This optional function is used to derive a unique ID for any given row. If not provided the rows index is used (nested rows join together with . using their grandparents' index eg. index.index.index). If you need to identify individual rows that are originating from any server-side operations, it's suggested you use this function to return an ID that makes sense regardless of network IO/ambiguity eg. a userId, taskId, database ID field, etc.
15
+ - `muiSelectAllCheckboxProps` - type `CheckboxProps | ({ table }) => CheckboxProps`
16
+ - `muiSelectCheckboxProps` - type `CheckboxProps | ({ row, table }) => CheckboxProps`
17
+ - `onRowSelectionChange` - type `OnChangeFn<RowSelectionState>` - If provided, this function will be called with an updaterFn when state.rowSelection changes. This overrides the default internal state management, so you will need to persist the state change either fully or partially outside of the table.
18
+ - `positionToolbarAlertBanner` - type `'bottom' | 'top' | 'none'` - default `'top'`
19
+ - `renderToolbarAlertBannerContent` - type `({ table, groupedAlert, selectedAlert }) => ReactNode`
20
+ - `rowPinningDisplayMode` - type `'sticky' | 'top' | 'bottom' | 'top-and-bottom' | 'select-sticky' | 'select-top' | 'select-bottom'` - default `'sticky'`
21
+ - `selectAllMode` - type `'all' | 'page'` - default `'page'`
22
+
23
+ ### Relevant State
24
+
25
+ Relevant state options (get_mrt_api has full details):
26
+
27
+ - `rowSelection` - type `Record<string, boolean>` - default `{}`
28
+
29
+ ### Enable Row Selection
30
+
31
+ Selection checkboxes can be enabled with the `enableRowSelection` table option.
32
+
33
+ ```jsx
34
+ const table = useMaterialReactTable({
35
+ columns,
36
+ data,
37
+ enableRowSelection: true,
38
+ });
39
+
40
+ return <MaterialReactTable table={table} />;
41
+ ```
42
+
43
+ #### Enable Row Selection Conditionally Per Row
44
+
45
+ You can also enable row selection conditionally per row with the same `enableRowSelection` table option, but with a callback function instead of a boolean.
46
+
47
+ ```jsx
48
+ const table = useMaterialReactTable({
49
+ columns,
50
+ data,
51
+ enableRowSelection: (row) => row.original.age > 18, //disable row selection for rows with age <= 18
52
+ });
53
+ ```
54
+
55
+ ### Batch Row Selection
56
+
57
+ > New in v2.11.0
58
+
59
+ By default, when the user holds down the <kbd>Shift</kbd> key and clicks a row, all rows between the last selected row and the clicked row will be selected. This can be disabled with the `enableBatchRowSelection` table option.
60
+
61
+ ```jsx
62
+ const table = useMaterialReactTable({
63
+ columns,
64
+ data,
65
+ enableRowSelection: true,
66
+ enableBatchRowSelection: false, //disable batch row selection with shift key
67
+ });
68
+ ```
69
+
70
+ ### Access Row Selection State
71
+
72
+ There are two ways to access the selection state. You can either manage the selection state yourself or read it from the table instance.
73
+
74
+ #### Manage Row Selection State
75
+
76
+ The row selection state is managed internally by default, but you will more than likely want to have access to that state yourself. Here is how you can simply get access to the row selection state, specifically:
77
+
78
+ ```tsx
79
+ const [rowSelection, setRowSelection] = useState<MRT_RowSelectionState>({}); //ts type available
80
+
81
+ const table = useMaterialReactTable({
82
+ columns,
83
+ data,
84
+ enableRowSelection: true,
85
+ onRowSelectionChange: setRowSelection,
86
+ state: { rowSelection },
87
+ });
88
+
89
+ return <MaterialReactTable table={table} />;
90
+ ```
91
+
92
+ #### Read Row Selection State from Table Instance
93
+
94
+ Alternatively, you can read the selection state directly from the `table` instance like so:
95
+
96
+ ```jsx
97
+ const table = useMaterialReactTable({
98
+ columns,
99
+ data,
100
+ enableRowSelection: true,
101
+ renderTopToolbarCustomActions: ({ table }) => (
102
+ <Button
103
+ onClick={() => {
104
+ const rowSelection = table.getState().rowSelection; //read state
105
+ const selectedRows = table.getSelectedRowModel().rows; //or read entire rows
106
+ }}
107
+ >
108
+ Download Selected Users
109
+ </Button>
110
+ ),
111
+ });
112
+
113
+ useEffect(() => {
114
+ //fetch data based on row selection state or something
115
+ }, [table.getState().rowSelection]);
116
+
117
+ return <MaterialReactTable table={table} />;
118
+ ```
119
+
120
+ > Note: `table.getSelectedRowModel().rows` only really works with client-side pagination. Use `rowSelection` state if you are using server-side pagination. Row Models only contain rows based on the `data` you pass in.
121
+
122
+ #### Useful Row IDs
123
+
124
+ By default, the `row.id` for each row in the table is simply the index of the row in the table. You can override this and instruct Material React Table to use a more useful Row ID with the `getRowId` table option. For example, you may want something like this:
125
+
126
+ ```jsx
127
+ const table = useMaterialReactTable({
128
+ columns,
129
+ data,
130
+ enableRowSelection: true,
131
+ getRowId: (originalRow) => originalRow.userId,
132
+ });
133
+ ```
134
+
135
+ As rows get selected, the `rowSelection` state will look like this:
136
+
137
+ ```tsx
138
+ {
139
+ "3f25309c-8fa1-470f-811e-cdb082ab9017": true,
140
+ "be731030-df83-419c-b3d6-9ef04e7f4a9f": true,
141
+ ...
142
+ }
143
+ ```
144
+
145
+ This can be very useful when you are trying to read your selection state and do something with your data as the row selection changes.
146
+
147
+ > Live example: `enable-row-selection` (call get_mrt_example with that id).
148
+
149
+ ### Select Row on Row Click
150
+
151
+ By default, a row can only be selected by either clicking the checkbox or radio button in the `mrt-row-select` column. If you want to be able to select a row by clicking anywhere on the row, you can add your own `onClick` function to a table body row like this:
152
+
153
+ ```jsx
154
+ const table = useMaterialReactTable({
155
+ columns,
156
+ data,
157
+ enableRowSelection: true,
158
+ //clicking anywhere on the row will select it
159
+ muiTableBodyRowProps: ({ row, staticRowIndex, table }) => ({
160
+ onClick: (event) =>
161
+ getMRT_RowSelectionHandler({ row, staticRowIndex, table })(event), //import this helper function from material-react-table
162
+ sx: { cursor: 'pointer' },
163
+ }),
164
+ });
165
+ ```
166
+
167
+ ### Disable Select All
168
+
169
+ By default, if you enable selection for each row, there will also be a select all checkbox in the header of the checkbox column. It can be hidden with the `enableSelectAll` table option.
170
+
171
+ ```tsx
172
+ const table = useMaterialReactTable({
173
+ columns,
174
+ data,
175
+ enableRowSelection: true,
176
+ enableSelectAll: false,
177
+ });
178
+ ```
179
+
180
+ ### Position or Hide Alert Banner Selection Message
181
+
182
+ By default, an alert banner will be show as rows are selected. You can use the `positionToolbarAlertBanner` table option to show the alert banner in the top toolbar, bottom toolbar, as an overlay in the table head, or hide it completely.
183
+
184
+ ```jsx
185
+ const table = useMaterialReactTable({
186
+ columns,
187
+ data,
188
+ enableRowSelection: true,
189
+ positionToolbarAlertBanner: 'head-overlay', //show alert banner over table head, top toolbar, or bottom toolbar
190
+ });
191
+ ```
192
+
193
+ ### Single Row Selection
194
+
195
+ By default, the `enableMultiRowSelection` table option is set to `true`, which means that multiple rows can be selected at once with a checkbox. If you want to only allow a single row to be selected at a time, you can set this table option to `false` and a radio button will be used instead of a checkbox.
196
+
197
+ ```jsx
198
+ const table = useMaterialReactTable({
199
+ columns,
200
+ data,
201
+ enableMultiRowSelection: false, //shows radio buttons instead of checkboxes
202
+ enableRowSelection: true,
203
+ });
204
+ ```
205
+
206
+ > Live example: `single-row-selection` (call get_mrt_example with that id).
207
+
208
+ ### Customize Select Checkboxes or Radio Buttons
209
+
210
+ The selection checkboxes can be customized with the `muiSelectCheckboxProps` table option. Any prop that can be passed to a Mui Checkbox component can be specified here. For example, you may want to use a different color for the checkbox or use some logic to disable certain rows from being selected.
211
+
212
+ ```tsx
213
+ const table = useMaterialReactTable({
214
+ columns,
215
+ data,
216
+ enableRowSelection: true,
217
+ muiSelectCheckboxProps: {
218
+ color: 'secondary',
219
+ },
220
+ });
221
+ ```
222
+
223
+ > Live example: `customize-row-selection` (call get_mrt_example with that id).
224
+
225
+ ### Manual Row Selection Without Checkboxes
226
+
227
+ You may have a use case where you want to be able to select rows by clicking them, but you do not want to show any checkboxes or radio buttons. You can do this by implementing a row selection feature yourself while keeping the `enableRowSelection` table option `false` so that the default selection behavior is disabled.
228
+
229
+ > Live example: `manual-selection` (call get_mrt_example with that id).
230
+
231
+ ### Sticky Pinned Row Selection
232
+
233
+ You can combine the row pinning feature with the row selection feature to create a cool user experience where selected rows always stay within view.
234
+
235
+ > Live example: `enable-row-pinning-select` (call get_mrt_example with that id).
236
+
237
+ View Extra Storybook **[Examples](https://www.material-react-table.dev/?path=/story/features-selection-examples)**