@mini_7/material-react-table-mcp 4.0.0 → 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 +1 -1
- package/data/examples/advanced.js +215 -0
- package/data/examples/aggregation-and-grouping.js +116 -0
- package/data/examples/aggregation-multi.js +89 -0
- package/data/examples/alternate-column-filtering.js +38 -0
- package/data/examples/alternate-detail-panel.js +65 -0
- package/data/examples/alternate-pagination.js +17 -0
- package/data/examples/basic.js +86 -0
- package/data/examples/chart-detail-panel.js +69 -0
- package/data/examples/column-actions-space.js +34 -0
- package/data/examples/column-alignment.js +58 -0
- package/data/examples/custom-column-actions.js +74 -0
- package/data/examples/custom-column-filtering-ui.js +59 -0
- package/data/examples/custom-headless.js +85 -0
- package/data/examples/custom-top-toolbar.js +60 -0
- package/data/examples/customize-display-columns.js +72 -0
- package/data/examples/customize-filter-components.js +78 -0
- package/data/examples/customize-filter-modes.js +59 -0
- package/data/examples/customize-filter-variants.js +98 -0
- package/data/examples/customize-global-filter-component.js +37 -0
- package/data/examples/customize-remove-column-grouping.js +75 -0
- package/data/examples/customize-row-selection.js +43 -0
- package/data/examples/customize-table-styles.js +81 -0
- package/data/examples/disable-column-actions.js +26 -0
- package/data/examples/disable-column-hiding.js +74 -0
- package/data/examples/disable-density-toggle.js +37 -0
- package/data/examples/dynamic-columns.js +124 -0
- package/data/examples/editing-crud-cell.js +288 -0
- package/data/examples/editing-crud-modal.js +275 -0
- package/data/examples/editing-crud-row.js +255 -0
- package/data/examples/editing-crud-table.js +280 -0
- package/data/examples/editing-crud-tree.js +328 -0
- package/data/examples/enable-cell-actions.js +52 -0
- package/data/examples/enable-click-to-copy.js +33 -0
- package/data/examples/enable-column-grouping.js +69 -0
- package/data/examples/enable-column-ordering.js +37 -0
- package/data/examples/enable-column-pinning.js +58 -0
- package/data/examples/enable-column-resizing.js +45 -0
- package/data/examples/enable-column-virtualization.js +19 -0
- package/data/examples/enable-detail-panel-conditionally.js +61 -0
- package/data/examples/enable-detail-panel-virtualized.js +64 -0
- package/data/examples/enable-expanding-tree.js +87 -0
- package/data/examples/enable-filter-facet-values.js +52 -0
- package/data/examples/enable-row-dragging.js +102 -0
- package/data/examples/enable-row-numbers-original.js +37 -0
- package/data/examples/enable-row-numbers-static.js +37 -0
- package/data/examples/enable-row-ordering.js +40 -0
- package/data/examples/enable-row-pinning-select.js +64 -0
- package/data/examples/enable-row-pinning-static.js +39 -0
- package/data/examples/enable-row-pinning-sticky.js +57 -0
- package/data/examples/enable-row-selection.js +71 -0
- package/data/examples/enable-row-virtualization.js +85 -0
- package/data/examples/enable-sticky-header.js +47 -0
- package/data/examples/expanding-tree-expanded.js +98 -0
- package/data/examples/expanding-tree-flat-parse.js +102 -0
- package/data/examples/expanding-tree-root-expanded.js +120 -0
- package/data/examples/export-to-csv.js +84 -0
- package/data/examples/export-to-pdf.js +76 -0
- package/data/examples/external-toolbar.js +82 -0
- package/data/examples/font-awesome-icons.js +62 -0
- package/data/examples/infinite-scrolling.js +137 -0
- package/data/examples/lazy-detail-panel.js +164 -0
- package/data/examples/lazy-sub-rows.js +118 -0
- package/data/examples/linear-progress.js +48 -0
- package/data/examples/loading.js +34 -0
- package/data/examples/localization-i18n-ar.js +40 -0
- package/data/examples/localization-i18n-az.js +38 -0
- package/data/examples/localization-i18n-bg.js +38 -0
- package/data/examples/localization-i18n-cs.js +38 -0
- package/data/examples/localization-i18n-da.js +38 -0
- package/data/examples/localization-i18n-de.js +38 -0
- package/data/examples/localization-i18n-el.js +38 -0
- package/data/examples/localization-i18n-en.js +38 -0
- package/data/examples/localization-i18n-es.js +38 -0
- package/data/examples/localization-i18n-et.js +38 -0
- package/data/examples/localization-i18n-fa.js +40 -0
- package/data/examples/localization-i18n-fi.js +38 -0
- package/data/examples/localization-i18n-fr.js +38 -0
- package/data/examples/localization-i18n-he.js +40 -0
- package/data/examples/localization-i18n-hr.js +38 -0
- package/data/examples/localization-i18n-hu.js +38 -0
- package/data/examples/localization-i18n-hy.js +40 -0
- package/data/examples/localization-i18n-id.js +38 -0
- package/data/examples/localization-i18n-it.js +38 -0
- package/data/examples/localization-i18n-ja.js +38 -0
- package/data/examples/localization-i18n-ko.js +38 -0
- package/data/examples/localization-i18n-nl.js +38 -0
- package/data/examples/localization-i18n-no.js +38 -0
- package/data/examples/localization-i18n-np.js +38 -0
- package/data/examples/localization-i18n-pl.js +38 -0
- package/data/examples/localization-i18n-pt-BR.js +38 -0
- package/data/examples/localization-i18n-pt.js +38 -0
- package/data/examples/localization-i18n-ro.js +38 -0
- package/data/examples/localization-i18n-ru.js +38 -0
- package/data/examples/localization-i18n-sk.js +38 -0
- package/data/examples/localization-i18n-sr-Cyrl-RS.js +38 -0
- package/data/examples/localization-i18n-sr-Latn-RS.js +38 -0
- package/data/examples/localization-i18n-sv.js +38 -0
- package/data/examples/localization-i18n-tr.js +38 -0
- package/data/examples/localization-i18n-uk.js +38 -0
- package/data/examples/localization-i18n-vi.js +38 -0
- package/data/examples/localization-i18n-zh-hans.js +38 -0
- package/data/examples/localization-i18n-zh-hant.js +38 -0
- package/data/examples/manual-selection.js +81 -0
- package/data/examples/minimal.js +66 -0
- package/data/examples/mui-theme.js +109 -0
- package/data/examples/multi-sorting.js +48 -0
- package/data/examples/persistent-state.js +126 -0
- package/data/examples/react-query.js +122 -0
- package/data/examples/remote.js +113 -0
- package/data/examples/row-actions-buttons.js +54 -0
- package/data/examples/row-actions-menu-items.js +36 -0
- package/data/examples/single-row-selection.js +74 -0
- package/data/examples/virtualized.js +122 -0
- package/dist/data.js +31 -9
- package/dist/index.js +18 -6
- package/package.json +1 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { MaterialReactTable, useMaterialReactTable, } from 'material-react-table';
|
|
3
|
+
//end
|
|
4
|
+
const data = [
|
|
5
|
+
{
|
|
6
|
+
userId: '3f25309c-8fa1-470f-811e-cdb082ab9017', //we'll use this as a unique row id
|
|
7
|
+
firstName: 'Dylan',
|
|
8
|
+
lastName: 'Murray',
|
|
9
|
+
age: 22,
|
|
10
|
+
address: '261 Erdman Ford',
|
|
11
|
+
city: 'East Daphne',
|
|
12
|
+
state: 'Kentucky',
|
|
13
|
+
}, //data definitions...
|
|
14
|
+
{
|
|
15
|
+
userId: 'be731030-df83-419c-b3d6-9ef04e7f4a9f',
|
|
16
|
+
firstName: 'Raquel',
|
|
17
|
+
lastName: 'Kohler',
|
|
18
|
+
age: 18,
|
|
19
|
+
address: '769 Dominic Grove',
|
|
20
|
+
city: 'Columbus',
|
|
21
|
+
state: 'Ohio',
|
|
22
|
+
},
|
|
23
|
+
//end
|
|
24
|
+
];
|
|
25
|
+
const Example = () => {
|
|
26
|
+
const columns = useMemo(
|
|
27
|
+
//column definitions...
|
|
28
|
+
() => [
|
|
29
|
+
{
|
|
30
|
+
accessorKey: 'firstName',
|
|
31
|
+
header: 'First Name',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
accessorKey: 'lastName',
|
|
35
|
+
header: 'Last Name',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
accessorKey: 'age',
|
|
39
|
+
header: 'Age',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
accessorKey: 'address',
|
|
43
|
+
header: 'Address',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
accessorKey: 'city',
|
|
47
|
+
header: 'City',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
accessorKey: 'state',
|
|
51
|
+
header: 'State',
|
|
52
|
+
},
|
|
53
|
+
], []);
|
|
54
|
+
//optionally, you can manage the row selection state yourself
|
|
55
|
+
const [rowSelection, setRowSelection] = useState({});
|
|
56
|
+
const table = useMaterialReactTable({
|
|
57
|
+
columns,
|
|
58
|
+
data,
|
|
59
|
+
enableRowSelection: true,
|
|
60
|
+
getRowId: (row) => row.userId, //give each row a more useful id
|
|
61
|
+
onRowSelectionChange: setRowSelection, //connect internal row selection state to your own
|
|
62
|
+
state: { rowSelection }, //pass our managed row selection state to the table to use
|
|
63
|
+
});
|
|
64
|
+
//do something when the row selection changes...
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
console.info({ rowSelection }); //read your managed row selection state
|
|
67
|
+
// console.info(table.getState().rowSelection); //alternate way to get the row selection state
|
|
68
|
+
}, [rowSelection]);
|
|
69
|
+
return <MaterialReactTable table={table}/>;
|
|
70
|
+
};
|
|
71
|
+
export default Example;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { MaterialReactTable, useMaterialReactTable, } from 'material-react-table';
|
|
3
|
+
import { makeData } from './makeData';
|
|
4
|
+
const Example = () => {
|
|
5
|
+
const columns = useMemo(
|
|
6
|
+
//column definitions...
|
|
7
|
+
() => [
|
|
8
|
+
{
|
|
9
|
+
accessorKey: 'firstName',
|
|
10
|
+
header: 'First Name',
|
|
11
|
+
size: 150,
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
accessorKey: 'middleName',
|
|
15
|
+
header: 'Middle Name',
|
|
16
|
+
size: 150,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
accessorKey: 'lastName',
|
|
20
|
+
header: 'Last Name',
|
|
21
|
+
size: 150,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
accessorKey: 'email',
|
|
25
|
+
header: 'Email Address',
|
|
26
|
+
size: 300,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
accessorKey: 'address',
|
|
30
|
+
header: 'Address',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
accessorKey: 'zipCode',
|
|
34
|
+
header: 'Zip Code',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
accessorKey: 'city',
|
|
38
|
+
header: 'City',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
accessorKey: 'state',
|
|
42
|
+
header: 'State',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
accessorKey: 'country',
|
|
46
|
+
header: 'Country',
|
|
47
|
+
},
|
|
48
|
+
], []);
|
|
49
|
+
//optionally access the underlying virtualizer instance
|
|
50
|
+
const rowVirtualizerInstanceRef = useRef(null);
|
|
51
|
+
const [data, setData] = useState([]);
|
|
52
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
53
|
+
const [sorting, setSorting] = useState([]);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (typeof window !== 'undefined') {
|
|
56
|
+
setData(makeData(10000));
|
|
57
|
+
setIsLoading(false);
|
|
58
|
+
}
|
|
59
|
+
}, []);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
//scroll to the top of the table when the sorting changes
|
|
62
|
+
try {
|
|
63
|
+
rowVirtualizerInstanceRef.current?.scrollToIndex?.(0);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.error(error);
|
|
67
|
+
}
|
|
68
|
+
}, [sorting]);
|
|
69
|
+
const table = useMaterialReactTable({
|
|
70
|
+
columns,
|
|
71
|
+
data, //10,000 rows
|
|
72
|
+
enableBottomToolbar: false,
|
|
73
|
+
enableGlobalFilterModes: true,
|
|
74
|
+
enablePagination: false,
|
|
75
|
+
enableRowNumbers: true,
|
|
76
|
+
enableRowVirtualization: true,
|
|
77
|
+
muiTableContainerProps: { sx: { maxHeight: '600px' } },
|
|
78
|
+
onSortingChange: setSorting,
|
|
79
|
+
state: { isLoading, sorting },
|
|
80
|
+
rowVirtualizerInstanceRef, //optional
|
|
81
|
+
rowVirtualizerOptions: { overscan: 5 }, //optionally customize the row virtualizer
|
|
82
|
+
});
|
|
83
|
+
return <MaterialReactTable table={table}/>;
|
|
84
|
+
};
|
|
85
|
+
export default Example;
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
//column definitions...
|
|
7
|
+
() => [
|
|
8
|
+
{
|
|
9
|
+
accessorKey: 'firstName',
|
|
10
|
+
header: 'First Name',
|
|
11
|
+
footer: 'First Name',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
accessorKey: 'lastName',
|
|
15
|
+
header: 'Last Name',
|
|
16
|
+
footer: 'Last Name',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
accessorKey: 'email',
|
|
20
|
+
header: 'Email',
|
|
21
|
+
footer: 'Email',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
accessorKey: 'city',
|
|
25
|
+
header: 'City',
|
|
26
|
+
footer: 'City',
|
|
27
|
+
},
|
|
28
|
+
], []);
|
|
29
|
+
const table = useMaterialReactTable({
|
|
30
|
+
columns,
|
|
31
|
+
data,
|
|
32
|
+
enableBottomToolbar: false,
|
|
33
|
+
enableStickyHeader: true,
|
|
34
|
+
enableStickyFooter: true,
|
|
35
|
+
enablePagination: false,
|
|
36
|
+
muiTableContainerProps: { sx: { maxHeight: '400px' } },
|
|
37
|
+
muiTableBodyCellProps: {
|
|
38
|
+
sx: (theme) => ({
|
|
39
|
+
backgroundColor: theme.palette.mode === 'dark'
|
|
40
|
+
? theme.palette.grey[900]
|
|
41
|
+
: theme.palette.grey[50],
|
|
42
|
+
}),
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
return <MaterialReactTable table={table}/>;
|
|
46
|
+
};
|
|
47
|
+
export default Example;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { MaterialReactTable, useMaterialReactTable, } from 'material-react-table';
|
|
3
|
+
export const data = [
|
|
4
|
+
{
|
|
5
|
+
firstName: 'Dylan',
|
|
6
|
+
lastName: 'Murray',
|
|
7
|
+
address: '261 Erdman Ford',
|
|
8
|
+
city: 'East Daphne',
|
|
9
|
+
state: 'Kentucky',
|
|
10
|
+
subRows: [
|
|
11
|
+
{
|
|
12
|
+
firstName: 'Ervin',
|
|
13
|
+
lastName: 'Reinger',
|
|
14
|
+
address: '566 Brakus Inlet',
|
|
15
|
+
city: 'South Linda',
|
|
16
|
+
state: 'West Virginia',
|
|
17
|
+
subRows: [
|
|
18
|
+
{
|
|
19
|
+
firstName: 'Jordane',
|
|
20
|
+
lastName: 'Homenick',
|
|
21
|
+
address: '1234 Brakus Inlet',
|
|
22
|
+
city: 'South Linda',
|
|
23
|
+
state: 'West Virginia',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
firstName: 'Jordan',
|
|
27
|
+
lastName: 'Clarkson',
|
|
28
|
+
address: '4882 Palm Rd',
|
|
29
|
+
city: 'San Francisco',
|
|
30
|
+
state: 'California',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
firstName: 'Brittany',
|
|
36
|
+
lastName: 'McCullough',
|
|
37
|
+
address: '722 Emie Stream',
|
|
38
|
+
city: 'Lincoln',
|
|
39
|
+
state: 'Nebraska',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
firstName: 'Raquel',
|
|
45
|
+
lastName: 'Kohler',
|
|
46
|
+
address: '769 Dominic Grove',
|
|
47
|
+
city: 'Columbus',
|
|
48
|
+
state: 'Ohio',
|
|
49
|
+
subRows: [
|
|
50
|
+
{
|
|
51
|
+
firstName: 'Branson',
|
|
52
|
+
lastName: 'Frami',
|
|
53
|
+
address: '32188 Larkin Turnpike',
|
|
54
|
+
city: 'Charleston',
|
|
55
|
+
state: 'South Carolina',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
const Example = () => {
|
|
61
|
+
const columns = useMemo(
|
|
62
|
+
//column definitions...
|
|
63
|
+
() => [
|
|
64
|
+
{
|
|
65
|
+
accessorKey: 'firstName',
|
|
66
|
+
header: 'First Name',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
accessorKey: 'lastName',
|
|
70
|
+
header: 'Last Name',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
accessorKey: 'address',
|
|
74
|
+
header: 'Address',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
accessorKey: 'city',
|
|
78
|
+
header: 'City',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
accessorKey: 'state',
|
|
82
|
+
enableColumnOrdering: false,
|
|
83
|
+
header: 'State',
|
|
84
|
+
},
|
|
85
|
+
], []);
|
|
86
|
+
const table = useMaterialReactTable({
|
|
87
|
+
columns,
|
|
88
|
+
data,
|
|
89
|
+
enableExpandAll: false, //hide expand all double arrow in column header
|
|
90
|
+
enableExpanding: true,
|
|
91
|
+
filterFromLeafRows: true, //apply filtering to all rows instead of just parent rows
|
|
92
|
+
getSubRows: (row) => row.subRows, //default
|
|
93
|
+
initialState: { expanded: true }, //expand all rows by default
|
|
94
|
+
paginateExpandedRows: false, //When rows are expanded, do not count sub-rows as number of rows on the page towards pagination
|
|
95
|
+
});
|
|
96
|
+
return <MaterialReactTable table={table}/>;
|
|
97
|
+
};
|
|
98
|
+
export default Example;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { MaterialReactTable, useMaterialReactTable, } from 'material-react-table';
|
|
3
|
+
//flat data that TanStack Table's getSubRows() function will parse into a tree
|
|
4
|
+
export const data = [
|
|
5
|
+
{
|
|
6
|
+
id: '9s41rp',
|
|
7
|
+
firstName: 'Kelvin',
|
|
8
|
+
lastName: 'Langosh',
|
|
9
|
+
email: 'Jerod14@hotmail.com',
|
|
10
|
+
state: 'Ohio',
|
|
11
|
+
managerId: '08m6rx',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
id: '08m6rx',
|
|
15
|
+
firstName: 'Molly',
|
|
16
|
+
lastName: 'Purdy',
|
|
17
|
+
email: 'Hugh.Dach79@hotmail.com',
|
|
18
|
+
state: 'Rhode Island',
|
|
19
|
+
managerId: '5ymtrc',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: '5ymtrc',
|
|
23
|
+
firstName: 'Henry',
|
|
24
|
+
lastName: 'Lynch',
|
|
25
|
+
email: 'Camden.Macejkovic@yahoo.com',
|
|
26
|
+
state: 'California',
|
|
27
|
+
managerId: null, //top of a tree
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: 'ek5b97',
|
|
31
|
+
firstName: 'Glenda',
|
|
32
|
+
lastName: 'Douglas',
|
|
33
|
+
email: 'Eric0@yahoo.com',
|
|
34
|
+
state: 'Montana',
|
|
35
|
+
managerId: '08m6rx',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: 'xxtydd',
|
|
39
|
+
firstName: 'Leone',
|
|
40
|
+
lastName: 'Williamson',
|
|
41
|
+
email: 'Ericka_Mueller52@yahoo.com',
|
|
42
|
+
state: 'Colorado',
|
|
43
|
+
managerId: '08m6rx',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: 'wzxj9m',
|
|
47
|
+
firstName: 'Mckenna',
|
|
48
|
+
lastName: 'Friesen',
|
|
49
|
+
email: 'Veda_Feeney@yahoo.com',
|
|
50
|
+
state: 'New York',
|
|
51
|
+
managerId: null, //top of a tree
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: '21dwtz',
|
|
55
|
+
firstName: 'Wyman',
|
|
56
|
+
lastName: 'Jast',
|
|
57
|
+
email: 'Melvin.Pacocha@yahoo.com',
|
|
58
|
+
state: 'Montana',
|
|
59
|
+
managerId: 'wzxj9m',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: 'o8oe4k',
|
|
63
|
+
firstName: 'Janick',
|
|
64
|
+
lastName: 'Willms',
|
|
65
|
+
email: 'Delfina12@gmail.com',
|
|
66
|
+
state: 'Nebraska',
|
|
67
|
+
managerId: 'wzxj9m',
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
const Example = () => {
|
|
71
|
+
const columns = useMemo(
|
|
72
|
+
//column definitions...
|
|
73
|
+
() => [
|
|
74
|
+
{
|
|
75
|
+
accessorKey: 'firstName',
|
|
76
|
+
header: 'First Name',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
accessorKey: 'lastName',
|
|
80
|
+
header: 'Last Name',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
accessorKey: 'email',
|
|
84
|
+
header: 'Email',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
accessorKey: 'state',
|
|
88
|
+
header: 'State',
|
|
89
|
+
},
|
|
90
|
+
], []);
|
|
91
|
+
//only root rows with no managerId
|
|
92
|
+
const rootData = useMemo(() => data.filter((r) => !r.managerId), [data]);
|
|
93
|
+
const table = useMaterialReactTable({
|
|
94
|
+
columns,
|
|
95
|
+
data: rootData,
|
|
96
|
+
enableExpanding: true,
|
|
97
|
+
//note: performance of this example should be improved with hash maps. This is currently 0(n^2)
|
|
98
|
+
getSubRows: (row) => data.filter((r) => r.managerId === row.id),
|
|
99
|
+
});
|
|
100
|
+
return <MaterialReactTable table={table}/>;
|
|
101
|
+
};
|
|
102
|
+
export default Example;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { MaterialReactTable, useMaterialReactTable, } from 'material-react-table';
|
|
3
|
+
import { Button } from '@mui/material';
|
|
4
|
+
//data definitions...
|
|
5
|
+
export const data = [
|
|
6
|
+
{
|
|
7
|
+
id: '1',
|
|
8
|
+
firstName: 'Dylan',
|
|
9
|
+
lastName: 'Murray',
|
|
10
|
+
address: '261 Erdman Ford',
|
|
11
|
+
city: 'East Daphne',
|
|
12
|
+
state: 'Kentucky',
|
|
13
|
+
subRows: [
|
|
14
|
+
{
|
|
15
|
+
id: '2',
|
|
16
|
+
firstName: 'Ervin',
|
|
17
|
+
lastName: 'Reinger',
|
|
18
|
+
address: '566 Brakus Inlet',
|
|
19
|
+
city: 'South Linda',
|
|
20
|
+
state: 'West Virginia',
|
|
21
|
+
subRows: [
|
|
22
|
+
{
|
|
23
|
+
id: '3',
|
|
24
|
+
firstName: 'Jordane',
|
|
25
|
+
lastName: 'Homenick',
|
|
26
|
+
address: '1234 Brakus Inlet',
|
|
27
|
+
city: 'South Linda',
|
|
28
|
+
state: 'West Virginia',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: '4',
|
|
32
|
+
firstName: 'Jordan',
|
|
33
|
+
lastName: 'Clarkson',
|
|
34
|
+
address: '4882 Palm Rd',
|
|
35
|
+
city: 'San Francisco',
|
|
36
|
+
state: 'California',
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: '5',
|
|
42
|
+
firstName: 'Brittany',
|
|
43
|
+
lastName: 'McCullough',
|
|
44
|
+
address: '722 Emie Stream',
|
|
45
|
+
city: 'Lincoln',
|
|
46
|
+
state: 'Nebraska',
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: '6',
|
|
52
|
+
firstName: 'Raquel',
|
|
53
|
+
lastName: 'Kohler',
|
|
54
|
+
address: '769 Dominic Grove',
|
|
55
|
+
city: 'Columbus',
|
|
56
|
+
state: 'Ohio',
|
|
57
|
+
subRows: [
|
|
58
|
+
{
|
|
59
|
+
id: '7',
|
|
60
|
+
firstName: 'Branson',
|
|
61
|
+
lastName: 'Frami',
|
|
62
|
+
address: '32188 Larkin Turnpike',
|
|
63
|
+
city: 'Charleston',
|
|
64
|
+
state: 'South Carolina',
|
|
65
|
+
subRows: [
|
|
66
|
+
{
|
|
67
|
+
id: '8',
|
|
68
|
+
firstName: 'Henry',
|
|
69
|
+
lastName: 'Ford',
|
|
70
|
+
address: '1234 Brakus Inlet',
|
|
71
|
+
city: 'Nashville',
|
|
72
|
+
state: 'Tennessee',
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
//end
|
|
80
|
+
const Example = () => {
|
|
81
|
+
const columns = useMemo(
|
|
82
|
+
//column definitions...
|
|
83
|
+
() => [
|
|
84
|
+
{
|
|
85
|
+
accessorKey: 'firstName',
|
|
86
|
+
header: 'First Name',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
accessorKey: 'lastName',
|
|
90
|
+
header: 'Last Name',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
accessorKey: 'address',
|
|
94
|
+
header: 'Address',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
accessorKey: 'city',
|
|
98
|
+
header: 'City',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
accessorKey: 'state',
|
|
102
|
+
enableColumnOrdering: false,
|
|
103
|
+
header: 'State',
|
|
104
|
+
},
|
|
105
|
+
], []);
|
|
106
|
+
const initialExpandedRootRows = useMemo(() => data
|
|
107
|
+
.map((originalRow) => originalRow.id) //get all the root row ids, use recursion for additional levels
|
|
108
|
+
.reduce((a, v) => ({ ...a, [v]: true }), {}), //convert to an object with all the ids as keys and `true` as values
|
|
109
|
+
[]);
|
|
110
|
+
const table = useMaterialReactTable({
|
|
111
|
+
columns,
|
|
112
|
+
data,
|
|
113
|
+
enableExpanding: true,
|
|
114
|
+
getRowId: (originalRow) => originalRow.id,
|
|
115
|
+
initialState: { expanded: initialExpandedRootRows }, //only expand the root rows by default
|
|
116
|
+
renderTopToolbarCustomActions: ({ table }) => (<Button onClick={() => table.resetExpanded()}>Reset Expanded</Button>),
|
|
117
|
+
});
|
|
118
|
+
return <MaterialReactTable table={table}/>;
|
|
119
|
+
};
|
|
120
|
+
export default Example;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { MaterialReactTable, useMaterialReactTable, createMRTColumnHelper, } from 'material-react-table';
|
|
2
|
+
import { Box, Button } from '@mui/material';
|
|
3
|
+
import FileDownloadIcon from '@mui/icons-material/FileDownload';
|
|
4
|
+
import { mkConfig, generateCsv, download } from 'export-to-csv'; //or use your library of choice here
|
|
5
|
+
import { data } from './makeData';
|
|
6
|
+
const columnHelper = createMRTColumnHelper();
|
|
7
|
+
const columns = [
|
|
8
|
+
columnHelper.accessor('id', {
|
|
9
|
+
header: 'ID',
|
|
10
|
+
size: 40,
|
|
11
|
+
}),
|
|
12
|
+
columnHelper.accessor('firstName', {
|
|
13
|
+
header: 'First Name',
|
|
14
|
+
size: 120,
|
|
15
|
+
}),
|
|
16
|
+
columnHelper.accessor('lastName', {
|
|
17
|
+
header: 'Last Name',
|
|
18
|
+
size: 120,
|
|
19
|
+
}),
|
|
20
|
+
columnHelper.accessor('company', {
|
|
21
|
+
header: 'Company',
|
|
22
|
+
size: 300,
|
|
23
|
+
}),
|
|
24
|
+
columnHelper.accessor('city', {
|
|
25
|
+
header: 'City',
|
|
26
|
+
}),
|
|
27
|
+
columnHelper.accessor('country', {
|
|
28
|
+
header: 'Country',
|
|
29
|
+
size: 220,
|
|
30
|
+
}),
|
|
31
|
+
];
|
|
32
|
+
const csvConfig = mkConfig({
|
|
33
|
+
fieldSeparator: ',',
|
|
34
|
+
decimalSeparator: '.',
|
|
35
|
+
useKeysAsHeaders: true,
|
|
36
|
+
});
|
|
37
|
+
const Example = () => {
|
|
38
|
+
const handleExportRows = (rows) => {
|
|
39
|
+
const rowData = rows.map((row) => row.original);
|
|
40
|
+
const csv = generateCsv(csvConfig)(rowData);
|
|
41
|
+
download(csvConfig)(csv);
|
|
42
|
+
};
|
|
43
|
+
const handleExportData = () => {
|
|
44
|
+
const csv = generateCsv(csvConfig)(data);
|
|
45
|
+
download(csvConfig)(csv);
|
|
46
|
+
};
|
|
47
|
+
const table = useMaterialReactTable({
|
|
48
|
+
columns,
|
|
49
|
+
data,
|
|
50
|
+
enableRowSelection: true,
|
|
51
|
+
columnFilterDisplayMode: 'popover',
|
|
52
|
+
paginationDisplayMode: 'pages',
|
|
53
|
+
positionToolbarAlertBanner: 'bottom',
|
|
54
|
+
renderTopToolbarCustomActions: ({ table }) => (<Box sx={{
|
|
55
|
+
display: 'flex',
|
|
56
|
+
gap: '16px',
|
|
57
|
+
padding: '8px',
|
|
58
|
+
flexWrap: 'wrap',
|
|
59
|
+
}}>
|
|
60
|
+
<Button
|
|
61
|
+
//export all data that is currently in the table (ignore pagination, sorting, filtering, etc.)
|
|
62
|
+
onClick={handleExportData} startIcon={<FileDownloadIcon />}>
|
|
63
|
+
Export All Data
|
|
64
|
+
</Button>
|
|
65
|
+
<Button disabled={table.getPrePaginatedRowModel().rows.length === 0}
|
|
66
|
+
//export all rows, including from the next page, (still respects filtering and sorting)
|
|
67
|
+
onClick={() => handleExportRows(table.getPrePaginatedRowModel().rows)} startIcon={<FileDownloadIcon />}>
|
|
68
|
+
Export All Rows
|
|
69
|
+
</Button>
|
|
70
|
+
<Button disabled={table.getRowModel().rows.length === 0}
|
|
71
|
+
//export all rows as seen on the screen (respects pagination, sorting, filtering, etc.)
|
|
72
|
+
onClick={() => handleExportRows(table.getRowModel().rows)} startIcon={<FileDownloadIcon />}>
|
|
73
|
+
Export Page Rows
|
|
74
|
+
</Button>
|
|
75
|
+
<Button disabled={!table.getIsSomeRowsSelected() && !table.getIsAllRowsSelected()}
|
|
76
|
+
//only export selected rows
|
|
77
|
+
onClick={() => handleExportRows(table.getSelectedRowModel().rows)} startIcon={<FileDownloadIcon />}>
|
|
78
|
+
Export Selected Rows
|
|
79
|
+
</Button>
|
|
80
|
+
</Box>),
|
|
81
|
+
});
|
|
82
|
+
return <MaterialReactTable table={table}/>;
|
|
83
|
+
};
|
|
84
|
+
export default Example;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { MaterialReactTable, useMaterialReactTable, createMRTColumnHelper, } from 'material-react-table';
|
|
2
|
+
import { Box, Button } from '@mui/material';
|
|
3
|
+
import FileDownloadIcon from '@mui/icons-material/FileDownload';
|
|
4
|
+
import { jsPDF } from 'jspdf'; //or use your library of choice here
|
|
5
|
+
import autoTable from 'jspdf-autotable';
|
|
6
|
+
import { data } from './makeData';
|
|
7
|
+
const columnHelper = createMRTColumnHelper();
|
|
8
|
+
const columns = [
|
|
9
|
+
columnHelper.accessor('id', {
|
|
10
|
+
header: 'ID',
|
|
11
|
+
size: 40,
|
|
12
|
+
}),
|
|
13
|
+
columnHelper.accessor('firstName', {
|
|
14
|
+
header: 'First Name',
|
|
15
|
+
size: 120,
|
|
16
|
+
}),
|
|
17
|
+
columnHelper.accessor('lastName', {
|
|
18
|
+
header: 'Last Name',
|
|
19
|
+
size: 120,
|
|
20
|
+
}),
|
|
21
|
+
columnHelper.accessor('company', {
|
|
22
|
+
header: 'Company',
|
|
23
|
+
size: 300,
|
|
24
|
+
}),
|
|
25
|
+
columnHelper.accessor('city', {
|
|
26
|
+
header: 'City',
|
|
27
|
+
}),
|
|
28
|
+
columnHelper.accessor('country', {
|
|
29
|
+
header: 'Country',
|
|
30
|
+
size: 220,
|
|
31
|
+
}),
|
|
32
|
+
];
|
|
33
|
+
const Example = () => {
|
|
34
|
+
const handleExportRows = (rows) => {
|
|
35
|
+
const doc = new jsPDF();
|
|
36
|
+
const tableData = rows.map((row) => Object.values(row.original));
|
|
37
|
+
const tableHeaders = columns.map((c) => c.header);
|
|
38
|
+
autoTable(doc, {
|
|
39
|
+
head: [tableHeaders],
|
|
40
|
+
body: tableData,
|
|
41
|
+
});
|
|
42
|
+
doc.save('mrt-pdf-example.pdf');
|
|
43
|
+
};
|
|
44
|
+
const table = useMaterialReactTable({
|
|
45
|
+
columns,
|
|
46
|
+
data,
|
|
47
|
+
enableRowSelection: true,
|
|
48
|
+
columnFilterDisplayMode: 'popover',
|
|
49
|
+
paginationDisplayMode: 'pages',
|
|
50
|
+
positionToolbarAlertBanner: 'bottom',
|
|
51
|
+
renderTopToolbarCustomActions: ({ table }) => (<Box sx={{
|
|
52
|
+
display: 'flex',
|
|
53
|
+
gap: '16px',
|
|
54
|
+
padding: '8px',
|
|
55
|
+
flexWrap: 'wrap',
|
|
56
|
+
}}>
|
|
57
|
+
<Button disabled={table.getPrePaginatedRowModel().rows.length === 0}
|
|
58
|
+
//export all rows, including from the next page, (still respects filtering and sorting)
|
|
59
|
+
onClick={() => handleExportRows(table.getPrePaginatedRowModel().rows)} startIcon={<FileDownloadIcon />}>
|
|
60
|
+
Export All Rows
|
|
61
|
+
</Button>
|
|
62
|
+
<Button disabled={table.getRowModel().rows.length === 0}
|
|
63
|
+
//export all rows as seen on the screen (respects pagination, sorting, filtering, etc.)
|
|
64
|
+
onClick={() => handleExportRows(table.getRowModel().rows)} startIcon={<FileDownloadIcon />}>
|
|
65
|
+
Export Page Rows
|
|
66
|
+
</Button>
|
|
67
|
+
<Button disabled={!table.getIsSomeRowsSelected() && !table.getIsAllRowsSelected()}
|
|
68
|
+
//only export selected rows
|
|
69
|
+
onClick={() => handleExportRows(table.getSelectedRowModel().rows)} startIcon={<FileDownloadIcon />}>
|
|
70
|
+
Export Selected Rows
|
|
71
|
+
</Button>
|
|
72
|
+
</Box>),
|
|
73
|
+
});
|
|
74
|
+
return <MaterialReactTable table={table}/>;
|
|
75
|
+
};
|
|
76
|
+
export default Example;
|