@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,88 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MaterialReactTable,
|
|
4
|
+
type MRT_ColumnDef,
|
|
5
|
+
MRT_ToggleDensePaddingButton,
|
|
6
|
+
MRT_ToggleFullScreenButton,
|
|
7
|
+
useMaterialReactTable,
|
|
8
|
+
} from 'material-react-table';
|
|
9
|
+
import { Box, Button, IconButton } from '@mui/material';
|
|
10
|
+
import PrintIcon from '@mui/icons-material/Print';
|
|
11
|
+
import { data, type Person } from './makeData';
|
|
12
|
+
|
|
13
|
+
const Example = () => {
|
|
14
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
15
|
+
//column definitions...
|
|
16
|
+
() => [
|
|
17
|
+
{
|
|
18
|
+
accessorKey: 'firstName',
|
|
19
|
+
header: 'First Name',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
accessorKey: 'lastName',
|
|
23
|
+
header: 'Last Name',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
accessorKey: 'age',
|
|
27
|
+
header: 'Age',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
accessorKey: 'salary',
|
|
31
|
+
header: 'Salary',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
[],
|
|
35
|
+
//end
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const table = useMaterialReactTable({
|
|
39
|
+
columns,
|
|
40
|
+
data,
|
|
41
|
+
enableRowSelection: true,
|
|
42
|
+
positionToolbarAlertBanner: 'bottom', //show selected rows count on bottom toolbar
|
|
43
|
+
//add custom action buttons to top-left of top toolbar
|
|
44
|
+
renderTopToolbarCustomActions: ({ table }) => (
|
|
45
|
+
<Box sx={{ display: 'flex', gap: '1rem', p: '4px' }}>
|
|
46
|
+
<Button
|
|
47
|
+
color="secondary"
|
|
48
|
+
onClick={() => {
|
|
49
|
+
alert('Create New Account');
|
|
50
|
+
}}
|
|
51
|
+
variant="contained"
|
|
52
|
+
>
|
|
53
|
+
Create Account
|
|
54
|
+
</Button>
|
|
55
|
+
<Button
|
|
56
|
+
color="error"
|
|
57
|
+
disabled={!table.getIsSomeRowsSelected()}
|
|
58
|
+
onClick={() => {
|
|
59
|
+
alert('Delete Selected Accounts');
|
|
60
|
+
}}
|
|
61
|
+
variant="contained"
|
|
62
|
+
>
|
|
63
|
+
Delete Selected Accounts
|
|
64
|
+
</Button>
|
|
65
|
+
</Box>
|
|
66
|
+
),
|
|
67
|
+
//customize built-in buttons in the top-right of top toolbar
|
|
68
|
+
renderToolbarInternalActions: ({ table }) => (
|
|
69
|
+
<Box>
|
|
70
|
+
{/* add custom button to print table */}
|
|
71
|
+
<IconButton
|
|
72
|
+
onClick={() => {
|
|
73
|
+
window.print();
|
|
74
|
+
}}
|
|
75
|
+
>
|
|
76
|
+
<PrintIcon />
|
|
77
|
+
</IconButton>
|
|
78
|
+
{/* along-side built-in buttons in whatever order you want them */}
|
|
79
|
+
<MRT_ToggleDensePaddingButton table={table} />
|
|
80
|
+
<MRT_ToggleFullScreenButton table={table} />
|
|
81
|
+
</Box>
|
|
82
|
+
),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return <MaterialReactTable table={table} />;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export default Example;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { Box, Button } 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 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
|
+
const table = useMaterialReactTable({
|
|
40
|
+
columns,
|
|
41
|
+
data,
|
|
42
|
+
defaultDisplayColumn: {
|
|
43
|
+
enableResizing: true, //turn on some features that are usually off for all display columns
|
|
44
|
+
},
|
|
45
|
+
displayColumnDefOptions: {
|
|
46
|
+
'mrt-row-actions': {
|
|
47
|
+
size: 350, //set custom width
|
|
48
|
+
muiTableHeadCellProps: {
|
|
49
|
+
align: 'center', //change head cell props
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
'mrt-row-numbers': {
|
|
53
|
+
enableColumnDragging: true,
|
|
54
|
+
enableColumnOrdering: true, //turn on some features that are usually off
|
|
55
|
+
enableResizing: true,
|
|
56
|
+
muiTableHeadCellProps: {
|
|
57
|
+
sx: {
|
|
58
|
+
fontSize: '1.2rem',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
'mrt-row-select': {
|
|
63
|
+
enableColumnActions: true,
|
|
64
|
+
enableHiding: true,
|
|
65
|
+
size: 100,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
enableColumnResizing: true,
|
|
69
|
+
enableColumnOrdering: true,
|
|
70
|
+
enableRowNumbers: true,
|
|
71
|
+
enableRowSelection: true,
|
|
72
|
+
enableRowActions: true,
|
|
73
|
+
renderRowActions: ({ row }) => (
|
|
74
|
+
<Box sx={{ display: 'flex', gap: '1rem' }}>
|
|
75
|
+
<Button>Button 1</Button>
|
|
76
|
+
<Button>Button 2</Button>
|
|
77
|
+
<Button>Button 3</Button>
|
|
78
|
+
</Box>
|
|
79
|
+
),
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return <MaterialReactTable table={table} />;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export default Example;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MaterialReactTable,
|
|
4
|
+
useMaterialReactTable,
|
|
5
|
+
type MRT_ColumnDef,
|
|
6
|
+
} from 'material-react-table';
|
|
7
|
+
|
|
8
|
+
export type Person = {
|
|
9
|
+
id: number;
|
|
10
|
+
firstName: string;
|
|
11
|
+
lastName: string;
|
|
12
|
+
gender: string;
|
|
13
|
+
age: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const Example = () => {
|
|
17
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
18
|
+
() => [
|
|
19
|
+
{
|
|
20
|
+
accessorKey: 'id',
|
|
21
|
+
header: 'ID',
|
|
22
|
+
muiFilterTextFieldProps: { placeholder: 'ID' },
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
accessorKey: 'firstName',
|
|
26
|
+
header: 'First Name',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
accessorKey: 'lastName',
|
|
30
|
+
header: 'Last Name',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
accessorKey: 'gender',
|
|
34
|
+
header: 'Gender',
|
|
35
|
+
filterFn: 'equals',
|
|
36
|
+
filterSelectOptions: [
|
|
37
|
+
{ label: 'Male', value: 'Male' },
|
|
38
|
+
{ label: 'Female', value: 'Female' },
|
|
39
|
+
{ label: 'Other', value: 'Other' },
|
|
40
|
+
],
|
|
41
|
+
filterVariant: 'select',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
accessorKey: 'age',
|
|
45
|
+
header: 'Age',
|
|
46
|
+
filterVariant: 'range',
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
[],
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const data = useMemo<Person[]>(
|
|
53
|
+
//data definitions...
|
|
54
|
+
() => [
|
|
55
|
+
{
|
|
56
|
+
id: 1,
|
|
57
|
+
firstName: 'Hugh',
|
|
58
|
+
lastName: 'Mungus',
|
|
59
|
+
gender: 'Male',
|
|
60
|
+
age: 42,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: 2,
|
|
64
|
+
firstName: 'Leroy',
|
|
65
|
+
lastName: 'Jenkins',
|
|
66
|
+
gender: 'Male',
|
|
67
|
+
age: 51,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: 3,
|
|
71
|
+
firstName: 'Candice',
|
|
72
|
+
lastName: 'Nutella',
|
|
73
|
+
gender: 'Female',
|
|
74
|
+
age: 27,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: 4,
|
|
78
|
+
firstName: 'Micah',
|
|
79
|
+
lastName: 'Johnson',
|
|
80
|
+
gender: 'Other',
|
|
81
|
+
age: 32,
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
[],
|
|
85
|
+
//end
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const table = useMaterialReactTable({
|
|
89
|
+
columns,
|
|
90
|
+
data,
|
|
91
|
+
initialState: { showColumnFilters: true },
|
|
92
|
+
muiFilterTextFieldProps: {
|
|
93
|
+
sx: { m: '0.5rem 0', width: '100%' },
|
|
94
|
+
variant: 'outlined',
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
return <MaterialReactTable table={table} />;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export default Example;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MaterialReactTable,
|
|
4
|
+
useMaterialReactTable,
|
|
5
|
+
type MRT_ColumnDef,
|
|
6
|
+
} from 'material-react-table';
|
|
7
|
+
import { 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
|
+
enableColumnFilterModes: false, //disable changing filter mode for this column
|
|
16
|
+
filterFn: 'equals', //set filter mode to equals
|
|
17
|
+
header: 'ID',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
accessorKey: 'firstName', //normal, all filter modes are enabled
|
|
21
|
+
header: 'First Name',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
accessorKey: 'middleName',
|
|
25
|
+
enableColumnFilterModes: false, //disable changing filter mode for this column
|
|
26
|
+
filterFn: 'startsWith', //even though changing the mode is disabled, you can still set the default filter mode
|
|
27
|
+
header: 'Middle Name',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
accessorKey: 'lastName',
|
|
31
|
+
header: 'Last Name',
|
|
32
|
+
//if you do not want to use the default filter modes, you can provide your own and render your own menu
|
|
33
|
+
renderColumnFilterModeMenuItems: ({ onSelectFilterMode }) => [
|
|
34
|
+
<MenuItem key="0" onClick={() => onSelectFilterMode('contains')}>
|
|
35
|
+
<div>Contains</div>
|
|
36
|
+
</MenuItem>,
|
|
37
|
+
<MenuItem
|
|
38
|
+
key="1"
|
|
39
|
+
onClick={() => onSelectFilterMode('customFilterFn')}
|
|
40
|
+
>
|
|
41
|
+
<div>Custom Filter Fn</div>
|
|
42
|
+
</MenuItem>,
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
accessorKey: 'age',
|
|
47
|
+
columnFilterModeOptions: ['between', 'greaterThan', 'lessThan'], //only allow these filter modes
|
|
48
|
+
filterFn: 'between',
|
|
49
|
+
header: 'Age',
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
[],
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const table = useMaterialReactTable({
|
|
56
|
+
columns,
|
|
57
|
+
data,
|
|
58
|
+
enableColumnFilterModes: true, //enable changing filter mode for all columns unless explicitly disabled in a column def
|
|
59
|
+
initialState: { showColumnFilters: true }, //show filters by default
|
|
60
|
+
filterFns: {
|
|
61
|
+
customFilterFn: (row, id, filterValue) => {
|
|
62
|
+
return row.getValue(id) === filterValue;
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
localization: {
|
|
66
|
+
filterCustomFilterFn: 'Custom Filter Fn',
|
|
67
|
+
} as any,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return <MaterialReactTable table={table} />;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export default Example;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MaterialReactTable,
|
|
4
|
+
useMaterialReactTable,
|
|
5
|
+
type MRT_ColumnDef,
|
|
6
|
+
} from 'material-react-table';
|
|
7
|
+
import { citiesList, data, type Person, usStateList } from './makeData';
|
|
8
|
+
|
|
9
|
+
const Example = () => {
|
|
10
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
11
|
+
() => [
|
|
12
|
+
{
|
|
13
|
+
header: 'Status',
|
|
14
|
+
accessorFn: (originalRow) => (originalRow.isActive ? 'true' : 'false'), //must be strings
|
|
15
|
+
id: 'isActive',
|
|
16
|
+
filterVariant: 'checkbox',
|
|
17
|
+
Cell: ({ cell }) =>
|
|
18
|
+
cell.getValue() === 'true' ? 'Active' : 'Inactive',
|
|
19
|
+
size: 170,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
accessorKey: 'name',
|
|
23
|
+
header: 'Name',
|
|
24
|
+
filterVariant: 'text', // default
|
|
25
|
+
size: 200,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
accessorKey: 'salary',
|
|
29
|
+
header: 'Salary',
|
|
30
|
+
Cell: ({ cell }) =>
|
|
31
|
+
cell.getValue<number>().toLocaleString('en-US', {
|
|
32
|
+
style: 'currency',
|
|
33
|
+
currency: 'USD',
|
|
34
|
+
}),
|
|
35
|
+
filterVariant: 'range-slider',
|
|
36
|
+
filterFn: 'betweenInclusive', // default (or between)
|
|
37
|
+
muiFilterSliderProps: {
|
|
38
|
+
marks: true,
|
|
39
|
+
max: 200_000, //custom max (as opposed to faceted max)
|
|
40
|
+
min: 30_000, //custom min (as opposed to faceted min)
|
|
41
|
+
step: 10_000,
|
|
42
|
+
valueLabelFormat: (value) =>
|
|
43
|
+
value.toLocaleString('en-US', {
|
|
44
|
+
style: 'currency',
|
|
45
|
+
currency: 'USD',
|
|
46
|
+
}),
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
accessorKey: 'age',
|
|
51
|
+
header: 'Age',
|
|
52
|
+
filterVariant: 'range',
|
|
53
|
+
filterFn: 'between',
|
|
54
|
+
size: 80,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
accessorKey: 'city',
|
|
58
|
+
header: 'City',
|
|
59
|
+
filterVariant: 'select',
|
|
60
|
+
filterSelectOptions: citiesList, //custom options list (as opposed to faceted list)
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
accessorKey: 'state',
|
|
64
|
+
header: 'State',
|
|
65
|
+
filterVariant: 'multi-select',
|
|
66
|
+
filterSelectOptions: usStateList, //custom options list (as opposed to faceted list)
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
accessorFn: (originalRow) => new Date(originalRow.hireDate), //convert to date for sorting and filtering
|
|
70
|
+
id: 'hireDate',
|
|
71
|
+
header: 'Hire Date',
|
|
72
|
+
filterVariant: 'date-range',
|
|
73
|
+
Cell: ({ cell }) => cell.getValue<Date>().toLocaleDateString(), // convert back to string for display
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
accessorFn: (originalRow) => new Date(originalRow.arrivalTime), //convert to date for sorting and filtering
|
|
77
|
+
id: 'arrivalTime',
|
|
78
|
+
header: 'Arrival Time',
|
|
79
|
+
filterVariant: 'datetime-range',
|
|
80
|
+
Cell: ({ cell }) =>
|
|
81
|
+
`${cell.getValue<Date>().toLocaleDateString()} ${cell
|
|
82
|
+
.getValue<Date>()
|
|
83
|
+
.toLocaleTimeString()}`, // convert back to string for display
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
accessorFn: (originalRow) => new Date(originalRow.departureTime), //convert to date for sorting and filtering
|
|
87
|
+
id: 'departureTime',
|
|
88
|
+
header: 'Departure Time',
|
|
89
|
+
filterVariant: 'time-range',
|
|
90
|
+
Cell: ({ cell }) => cell.getValue<Date>().toLocaleTimeString(), // convert back to string for display
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
[],
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const table = useMaterialReactTable({
|
|
97
|
+
columns,
|
|
98
|
+
data,
|
|
99
|
+
initialState: { showColumnFilters: true },
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return <MaterialReactTable table={table} />;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
//Date Picker Imports - these should just be in your Context Provider
|
|
106
|
+
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
|
|
107
|
+
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
|
|
108
|
+
|
|
109
|
+
const ExampleWithLocalizationProvider = () => (
|
|
110
|
+
//App.tsx or AppProviders file
|
|
111
|
+
<LocalizationProvider dateAdapter={AdapterDayjs}>
|
|
112
|
+
<Example />
|
|
113
|
+
</LocalizationProvider>
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
export default ExampleWithLocalizationProvider;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { MaterialReactTable, type MRT_ColumnDef } from 'material-react-table';
|
|
3
|
+
import { data, type Person } from './makeData';
|
|
4
|
+
|
|
5
|
+
const Example = () => {
|
|
6
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
7
|
+
//column definitions...
|
|
8
|
+
() => [
|
|
9
|
+
{
|
|
10
|
+
accessorKey: 'id',
|
|
11
|
+
header: 'ID',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
accessorKey: 'firstName',
|
|
15
|
+
header: 'First Name',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
accessorKey: 'middleName',
|
|
19
|
+
header: 'Middle Name',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
accessorKey: 'lastName',
|
|
23
|
+
header: 'Last Name',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
accessorKey: 'age',
|
|
27
|
+
header: 'Age',
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
[],
|
|
31
|
+
//end
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<MaterialReactTable
|
|
36
|
+
columns={columns}
|
|
37
|
+
data={data}
|
|
38
|
+
enableGlobalFilterModes
|
|
39
|
+
initialState={{
|
|
40
|
+
showGlobalFilter: true,
|
|
41
|
+
}}
|
|
42
|
+
positionGlobalFilter="left"
|
|
43
|
+
muiSearchTextFieldProps={{
|
|
44
|
+
placeholder: `Search ${data.length} rows`,
|
|
45
|
+
sx: { minWidth: '300px' },
|
|
46
|
+
variant: 'outlined',
|
|
47
|
+
}}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export default Example;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { useMemo, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MaterialReactTable,
|
|
4
|
+
useMaterialReactTable,
|
|
5
|
+
type MRT_ColumnDef,
|
|
6
|
+
type MRT_Row,
|
|
7
|
+
MRT_ExpandAllButton,
|
|
8
|
+
} from 'material-react-table';
|
|
9
|
+
import { data, type Person } from './makeData';
|
|
10
|
+
import { Box, Stack } from '@mui/material';
|
|
11
|
+
|
|
12
|
+
const Example = () => {
|
|
13
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
14
|
+
//column definitions...
|
|
15
|
+
() => [
|
|
16
|
+
{
|
|
17
|
+
header: 'First Name',
|
|
18
|
+
accessorKey: 'firstName',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
header: 'Last Name',
|
|
22
|
+
accessorKey: 'lastName',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
header: 'Age',
|
|
26
|
+
accessorKey: 'age',
|
|
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
|
+
},
|
|
40
|
+
],
|
|
41
|
+
[],
|
|
42
|
+
//end
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const table = useMaterialReactTable({
|
|
46
|
+
columns,
|
|
47
|
+
data,
|
|
48
|
+
displayColumnDefOptions: {
|
|
49
|
+
'mrt-row-expand': {
|
|
50
|
+
Header: () => (
|
|
51
|
+
<Stack
|
|
52
|
+
direction="row"
|
|
53
|
+
sx={{
|
|
54
|
+
alignItems: 'center',
|
|
55
|
+
}}
|
|
56
|
+
>
|
|
57
|
+
<MRT_ExpandAllButton table={table} />
|
|
58
|
+
<Box>Groups</Box>
|
|
59
|
+
</Stack>
|
|
60
|
+
),
|
|
61
|
+
GroupedCell: ({ row, table }) => {
|
|
62
|
+
const { grouping } = table.getState();
|
|
63
|
+
return row.getValue(grouping[grouping.length - 1]);
|
|
64
|
+
},
|
|
65
|
+
enableResizing: true,
|
|
66
|
+
muiTableBodyCellProps: ({ row }) => ({
|
|
67
|
+
sx: (theme) => ({
|
|
68
|
+
color:
|
|
69
|
+
row.depth === 0
|
|
70
|
+
? theme.palette.primary.main
|
|
71
|
+
: row.depth === 1
|
|
72
|
+
? theme.palette.secondary.main
|
|
73
|
+
: undefined,
|
|
74
|
+
}),
|
|
75
|
+
}),
|
|
76
|
+
size: 200,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
enableGrouping: true,
|
|
80
|
+
enableColumnResizing: true,
|
|
81
|
+
groupedColumnMode: 'remove',
|
|
82
|
+
initialState: {
|
|
83
|
+
density: 'compact',
|
|
84
|
+
expanded: true, //expand all groups by default
|
|
85
|
+
grouping: ['state', 'gender'], //an array of columns to group by by default (can be multiple)
|
|
86
|
+
pagination: { pageIndex: 0, pageSize: 20 },
|
|
87
|
+
sorting: [{ id: 'state', desc: false }],
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return <MaterialReactTable table={table} />;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export default Example;
|
|
@@ -0,0 +1,54 @@
|
|
|
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: 'firstName',
|
|
15
|
+
header: 'First Name',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
accessorKey: 'lastName',
|
|
19
|
+
header: 'Last Name',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
accessorKey: 'age',
|
|
23
|
+
header: 'Age',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
accessorKey: 'address',
|
|
27
|
+
header: 'Address',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
accessorKey: 'city',
|
|
31
|
+
header: 'City',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
accessorKey: 'state',
|
|
35
|
+
header: 'State',
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
[],
|
|
39
|
+
//end
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const table = useMaterialReactTable({
|
|
43
|
+
columns,
|
|
44
|
+
data,
|
|
45
|
+
enableSelectAll: false,
|
|
46
|
+
enableRowSelection: (row) => row.original.age >= 21, //enable row selection conditionally per row
|
|
47
|
+
muiSelectCheckboxProps: { color: 'secondary' },
|
|
48
|
+
positionToolbarAlertBanner: 'head-overlay',
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return <MaterialReactTable table={table} />;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default Example;
|