@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,150 @@
1
+ import { useEffect, useMemo, useState } from 'react';
2
+ import {
3
+ MaterialReactTable,
4
+ useMaterialReactTable,
5
+ type MRT_ColumnDef,
6
+ type MRT_ColumnFiltersState,
7
+ type MRT_PaginationState,
8
+ type MRT_SortingState,
9
+ } from 'material-react-table';
10
+
11
+ type UserApiResponse = {
12
+ data: Array<User>;
13
+ meta: {
14
+ totalRowCount: number;
15
+ };
16
+ };
17
+
18
+ type User = {
19
+ firstName: string;
20
+ lastName: string;
21
+ address: string;
22
+ state: string;
23
+ phoneNumber: string;
24
+ };
25
+
26
+ const Example = () => {
27
+ //data and fetching state
28
+ const [data, setData] = useState<User[]>([]);
29
+ const [isError, setIsError] = useState(false);
30
+ const [isLoading, setIsLoading] = useState(false);
31
+ const [isRefetching, setIsRefetching] = useState(false);
32
+ const [rowCount, setRowCount] = useState(0);
33
+
34
+ //table state
35
+ const [columnFilters, setColumnFilters] = useState<MRT_ColumnFiltersState>(
36
+ [],
37
+ );
38
+ const [globalFilter, setGlobalFilter] = useState('');
39
+ const [sorting, setSorting] = useState<MRT_SortingState>([]);
40
+ const [pagination, setPagination] = useState<MRT_PaginationState>({
41
+ pageIndex: 0,
42
+ pageSize: 10,
43
+ });
44
+
45
+ //if you want to avoid useEffect, look at the React Query example instead
46
+ useEffect(() => {
47
+ const fetchData = async () => {
48
+ if (!data.length) {
49
+ setIsLoading(true);
50
+ } else {
51
+ setIsRefetching(true);
52
+ }
53
+
54
+ const url = new URL('/api/data', location.origin);
55
+ url.searchParams.set(
56
+ 'start',
57
+ `${pagination.pageIndex * pagination.pageSize}`,
58
+ );
59
+ url.searchParams.set('size', `${pagination.pageSize}`);
60
+ url.searchParams.set('filters', JSON.stringify(columnFilters ?? []));
61
+ url.searchParams.set('globalFilter', globalFilter ?? '');
62
+ url.searchParams.set('sorting', JSON.stringify(sorting ?? []));
63
+
64
+ try {
65
+ const response = await fetch(url.href);
66
+ const json = (await response.json()) as UserApiResponse;
67
+ setData(json.data);
68
+ setRowCount(json.meta.totalRowCount);
69
+ } catch (error) {
70
+ setIsError(true);
71
+ console.error(error);
72
+ return;
73
+ }
74
+ setIsError(false);
75
+ setIsLoading(false);
76
+ setIsRefetching(false);
77
+ };
78
+ fetchData();
79
+ // eslint-disable-next-line react-hooks/exhaustive-deps
80
+ }, [
81
+ columnFilters, //re-fetch when column filters change
82
+ globalFilter, //re-fetch when global filter changes
83
+ pagination.pageIndex, //re-fetch when page index changes
84
+ pagination.pageSize, //re-fetch when page size changes
85
+ sorting, //re-fetch when sorting changes
86
+ ]);
87
+
88
+ const columns = useMemo<MRT_ColumnDef<User>[]>(
89
+ () => [
90
+ {
91
+ accessorKey: 'firstName',
92
+ header: 'First Name',
93
+ },
94
+ //column definitions...
95
+ {
96
+ accessorKey: 'lastName',
97
+ header: 'Last Name',
98
+ },
99
+ {
100
+ accessorKey: 'address',
101
+ header: 'Address',
102
+ },
103
+ {
104
+ accessorKey: 'state',
105
+ header: 'State',
106
+ },
107
+ {
108
+ accessorKey: 'phoneNumber',
109
+ header: 'Phone Number',
110
+ },
111
+ //end
112
+ ],
113
+ [],
114
+ );
115
+
116
+ const table = useMaterialReactTable({
117
+ columns,
118
+ data,
119
+ enableRowSelection: true,
120
+ getRowId: (row) => row.phoneNumber,
121
+ initialState: { showColumnFilters: true },
122
+ manualFiltering: true,
123
+ manualPagination: true,
124
+ manualSorting: true,
125
+ muiToolbarAlertBannerProps: isError
126
+ ? {
127
+ color: 'error',
128
+ children: 'Error loading data',
129
+ }
130
+ : undefined,
131
+ onColumnFiltersChange: setColumnFilters,
132
+ onGlobalFilterChange: setGlobalFilter,
133
+ onPaginationChange: setPagination,
134
+ onSortingChange: setSorting,
135
+ rowCount,
136
+ state: {
137
+ columnFilters,
138
+ globalFilter,
139
+ isLoading,
140
+ pagination,
141
+ showAlertBanner: isError,
142
+ showProgressBars: isRefetching,
143
+ sorting,
144
+ },
145
+ });
146
+
147
+ return <MaterialReactTable table={table} />;
148
+ };
149
+
150
+ export default Example;
@@ -0,0 +1,54 @@
1
+ import { useMemo, useState } from 'react';
2
+ import { MaterialReactTable } from 'material-react-table';
3
+ import { Box, IconButton } from '@mui/material';
4
+ import { Edit as EditIcon, Delete as DeleteIcon, Email as EmailIcon, } from '@mui/icons-material';
5
+ import { data as initialData } from './makeData';
6
+ export const Example = () => {
7
+ const columns = useMemo(
8
+ //column definitions...
9
+ () => [
10
+ {
11
+ accessorKey: 'firstName',
12
+ header: 'First Name',
13
+ },
14
+ {
15
+ accessorKey: 'lastName',
16
+ header: 'Last Name',
17
+ },
18
+ {
19
+ accessorKey: 'address',
20
+ header: 'Address',
21
+ },
22
+ {
23
+ accessorKey: 'city',
24
+ header: 'City',
25
+ },
26
+ {
27
+ accessorKey: 'state',
28
+ header: 'State',
29
+ },
30
+ ], []);
31
+ const [data, setData] = useState(initialData);
32
+ return (<MaterialReactTable columns={columns} data={data} layoutMode="grid" displayColumnDefOptions={{
33
+ 'mrt-row-actions': {
34
+ size: 180, //if using layoutMode that is not 'semantic', the columns will not auto-size, so you need to set the size manually
35
+ grow: false,
36
+ },
37
+ }} enableRowActions renderRowActions={({ row, table }) => (<Box sx={{ display: 'flex', flexWrap: 'nowrap', gap: '8px' }}>
38
+ <IconButton color="primary" onClick={() => window.open(`mailto:kevinvandy@mailinator.com?subject=Hello ${row.original.firstName}!`)}>
39
+ <EmailIcon />
40
+ </IconButton>
41
+ <IconButton color="secondary" onClick={() => {
42
+ table.setEditingRow(row);
43
+ }}>
44
+ <EditIcon />
45
+ </IconButton>
46
+ <IconButton color="error" onClick={() => {
47
+ data.splice(row.index, 1); //assuming simple data table
48
+ setData([...data]);
49
+ }}>
50
+ <DeleteIcon />
51
+ </IconButton>
52
+ </Box>)}/>);
53
+ };
54
+ export default Example;
@@ -0,0 +1,89 @@
1
+ import { useMemo, useState } from 'react';
2
+ import { MaterialReactTable, type MRT_ColumnDef } from 'material-react-table';
3
+ import { Box, IconButton } from '@mui/material';
4
+ import {
5
+ Edit as EditIcon,
6
+ Delete as DeleteIcon,
7
+ Email as EmailIcon,
8
+ } from '@mui/icons-material';
9
+ import { data as initialData, type Person } from './makeData';
10
+
11
+ export const Example = () => {
12
+ const columns = useMemo<MRT_ColumnDef<Person>[]>(
13
+ //column definitions...
14
+ () => [
15
+ {
16
+ accessorKey: 'firstName',
17
+ header: 'First Name',
18
+ },
19
+ {
20
+ accessorKey: 'lastName',
21
+ header: 'Last Name',
22
+ },
23
+ {
24
+ accessorKey: 'address',
25
+ header: 'Address',
26
+ },
27
+ {
28
+ accessorKey: 'city',
29
+ header: 'City',
30
+ },
31
+ {
32
+ accessorKey: 'state',
33
+ header: 'State',
34
+ },
35
+ ],
36
+ [],
37
+ //end
38
+ );
39
+
40
+ const [data, setData] = useState<Person[]>(initialData);
41
+
42
+ return (
43
+ <MaterialReactTable
44
+ columns={columns}
45
+ data={data}
46
+ layoutMode="grid"
47
+ displayColumnDefOptions={{
48
+ 'mrt-row-actions': {
49
+ size: 180, //if using layoutMode that is not 'semantic', the columns will not auto-size, so you need to set the size manually
50
+ grow: false,
51
+ },
52
+ }}
53
+ enableRowActions
54
+ renderRowActions={({ row, table }) => (
55
+ <Box sx={{ display: 'flex', flexWrap: 'nowrap', gap: '8px' }}>
56
+ <IconButton
57
+ color="primary"
58
+ onClick={() =>
59
+ window.open(
60
+ `mailto:kevinvandy@mailinator.com?subject=Hello ${row.original.firstName}!`,
61
+ )
62
+ }
63
+ >
64
+ <EmailIcon />
65
+ </IconButton>
66
+ <IconButton
67
+ color="secondary"
68
+ onClick={() => {
69
+ table.setEditingRow(row);
70
+ }}
71
+ >
72
+ <EditIcon />
73
+ </IconButton>
74
+ <IconButton
75
+ color="error"
76
+ onClick={() => {
77
+ data.splice(row.index, 1); //assuming simple data table
78
+ setData([...data]);
79
+ }}
80
+ >
81
+ <DeleteIcon />
82
+ </IconButton>
83
+ </Box>
84
+ )}
85
+ />
86
+ );
87
+ };
88
+
89
+ export default Example;
@@ -0,0 +1,36 @@
1
+ import { useMemo } from 'react';
2
+ import { MaterialReactTable, MRT_ActionMenuItem, } from 'material-react-table';
3
+ import { data } from './makeData';
4
+ import { Edit, Delete } from '@mui/icons-material';
5
+ export const Example = () => {
6
+ const columns = useMemo(
7
+ //column definitions...
8
+ () => [
9
+ {
10
+ accessorKey: 'firstName',
11
+ header: 'First Name',
12
+ },
13
+ {
14
+ accessorKey: 'lastName',
15
+ header: 'Last Name',
16
+ },
17
+ {
18
+ accessorKey: 'address',
19
+ header: 'Address',
20
+ },
21
+ {
22
+ accessorKey: 'city',
23
+ header: 'City',
24
+ },
25
+ {
26
+ accessorKey: 'state',
27
+ header: 'State',
28
+ },
29
+ ], []);
30
+ return (<MaterialReactTable columns={columns} data={data} enableRowActions renderRowActionMenuItems={({ row, table }) => [
31
+ <MRT_ActionMenuItem //or just use a normal MUI MenuItem component
32
+ icon={<Edit />} key="edit" label="Edit" onClick={() => console.info('Edit')} table={table}/>,
33
+ <MRT_ActionMenuItem icon={<Delete />} key="delete" label="Delete" onClick={() => console.info('Delete')} table={table}/>,
34
+ ]}/>);
35
+ };
36
+ export default Example;
@@ -0,0 +1,64 @@
1
+ import { useMemo } from 'react';
2
+ import {
3
+ MaterialReactTable,
4
+ MRT_ActionMenuItem,
5
+ type MRT_ColumnDef,
6
+ } from 'material-react-table';
7
+ import { data, type Person } from './makeData';
8
+ import { Edit, Delete } from '@mui/icons-material';
9
+
10
+ export const Example = () => {
11
+ const columns = useMemo<MRT_ColumnDef<Person>[]>(
12
+ //column definitions...
13
+ () => [
14
+ {
15
+ accessorKey: 'firstName',
16
+ header: 'First Name',
17
+ },
18
+ {
19
+ accessorKey: 'lastName',
20
+ header: 'Last Name',
21
+ },
22
+ {
23
+ accessorKey: 'address',
24
+ header: 'Address',
25
+ },
26
+ {
27
+ accessorKey: 'city',
28
+ header: 'City',
29
+ },
30
+ {
31
+ accessorKey: 'state',
32
+ header: 'State',
33
+ },
34
+ ],
35
+ [],
36
+ //end
37
+ );
38
+
39
+ return (
40
+ <MaterialReactTable
41
+ columns={columns}
42
+ data={data}
43
+ enableRowActions
44
+ renderRowActionMenuItems={({ row, table }) => [
45
+ <MRT_ActionMenuItem //or just use a normal MUI MenuItem component
46
+ icon={<Edit />}
47
+ key="edit"
48
+ label="Edit"
49
+ onClick={() => console.info('Edit')}
50
+ table={table}
51
+ />,
52
+ <MRT_ActionMenuItem
53
+ icon={<Delete />}
54
+ key="delete"
55
+ label="Delete"
56
+ onClick={() => console.info('Delete')}
57
+ table={table}
58
+ />,
59
+ ]}
60
+ />
61
+ );
62
+ };
63
+
64
+ export default Example;
@@ -0,0 +1,74 @@
1
+ import { useMemo, useState } from 'react';
2
+ import { MaterialReactTable, useMaterialReactTable, } from 'material-react-table';
3
+ //end
4
+ const data = [
5
+ //data definitions...
6
+ {
7
+ userId: '3f25309c-8fa1-470f-811e-cdb082ab9017', //we'll use this as a unique row id
8
+ firstName: 'Dylan',
9
+ lastName: 'Murray',
10
+ age: 22,
11
+ address: '261 Erdman Ford',
12
+ city: 'East Daphne',
13
+ state: 'Kentucky',
14
+ },
15
+ {
16
+ userId: 'be731030-df83-419c-b3d6-9ef04e7f4a9f',
17
+ firstName: 'Raquel',
18
+ lastName: 'Kohler',
19
+ age: 18,
20
+ address: '769 Dominic Grove',
21
+ city: 'Columbus',
22
+ state: 'Ohio',
23
+ },
24
+ //end
25
+ ];
26
+ const Example = () => {
27
+ const columns = useMemo(
28
+ //column definitions...
29
+ () => [
30
+ {
31
+ accessorKey: 'firstName',
32
+ header: 'First Name',
33
+ },
34
+ {
35
+ accessorKey: 'lastName',
36
+ header: 'Last Name',
37
+ },
38
+ {
39
+ accessorKey: 'age',
40
+ header: 'Age',
41
+ },
42
+ {
43
+ accessorKey: 'address',
44
+ header: 'Address',
45
+ },
46
+ {
47
+ accessorKey: 'city',
48
+ header: 'City',
49
+ },
50
+ {
51
+ accessorKey: 'state',
52
+ header: 'State',
53
+ },
54
+ ], []);
55
+ //optionally, you can manage the row selection state yourself
56
+ const [rowSelection, setRowSelection] = useState({});
57
+ const table = useMaterialReactTable({
58
+ columns,
59
+ data,
60
+ enableRowSelection: true,
61
+ enableMultiRowSelection: false, //use radio buttons instead of checkboxes
62
+ getRowId: (row) => row.userId, //give each row a more useful id
63
+ muiTableBodyRowProps: ({ row }) => ({
64
+ //add onClick to row to select upon clicking anywhere in the row
65
+ onClick: row.getToggleSelectedHandler(),
66
+ sx: { cursor: 'pointer' },
67
+ }),
68
+ positionToolbarAlertBanner: 'bottom', //move the alert banner to the bottom
69
+ onRowSelectionChange: setRowSelection, //connect internal row selection state to your own
70
+ state: { rowSelection }, //pass our managed row selection state to the table to use
71
+ });
72
+ return <MaterialReactTable table={table}/>;
73
+ };
74
+ export default Example;
@@ -0,0 +1,98 @@
1
+ import { useMemo, useState } from 'react';
2
+ import {
3
+ MaterialReactTable,
4
+ useMaterialReactTable,
5
+ type MRT_ColumnDef,
6
+ type MRT_RowSelectionState,
7
+ } from 'material-react-table';
8
+
9
+ //data definitions...
10
+ interface Person {
11
+ userId: string;
12
+ firstName: string;
13
+ lastName: string;
14
+ age: number;
15
+ address: string;
16
+ city: string;
17
+ state: string;
18
+ }
19
+ //end
20
+
21
+ const data = [
22
+ //data definitions...
23
+ {
24
+ userId: '3f25309c-8fa1-470f-811e-cdb082ab9017', //we'll use this as a unique row id
25
+ firstName: 'Dylan',
26
+ lastName: 'Murray',
27
+ age: 22,
28
+ address: '261 Erdman Ford',
29
+ city: 'East Daphne',
30
+ state: 'Kentucky',
31
+ },
32
+ {
33
+ userId: 'be731030-df83-419c-b3d6-9ef04e7f4a9f',
34
+ firstName: 'Raquel',
35
+ lastName: 'Kohler',
36
+ age: 18,
37
+ address: '769 Dominic Grove',
38
+ city: 'Columbus',
39
+ state: 'Ohio',
40
+ },
41
+ //end
42
+ ];
43
+
44
+ const Example = () => {
45
+ const columns = useMemo<MRT_ColumnDef<Person>[]>(
46
+ //column definitions...
47
+ () => [
48
+ {
49
+ accessorKey: 'firstName',
50
+ header: 'First Name',
51
+ },
52
+ {
53
+ accessorKey: 'lastName',
54
+ header: 'Last Name',
55
+ },
56
+ {
57
+ accessorKey: 'age',
58
+ header: 'Age',
59
+ },
60
+ {
61
+ accessorKey: 'address',
62
+ header: 'Address',
63
+ },
64
+ {
65
+ accessorKey: 'city',
66
+ header: 'City',
67
+ },
68
+ {
69
+ accessorKey: 'state',
70
+ header: 'State',
71
+ },
72
+ ],
73
+ [], //end
74
+ );
75
+
76
+ //optionally, you can manage the row selection state yourself
77
+ const [rowSelection, setRowSelection] = useState<MRT_RowSelectionState>({});
78
+
79
+ const table = useMaterialReactTable({
80
+ columns,
81
+ data,
82
+ enableRowSelection: true,
83
+ enableMultiRowSelection: false, //use radio buttons instead of checkboxes
84
+ getRowId: (row) => row.userId, //give each row a more useful id
85
+ muiTableBodyRowProps: ({ row }) => ({
86
+ //add onClick to row to select upon clicking anywhere in the row
87
+ onClick: row.getToggleSelectedHandler(),
88
+ sx: { cursor: 'pointer' },
89
+ }),
90
+ positionToolbarAlertBanner: 'bottom', //move the alert banner to the bottom
91
+ onRowSelectionChange: setRowSelection, //connect internal row selection state to your own
92
+ state: { rowSelection }, //pass our managed row selection state to the table to use
93
+ });
94
+
95
+ return <MaterialReactTable table={table} />;
96
+ };
97
+
98
+ export default Example;
@@ -0,0 +1,122 @@
1
+ import { useEffect, useMemo, useRef, useState } from 'react';
2
+ import { MaterialReactTable, useMaterialReactTable, } from 'material-react-table';
3
+ import { makeData } from './makeData';
4
+ const Example = () => {
5
+ const columns = useMemo(
6
+ //column definitions...
7
+ () => [
8
+ {
9
+ accessorKey: 'firstName',
10
+ header: 'First Name',
11
+ size: 150,
12
+ },
13
+ {
14
+ accessorKey: 'middleName',
15
+ header: 'Middle Name',
16
+ size: 170,
17
+ },
18
+ {
19
+ accessorKey: 'lastName',
20
+ header: 'Last Name',
21
+ size: 150,
22
+ },
23
+ {
24
+ accessorKey: 'email',
25
+ header: 'Email Address',
26
+ size: 300,
27
+ },
28
+ {
29
+ accessorKey: 'phoneNumber',
30
+ header: 'Phone Number',
31
+ size: 250,
32
+ },
33
+ {
34
+ accessorKey: 'address',
35
+ header: 'Address',
36
+ size: 300,
37
+ },
38
+ {
39
+ accessorKey: 'zipCode',
40
+ header: 'Zip Code',
41
+ },
42
+ {
43
+ accessorKey: 'city',
44
+ header: 'City',
45
+ size: 220,
46
+ },
47
+ {
48
+ accessorKey: 'state',
49
+ header: 'State',
50
+ },
51
+ {
52
+ accessorKey: 'country',
53
+ header: 'Country',
54
+ size: 350,
55
+ },
56
+ {
57
+ accessorKey: 'petName',
58
+ header: 'Pet Name',
59
+ },
60
+ {
61
+ accessorKey: 'age',
62
+ header: 'Age',
63
+ },
64
+ {
65
+ accessorKey: 'salary',
66
+ header: 'Salary',
67
+ },
68
+ {
69
+ accessorKey: 'dateOfBirth',
70
+ header: 'Date of Birth',
71
+ },
72
+ {
73
+ accessorKey: 'dateOfJoining',
74
+ header: 'Date of Joining',
75
+ },
76
+ {
77
+ accessorKey: 'isActive',
78
+ header: 'Is Active',
79
+ },
80
+ ], []);
81
+ //optionally access the underlying virtualizer instance
82
+ const rowVirtualizerInstanceRef = useRef(null);
83
+ const [data, setData] = useState([]);
84
+ const [isLoading, setIsLoading] = useState(true);
85
+ const [sorting, setSorting] = useState([]);
86
+ useEffect(() => {
87
+ if (typeof window !== 'undefined') {
88
+ setData(makeData(10000));
89
+ setIsLoading(false);
90
+ }
91
+ }, []);
92
+ useEffect(() => {
93
+ //scroll to the top of the table when the sorting changes
94
+ try {
95
+ rowVirtualizerInstanceRef.current?.scrollToIndex?.(0);
96
+ }
97
+ catch (error) {
98
+ console.error(error);
99
+ }
100
+ }, [sorting]);
101
+ const table = useMaterialReactTable({
102
+ columns,
103
+ data, //10,000 rows
104
+ defaultDisplayColumn: { enableResizing: true },
105
+ enableBottomToolbar: false,
106
+ enableColumnResizing: true,
107
+ enableColumnVirtualization: true,
108
+ enableGlobalFilterModes: true,
109
+ enablePagination: false,
110
+ enableColumnPinning: true,
111
+ enableRowNumbers: true,
112
+ enableRowVirtualization: true,
113
+ muiTableContainerProps: { sx: { maxHeight: '600px' } },
114
+ onSortingChange: setSorting,
115
+ state: { isLoading, sorting },
116
+ rowVirtualizerInstanceRef, //optional
117
+ rowVirtualizerOptions: { overscan: 5 }, //optionally customize the row virtualizer
118
+ columnVirtualizerOptions: { overscan: 2 }, //optionally customize the column virtualizer
119
+ });
120
+ return <MaterialReactTable table={table}/>;
121
+ };
122
+ export default Example;