@lminii/material-react-table-mcp 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -0
- package/data/MIGRATION.md +136 -0
- package/data/api.json +5379 -0
- package/data/examples/advanced.js +215 -0
- package/data/examples/advanced.tsx +309 -0
- package/data/examples/aggregation-and-grouping.js +116 -0
- package/data/examples/aggregation-and-grouping.tsx +153 -0
- package/data/examples/aggregation-multi.js +89 -0
- package/data/examples/aggregation-multi.tsx +105 -0
- package/data/examples/alternate-column-filtering.js +38 -0
- package/data/examples/alternate-column-filtering.tsx +49 -0
- package/data/examples/alternate-detail-panel.js +65 -0
- package/data/examples/alternate-detail-panel.tsx +81 -0
- package/data/examples/alternate-pagination.js +17 -0
- package/data/examples/alternate-pagination.tsx +23 -0
- package/data/examples/basic.js +86 -0
- package/data/examples/basic.tsx +109 -0
- package/data/examples/chart-detail-panel.js +69 -0
- package/data/examples/chart-detail-panel.tsx +89 -0
- package/data/examples/column-actions-space.js +34 -0
- package/data/examples/column-actions-space.tsx +44 -0
- package/data/examples/column-alignment.js +58 -0
- package/data/examples/column-alignment.tsx +70 -0
- package/data/examples/custom-column-actions.js +74 -0
- package/data/examples/custom-column-actions.tsx +109 -0
- package/data/examples/custom-column-filtering-ui.js +59 -0
- package/data/examples/custom-column-filtering-ui.tsx +89 -0
- package/data/examples/custom-headless.js +85 -0
- package/data/examples/custom-headless.tsx +125 -0
- package/data/examples/custom-top-toolbar.js +60 -0
- package/data/examples/custom-top-toolbar.tsx +88 -0
- package/data/examples/customize-display-columns.js +72 -0
- package/data/examples/customize-display-columns.tsx +85 -0
- package/data/examples/customize-filter-components.js +78 -0
- package/data/examples/customize-filter-components.tsx +101 -0
- package/data/examples/customize-filter-modes.js +59 -0
- package/data/examples/customize-filter-modes.tsx +73 -0
- package/data/examples/customize-filter-variants.js +98 -0
- package/data/examples/customize-filter-variants.tsx +116 -0
- package/data/examples/customize-global-filter-component.js +37 -0
- package/data/examples/customize-global-filter-component.tsx +52 -0
- package/data/examples/customize-remove-column-grouping.js +75 -0
- package/data/examples/customize-remove-column-grouping.tsx +94 -0
- package/data/examples/customize-row-selection.js +43 -0
- package/data/examples/customize-row-selection.tsx +54 -0
- package/data/examples/customize-table-styles.js +81 -0
- package/data/examples/customize-table-styles.tsx +100 -0
- package/data/examples/disable-column-actions.js +26 -0
- package/data/examples/disable-column-actions.tsx +37 -0
- package/data/examples/disable-column-hiding.js +74 -0
- package/data/examples/disable-column-hiding.tsx +90 -0
- package/data/examples/disable-density-toggle.js +37 -0
- package/data/examples/disable-density-toggle.tsx +49 -0
- package/data/examples/dynamic-columns.js +124 -0
- package/data/examples/dynamic-columns.tsx +189 -0
- package/data/examples/editing-crud-cell.js +288 -0
- package/data/examples/editing-crud-cell.tsx +377 -0
- package/data/examples/editing-crud-modal.js +275 -0
- package/data/examples/editing-crud-modal.tsx +370 -0
- package/data/examples/editing-crud-row.js +255 -0
- package/data/examples/editing-crud-row.tsx +333 -0
- package/data/examples/editing-crud-table.js +280 -0
- package/data/examples/editing-crud-table.tsx +369 -0
- package/data/examples/editing-crud-tree.js +328 -0
- package/data/examples/editing-crud-tree.tsx +416 -0
- package/data/examples/enable-cell-actions.js +52 -0
- package/data/examples/enable-cell-actions.tsx +76 -0
- package/data/examples/enable-click-to-copy.js +33 -0
- package/data/examples/enable-click-to-copy.tsx +39 -0
- package/data/examples/enable-column-grouping.js +69 -0
- package/data/examples/enable-column-grouping.tsx +120 -0
- package/data/examples/enable-column-ordering.js +37 -0
- package/data/examples/enable-column-ordering.tsx +48 -0
- package/data/examples/enable-column-pinning.js +58 -0
- package/data/examples/enable-column-pinning.tsx +69 -0
- package/data/examples/enable-column-resizing.js +45 -0
- package/data/examples/enable-column-resizing.tsx +56 -0
- package/data/examples/enable-column-virtualization.js +19 -0
- package/data/examples/enable-column-virtualization.tsx +27 -0
- package/data/examples/enable-detail-panel-conditionally.js +61 -0
- package/data/examples/enable-detail-panel-conditionally.tsx +78 -0
- package/data/examples/enable-detail-panel-virtualized.js +64 -0
- package/data/examples/enable-detail-panel-virtualized.tsx +80 -0
- package/data/examples/enable-expanding-tree.js +87 -0
- package/data/examples/enable-expanding-tree.tsx +110 -0
- package/data/examples/enable-filter-facet-values.js +52 -0
- package/data/examples/enable-filter-facet-values.tsx +65 -0
- package/data/examples/enable-row-dragging.js +102 -0
- package/data/examples/enable-row-dragging.tsx +137 -0
- package/data/examples/enable-row-numbers-original.js +37 -0
- package/data/examples/enable-row-numbers-original.tsx +48 -0
- package/data/examples/enable-row-numbers-static.js +37 -0
- package/data/examples/enable-row-numbers-static.tsx +48 -0
- package/data/examples/enable-row-ordering.js +40 -0
- package/data/examples/enable-row-ordering.tsx +57 -0
- package/data/examples/enable-row-pinning-select.js +64 -0
- package/data/examples/enable-row-pinning-select.tsx +76 -0
- package/data/examples/enable-row-pinning-static.js +39 -0
- package/data/examples/enable-row-pinning-static.tsx +50 -0
- package/data/examples/enable-row-pinning-sticky.js +57 -0
- package/data/examples/enable-row-pinning-sticky.tsx +69 -0
- package/data/examples/enable-row-selection.js +71 -0
- package/data/examples/enable-row-selection.tsx +96 -0
- package/data/examples/enable-row-virtualization.js +85 -0
- package/data/examples/enable-row-virtualization.tsx +101 -0
- package/data/examples/enable-sticky-header.js +47 -0
- package/data/examples/enable-sticky-header.tsx +59 -0
- package/data/examples/expanding-tree-expanded.js +98 -0
- package/data/examples/expanding-tree-expanded.tsx +121 -0
- package/data/examples/expanding-tree-flat-parse.js +102 -0
- package/data/examples/expanding-tree-flat-parse.tsx +125 -0
- package/data/examples/expanding-tree-root-expanded.js +120 -0
- package/data/examples/expanding-tree-root-expanded.tsx +151 -0
- package/data/examples/export-to-csv.js +84 -0
- package/data/examples/export-to-csv.tsx +114 -0
- package/data/examples/export-to-pdf.js +76 -0
- package/data/examples/export-to-pdf.tsx +104 -0
- package/data/examples/external-toolbar.js +82 -0
- package/data/examples/external-toolbar.tsx +108 -0
- package/data/examples/font-awesome-icons.js +62 -0
- package/data/examples/font-awesome-icons.tsx +106 -0
- package/data/examples/infinite-scrolling.js +137 -0
- package/data/examples/infinite-scrolling.tsx +208 -0
- package/data/examples/lazy-detail-panel.js +164 -0
- package/data/examples/lazy-detail-panel.tsx +262 -0
- package/data/examples/lazy-sub-rows.js +118 -0
- package/data/examples/lazy-sub-rows.tsx +190 -0
- package/data/examples/linear-progress.js +48 -0
- package/data/examples/linear-progress.tsx +66 -0
- package/data/examples/loading.js +34 -0
- package/data/examples/loading.tsx +50 -0
- package/data/examples/localization-i18n-ar.js +40 -0
- package/data/examples/localization-i18n-ar.tsx +65 -0
- package/data/examples/localization-i18n-az.js +38 -0
- package/data/examples/localization-i18n-az.tsx +60 -0
- package/data/examples/localization-i18n-bg.js +38 -0
- package/data/examples/localization-i18n-bg.tsx +60 -0
- package/data/examples/localization-i18n-cs.js +38 -0
- package/data/examples/localization-i18n-cs.tsx +60 -0
- package/data/examples/localization-i18n-da.js +38 -0
- package/data/examples/localization-i18n-da.tsx +60 -0
- package/data/examples/localization-i18n-de.js +38 -0
- package/data/examples/localization-i18n-de.tsx +60 -0
- package/data/examples/localization-i18n-el.js +38 -0
- package/data/examples/localization-i18n-el.tsx +60 -0
- package/data/examples/localization-i18n-en.js +38 -0
- package/data/examples/localization-i18n-en.tsx +60 -0
- package/data/examples/localization-i18n-es.js +38 -0
- package/data/examples/localization-i18n-es.tsx +60 -0
- package/data/examples/localization-i18n-et.js +38 -0
- package/data/examples/localization-i18n-et.tsx +60 -0
- package/data/examples/localization-i18n-fa.js +40 -0
- package/data/examples/localization-i18n-fa.tsx +66 -0
- package/data/examples/localization-i18n-fi.js +38 -0
- package/data/examples/localization-i18n-fi.tsx +60 -0
- package/data/examples/localization-i18n-fr.js +38 -0
- package/data/examples/localization-i18n-fr.tsx +60 -0
- package/data/examples/localization-i18n-he.js +40 -0
- package/data/examples/localization-i18n-he.tsx +66 -0
- package/data/examples/localization-i18n-hr.js +38 -0
- package/data/examples/localization-i18n-hr.tsx +60 -0
- package/data/examples/localization-i18n-hu.js +38 -0
- package/data/examples/localization-i18n-hu.tsx +60 -0
- package/data/examples/localization-i18n-hy.js +40 -0
- package/data/examples/localization-i18n-hy.tsx +65 -0
- package/data/examples/localization-i18n-id.js +38 -0
- package/data/examples/localization-i18n-id.tsx +60 -0
- package/data/examples/localization-i18n-it.js +38 -0
- package/data/examples/localization-i18n-it.tsx +60 -0
- package/data/examples/localization-i18n-ja.js +38 -0
- package/data/examples/localization-i18n-ja.tsx +60 -0
- package/data/examples/localization-i18n-ko.js +38 -0
- package/data/examples/localization-i18n-ko.tsx +60 -0
- package/data/examples/localization-i18n-nl.js +38 -0
- package/data/examples/localization-i18n-nl.tsx +60 -0
- package/data/examples/localization-i18n-no.js +38 -0
- package/data/examples/localization-i18n-no.tsx +60 -0
- package/data/examples/localization-i18n-np.js +38 -0
- package/data/examples/localization-i18n-np.tsx +60 -0
- package/data/examples/localization-i18n-pl.js +38 -0
- package/data/examples/localization-i18n-pl.tsx +60 -0
- package/data/examples/localization-i18n-pt-BR.js +38 -0
- package/data/examples/localization-i18n-pt-BR.tsx +60 -0
- package/data/examples/localization-i18n-pt.js +38 -0
- package/data/examples/localization-i18n-pt.tsx +60 -0
- package/data/examples/localization-i18n-ro.js +38 -0
- package/data/examples/localization-i18n-ro.tsx +60 -0
- package/data/examples/localization-i18n-ru.js +38 -0
- package/data/examples/localization-i18n-ru.tsx +60 -0
- package/data/examples/localization-i18n-sk.js +38 -0
- package/data/examples/localization-i18n-sk.tsx +60 -0
- package/data/examples/localization-i18n-sr-Cyrl-RS.js +38 -0
- package/data/examples/localization-i18n-sr-Cyrl-RS.tsx +60 -0
- package/data/examples/localization-i18n-sr-Latn-RS.js +38 -0
- package/data/examples/localization-i18n-sr-Latn-RS.tsx +60 -0
- package/data/examples/localization-i18n-sv.js +38 -0
- package/data/examples/localization-i18n-sv.tsx +60 -0
- package/data/examples/localization-i18n-tr.js +38 -0
- package/data/examples/localization-i18n-tr.tsx +60 -0
- package/data/examples/localization-i18n-uk.js +38 -0
- package/data/examples/localization-i18n-uk.tsx +60 -0
- package/data/examples/localization-i18n-vi.js +38 -0
- package/data/examples/localization-i18n-vi.tsx +60 -0
- package/data/examples/localization-i18n-zh-hans.js +38 -0
- package/data/examples/localization-i18n-zh-hans.tsx +60 -0
- package/data/examples/localization-i18n-zh-hant.js +38 -0
- package/data/examples/localization-i18n-zh-hant.tsx +60 -0
- package/data/examples/manual-selection.js +81 -0
- package/data/examples/manual-selection.tsx +105 -0
- package/data/examples/minimal.js +66 -0
- package/data/examples/minimal.tsx +78 -0
- package/data/examples/mui-theme.js +109 -0
- package/data/examples/mui-theme.tsx +136 -0
- package/data/examples/multi-sorting.js +48 -0
- package/data/examples/multi-sorting.tsx +58 -0
- package/data/examples/persistent-state.js +126 -0
- package/data/examples/persistent-state.tsx +184 -0
- package/data/examples/react-query.js +122 -0
- package/data/examples/react-query.tsx +182 -0
- package/data/examples/remote.js +113 -0
- package/data/examples/remote.tsx +150 -0
- package/data/examples/row-actions-buttons.js +54 -0
- package/data/examples/row-actions-buttons.tsx +89 -0
- package/data/examples/row-actions-menu-items.js +36 -0
- package/data/examples/row-actions-menu-items.tsx +64 -0
- package/data/examples/single-row-selection.js +74 -0
- package/data/examples/single-row-selection.tsx +98 -0
- package/data/examples/virtualized.js +122 -0
- package/data/examples/virtualized.tsx +138 -0
- package/data/guides/accessibility.md +119 -0
- package/data/guides/aggregation.md +210 -0
- package/data/guides/async-loading.md +132 -0
- package/data/guides/best-practices.md +363 -0
- package/data/guides/cell-actions.md +139 -0
- package/data/guides/click-to-copy.md +67 -0
- package/data/guides/column-actions.md +69 -0
- package/data/guides/column-filtering.md +366 -0
- package/data/guides/column-grouping.md +192 -0
- package/data/guides/column-hiding.md +133 -0
- package/data/guides/column-ordering-dnd.md +99 -0
- package/data/guides/column-pinning.md +72 -0
- package/data/guides/column-resizing.md +157 -0
- package/data/guides/column-size.md +162 -0
- package/data/guides/customize-components.md +395 -0
- package/data/guides/customize-icons.md +35 -0
- package/data/guides/data-columns.md +292 -0
- package/data/guides/density-toggle.md +46 -0
- package/data/guides/detail-panel.md +195 -0
- package/data/guides/display-columns.md +135 -0
- package/data/guides/editing.md +367 -0
- package/data/guides/expanding-sub-rows.md +194 -0
- package/data/guides/full-screen-toggle.md +63 -0
- package/data/guides/global-filtering.md +237 -0
- package/data/guides/localization.md +57 -0
- package/data/guides/memoization.md +157 -0
- package/data/guides/pagination.md +171 -0
- package/data/guides/row-actions.md +116 -0
- package/data/guides/row-numbers.md +24 -0
- package/data/guides/row-ordering-dnd.md +51 -0
- package/data/guides/row-pinning.md +96 -0
- package/data/guides/row-selection.md +237 -0
- package/data/guides/sorting.md +190 -0
- package/data/guides/state-management.md +165 -0
- package/data/guides/sticky-header.md +41 -0
- package/data/guides/table-event-listeners.md +103 -0
- package/data/guides/toolbar-customization.md +251 -0
- package/data/guides/virtualization.md +183 -0
- package/data/index.json +1930 -0
- package/data/reference/mrt-components.md +183 -0
- package/data/reference/mrt-hooks.md +125 -0
- package/data/skills/README.md +81 -0
- package/data/skills/composable-components/SKILL.md +189 -0
- package/data/skills/customization/SKILL.md +190 -0
- package/data/skills/drag-and-drop-ordering/SKILL.md +227 -0
- package/data/skills/editing/SKILL.md +243 -0
- package/data/skills/filtering/SKILL.md +213 -0
- package/data/skills/getting-started/SKILL.md +213 -0
- package/data/skills/localization/SKILL.md +182 -0
- package/data/skills/migrate-v3-to-v4/SKILL.md +161 -0
- package/data/skills/state-and-server-data/SKILL.md +200 -0
- package/data/skills/virtualization/SKILL.md +203 -0
- package/dist/data.js +159 -0
- package/dist/index.js +244 -0
- package/package.json +50 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { Box, Stack } from '@mui/material';
|
|
3
|
+
import {
|
|
4
|
+
MaterialReactTable,
|
|
5
|
+
useMaterialReactTable,
|
|
6
|
+
type MRT_ColumnDef,
|
|
7
|
+
} from 'material-react-table';
|
|
8
|
+
import { data, type Person } from './makeData';
|
|
9
|
+
|
|
10
|
+
const Example = () => {
|
|
11
|
+
const averageSalary = useMemo(
|
|
12
|
+
() => data.reduce((acc, curr) => acc + curr.salary, 0) / data.length,
|
|
13
|
+
[],
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const maxAge = useMemo(
|
|
17
|
+
() => data.reduce((acc, curr) => Math.max(acc, curr.age), 0),
|
|
18
|
+
[],
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
22
|
+
() => [
|
|
23
|
+
{
|
|
24
|
+
header: 'First Name',
|
|
25
|
+
accessorKey: 'firstName',
|
|
26
|
+
enableGrouping: false, //do not let this column be grouped
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
header: 'Last Name',
|
|
30
|
+
accessorKey: 'lastName',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
header: 'Age',
|
|
34
|
+
accessorKey: 'age',
|
|
35
|
+
aggregationFn: 'max', //show the max age in the group (lots of pre-built aggregationFns to choose from)
|
|
36
|
+
//required to render an aggregated cell
|
|
37
|
+
AggregatedCell: ({ cell, table }) => (
|
|
38
|
+
<>
|
|
39
|
+
Oldest by{' '}
|
|
40
|
+
{table.getColumn(cell.row.groupingColumnId ?? '').columnDef.header}:{' '}
|
|
41
|
+
<Box
|
|
42
|
+
sx={{ color: 'info.main', display: 'inline', fontWeight: 'bold' }}
|
|
43
|
+
>
|
|
44
|
+
{cell.getValue<number>()}
|
|
45
|
+
</Box>
|
|
46
|
+
</>
|
|
47
|
+
),
|
|
48
|
+
Footer: () => (
|
|
49
|
+
<Stack>
|
|
50
|
+
Max Age:
|
|
51
|
+
<Box
|
|
52
|
+
sx={{
|
|
53
|
+
color: 'warning.main',
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
{Math.round(maxAge)}
|
|
57
|
+
</Box>
|
|
58
|
+
</Stack>
|
|
59
|
+
),
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
header: 'Gender',
|
|
63
|
+
accessorKey: 'gender',
|
|
64
|
+
//optionally, customize the cell render when this column is grouped. Make the text blue and pluralize the word
|
|
65
|
+
GroupedCell: ({ cell, row }) => (
|
|
66
|
+
<Box sx={{ color: 'primary.main' }}>
|
|
67
|
+
<strong>{cell.getValue<string>()}s </strong> ({row.subRows?.length})
|
|
68
|
+
</Box>
|
|
69
|
+
),
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
header: 'State',
|
|
73
|
+
accessorKey: 'state',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
header: 'Salary',
|
|
77
|
+
accessorKey: 'salary',
|
|
78
|
+
aggregationFn: 'mean',
|
|
79
|
+
//required to render an aggregated cell, show the average salary in the group
|
|
80
|
+
AggregatedCell: ({ cell, table }) => (
|
|
81
|
+
<>
|
|
82
|
+
Average by{' '}
|
|
83
|
+
{table.getColumn(cell.row.groupingColumnId ?? '').columnDef.header}:{' '}
|
|
84
|
+
<Box sx={{ color: 'success.main', fontWeight: 'bold' }}>
|
|
85
|
+
{cell.getValue<number>()?.toLocaleString?.('en-US', {
|
|
86
|
+
style: 'currency',
|
|
87
|
+
currency: 'USD',
|
|
88
|
+
minimumFractionDigits: 0,
|
|
89
|
+
maximumFractionDigits: 0,
|
|
90
|
+
})}
|
|
91
|
+
</Box>
|
|
92
|
+
</>
|
|
93
|
+
),
|
|
94
|
+
//customize normal cell render on normal non-aggregated rows
|
|
95
|
+
Cell: ({ cell }) => (
|
|
96
|
+
<>
|
|
97
|
+
{cell.getValue<number>()?.toLocaleString?.('en-US', {
|
|
98
|
+
style: 'currency',
|
|
99
|
+
currency: 'USD',
|
|
100
|
+
minimumFractionDigits: 0,
|
|
101
|
+
maximumFractionDigits: 0,
|
|
102
|
+
})}
|
|
103
|
+
</>
|
|
104
|
+
),
|
|
105
|
+
Footer: () => (
|
|
106
|
+
<Stack>
|
|
107
|
+
Average Salary:
|
|
108
|
+
<Box
|
|
109
|
+
sx={{
|
|
110
|
+
color: 'warning.main',
|
|
111
|
+
}}
|
|
112
|
+
>
|
|
113
|
+
{averageSalary?.toLocaleString?.('en-US', {
|
|
114
|
+
style: 'currency',
|
|
115
|
+
currency: 'USD',
|
|
116
|
+
minimumFractionDigits: 0,
|
|
117
|
+
maximumFractionDigits: 0,
|
|
118
|
+
})}
|
|
119
|
+
</Box>
|
|
120
|
+
</Stack>
|
|
121
|
+
),
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
[averageSalary, maxAge],
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const table = useMaterialReactTable({
|
|
128
|
+
columns,
|
|
129
|
+
data,
|
|
130
|
+
displayColumnDefOptions: {
|
|
131
|
+
'mrt-row-expand': {
|
|
132
|
+
enableResizing: true,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
enableColumnResizing: true,
|
|
136
|
+
enableGrouping: true,
|
|
137
|
+
enableStickyHeader: true,
|
|
138
|
+
enableStickyFooter: true,
|
|
139
|
+
initialState: {
|
|
140
|
+
density: 'compact',
|
|
141
|
+
expanded: true, //expand all groups by default
|
|
142
|
+
grouping: ['state'], //an array of columns to group by by default (can be multiple)
|
|
143
|
+
pagination: { pageIndex: 0, pageSize: 20 },
|
|
144
|
+
sorting: [{ id: 'state', desc: false }], //sort by state by default
|
|
145
|
+
},
|
|
146
|
+
muiToolbarAlertBannerChipProps: { color: 'primary' },
|
|
147
|
+
muiTableContainerProps: { sx: { maxHeight: 700 } },
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
return <MaterialReactTable table={table} />;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export default Example;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { Box } from '@mui/material';
|
|
3
|
+
import { MaterialReactTable, useMaterialReactTable, } from 'material-react-table';
|
|
4
|
+
import { data } from './makeData';
|
|
5
|
+
const localeStringOptions = {
|
|
6
|
+
style: 'currency',
|
|
7
|
+
currency: 'USD',
|
|
8
|
+
minimumFractionDigits: 0,
|
|
9
|
+
maximumFractionDigits: 0,
|
|
10
|
+
};
|
|
11
|
+
const Example = () => {
|
|
12
|
+
const columns = useMemo(() => [
|
|
13
|
+
{
|
|
14
|
+
header: 'First Name',
|
|
15
|
+
accessorKey: 'firstName',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
header: 'Last Name',
|
|
19
|
+
accessorKey: 'lastName',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
header: 'Gender',
|
|
23
|
+
accessorKey: 'gender',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
header: 'State',
|
|
27
|
+
accessorKey: 'state',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
header: 'Salary',
|
|
31
|
+
accessorKey: 'salary',
|
|
32
|
+
aggregationFn: ['count', 'mean', 'median', 'min', 'max'],
|
|
33
|
+
//required to render an aggregated cell, show the average salary in the group
|
|
34
|
+
AggregatedCell: ({ cell }) => (<>
|
|
35
|
+
Count:{' '}
|
|
36
|
+
<Box sx={{ color: 'success.main', fontWeight: 'bold' }}>
|
|
37
|
+
{cell.getValue()?.[0]}
|
|
38
|
+
</Box>
|
|
39
|
+
Average:{' '}
|
|
40
|
+
<Box sx={{ color: 'success.main', fontWeight: 'bold' }}>
|
|
41
|
+
{cell
|
|
42
|
+
.getValue()?.[1]
|
|
43
|
+
?.toLocaleString?.('en-US', localeStringOptions)}
|
|
44
|
+
</Box>
|
|
45
|
+
Median:{' '}
|
|
46
|
+
<Box sx={{ color: 'success.main', fontWeight: 'bold' }}>
|
|
47
|
+
{cell
|
|
48
|
+
.getValue()?.[2]
|
|
49
|
+
?.toLocaleString?.('en-US', localeStringOptions)}
|
|
50
|
+
</Box>
|
|
51
|
+
Min:{' '}
|
|
52
|
+
<Box sx={{ color: 'success.main', fontWeight: 'bold' }}>
|
|
53
|
+
{cell
|
|
54
|
+
.getValue()?.[3]
|
|
55
|
+
?.toLocaleString?.('en-US', localeStringOptions)}
|
|
56
|
+
</Box>
|
|
57
|
+
Max:{' '}
|
|
58
|
+
<Box sx={{ color: 'success.main', fontWeight: 'bold' }}>
|
|
59
|
+
{cell
|
|
60
|
+
.getValue()?.[4]
|
|
61
|
+
?.toLocaleString?.('en-US', localeStringOptions)}
|
|
62
|
+
</Box>
|
|
63
|
+
</>),
|
|
64
|
+
//customize normal cell render on normal non-aggregated rows
|
|
65
|
+
Cell: ({ cell }) => (<>
|
|
66
|
+
{cell
|
|
67
|
+
.getValue()
|
|
68
|
+
?.toLocaleString?.('en-US', localeStringOptions)}
|
|
69
|
+
</>),
|
|
70
|
+
},
|
|
71
|
+
], []);
|
|
72
|
+
const table = useMaterialReactTable({
|
|
73
|
+
columns,
|
|
74
|
+
data,
|
|
75
|
+
enableGrouping: true,
|
|
76
|
+
enableStickyHeader: true,
|
|
77
|
+
initialState: {
|
|
78
|
+
density: 'compact',
|
|
79
|
+
expanded: true, //expand all groups by default
|
|
80
|
+
grouping: ['state'], //an array of columns to group by by default (can be multiple)
|
|
81
|
+
pagination: { pageIndex: 0, pageSize: 20 },
|
|
82
|
+
sorting: [{ id: 'state', desc: false }], //sort by state by default
|
|
83
|
+
},
|
|
84
|
+
muiToolbarAlertBannerChipProps: { color: 'primary' },
|
|
85
|
+
muiTableContainerProps: { sx: { maxHeight: 700 } },
|
|
86
|
+
});
|
|
87
|
+
return <MaterialReactTable table={table}/>;
|
|
88
|
+
};
|
|
89
|
+
export default Example;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { Box } from '@mui/material';
|
|
3
|
+
import {
|
|
4
|
+
MaterialReactTable,
|
|
5
|
+
useMaterialReactTable,
|
|
6
|
+
type MRT_ColumnDef,
|
|
7
|
+
} from 'material-react-table';
|
|
8
|
+
import { data, type Person } from './makeData';
|
|
9
|
+
|
|
10
|
+
const localeStringOptions = {
|
|
11
|
+
style: 'currency',
|
|
12
|
+
currency: 'USD',
|
|
13
|
+
minimumFractionDigits: 0,
|
|
14
|
+
maximumFractionDigits: 0,
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
const Example = () => {
|
|
18
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
19
|
+
() => [
|
|
20
|
+
{
|
|
21
|
+
header: 'First Name',
|
|
22
|
+
accessorKey: 'firstName',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
header: 'Last Name',
|
|
26
|
+
accessorKey: 'lastName',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
header: 'Gender',
|
|
30
|
+
accessorKey: 'gender',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
header: 'State',
|
|
34
|
+
accessorKey: 'state',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
header: 'Salary',
|
|
38
|
+
accessorKey: 'salary',
|
|
39
|
+
aggregationFn: ['count', 'mean', 'median', 'min', 'max'],
|
|
40
|
+
//required to render an aggregated cell, show the average salary in the group
|
|
41
|
+
AggregatedCell: ({ cell }) => (
|
|
42
|
+
<>
|
|
43
|
+
Count:{' '}
|
|
44
|
+
<Box sx={{ color: 'success.main', fontWeight: 'bold' }}>
|
|
45
|
+
{cell.getValue<Array<number>>()?.[0]}
|
|
46
|
+
</Box>
|
|
47
|
+
Average:{' '}
|
|
48
|
+
<Box sx={{ color: 'success.main', fontWeight: 'bold' }}>
|
|
49
|
+
{cell
|
|
50
|
+
.getValue<Array<number>>()?.[1]
|
|
51
|
+
?.toLocaleString?.('en-US', localeStringOptions)}
|
|
52
|
+
</Box>
|
|
53
|
+
Median:{' '}
|
|
54
|
+
<Box sx={{ color: 'success.main', fontWeight: 'bold' }}>
|
|
55
|
+
{cell
|
|
56
|
+
.getValue<Array<number>>()?.[2]
|
|
57
|
+
?.toLocaleString?.('en-US', localeStringOptions)}
|
|
58
|
+
</Box>
|
|
59
|
+
Min:{' '}
|
|
60
|
+
<Box sx={{ color: 'success.main', fontWeight: 'bold' }}>
|
|
61
|
+
{cell
|
|
62
|
+
.getValue<Array<number>>()?.[3]
|
|
63
|
+
?.toLocaleString?.('en-US', localeStringOptions)}
|
|
64
|
+
</Box>
|
|
65
|
+
Max:{' '}
|
|
66
|
+
<Box sx={{ color: 'success.main', fontWeight: 'bold' }}>
|
|
67
|
+
{cell
|
|
68
|
+
.getValue<Array<number>>()?.[4]
|
|
69
|
+
?.toLocaleString?.('en-US', localeStringOptions)}
|
|
70
|
+
</Box>
|
|
71
|
+
</>
|
|
72
|
+
),
|
|
73
|
+
//customize normal cell render on normal non-aggregated rows
|
|
74
|
+
Cell: ({ cell }) => (
|
|
75
|
+
<>
|
|
76
|
+
{cell
|
|
77
|
+
.getValue<number>()
|
|
78
|
+
?.toLocaleString?.('en-US', localeStringOptions)}
|
|
79
|
+
</>
|
|
80
|
+
),
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
[],
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const table = useMaterialReactTable({
|
|
87
|
+
columns,
|
|
88
|
+
data,
|
|
89
|
+
enableGrouping: true,
|
|
90
|
+
enableStickyHeader: true,
|
|
91
|
+
initialState: {
|
|
92
|
+
density: 'compact',
|
|
93
|
+
expanded: true, //expand all groups by default
|
|
94
|
+
grouping: ['state'], //an array of columns to group by by default (can be multiple)
|
|
95
|
+
pagination: { pageIndex: 0, pageSize: 20 },
|
|
96
|
+
sorting: [{ id: 'state', desc: false }], //sort by state by default
|
|
97
|
+
},
|
|
98
|
+
muiToolbarAlertBannerChipProps: { color: 'primary' },
|
|
99
|
+
muiTableContainerProps: { sx: { maxHeight: 700 } },
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return <MaterialReactTable table={table} />;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export default Example;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { MaterialReactTable, useMaterialReactTable, } from 'material-react-table';
|
|
3
|
+
import { data } from './makeData';
|
|
4
|
+
const Example = () => {
|
|
5
|
+
const columns = useMemo(() => [
|
|
6
|
+
{
|
|
7
|
+
accessorKey: 'id',
|
|
8
|
+
header: 'ID',
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
accessorKey: 'firstName',
|
|
12
|
+
header: 'First Name',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
accessorKey: 'lastName',
|
|
16
|
+
header: 'Last Name',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
accessorKey: 'gender',
|
|
20
|
+
header: 'Gender',
|
|
21
|
+
filterFn: 'equals',
|
|
22
|
+
filterSelectOptions: ['Male', 'Female', 'Other'],
|
|
23
|
+
filterVariant: 'select',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
accessorKey: 'age',
|
|
27
|
+
header: 'Age',
|
|
28
|
+
filterVariant: 'range',
|
|
29
|
+
},
|
|
30
|
+
], []);
|
|
31
|
+
const table = useMaterialReactTable({
|
|
32
|
+
columns,
|
|
33
|
+
data,
|
|
34
|
+
columnFilterDisplayMode: 'popover',
|
|
35
|
+
});
|
|
36
|
+
return <MaterialReactTable table={table}/>;
|
|
37
|
+
};
|
|
38
|
+
export default Example;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MaterialReactTable,
|
|
4
|
+
useMaterialReactTable,
|
|
5
|
+
type MRT_ColumnDef,
|
|
6
|
+
} from 'material-react-table';
|
|
7
|
+
import { data, type Person } from './makeData';
|
|
8
|
+
|
|
9
|
+
const Example = () => {
|
|
10
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
11
|
+
() => [
|
|
12
|
+
{
|
|
13
|
+
accessorKey: 'id',
|
|
14
|
+
header: 'ID',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
accessorKey: 'firstName',
|
|
18
|
+
header: 'First Name',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
accessorKey: 'lastName',
|
|
22
|
+
header: 'Last Name',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
accessorKey: 'gender',
|
|
26
|
+
header: 'Gender',
|
|
27
|
+
filterFn: 'equals',
|
|
28
|
+
filterSelectOptions: ['Male', 'Female', 'Other'],
|
|
29
|
+
filterVariant: 'select',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
accessorKey: 'age',
|
|
33
|
+
header: 'Age',
|
|
34
|
+
filterVariant: 'range',
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
[],
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const table = useMaterialReactTable({
|
|
41
|
+
columns,
|
|
42
|
+
data,
|
|
43
|
+
columnFilterDisplayMode: 'popover',
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return <MaterialReactTable table={table} />;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default Example;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { MaterialReactTable, useMaterialReactTable, } from 'material-react-table';
|
|
3
|
+
import { Box, Typography, useMediaQuery } from '@mui/material';
|
|
4
|
+
import { data } from './makeData';
|
|
5
|
+
const Example = () => {
|
|
6
|
+
const isMobile = useMediaQuery('(max-width: 720px)');
|
|
7
|
+
const columns = useMemo(
|
|
8
|
+
//column definitions...
|
|
9
|
+
() => [
|
|
10
|
+
{
|
|
11
|
+
accessorKey: 'id',
|
|
12
|
+
header: 'ID',
|
|
13
|
+
size: 50,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
accessorKey: 'firstName',
|
|
17
|
+
header: 'First Name',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
accessorKey: 'middleName',
|
|
21
|
+
header: 'Middle Name',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
accessorKey: 'lastName',
|
|
25
|
+
header: 'Last Name',
|
|
26
|
+
},
|
|
27
|
+
], []);
|
|
28
|
+
const table = useMaterialReactTable({
|
|
29
|
+
columns,
|
|
30
|
+
data,
|
|
31
|
+
// displayColumnDefOptions: { //built-in now in v2.6.0 when positionExpandColumn is 'last'
|
|
32
|
+
// 'mrt-row-expand': {
|
|
33
|
+
// muiTableHeadCellProps: {
|
|
34
|
+
// align: 'right',
|
|
35
|
+
// },
|
|
36
|
+
// muiTableBodyCellProps: {
|
|
37
|
+
// align: 'right',
|
|
38
|
+
// },
|
|
39
|
+
// },
|
|
40
|
+
// },
|
|
41
|
+
enableColumnPinning: isMobile, //alternative
|
|
42
|
+
initialState: {
|
|
43
|
+
expanded: true,
|
|
44
|
+
},
|
|
45
|
+
state: {
|
|
46
|
+
columnPinning: isMobile
|
|
47
|
+
? { end: ['mrt-row-expand'], start: [] }
|
|
48
|
+
: { end: [], start: [] }, //alternative
|
|
49
|
+
},
|
|
50
|
+
renderDetailPanel: ({ row }) => (<Box sx={{
|
|
51
|
+
display: 'grid',
|
|
52
|
+
margin: 'auto',
|
|
53
|
+
gridTemplateColumns: '1fr 1fr',
|
|
54
|
+
width: '100%',
|
|
55
|
+
}}>
|
|
56
|
+
<Typography>Address: {row.original.address}</Typography>
|
|
57
|
+
<Typography>City: {row.original.city}</Typography>
|
|
58
|
+
<Typography>State: {row.original.state}</Typography>
|
|
59
|
+
<Typography>Country: {row.original.country}</Typography>
|
|
60
|
+
</Box>),
|
|
61
|
+
positionExpandColumn: 'last',
|
|
62
|
+
});
|
|
63
|
+
return <MaterialReactTable table={table}/>;
|
|
64
|
+
};
|
|
65
|
+
export default Example;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MaterialReactTable,
|
|
4
|
+
useMaterialReactTable,
|
|
5
|
+
type MRT_ColumnDef,
|
|
6
|
+
} from 'material-react-table';
|
|
7
|
+
import { Box, Typography, useMediaQuery } from '@mui/material';
|
|
8
|
+
import { data, type Person } from './makeData';
|
|
9
|
+
|
|
10
|
+
const Example = () => {
|
|
11
|
+
const isMobile = useMediaQuery('(max-width: 720px)');
|
|
12
|
+
|
|
13
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
14
|
+
//column definitions...
|
|
15
|
+
() => [
|
|
16
|
+
{
|
|
17
|
+
accessorKey: 'id',
|
|
18
|
+
header: 'ID',
|
|
19
|
+
size: 50,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
accessorKey: 'firstName',
|
|
23
|
+
header: 'First Name',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
accessorKey: 'middleName',
|
|
27
|
+
header: 'Middle Name',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
accessorKey: 'lastName',
|
|
31
|
+
header: 'Last Name',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
[],
|
|
35
|
+
//end
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const table = useMaterialReactTable({
|
|
39
|
+
columns,
|
|
40
|
+
data,
|
|
41
|
+
// displayColumnDefOptions: { //built-in now in v2.6.0 when positionExpandColumn is 'last'
|
|
42
|
+
// 'mrt-row-expand': {
|
|
43
|
+
// muiTableHeadCellProps: {
|
|
44
|
+
// align: 'right',
|
|
45
|
+
// },
|
|
46
|
+
// muiTableBodyCellProps: {
|
|
47
|
+
// align: 'right',
|
|
48
|
+
// },
|
|
49
|
+
// },
|
|
50
|
+
// },
|
|
51
|
+
enableColumnPinning: isMobile, //alternative
|
|
52
|
+
initialState: {
|
|
53
|
+
expanded: true,
|
|
54
|
+
},
|
|
55
|
+
state: {
|
|
56
|
+
columnPinning: isMobile
|
|
57
|
+
? { end: ['mrt-row-expand'], start: [] }
|
|
58
|
+
: { end: [], start: [] }, //alternative
|
|
59
|
+
},
|
|
60
|
+
renderDetailPanel: ({ row }) => (
|
|
61
|
+
<Box
|
|
62
|
+
sx={{
|
|
63
|
+
display: 'grid',
|
|
64
|
+
margin: 'auto',
|
|
65
|
+
gridTemplateColumns: '1fr 1fr',
|
|
66
|
+
width: '100%',
|
|
67
|
+
}}
|
|
68
|
+
>
|
|
69
|
+
<Typography>Address: {row.original.address}</Typography>
|
|
70
|
+
<Typography>City: {row.original.city}</Typography>
|
|
71
|
+
<Typography>State: {row.original.state}</Typography>
|
|
72
|
+
<Typography>Country: {row.original.country}</Typography>
|
|
73
|
+
</Box>
|
|
74
|
+
),
|
|
75
|
+
positionExpandColumn: 'last',
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return <MaterialReactTable table={table} />;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export default Example;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MaterialReactTable, useMaterialReactTable, } from 'material-react-table';
|
|
2
|
+
import { columns, data } from './makeData';
|
|
3
|
+
const Example = () => {
|
|
4
|
+
const table = useMaterialReactTable({
|
|
5
|
+
columns,
|
|
6
|
+
data,
|
|
7
|
+
muiPaginationProps: {
|
|
8
|
+
color: 'primary',
|
|
9
|
+
shape: 'rounded',
|
|
10
|
+
showRowsPerPage: false,
|
|
11
|
+
variant: 'outlined',
|
|
12
|
+
},
|
|
13
|
+
paginationDisplayMode: 'pages',
|
|
14
|
+
});
|
|
15
|
+
return <MaterialReactTable table={table}/>;
|
|
16
|
+
};
|
|
17
|
+
export default Example;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MaterialReactTable,
|
|
3
|
+
useMaterialReactTable,
|
|
4
|
+
} from 'material-react-table';
|
|
5
|
+
import { columns, data } from './makeData';
|
|
6
|
+
|
|
7
|
+
const Example = () => {
|
|
8
|
+
const table = useMaterialReactTable({
|
|
9
|
+
columns,
|
|
10
|
+
data,
|
|
11
|
+
muiPaginationProps: {
|
|
12
|
+
color: 'primary',
|
|
13
|
+
shape: 'rounded',
|
|
14
|
+
showRowsPerPage: false,
|
|
15
|
+
variant: 'outlined',
|
|
16
|
+
},
|
|
17
|
+
paginationDisplayMode: 'pages',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return <MaterialReactTable table={table} />;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default Example;
|