@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.
Files changed (284) 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.js +215 -0
  5. package/data/examples/advanced.tsx +309 -0
  6. package/data/examples/aggregation-and-grouping.js +116 -0
  7. package/data/examples/aggregation-and-grouping.tsx +153 -0
  8. package/data/examples/aggregation-multi.js +89 -0
  9. package/data/examples/aggregation-multi.tsx +105 -0
  10. package/data/examples/alternate-column-filtering.js +38 -0
  11. package/data/examples/alternate-column-filtering.tsx +49 -0
  12. package/data/examples/alternate-detail-panel.js +65 -0
  13. package/data/examples/alternate-detail-panel.tsx +81 -0
  14. package/data/examples/alternate-pagination.js +17 -0
  15. package/data/examples/alternate-pagination.tsx +23 -0
  16. package/data/examples/basic.js +86 -0
  17. package/data/examples/basic.tsx +109 -0
  18. package/data/examples/chart-detail-panel.js +69 -0
  19. package/data/examples/chart-detail-panel.tsx +89 -0
  20. package/data/examples/column-actions-space.js +34 -0
  21. package/data/examples/column-actions-space.tsx +44 -0
  22. package/data/examples/column-alignment.js +58 -0
  23. package/data/examples/column-alignment.tsx +70 -0
  24. package/data/examples/custom-column-actions.js +74 -0
  25. package/data/examples/custom-column-actions.tsx +109 -0
  26. package/data/examples/custom-column-filtering-ui.js +59 -0
  27. package/data/examples/custom-column-filtering-ui.tsx +89 -0
  28. package/data/examples/custom-headless.js +85 -0
  29. package/data/examples/custom-headless.tsx +125 -0
  30. package/data/examples/custom-top-toolbar.js +60 -0
  31. package/data/examples/custom-top-toolbar.tsx +88 -0
  32. package/data/examples/customize-display-columns.js +72 -0
  33. package/data/examples/customize-display-columns.tsx +85 -0
  34. package/data/examples/customize-filter-components.js +78 -0
  35. package/data/examples/customize-filter-components.tsx +101 -0
  36. package/data/examples/customize-filter-modes.js +59 -0
  37. package/data/examples/customize-filter-modes.tsx +73 -0
  38. package/data/examples/customize-filter-variants.js +98 -0
  39. package/data/examples/customize-filter-variants.tsx +116 -0
  40. package/data/examples/customize-global-filter-component.js +37 -0
  41. package/data/examples/customize-global-filter-component.tsx +52 -0
  42. package/data/examples/customize-remove-column-grouping.js +75 -0
  43. package/data/examples/customize-remove-column-grouping.tsx +94 -0
  44. package/data/examples/customize-row-selection.js +43 -0
  45. package/data/examples/customize-row-selection.tsx +54 -0
  46. package/data/examples/customize-table-styles.js +81 -0
  47. package/data/examples/customize-table-styles.tsx +100 -0
  48. package/data/examples/disable-column-actions.js +26 -0
  49. package/data/examples/disable-column-actions.tsx +37 -0
  50. package/data/examples/disable-column-hiding.js +74 -0
  51. package/data/examples/disable-column-hiding.tsx +90 -0
  52. package/data/examples/disable-density-toggle.js +37 -0
  53. package/data/examples/disable-density-toggle.tsx +49 -0
  54. package/data/examples/dynamic-columns.js +124 -0
  55. package/data/examples/dynamic-columns.tsx +189 -0
  56. package/data/examples/editing-crud-cell.js +288 -0
  57. package/data/examples/editing-crud-cell.tsx +377 -0
  58. package/data/examples/editing-crud-modal.js +275 -0
  59. package/data/examples/editing-crud-modal.tsx +370 -0
  60. package/data/examples/editing-crud-row.js +255 -0
  61. package/data/examples/editing-crud-row.tsx +333 -0
  62. package/data/examples/editing-crud-table.js +280 -0
  63. package/data/examples/editing-crud-table.tsx +369 -0
  64. package/data/examples/editing-crud-tree.js +328 -0
  65. package/data/examples/editing-crud-tree.tsx +416 -0
  66. package/data/examples/enable-cell-actions.js +52 -0
  67. package/data/examples/enable-cell-actions.tsx +76 -0
  68. package/data/examples/enable-click-to-copy.js +33 -0
  69. package/data/examples/enable-click-to-copy.tsx +39 -0
  70. package/data/examples/enable-column-grouping.js +69 -0
  71. package/data/examples/enable-column-grouping.tsx +120 -0
  72. package/data/examples/enable-column-ordering.js +37 -0
  73. package/data/examples/enable-column-ordering.tsx +48 -0
  74. package/data/examples/enable-column-pinning.js +58 -0
  75. package/data/examples/enable-column-pinning.tsx +69 -0
  76. package/data/examples/enable-column-resizing.js +45 -0
  77. package/data/examples/enable-column-resizing.tsx +56 -0
  78. package/data/examples/enable-column-virtualization.js +19 -0
  79. package/data/examples/enable-column-virtualization.tsx +27 -0
  80. package/data/examples/enable-detail-panel-conditionally.js +61 -0
  81. package/data/examples/enable-detail-panel-conditionally.tsx +78 -0
  82. package/data/examples/enable-detail-panel-virtualized.js +64 -0
  83. package/data/examples/enable-detail-panel-virtualized.tsx +80 -0
  84. package/data/examples/enable-expanding-tree.js +87 -0
  85. package/data/examples/enable-expanding-tree.tsx +110 -0
  86. package/data/examples/enable-filter-facet-values.js +52 -0
  87. package/data/examples/enable-filter-facet-values.tsx +65 -0
  88. package/data/examples/enable-row-dragging.js +102 -0
  89. package/data/examples/enable-row-dragging.tsx +137 -0
  90. package/data/examples/enable-row-numbers-original.js +37 -0
  91. package/data/examples/enable-row-numbers-original.tsx +48 -0
  92. package/data/examples/enable-row-numbers-static.js +37 -0
  93. package/data/examples/enable-row-numbers-static.tsx +48 -0
  94. package/data/examples/enable-row-ordering.js +40 -0
  95. package/data/examples/enable-row-ordering.tsx +57 -0
  96. package/data/examples/enable-row-pinning-select.js +64 -0
  97. package/data/examples/enable-row-pinning-select.tsx +76 -0
  98. package/data/examples/enable-row-pinning-static.js +39 -0
  99. package/data/examples/enable-row-pinning-static.tsx +50 -0
  100. package/data/examples/enable-row-pinning-sticky.js +57 -0
  101. package/data/examples/enable-row-pinning-sticky.tsx +69 -0
  102. package/data/examples/enable-row-selection.js +71 -0
  103. package/data/examples/enable-row-selection.tsx +96 -0
  104. package/data/examples/enable-row-virtualization.js +85 -0
  105. package/data/examples/enable-row-virtualization.tsx +101 -0
  106. package/data/examples/enable-sticky-header.js +47 -0
  107. package/data/examples/enable-sticky-header.tsx +59 -0
  108. package/data/examples/expanding-tree-expanded.js +98 -0
  109. package/data/examples/expanding-tree-expanded.tsx +121 -0
  110. package/data/examples/expanding-tree-flat-parse.js +102 -0
  111. package/data/examples/expanding-tree-flat-parse.tsx +125 -0
  112. package/data/examples/expanding-tree-root-expanded.js +120 -0
  113. package/data/examples/expanding-tree-root-expanded.tsx +151 -0
  114. package/data/examples/export-to-csv.js +84 -0
  115. package/data/examples/export-to-csv.tsx +114 -0
  116. package/data/examples/export-to-pdf.js +76 -0
  117. package/data/examples/export-to-pdf.tsx +104 -0
  118. package/data/examples/external-toolbar.js +82 -0
  119. package/data/examples/external-toolbar.tsx +108 -0
  120. package/data/examples/font-awesome-icons.js +62 -0
  121. package/data/examples/font-awesome-icons.tsx +106 -0
  122. package/data/examples/infinite-scrolling.js +137 -0
  123. package/data/examples/infinite-scrolling.tsx +208 -0
  124. package/data/examples/lazy-detail-panel.js +164 -0
  125. package/data/examples/lazy-detail-panel.tsx +262 -0
  126. package/data/examples/lazy-sub-rows.js +118 -0
  127. package/data/examples/lazy-sub-rows.tsx +190 -0
  128. package/data/examples/linear-progress.js +48 -0
  129. package/data/examples/linear-progress.tsx +66 -0
  130. package/data/examples/loading.js +34 -0
  131. package/data/examples/loading.tsx +50 -0
  132. package/data/examples/localization-i18n-ar.js +40 -0
  133. package/data/examples/localization-i18n-ar.tsx +65 -0
  134. package/data/examples/localization-i18n-az.js +38 -0
  135. package/data/examples/localization-i18n-az.tsx +60 -0
  136. package/data/examples/localization-i18n-bg.js +38 -0
  137. package/data/examples/localization-i18n-bg.tsx +60 -0
  138. package/data/examples/localization-i18n-cs.js +38 -0
  139. package/data/examples/localization-i18n-cs.tsx +60 -0
  140. package/data/examples/localization-i18n-da.js +38 -0
  141. package/data/examples/localization-i18n-da.tsx +60 -0
  142. package/data/examples/localization-i18n-de.js +38 -0
  143. package/data/examples/localization-i18n-de.tsx +60 -0
  144. package/data/examples/localization-i18n-el.js +38 -0
  145. package/data/examples/localization-i18n-el.tsx +60 -0
  146. package/data/examples/localization-i18n-en.js +38 -0
  147. package/data/examples/localization-i18n-en.tsx +60 -0
  148. package/data/examples/localization-i18n-es.js +38 -0
  149. package/data/examples/localization-i18n-es.tsx +60 -0
  150. package/data/examples/localization-i18n-et.js +38 -0
  151. package/data/examples/localization-i18n-et.tsx +60 -0
  152. package/data/examples/localization-i18n-fa.js +40 -0
  153. package/data/examples/localization-i18n-fa.tsx +66 -0
  154. package/data/examples/localization-i18n-fi.js +38 -0
  155. package/data/examples/localization-i18n-fi.tsx +60 -0
  156. package/data/examples/localization-i18n-fr.js +38 -0
  157. package/data/examples/localization-i18n-fr.tsx +60 -0
  158. package/data/examples/localization-i18n-he.js +40 -0
  159. package/data/examples/localization-i18n-he.tsx +66 -0
  160. package/data/examples/localization-i18n-hr.js +38 -0
  161. package/data/examples/localization-i18n-hr.tsx +60 -0
  162. package/data/examples/localization-i18n-hu.js +38 -0
  163. package/data/examples/localization-i18n-hu.tsx +60 -0
  164. package/data/examples/localization-i18n-hy.js +40 -0
  165. package/data/examples/localization-i18n-hy.tsx +65 -0
  166. package/data/examples/localization-i18n-id.js +38 -0
  167. package/data/examples/localization-i18n-id.tsx +60 -0
  168. package/data/examples/localization-i18n-it.js +38 -0
  169. package/data/examples/localization-i18n-it.tsx +60 -0
  170. package/data/examples/localization-i18n-ja.js +38 -0
  171. package/data/examples/localization-i18n-ja.tsx +60 -0
  172. package/data/examples/localization-i18n-ko.js +38 -0
  173. package/data/examples/localization-i18n-ko.tsx +60 -0
  174. package/data/examples/localization-i18n-nl.js +38 -0
  175. package/data/examples/localization-i18n-nl.tsx +60 -0
  176. package/data/examples/localization-i18n-no.js +38 -0
  177. package/data/examples/localization-i18n-no.tsx +60 -0
  178. package/data/examples/localization-i18n-np.js +38 -0
  179. package/data/examples/localization-i18n-np.tsx +60 -0
  180. package/data/examples/localization-i18n-pl.js +38 -0
  181. package/data/examples/localization-i18n-pl.tsx +60 -0
  182. package/data/examples/localization-i18n-pt-BR.js +38 -0
  183. package/data/examples/localization-i18n-pt-BR.tsx +60 -0
  184. package/data/examples/localization-i18n-pt.js +38 -0
  185. package/data/examples/localization-i18n-pt.tsx +60 -0
  186. package/data/examples/localization-i18n-ro.js +38 -0
  187. package/data/examples/localization-i18n-ro.tsx +60 -0
  188. package/data/examples/localization-i18n-ru.js +38 -0
  189. package/data/examples/localization-i18n-ru.tsx +60 -0
  190. package/data/examples/localization-i18n-sk.js +38 -0
  191. package/data/examples/localization-i18n-sk.tsx +60 -0
  192. package/data/examples/localization-i18n-sr-Cyrl-RS.js +38 -0
  193. package/data/examples/localization-i18n-sr-Cyrl-RS.tsx +60 -0
  194. package/data/examples/localization-i18n-sr-Latn-RS.js +38 -0
  195. package/data/examples/localization-i18n-sr-Latn-RS.tsx +60 -0
  196. package/data/examples/localization-i18n-sv.js +38 -0
  197. package/data/examples/localization-i18n-sv.tsx +60 -0
  198. package/data/examples/localization-i18n-tr.js +38 -0
  199. package/data/examples/localization-i18n-tr.tsx +60 -0
  200. package/data/examples/localization-i18n-uk.js +38 -0
  201. package/data/examples/localization-i18n-uk.tsx +60 -0
  202. package/data/examples/localization-i18n-vi.js +38 -0
  203. package/data/examples/localization-i18n-vi.tsx +60 -0
  204. package/data/examples/localization-i18n-zh-hans.js +38 -0
  205. package/data/examples/localization-i18n-zh-hans.tsx +60 -0
  206. package/data/examples/localization-i18n-zh-hant.js +38 -0
  207. package/data/examples/localization-i18n-zh-hant.tsx +60 -0
  208. package/data/examples/manual-selection.js +81 -0
  209. package/data/examples/manual-selection.tsx +105 -0
  210. package/data/examples/minimal.js +66 -0
  211. package/data/examples/minimal.tsx +78 -0
  212. package/data/examples/mui-theme.js +109 -0
  213. package/data/examples/mui-theme.tsx +136 -0
  214. package/data/examples/multi-sorting.js +48 -0
  215. package/data/examples/multi-sorting.tsx +58 -0
  216. package/data/examples/persistent-state.js +126 -0
  217. package/data/examples/persistent-state.tsx +184 -0
  218. package/data/examples/react-query.js +122 -0
  219. package/data/examples/react-query.tsx +182 -0
  220. package/data/examples/remote.js +113 -0
  221. package/data/examples/remote.tsx +150 -0
  222. package/data/examples/row-actions-buttons.js +54 -0
  223. package/data/examples/row-actions-buttons.tsx +89 -0
  224. package/data/examples/row-actions-menu-items.js +36 -0
  225. package/data/examples/row-actions-menu-items.tsx +64 -0
  226. package/data/examples/single-row-selection.js +74 -0
  227. package/data/examples/single-row-selection.tsx +98 -0
  228. package/data/examples/virtualized.js +122 -0
  229. package/data/examples/virtualized.tsx +138 -0
  230. package/data/guides/accessibility.md +119 -0
  231. package/data/guides/aggregation.md +210 -0
  232. package/data/guides/async-loading.md +132 -0
  233. package/data/guides/best-practices.md +363 -0
  234. package/data/guides/cell-actions.md +139 -0
  235. package/data/guides/click-to-copy.md +67 -0
  236. package/data/guides/column-actions.md +69 -0
  237. package/data/guides/column-filtering.md +366 -0
  238. package/data/guides/column-grouping.md +192 -0
  239. package/data/guides/column-hiding.md +133 -0
  240. package/data/guides/column-ordering-dnd.md +99 -0
  241. package/data/guides/column-pinning.md +72 -0
  242. package/data/guides/column-resizing.md +157 -0
  243. package/data/guides/column-size.md +162 -0
  244. package/data/guides/customize-components.md +395 -0
  245. package/data/guides/customize-icons.md +35 -0
  246. package/data/guides/data-columns.md +292 -0
  247. package/data/guides/density-toggle.md +46 -0
  248. package/data/guides/detail-panel.md +195 -0
  249. package/data/guides/display-columns.md +135 -0
  250. package/data/guides/editing.md +367 -0
  251. package/data/guides/expanding-sub-rows.md +194 -0
  252. package/data/guides/full-screen-toggle.md +63 -0
  253. package/data/guides/global-filtering.md +237 -0
  254. package/data/guides/localization.md +57 -0
  255. package/data/guides/memoization.md +157 -0
  256. package/data/guides/pagination.md +171 -0
  257. package/data/guides/row-actions.md +116 -0
  258. package/data/guides/row-numbers.md +24 -0
  259. package/data/guides/row-ordering-dnd.md +51 -0
  260. package/data/guides/row-pinning.md +96 -0
  261. package/data/guides/row-selection.md +237 -0
  262. package/data/guides/sorting.md +190 -0
  263. package/data/guides/state-management.md +165 -0
  264. package/data/guides/sticky-header.md +41 -0
  265. package/data/guides/table-event-listeners.md +103 -0
  266. package/data/guides/toolbar-customization.md +251 -0
  267. package/data/guides/virtualization.md +183 -0
  268. package/data/index.json +1930 -0
  269. package/data/reference/mrt-components.md +183 -0
  270. package/data/reference/mrt-hooks.md +125 -0
  271. package/data/skills/README.md +81 -0
  272. package/data/skills/composable-components/SKILL.md +189 -0
  273. package/data/skills/customization/SKILL.md +190 -0
  274. package/data/skills/drag-and-drop-ordering/SKILL.md +227 -0
  275. package/data/skills/editing/SKILL.md +243 -0
  276. package/data/skills/filtering/SKILL.md +213 -0
  277. package/data/skills/getting-started/SKILL.md +213 -0
  278. package/data/skills/localization/SKILL.md +182 -0
  279. package/data/skills/migrate-v3-to-v4/SKILL.md +161 -0
  280. package/data/skills/state-and-server-data/SKILL.md +200 -0
  281. package/data/skills/virtualization/SKILL.md +203 -0
  282. package/dist/data.js +159 -0
  283. package/dist/index.js +244 -0
  284. package/package.json +50 -0
