@mini_7/material-react-table-mcp 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -0
- package/data/MIGRATION.md +136 -0
- package/data/api.json +5379 -0
- package/data/examples/advanced.tsx +309 -0
- package/data/examples/aggregation-and-grouping.tsx +153 -0
- package/data/examples/aggregation-multi.tsx +105 -0
- package/data/examples/alternate-column-filtering.tsx +49 -0
- package/data/examples/alternate-detail-panel.tsx +81 -0
- package/data/examples/alternate-pagination.tsx +23 -0
- package/data/examples/basic.tsx +109 -0
- package/data/examples/chart-detail-panel.tsx +89 -0
- package/data/examples/column-actions-space.tsx +44 -0
- package/data/examples/column-alignment.tsx +70 -0
- package/data/examples/custom-column-actions.tsx +109 -0
- package/data/examples/custom-column-filtering-ui.tsx +89 -0
- package/data/examples/custom-headless.tsx +125 -0
- package/data/examples/custom-top-toolbar.tsx +88 -0
- package/data/examples/customize-display-columns.tsx +85 -0
- package/data/examples/customize-filter-components.tsx +101 -0
- package/data/examples/customize-filter-modes.tsx +73 -0
- package/data/examples/customize-filter-variants.tsx +116 -0
- package/data/examples/customize-global-filter-component.tsx +52 -0
- package/data/examples/customize-remove-column-grouping.tsx +94 -0
- package/data/examples/customize-row-selection.tsx +54 -0
- package/data/examples/customize-table-styles.tsx +100 -0
- package/data/examples/disable-column-actions.tsx +37 -0
- package/data/examples/disable-column-hiding.tsx +90 -0
- package/data/examples/disable-density-toggle.tsx +49 -0
- package/data/examples/dynamic-columns.tsx +189 -0
- package/data/examples/editing-crud-cell.tsx +377 -0
- package/data/examples/editing-crud-modal.tsx +370 -0
- package/data/examples/editing-crud-row.tsx +333 -0
- package/data/examples/editing-crud-table.tsx +369 -0
- package/data/examples/editing-crud-tree.tsx +416 -0
- package/data/examples/enable-cell-actions.tsx +76 -0
- package/data/examples/enable-click-to-copy.tsx +39 -0
- package/data/examples/enable-column-grouping.tsx +120 -0
- package/data/examples/enable-column-ordering.tsx +48 -0
- package/data/examples/enable-column-pinning.tsx +69 -0
- package/data/examples/enable-column-resizing.tsx +56 -0
- package/data/examples/enable-column-virtualization.tsx +27 -0
- package/data/examples/enable-detail-panel-conditionally.tsx +78 -0
- package/data/examples/enable-detail-panel-virtualized.tsx +80 -0
- package/data/examples/enable-expanding-tree.tsx +110 -0
- package/data/examples/enable-filter-facet-values.tsx +65 -0
- package/data/examples/enable-row-dragging.tsx +137 -0
- package/data/examples/enable-row-numbers-original.tsx +48 -0
- package/data/examples/enable-row-numbers-static.tsx +48 -0
- package/data/examples/enable-row-ordering.tsx +57 -0
- package/data/examples/enable-row-pinning-select.tsx +76 -0
- package/data/examples/enable-row-pinning-static.tsx +50 -0
- package/data/examples/enable-row-pinning-sticky.tsx +69 -0
- package/data/examples/enable-row-selection.tsx +96 -0
- package/data/examples/enable-row-virtualization.tsx +101 -0
- package/data/examples/enable-sticky-header.tsx +59 -0
- package/data/examples/expanding-tree-expanded.tsx +121 -0
- package/data/examples/expanding-tree-flat-parse.tsx +125 -0
- package/data/examples/expanding-tree-root-expanded.tsx +151 -0
- package/data/examples/export-to-csv.tsx +114 -0
- package/data/examples/export-to-pdf.tsx +104 -0
- package/data/examples/external-toolbar.tsx +108 -0
- package/data/examples/font-awesome-icons.tsx +106 -0
- package/data/examples/infinite-scrolling.tsx +208 -0
- package/data/examples/lazy-detail-panel.tsx +262 -0
- package/data/examples/lazy-sub-rows.tsx +190 -0
- package/data/examples/linear-progress.tsx +66 -0
- package/data/examples/loading.tsx +50 -0
- package/data/examples/localization-i18n-ar.tsx +65 -0
- package/data/examples/localization-i18n-az.tsx +60 -0
- package/data/examples/localization-i18n-bg.tsx +60 -0
- package/data/examples/localization-i18n-cs.tsx +60 -0
- package/data/examples/localization-i18n-da.tsx +60 -0
- package/data/examples/localization-i18n-de.tsx +60 -0
- package/data/examples/localization-i18n-el.tsx +60 -0
- package/data/examples/localization-i18n-en.tsx +60 -0
- package/data/examples/localization-i18n-es.tsx +60 -0
- package/data/examples/localization-i18n-et.tsx +60 -0
- package/data/examples/localization-i18n-fa.tsx +66 -0
- package/data/examples/localization-i18n-fi.tsx +60 -0
- package/data/examples/localization-i18n-fr.tsx +60 -0
- package/data/examples/localization-i18n-he.tsx +66 -0
- package/data/examples/localization-i18n-hr.tsx +60 -0
- package/data/examples/localization-i18n-hu.tsx +60 -0
- package/data/examples/localization-i18n-hy.tsx +65 -0
- package/data/examples/localization-i18n-id.tsx +60 -0
- package/data/examples/localization-i18n-it.tsx +60 -0
- package/data/examples/localization-i18n-ja.tsx +60 -0
- package/data/examples/localization-i18n-ko.tsx +60 -0
- package/data/examples/localization-i18n-nl.tsx +60 -0
- package/data/examples/localization-i18n-no.tsx +60 -0
- package/data/examples/localization-i18n-np.tsx +60 -0
- package/data/examples/localization-i18n-pl.tsx +60 -0
- package/data/examples/localization-i18n-pt-BR.tsx +60 -0
- package/data/examples/localization-i18n-pt.tsx +60 -0
- package/data/examples/localization-i18n-ro.tsx +60 -0
- package/data/examples/localization-i18n-ru.tsx +60 -0
- package/data/examples/localization-i18n-sk.tsx +60 -0
- package/data/examples/localization-i18n-sr-Cyrl-RS.tsx +60 -0
- package/data/examples/localization-i18n-sr-Latn-RS.tsx +60 -0
- package/data/examples/localization-i18n-sv.tsx +60 -0
- package/data/examples/localization-i18n-tr.tsx +60 -0
- package/data/examples/localization-i18n-uk.tsx +60 -0
- package/data/examples/localization-i18n-vi.tsx +60 -0
- package/data/examples/localization-i18n-zh-hans.tsx +60 -0
- package/data/examples/localization-i18n-zh-hant.tsx +60 -0
- package/data/examples/manual-selection.tsx +105 -0
- package/data/examples/minimal.tsx +78 -0
- package/data/examples/mui-theme.tsx +136 -0
- package/data/examples/multi-sorting.tsx +58 -0
- package/data/examples/persistent-state.tsx +184 -0
- package/data/examples/react-query.tsx +182 -0
- package/data/examples/remote.tsx +150 -0
- package/data/examples/row-actions-buttons.tsx +89 -0
- package/data/examples/row-actions-menu-items.tsx +64 -0
- package/data/examples/single-row-selection.tsx +98 -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/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 +137 -0
- package/dist/index.js +232 -0
- package/package.json +50 -0
|
@@ -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;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MaterialReactTable,
|
|
4
|
+
useMaterialReactTable,
|
|
5
|
+
type MRT_ColumnDef,
|
|
6
|
+
} from 'material-react-table';
|
|
7
|
+
|
|
8
|
+
//example data type
|
|
9
|
+
type Person = {
|
|
10
|
+
name: {
|
|
11
|
+
firstName: string;
|
|
12
|
+
lastName: string;
|
|
13
|
+
};
|
|
14
|
+
address: string;
|
|
15
|
+
city: string;
|
|
16
|
+
state: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
//nested data is ok, see accessorKeys in ColumnDef below
|
|
20
|
+
const data: Person[] = [
|
|
21
|
+
{
|
|
22
|
+
name: {
|
|
23
|
+
firstName: 'John',
|
|
24
|
+
lastName: 'Doe',
|
|
25
|
+
},
|
|
26
|
+
address: '261 Erdman Ford',
|
|
27
|
+
city: 'East Daphne',
|
|
28
|
+
state: 'Kentucky',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: {
|
|
32
|
+
firstName: 'Jane',
|
|
33
|
+
lastName: 'Doe',
|
|
34
|
+
},
|
|
35
|
+
address: '769 Dominic Grove',
|
|
36
|
+
city: 'Columbus',
|
|
37
|
+
state: 'Ohio',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: {
|
|
41
|
+
firstName: 'Joe',
|
|
42
|
+
lastName: 'Doe',
|
|
43
|
+
},
|
|
44
|
+
address: '566 Brakus Inlet',
|
|
45
|
+
city: 'South Linda',
|
|
46
|
+
state: 'West Virginia',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: {
|
|
50
|
+
firstName: 'Kevin',
|
|
51
|
+
lastName: 'Vandy',
|
|
52
|
+
},
|
|
53
|
+
address: '722 Emie Stream',
|
|
54
|
+
city: 'Lincoln',
|
|
55
|
+
state: 'Nebraska',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: {
|
|
59
|
+
firstName: 'Joshua',
|
|
60
|
+
lastName: 'Rolluffs',
|
|
61
|
+
},
|
|
62
|
+
address: '32188 Larkin Turnpike',
|
|
63
|
+
city: 'Omaha',
|
|
64
|
+
state: 'Nebraska',
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
const Example = () => {
|
|
69
|
+
//should be memoized or stable
|
|
70
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
71
|
+
() => [
|
|
72
|
+
{
|
|
73
|
+
accessorKey: 'name.firstName', //access nested data with dot notation
|
|
74
|
+
header: 'First Name',
|
|
75
|
+
size: 150,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
accessorKey: 'name.lastName',
|
|
79
|
+
header: 'Last Name',
|
|
80
|
+
size: 150,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
accessorKey: 'address', //normal accessorKey
|
|
84
|
+
header: 'Address',
|
|
85
|
+
size: 200,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
accessorKey: 'city',
|
|
89
|
+
header: 'City',
|
|
90
|
+
size: 150,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
accessorKey: 'state',
|
|
94
|
+
header: 'State',
|
|
95
|
+
size: 150,
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
[],
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const table = useMaterialReactTable({
|
|
102
|
+
columns,
|
|
103
|
+
data, //data must be memoized or stable (useState, useMemo, defined outside of this component, etc.)
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return <MaterialReactTable table={table} />;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export default Example;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MaterialReactTable,
|
|
4
|
+
useMaterialReactTable,
|
|
5
|
+
type MRT_ColumnDef,
|
|
6
|
+
} from 'material-react-table';
|
|
7
|
+
import { useTheme } from '@mui/material/styles';
|
|
8
|
+
import { LineChart } from '@mui/x-charts/LineChart';
|
|
9
|
+
import { data, type Person } from './makeData';
|
|
10
|
+
|
|
11
|
+
const Example = () => {
|
|
12
|
+
const theme = useTheme();
|
|
13
|
+
|
|
14
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
15
|
+
//column definitions...
|
|
16
|
+
() => [
|
|
17
|
+
{
|
|
18
|
+
accessorKey: 'id',
|
|
19
|
+
header: 'ID',
|
|
20
|
+
size: 50,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
accessorKey: 'firstName',
|
|
24
|
+
header: 'First Name',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
accessorKey: 'middleName',
|
|
28
|
+
header: 'Middle Name',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
accessorKey: 'lastName',
|
|
32
|
+
header: 'Last Name',
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
[],
|
|
36
|
+
//end
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const table = useMaterialReactTable({
|
|
40
|
+
columns,
|
|
41
|
+
data,
|
|
42
|
+
initialState: { expanded: { 0: true } },
|
|
43
|
+
muiTableBodyRowProps: {
|
|
44
|
+
sx: {
|
|
45
|
+
'.Mui-TableBodyCell-DetailPanel': {
|
|
46
|
+
backgroundColor:
|
|
47
|
+
theme.palette.mode === 'dark'
|
|
48
|
+
? theme.palette.grey[900]
|
|
49
|
+
: theme.palette.grey[100],
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
renderDetailPanel: ({ row }) => (
|
|
54
|
+
<LineChart
|
|
55
|
+
xAxis={[
|
|
56
|
+
{
|
|
57
|
+
data: row.original.gamesPlayed,
|
|
58
|
+
label: 'Games Played',
|
|
59
|
+
valueFormatter: (value) => `#${value}`,
|
|
60
|
+
tickLabelInterval: (value) => value % 1 === 0,
|
|
61
|
+
},
|
|
62
|
+
]}
|
|
63
|
+
yAxis={[{ min: 0, max: 60 }]}
|
|
64
|
+
series={[
|
|
65
|
+
{
|
|
66
|
+
color: theme.palette.primary.dark,
|
|
67
|
+
data: row.original.points,
|
|
68
|
+
label: 'Points',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
color: theme.palette.secondary.main,
|
|
72
|
+
data: row.original.assists,
|
|
73
|
+
label: 'Assists',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
color: theme.palette.error.main,
|
|
77
|
+
data: row.original.turnovers,
|
|
78
|
+
label: 'Turnovers',
|
|
79
|
+
},
|
|
80
|
+
]}
|
|
81
|
+
height={250}
|
|
82
|
+
/>
|
|
83
|
+
),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
return <MaterialReactTable table={table} />;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export default Example;
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
//column definitions...
|
|
12
|
+
() => [
|
|
13
|
+
{
|
|
14
|
+
accessorKey: 'id',
|
|
15
|
+
header: 'ID',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
accessorKey: 'firstName',
|
|
19
|
+
header: 'First Name',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
accessorKey: 'lastName',
|
|
23
|
+
header: 'Last Name',
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
[], //end
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const table = useMaterialReactTable({
|
|
30
|
+
columns,
|
|
31
|
+
data,
|
|
32
|
+
muiTableHeadCellProps: {
|
|
33
|
+
sx: {
|
|
34
|
+
'& .Mui-TableHeadCell-Content': {
|
|
35
|
+
justifyContent: 'space-between',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return <MaterialReactTable table={table} />;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default Example;
|
|
@@ -0,0 +1,70 @@
|
|
|
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: 'firstName',
|
|
14
|
+
header: 'First Name',
|
|
15
|
+
size: 100,
|
|
16
|
+
muiTableHeadCellProps: {
|
|
17
|
+
align: 'center',
|
|
18
|
+
},
|
|
19
|
+
muiTableBodyCellProps: {
|
|
20
|
+
align: 'center',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
accessorKey: 'lastName',
|
|
25
|
+
header: 'Last Name',
|
|
26
|
+
size: 100,
|
|
27
|
+
muiTableHeadCellProps: {
|
|
28
|
+
align: 'center',
|
|
29
|
+
},
|
|
30
|
+
muiTableBodyCellProps: {
|
|
31
|
+
align: 'center',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
accessorKey: 'age',
|
|
36
|
+
header: 'Age',
|
|
37
|
+
muiTableHeadCellProps: {
|
|
38
|
+
align: 'right',
|
|
39
|
+
},
|
|
40
|
+
muiTableBodyCellProps: {
|
|
41
|
+
align: 'right',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
accessorKey: 'salary',
|
|
46
|
+
header: 'Salary',
|
|
47
|
+
muiTableHeadCellProps: {
|
|
48
|
+
align: 'right',
|
|
49
|
+
},
|
|
50
|
+
muiTableBodyCellProps: {
|
|
51
|
+
align: 'right',
|
|
52
|
+
},
|
|
53
|
+
Cell: ({ cell }) =>
|
|
54
|
+
cell
|
|
55
|
+
.getValue<number>()
|
|
56
|
+
.toLocaleString('en-US', { style: 'currency', currency: 'USD' }),
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
[],
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const table = useMaterialReactTable({
|
|
63
|
+
columns,
|
|
64
|
+
data,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return <MaterialReactTable table={table} />;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default Example;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MaterialReactTable,
|
|
4
|
+
useMaterialReactTable,
|
|
5
|
+
type MRT_ColumnDef,
|
|
6
|
+
} from 'material-react-table';
|
|
7
|
+
import { Divider, MenuItem } from '@mui/material';
|
|
8
|
+
import { data, type Person } from './makeData';
|
|
9
|
+
|
|
10
|
+
const Example = () => {
|
|
11
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
12
|
+
() => [
|
|
13
|
+
{
|
|
14
|
+
accessorKey: 'id',
|
|
15
|
+
header: 'ID',
|
|
16
|
+
renderColumnActionsMenuItems: ({ closeMenu }) => [
|
|
17
|
+
<MenuItem
|
|
18
|
+
key={1}
|
|
19
|
+
onClick={() => {
|
|
20
|
+
console.log('Item 1 clicked');
|
|
21
|
+
closeMenu();
|
|
22
|
+
}}
|
|
23
|
+
>
|
|
24
|
+
Item 1
|
|
25
|
+
</MenuItem>,
|
|
26
|
+
<MenuItem
|
|
27
|
+
key={2}
|
|
28
|
+
onClick={() => {
|
|
29
|
+
console.log('Item 2 clicked');
|
|
30
|
+
closeMenu();
|
|
31
|
+
}}
|
|
32
|
+
>
|
|
33
|
+
Item 2
|
|
34
|
+
</MenuItem>,
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
accessorKey: 'firstName',
|
|
39
|
+
header: 'First Name',
|
|
40
|
+
renderColumnActionsMenuItems: ({
|
|
41
|
+
closeMenu,
|
|
42
|
+
internalColumnMenuItems,
|
|
43
|
+
}) => [
|
|
44
|
+
...internalColumnMenuItems,
|
|
45
|
+
<Divider key="divider-1" />,
|
|
46
|
+
<MenuItem
|
|
47
|
+
key={'item-1'}
|
|
48
|
+
onClick={() => {
|
|
49
|
+
console.log('Item 1 clicked');
|
|
50
|
+
closeMenu();
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
Item 1
|
|
54
|
+
</MenuItem>,
|
|
55
|
+
<MenuItem
|
|
56
|
+
key={'item-2'}
|
|
57
|
+
onClick={() => {
|
|
58
|
+
console.log('Item 2 clicked');
|
|
59
|
+
closeMenu();
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
Item 2
|
|
63
|
+
</MenuItem>,
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
accessorKey: 'lastName',
|
|
68
|
+
header: 'Last Name',
|
|
69
|
+
renderColumnActionsMenuItems: ({
|
|
70
|
+
closeMenu,
|
|
71
|
+
internalColumnMenuItems,
|
|
72
|
+
}) => [
|
|
73
|
+
<MenuItem
|
|
74
|
+
key={'item-1'}
|
|
75
|
+
onClick={() => {
|
|
76
|
+
console.log('Item 1 clicked');
|
|
77
|
+
closeMenu();
|
|
78
|
+
}}
|
|
79
|
+
>
|
|
80
|
+
Item 1
|
|
81
|
+
</MenuItem>,
|
|
82
|
+
<MenuItem
|
|
83
|
+
key={'item-2'}
|
|
84
|
+
onClick={() => {
|
|
85
|
+
console.log('Item 2 clicked');
|
|
86
|
+
closeMenu();
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
Item 2
|
|
90
|
+
</MenuItem>,
|
|
91
|
+
<Divider key="divider-1" />,
|
|
92
|
+
...internalColumnMenuItems.splice(0, 3),
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
[],
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const table = useMaterialReactTable({
|
|
100
|
+
columns,
|
|
101
|
+
data,
|
|
102
|
+
//or you could define the menu items here for all columns
|
|
103
|
+
// renderColumnActionsMenuItems: ({ closeMenu }) => [],
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return <MaterialReactTable table={table} />;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export default Example;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
useMaterialReactTable,
|
|
4
|
+
type MRT_ColumnDef,
|
|
5
|
+
MRT_TableContainer,
|
|
6
|
+
MRT_TableHeadCellFilterContainer,
|
|
7
|
+
} from 'material-react-table';
|
|
8
|
+
import { data, type Person } from './makeData';
|
|
9
|
+
import { Paper, Stack, useMediaQuery } from '@mui/material';
|
|
10
|
+
|
|
11
|
+
const Example = () => {
|
|
12
|
+
const isMobile = useMediaQuery('(max-width: 1000px)');
|
|
13
|
+
|
|
14
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
15
|
+
() => [
|
|
16
|
+
{
|
|
17
|
+
accessorKey: 'id',
|
|
18
|
+
header: 'ID',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
accessorKey: 'firstName',
|
|
22
|
+
header: 'First Name',
|
|
23
|
+
filterVariant: 'autocomplete',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
accessorKey: 'lastName',
|
|
27
|
+
header: 'Last Name',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
accessorKey: 'gender',
|
|
31
|
+
header: 'Gender',
|
|
32
|
+
filterFn: 'equals',
|
|
33
|
+
filterSelectOptions: ['Male', 'Female', 'Other'],
|
|
34
|
+
filterVariant: 'select',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
accessorKey: 'age',
|
|
38
|
+
header: 'Age',
|
|
39
|
+
filterVariant: 'range',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
[],
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const table = useMaterialReactTable({
|
|
46
|
+
columns,
|
|
47
|
+
data,
|
|
48
|
+
columnFilterDisplayMode: 'custom', //we will render our own filtering UI
|
|
49
|
+
enableFacetedValues: true,
|
|
50
|
+
muiFilterTextFieldProps: ({ column }) => ({
|
|
51
|
+
label: `Filter by ${column.columnDef.header}`,
|
|
52
|
+
}),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<Stack
|
|
57
|
+
direction={isMobile ? 'column-reverse' : 'row'}
|
|
58
|
+
sx={{
|
|
59
|
+
gap: '8px',
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
<MRT_TableContainer table={table} />
|
|
63
|
+
<Paper>
|
|
64
|
+
<Stack
|
|
65
|
+
sx={{
|
|
66
|
+
p: '8px',
|
|
67
|
+
gap: '8px',
|
|
68
|
+
}}
|
|
69
|
+
>
|
|
70
|
+
{table
|
|
71
|
+
.getLeafHeaders()
|
|
72
|
+
.map(
|
|
73
|
+
(header) =>
|
|
74
|
+
header.column.getCanFilter() && (
|
|
75
|
+
<MRT_TableHeadCellFilterContainer
|
|
76
|
+
key={header.id}
|
|
77
|
+
header={header}
|
|
78
|
+
table={table}
|
|
79
|
+
in
|
|
80
|
+
/>
|
|
81
|
+
),
|
|
82
|
+
)}
|
|
83
|
+
</Stack>
|
|
84
|
+
</Paper>
|
|
85
|
+
</Stack>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export default Example;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MRT_GlobalFilterTextField,
|
|
3
|
+
MRT_TableBodyCellValue,
|
|
4
|
+
MRT_TablePagination,
|
|
5
|
+
MRT_ToolbarAlertBanner,
|
|
6
|
+
flexRender,
|
|
7
|
+
type MRT_ColumnDef,
|
|
8
|
+
useMaterialReactTable,
|
|
9
|
+
} from 'material-react-table';
|
|
10
|
+
import {
|
|
11
|
+
Box,
|
|
12
|
+
Stack,
|
|
13
|
+
Table,
|
|
14
|
+
TableBody,
|
|
15
|
+
TableCell,
|
|
16
|
+
TableContainer,
|
|
17
|
+
TableHead,
|
|
18
|
+
TableRow,
|
|
19
|
+
Typography,
|
|
20
|
+
} from '@mui/material';
|
|
21
|
+
import { type Person, data } from './makeData';
|
|
22
|
+
|
|
23
|
+
const columns: MRT_ColumnDef<Person>[] = [
|
|
24
|
+
{
|
|
25
|
+
accessorKey: 'name.firstName',
|
|
26
|
+
header: 'First Name',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
accessorKey: 'name.lastName',
|
|
30
|
+
header: 'Last Name',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
accessorKey: 'address',
|
|
34
|
+
header: 'Address',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
accessorKey: 'city',
|
|
38
|
+
header: 'City',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
accessorKey: 'state',
|
|
42
|
+
header: 'State',
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const Example = () => {
|
|
47
|
+
const table = useMaterialReactTable({
|
|
48
|
+
columns,
|
|
49
|
+
data, //must be memoized or stable (useState, useMemo, defined outside of this component, etc.)
|
|
50
|
+
//MRT display columns can still work, optionally override cell renders with `displayColumnDefOptions`
|
|
51
|
+
enableRowSelection: true,
|
|
52
|
+
initialState: {
|
|
53
|
+
pagination: { pageSize: 5, pageIndex: 0 },
|
|
54
|
+
showGlobalFilter: true,
|
|
55
|
+
},
|
|
56
|
+
//customize the MRT components
|
|
57
|
+
muiPaginationProps: {
|
|
58
|
+
rowsPerPageOptions: [5, 10, 15],
|
|
59
|
+
variant: 'outlined',
|
|
60
|
+
},
|
|
61
|
+
paginationDisplayMode: 'pages',
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<Stack sx={{ m: '2rem 0' }}>
|
|
66
|
+
<Typography variant="h4">My Custom Headless Table</Typography>
|
|
67
|
+
<Box
|
|
68
|
+
sx={{
|
|
69
|
+
display: 'flex',
|
|
70
|
+
justifyContent: 'space-between',
|
|
71
|
+
alignItems: 'center',
|
|
72
|
+
}}
|
|
73
|
+
>
|
|
74
|
+
{/**
|
|
75
|
+
* Use MRT components along side your own markup.
|
|
76
|
+
* They just need the `table` instance passed as a prop to work!
|
|
77
|
+
*/}
|
|
78
|
+
<MRT_GlobalFilterTextField table={table} />
|
|
79
|
+
<MRT_TablePagination table={table} />
|
|
80
|
+
</Box>
|
|
81
|
+
{/* Using Vanilla Material-UI Table components here */}
|
|
82
|
+
<TableContainer>
|
|
83
|
+
<Table>
|
|
84
|
+
{/* Use your own markup, customize however you want using the power of TanStack Table */}
|
|
85
|
+
<TableHead>
|
|
86
|
+
{table.getHeaderGroups().map((headerGroup) => (
|
|
87
|
+
<TableRow key={headerGroup.id}>
|
|
88
|
+
{headerGroup.headers.map((header) => (
|
|
89
|
+
<TableCell align="center" variant="head" key={header.id}>
|
|
90
|
+
{header.isPlaceholder
|
|
91
|
+
? null
|
|
92
|
+
: flexRender(
|
|
93
|
+
header.column.columnDef.Header ??
|
|
94
|
+
header.column.columnDef.header,
|
|
95
|
+
header.getContext(),
|
|
96
|
+
)}
|
|
97
|
+
</TableCell>
|
|
98
|
+
))}
|
|
99
|
+
</TableRow>
|
|
100
|
+
))}
|
|
101
|
+
</TableHead>
|
|
102
|
+
<TableBody>
|
|
103
|
+
{table.getRowModel().rows.map((row, rowIndex) => (
|
|
104
|
+
<TableRow key={row.id} selected={row.getIsSelected()}>
|
|
105
|
+
{row.getVisibleCells().map((cell, _columnIndex) => (
|
|
106
|
+
<TableCell align="center" variant="body" key={cell.id}>
|
|
107
|
+
{/* Use MRT's cell renderer that provides better logic than flexRender */}
|
|
108
|
+
<MRT_TableBodyCellValue
|
|
109
|
+
cell={cell}
|
|
110
|
+
table={table}
|
|
111
|
+
staticRowIndex={rowIndex} //just for batch row selection to work
|
|
112
|
+
/>
|
|
113
|
+
</TableCell>
|
|
114
|
+
))}
|
|
115
|
+
</TableRow>
|
|
116
|
+
))}
|
|
117
|
+
</TableBody>
|
|
118
|
+
</Table>
|
|
119
|
+
</TableContainer>
|
|
120
|
+
<MRT_ToolbarAlertBanner stackAlertBanner table={table} />
|
|
121
|
+
</Stack>
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export default Example;
|