@@ -0,0 +1,138 @@
1
+ import { useEffect, useMemo, useRef, useState } from 'react';
2
+ import {
3
+ MaterialReactTable,
4
+ useMaterialReactTable,
5
+ type MRT_ColumnDef,
6
+ type MRT_SortingState,
7
+ type MRT_RowVirtualizer,
8
+ } from 'material-react-table';
9
+ import { makeData, type Person } from './makeData';
10
+
11
+ const Example = () => {
12
+ const columns = useMemo<MRT_ColumnDef<Person>[]>(
13
+ //column definitions...
14
+ () => [
15
+ {
16
+ accessorKey: 'firstName',
17
+ header: 'First Name',
18
+ size: 150,
19
+ },
20
+ {
21
+ accessorKey: 'middleName',
22
+ header: 'Middle Name',
23
+ size: 170,
24
+ },
25
+ {
26
+ accessorKey: 'lastName',
27
+ header: 'Last Name',
28
+ size: 150,
29
+ },
30
+ {
31
+ accessorKey: 'email',
32
+ header: 'Email Address',
33
+ size: 300,
34
+ },
35
+ {
36
+ accessorKey: 'phoneNumber',
37
+ header: 'Phone Number',
38
+ size: 250,
39
+ },
40
+ {
41
+ accessorKey: 'address',
42
+ header: 'Address',
43
+ size: 300,
44
+ },
45
+ {
46
+ accessorKey: 'zipCode',
47
+ header: 'Zip Code',
48
+ },
49
+ {
50
+ accessorKey: 'city',
51
+ header: 'City',
52
+ size: 220,
53
+ },
54
+ {
55
+ accessorKey: 'state',
56
+ header: 'State',
57
+ },
58
+ {
59
+ accessorKey: 'country',
60
+ header: 'Country',
61
+ size: 350,
62
+ },
63
+ {
64
+ accessorKey: 'petName',
65
+ header: 'Pet Name',
66
+ },
67
+ {
68
+ accessorKey: 'age',
69
+ header: 'Age',
70
+ },
71
+ {
72
+ accessorKey: 'salary',
73
+ header: 'Salary',
74
+ },
75
+ {
76
+ accessorKey: 'dateOfBirth',
77
+ header: 'Date of Birth',
78
+ },
79
+ {
80
+ accessorKey: 'dateOfJoining',
81
+ header: 'Date of Joining',
82
+ },
83
+ {
84
+ accessorKey: 'isActive',
85
+ header: 'Is Active',
86
+ },
87
+ ],
88
+ [],
89
+ //end
90
+ );
91
+
92
+ //optionally access the underlying virtualizer instance
93
+ const rowVirtualizerInstanceRef = useRef<MRT_RowVirtualizer>(null);
94
+
95
+ const [data, setData] = useState<Person[]>([]);
96
+ const [isLoading, setIsLoading] = useState(true);
97
+ const [sorting, setSorting] = useState<MRT_SortingState>([]);
98
+
99
+ useEffect(() => {
100
+ if (typeof window !== 'undefined') {
101
+ setData(makeData(10_000));
102
+ setIsLoading(false);
103
+ }
104
+ }, []);
105
+
106
+ useEffect(() => {
107
+ //scroll to the top of the table when the sorting changes
108
+ try {
109
+ rowVirtualizerInstanceRef.current?.scrollToIndex?.(0);
110
+ } catch (error) {
111
+ console.error(error);
112
+ }
113
+ }, [sorting]);
114
+
115
+ const table = useMaterialReactTable({
116
+ columns,
117
+ data, //10,000 rows
118
+ defaultDisplayColumn: { enableResizing: true },
119
+ enableBottomToolbar: false,
120
+ enableColumnResizing: true,
121
+ enableColumnVirtualization: true,
122
+ enableGlobalFilterModes: true,
123
+ enablePagination: false,
124
+ enableColumnPinning: true,
125
+ enableRowNumbers: true,
126
+ enableRowVirtualization: true,
127
+ muiTableContainerProps: { sx: { maxHeight: '600px' } },
128
+ onSortingChange: setSorting,
129
+ state: { isLoading, sorting },
130
+ rowVirtualizerInstanceRef, //optional
131
+ rowVirtualizerOptions: { overscan: 5 }, //optionally customize the row virtualizer
132
+ columnVirtualizerOptions: { overscan: 2 }, //optionally customize the column virtualizer
133
+ });
134
+
135
+ return <MaterialReactTable table={table} />;
136
+ };
137
+
138
+ export default Example;
@@ -0,0 +1,119 @@
1
+ ## Accessibility / Keyboard Navigation Guide
2
+
3
+ Material React Table tries to get the basics of data grid accessibility right out of the box. But since you can easily add event handlers to just about any interaction inside of the table, you can heavily customize the accessibility of your table to your needs too.
4
+
5
+ ### Relevant Table Options
6
+
7
+ Relevant table options (get_mrt_api has full details):
8
+
9
+ - `enableKeyboardShortcuts` - type `boolean` - default `true`
10
+
11
+ ### Keyboard Navigation
12
+
13
+ > New in v3
14
+
15
+ Material React Table V3 introduces a new table option that is `true` by default: `enableKeyboardShortcuts`
16
+
17
+ #### `enableKeyboardShortcuts`
18
+
19
+ This option enables the following keyboard shortcuts:
20
+
21
+ - `Tab` - Moves the focus to the next cell or element in the table (standard browser behavior)
22
+ - `Arrow Up` - Moves the focus 1 cell up
23
+ - `Arrow Down` - Moves the focus 1 cell down
24
+ - `Arrow Left` - Moves the focus 1 cell left
25
+ - `Arrow Right` - Moves the focus 1 cell right
26
+ - `Home` - Moves the focus to the first cell in the current row
27
+ - `End` - Moves the focus to the last cell in the current row
28
+ - `Page Up` - Moves the focus to the first cell in the current column
29
+ - `Page Down` - Moves the focus to the last cell in the current column
30
+ - `Ctrl/Cmd + Home` - Moves the focus to the first cell in the table (top left in left-to-right languages)
31
+ - `Ctrl/Cmd + End` - Moves the focus to the last cell in the table (bottom right in left-to-right languages)
32
+ - `Enter` - Performs certain actions in the currently focused cell such as sorting, row selection, row expansion, row pinning, etc.
33
+ - `Space` - Also performs certain actions in the currently focused cell such as sorting, row selection, row expansion, row pinning, etc.
34
+ - `Ctrl/Cmd + Enter` - Opens column actions menu on a header
35
+ - `Escape` - Exits full screen mode
36
+
37
+ A `tabIndex={0}` is also automatically added to all cells, headers, and footers when `enableKeyboardShortcuts` is enabled to allow for keyboard focus.
38
+
39
+ ### Custom Keyboard Shortcuts
40
+
41
+ You do not have to use the provided keyboard shortcuts. You can turn off `enableKeyboardShortcuts` and add your own keyboard shortcuts using the `onKeyDown` event handler on all of the table cells (or any other element).
42
+
43
+ You can also add custom focus styles to any element using the `sx` prop.
44
+
45
+ ```tsx
46
+ const table = useMaterialReactTable({
47
+ columns,
48
+ data,
49
+ //add custom keyboard shortcuts
50
+ defaultColumn: {
51
+ //header
52
+ muiTableHeadCellProps: {
53
+ onKeyDown: (event) => {
54
+ if (event.key === 't' && event.metaKey) {
55
+ alert('You pressed the custom shortcut!');
56
+ }
57
+ },
58
+ tabIndex: 0, //allow for keyboard focus
59
+ },
60
+ //body
61
+ muiTableBodyCellProps: {
62
+ onKeyDown: (event) => {
63
+ if (event.key === 't' && event.metaKey) {
64
+ alert('You pressed the custom shortcut!');
65
+ }
66
+ },
67
+ //add custom focus styles
68
+ sx: {
69
+ '&:focus-visible': {
70
+ //or just `&:focus` if you want all focus events to be visible
71
+ outline: '2px solid red',
72
+ outlineOffset: '-2px',
73
+ },
74
+ },
75
+ tabIndex: 0, //allow for keyboard focus
76
+ },
77
+ },
78
+ enableKeyboardShortcuts: false, //turn off default keyboard shortcuts from MRT
79
+ });
80
+ ```
81
+
82
+ ### Custom Focus Styles
83
+
84
+ An outline is automatically added to all elements when they are focused. You can easily customize the color of the outline by setting `cellNavigationOutlineColor` property in the `mrtTheme` table option.
85
+
86
+ ```tsx
87
+ const table = useMaterialReactTable({
88
+ columns,
89
+ data,
90
+ mrtTheme: {
91
+ cellNavigationOutlineColor 'limegreen'
92
+ }
93
+ });
94
+ ```
95
+
96
+ Or, of course, you can just use the `sx` props to override any styles you want, just like any other style override in MRT.
97
+
98
+ ```tsx
99
+ const table = useMaterialReactTable({
100
+ columns,
101
+ data,
102
+ defaultColumn: {
103
+ muiTableBodyCellProps: {
104
+ sx: {
105
+ '&:focus-visible': {
106
+ outline: '4px solid red',
107
+ outlineOffset: '-4px',
108
+ },
109
+ },
110
+ },
111
+ },
112
+ });
113
+ ```
114
+
115
+ ### Full Screen Mode
116
+
117
+ Now in V3, a focus trap is applied to the table when in full screen mode. This is to prevent the user from navigating outside of the table when using the arrow keys.
118
+
119
+ The user can exit full screen mode by pressing `Escape`.
@@ -0,0 +1,210 @@
1
+ ## Aggregation Feature Guide
2
+
3
+ Material React Table has built-in aggregation features. There are options for both automatic client-side grouping and aggregation, as well as manual server-side grouping and aggregation. This guide will walk you through the different options and how to use and customize them.
4
+
5
+ > See the [Column Grouping Guide](/docs/guides/column-grouping) as a prerequisite to this guide. The Aggregation and Grouping Guide was recently split into two separate guides.
6
+
7
+ ### Relevant Table Options
8
+
9
+ Relevant table options (get_mrt_api has full details):
10
+
11
+ - `aggregationFns` - type `Record<string, AggregationFn>` - This option allows you to define custom aggregation functions that can be referenced in a column's aggregationFn option by their key
12
+ - `enableExpandAll` - type `boolean` - default `true`
13
+ - `enableGrouping` - type `boolean`
14
+ - `enableStickyFooter` - type `boolean`
15
+ - `groupedColumnMode` - type `false | 'reorder' | 'remove'` - default `reorder` - Grouping columns are automatically reordered by default to the start of the columns list. If you would rather remove them or leave them as-is, set the appropriate mode here.
16
+ - `manualGrouping` - type `boolean` - Enables manual grouping. If this option is set to true, the table will not automatically group rows using getGroupedRowModel() and instead will expect you to manually group the rows before passing them to the table. This is useful if you are doing server-side grouping and aggregation.
17
+ - `muiToolbarAlertBannerChipProps` - type `ChipProps| ({ table }} => ChipProps`
18
+ - `onGroupingChange` - type `OnChangeFn<GroupingState>` - If this function is provided, it will be called when the grouping state changes and you will be expected to manage the state yourself. You can pass the managed state back to the table via the tableOptions.state.grouping option.
19
+ - `positionToolbarAlertBanner` - type `'bottom' | 'top' | 'none'` - default `'top'`
20
+
21
+ ### Relevant Column Options
22
+
23
+ Relevant column options (get_mrt_api has full details):
24
+
25
+ - `AggregatedCell` - type `({ cell, column, row, table }) => ReactNode` - Define a custom cell render for an aggregated cell.
26
+ - `enableGrouping` - type `boolean`
27
+ - `Footer` - type `ReactNode | ({ column, footer, table }) => ReactNode` - Render custom markup for a column footer.
28
+ - `GroupedCell` - type `({ cell, column, row, table }) => ReactNode` - Define a custom cell render for a grouped cell.
29
+ - `PlaceholderCell` - type `({ cell, column, row, table }) => ReactNode` - Define a custom cell render for a placeholder cell.
30
+
31
+ ### Relevant State
32
+
33
+ Relevant state options (get_mrt_api has full details):
34
+
35
+ - `expanded` - type `Record<string, boolean> | boolean` - default `{}`
36
+ - `grouping` - type `Array<string>` - default `[]`
37
+
38
+ ### Aggregation on Grouped Rows
39
+
40
+ One of the cool features of Material React Table is that it can automatically aggregate the data in grouped rows. To enable this, you must specify both an `aggregationFn` and an `AggregatedCell` render option on a column definition.
41
+
42
+ #### Built-in Aggregation Functions
43
+
44
+ There are several built-in aggregation functions available that you can use. They are:
45
+
46
+ - `count` - Finds the number of rows in a group
47
+ - `extent` - Finds the minimum and maximum values of a group of rows
48
+ - `max` - Finds the maximum value of a group of rows
49
+ - `mean` - Finds the average value of a group of rows
50
+ - `median` - Finds the median value of a group of rows
51
+ - `min` - Finds the minimum value of a group of rows
52
+ - `sum` - sums the values of a group of rows
53
+ - `uniqueCount` - Finds the number of unique values of a group of rows
54
+ - `unique` - Finds the unique values of a group of rows
55
+
56
+ _All of these built-in aggregation functions are from [TanStack Table](https://tanstack.com/table/v9/docs/framework/react/guide/grouping)_
57
+
58
+ ```jsx
59
+ const columns = [
60
+ {
61
+ accessorKey: 'team', //grouped by team in initial state below
62
+ header: 'Team',
63
+ },
64
+ {
65
+ accessorKey: 'player',
66
+ header: 'Player',
67
+ },
68
+ {
69
+ accessorKey: 'points',
70
+ header: 'Points',
71
+ aggregationFn: 'sum', //calc total points for each team by adding up all the points for each player on the team
72
+ AggregatedCell: ({ cell }) => <div>Team Score: {cell.getValue()}</div>,
73
+ },
74
+ ];
75
+
76
+ const table = useMaterialReactTable({
77
+ columns,
78
+ data,
79
+ enableGrouping: true,
80
+ initialState: { grouping: ['team'], expanded: true },
81
+ });
82
+
83
+ return <MaterialReactTable table={table} />;
84
+ ```
85
+
86
+ #### Custom Aggregation Functions
87
+
88
+ If none of these pre-built aggregation functions work for you, you can also pass in a custom aggregation function. The aggregation function will be passed in an array of values from the column that you are aggregating. It should return a single value that will be displayed in the aggregated cell.
89
+
90
+ If you are specifying a custom aggregation function, it must implement the following type:
91
+
92
+ ```jsx
93
+ export type AggregationFn<TData extends AnyData> = (
94
+ getLeafRows: () => Row<TData>[],
95
+ getChildRows: () => Row<TData>[]
96
+ ) => any
97
+ ```
98
+
99
+ ### Aggregation on All Rows in Footer
100
+
101
+ Material React Table does not automatically aggregate all rows for you to calculate totals for the entire table. However, it is still easy enough to do this manually and add in your custom calculations into the `footer` or `Footer` of a column definition. It is recommended that you do any necessary aggregation calculations on your data in a useMemo hook before passing it to the columns footer in your columns definition.
102
+
103
+ ```jsx
104
+ //calculate the total points for all players in the table in a useMemo hook
105
+ const averageScore = useMemo(() => {
106
+ const totalPoints = data.reduce((acc, row) => acc + row.points, 0);
107
+ const totalPlayers = data.length;
108
+ return totalPoints / totalPlayers;
109
+ }, [data]);
110
+
111
+ const columns = useMemo(
112
+ () => [
113
+ {
114
+ accessorKey: 'name',
115
+ header: 'Name',
116
+ },
117
+ {
118
+ accessorKey: 'score',
119
+ header: 'Score',
120
+ Footer: () => <div>Average Score: {averageScore}</div>, //do not do calculations in render, do them in useMemo hook and pass them in here
121
+ },
122
+ ],
123
+ [averageScore],
124
+ );
125
+ ```
126
+
127
+ > Please remember to perform heavy aggregation calculations in a useMemo hook to avoid unnecessary re-renders!
128
+
129
+ ### Custom Cell Renders for Aggregation and Grouping
130
+
131
+ There are a few custom cell render overrides that you should be aware of when using grouping and aggregation features.
132
+
133
+ #### AggregatedCell Column Option
134
+
135
+ "Aggregation Cells" are cells in an aggregated row (not a normal data row) that can display aggregates (avg, sum, etc.) of the data in a group. The cell that the table is grouped on, however, is not an Aggregate Cell, but rather a [GroupedCell](#groupedcell-column-option).
136
+
137
+ You can specify the custom render for these cells with the `AggregatedCell` render option on a column definition.
138
+
139
+ ```jsx
140
+ const columns = [
141
+ {
142
+ accessorKey: 'points',
143
+ header: 'Points',
144
+ aggregationFn: 'sum',
145
+ AggregatedCell: ({ cell }) => <div>Total Score: {cell.getValue()}</div>,
146
+ },
147
+ ];
148
+ ```
149
+
150
+ #### GroupedCell Column Option
151
+
152
+ "Grouped Cells" are cells in a grouped row (not a normal data row) that by default display the value that the rows are grouped on and the number of rows in the group. You can override the default render for these cells with the `GroupedCell` render option on a column definition.
153
+
154
+ ```jsx
155
+ const columns = [
156
+ {
157
+ accessorKey: 'team',
158
+ header: 'Team',
159
+ GroupedCell: ({ cell }) => <div>Team: {cell.getValue()}</div>,
160
+ },
161
+ ];
162
+ ```
163
+
164
+ #### PlaceholderCell Column Option
165
+
166
+ "Placeholder Cells" are cells that are usually meant to be empty in grouped rows and columns. They are simply rendered with a value of `null` by default, but you can override the default render for these cells with the `PlaceholderCell` render option on a column definition.
167
+
168
+ ```jsx
169
+ const columns = [
170
+ {
171
+ accessorKey: 'team',
172
+ header: 'Team',
173
+ PlaceholderCell: ({ cell, row }) => (
174
+ <div>{row.original.someOtherRowValue}</div>
175
+ ),
176
+ },
177
+ ];
178
+ ```
179
+
180
+ ### Aggregation/Grouping Example
181
+
182
+ > Live example: `aggregation-and-grouping` (call get_mrt_example with that id).
183
+
184
+ ### Multiple Aggregations Per column
185
+
186
+ You may want to calculate more than one aggregation per column. This is now easier if you are upgraded to at least v1.3.0. You can now specify an array of `aggregationFn`s, and then reference the aggregation results from an array in the `AggregatedCell` render option.
187
+
188
+ ```jsx
189
+ const columns = [
190
+ {
191
+ header: 'Salary',
192
+ accessorKey: 'salary',
193
+ aggregationFn: ['count', 'mean'], //multiple aggregation functions
194
+ AggregatedCell: ({ cell, table }) => (
195
+ <div>
196
+ {/*get the count from the first aggregation*/}
197
+ <div>Count: {cell.getValue()[0]}</div>
198
+ {/*get the average from the second aggregation*/}
199
+ <div>Average Salary: {cell.getValue()[1]}</div>
200
+ </div>
201
+ ),
202
+ },
203
+ ];
204
+ ```
205
+
206
+ > Live example: `aggregation-multi` (call get_mrt_example with that id).
207
+
208
+ ### Manual Grouping
209
+
210
+ Manual Grouping means that the `data` that you pass to the table is already grouped and aggregated, and you do not want Material React Table to do any of the grouping or aggregation for you. This is useful if you are using a backend API to do the grouping and aggregation for you, and you just want to display the results. However, you will need to put your data in the specific format that the `expanding` features understand.
@@ -0,0 +1,132 @@
1
+ ## Async Loading UI Feature Guide
2
+
3
+ While you are fetching your data, you may want to show some loading indicators. Material React Table has some nice loading UI features built in that look better than a simple spinner.
4
+
5
+ > This guide is mostly focused on the loading UI features. Make sure to also check out the [Remote Data](/docs/examples/remote) and [React Query](/docs/examples/react-query) examples for server-side logic examples.
6
+
7
+ ### Relevant Table Options
8
+
9
+ Relevant table options (get_mrt_api has full details):
10
+
11
+ - `muiCircularProgressProps` - type `CircularProgressProps | ({ table }) => CircularProgressProps`
12
+ - `muiLinearProgressProps` - type `LinearProgressProps | ({ isTopToolbar, table }) => LinearProgressProps`
13
+ - `muiSkeletonProps` - type `SkeletonProps | ({ cell, column, row, table }) => SkeletonProps`
14
+
15
+ ### Relevant State Options
16
+
17
+ Relevant state options (get_mrt_api has full details):
18
+
19
+ - `isLoading` - type `boolean` - default `false`
20
+ - `isSaving` - type `boolean` - default `false`
21
+ - `showLoadingOverlay` - type `boolean` - default `false`
22
+ - `showProgressBars` - type `boolean` - default `false`
23
+ - `showSkeletons` - type `boolean` - default `false`
24
+
25
+ ### isLoading UI
26
+
27
+ There are three different loading UI features that are built into Material React Table:
28
+
29
+ 1. Loading Overlay - shows spinner overlay over the table container.
30
+ 2. Cell Skeletons - show pretty and shimmering skeletons for each cell.
31
+ 3. Linear Progress Bars - shows progress bars above and/or below the table.
32
+
33
+ You can use any combination of these loading UIs by managing the `showLoadingOverlay`, `showSkeletons`, and `showProgressBars` states.
34
+
35
+ There are also two other loading states that are shortcuts for combining some of the above states:
36
+
37
+ - `isLoading` - shows loading overlay and cell skeletons.
38
+ - `isSaving` - shows the progress bars and adds spinners to the save buttons in editing features.
39
+
40
+ Here is some of the recommended loading UI that you might use with React Query:
41
+
42
+ ```jsx
43
+ const {
44
+ data = [],
45
+ isLoading: isLoadingTodos,
46
+ isRefetching: isRefetchingTodos,
47
+ } = useQuery({
48
+ /**/
49
+ });
50
+
51
+ const { mutate, isPending: isSavingTodos } = useMutation({
52
+ /**/
53
+ });
54
+
55
+ const table = useMaterialReactTable({
56
+ columns,
57
+ data,
58
+ state: {
59
+ isLoading: isLoadingTodos, //cell skeletons and loading overlay
60
+ showProgressBars: isRefetchingTodos, //progress bars while refetching
61
+ isSaving: isSavingTodos, //progress bars and save button spinners
62
+ },
63
+ });
64
+
65
+ return <MaterialReactTable table={table} />;
66
+ ```
67
+
68
+ > Note: The Loading Overlay UI makes the table container non-interactive while it is showing. This is usually desired while no data is yet in the table. Consider avoiding using the Loading Overlay UI during "refetching" operations like filtering, sorting, or pagination.
69
+
70
+ ### Customize Loading UI
71
+
72
+ You can customize the loading UI by passing props to the `muiSkeletonProps`, `muiLinearProgressProps`, and `muiCircularProgressProps` props.
73
+
74
+ ```jsx
75
+ const table = useMaterialReactTable({
76
+ columns,
77
+ data,
78
+ muiSkeletonProps: {
79
+ animation: 'wave',
80
+ },
81
+ muiLinearProgressProps: {
82
+ color: 'secondary',
83
+ },
84
+ muiCircularProgressProps: {
85
+ color: 'secondary',
86
+ },
87
+ });
88
+
89
+ return <MaterialReactTable table={table} />;
90
+ ```
91
+
92
+ > Live example: `loading` (call get_mrt_example with that id).
93
+
94
+ #### Custom Loading Spinner component
95
+
96
+ > New in v2.11.0
97
+
98
+ If you need to use a custom loading spinner component other than the built-in MUI one, you can now pass in custom component in the `muiCircularProgressProps` `Component` prop.
99
+
100
+ ```jsx
101
+ import { MyCustomSpinner } from './MyCustomSpinner';
102
+
103
+ const table = useMaterialReactTable({
104
+ columns,
105
+ data,
106
+ muiCircularProgressProps: {
107
+ Component: <MyCustomSpinner />,
108
+ },
109
+ });
110
+ ```
111
+
112
+ ### Only Show Progress Bars or Skeletons
113
+
114
+ If you do not want both progress bars and cell skeletons to show, you can use the `showProgressBars` and `showSkeletons` states, instead.
115
+
116
+ ```jsx
117
+ const table = useMaterialReactTable({
118
+ columns,
119
+ data,
120
+ state: {
121
+ showProgressBars: true, //or showSkeletons
122
+ },
123
+ });
124
+ ```
125
+
126
+ > Live example: `linear-progress` (call get_mrt_example with that id).
127
+
128
+ ### Full Loading and Server-Side Logic Example
129
+
130
+ Here is a copy of the full [React Query](/docs/examples/react-query) example.
131
+
132
+ > Live example: `react-query` (call get_mrt_example with that id).