@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,125 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MaterialReactTable,
|
|
4
|
+
useMaterialReactTable,
|
|
5
|
+
type MRT_ColumnDef,
|
|
6
|
+
} from 'material-react-table';
|
|
7
|
+
|
|
8
|
+
export type Employee = {
|
|
9
|
+
id: string;
|
|
10
|
+
firstName: string;
|
|
11
|
+
lastName: string;
|
|
12
|
+
email: string;
|
|
13
|
+
state: string;
|
|
14
|
+
managerId: string | null;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//flat data that TanStack Table's getSubRows() function will parse into a tree
|
|
18
|
+
export const data: Employee[] = [
|
|
19
|
+
{
|
|
20
|
+
id: '9s41rp',
|
|
21
|
+
firstName: 'Kelvin',
|
|
22
|
+
lastName: 'Langosh',
|
|
23
|
+
email: 'Jerod14@hotmail.com',
|
|
24
|
+
state: 'Ohio',
|
|
25
|
+
managerId: '08m6rx',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: '08m6rx',
|
|
29
|
+
firstName: 'Molly',
|
|
30
|
+
lastName: 'Purdy',
|
|
31
|
+
email: 'Hugh.Dach79@hotmail.com',
|
|
32
|
+
state: 'Rhode Island',
|
|
33
|
+
managerId: '5ymtrc',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: '5ymtrc',
|
|
37
|
+
firstName: 'Henry',
|
|
38
|
+
lastName: 'Lynch',
|
|
39
|
+
email: 'Camden.Macejkovic@yahoo.com',
|
|
40
|
+
state: 'California',
|
|
41
|
+
managerId: null, //top of a tree
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: 'ek5b97',
|
|
45
|
+
firstName: 'Glenda',
|
|
46
|
+
lastName: 'Douglas',
|
|
47
|
+
email: 'Eric0@yahoo.com',
|
|
48
|
+
state: 'Montana',
|
|
49
|
+
managerId: '08m6rx',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: 'xxtydd',
|
|
53
|
+
firstName: 'Leone',
|
|
54
|
+
lastName: 'Williamson',
|
|
55
|
+
email: 'Ericka_Mueller52@yahoo.com',
|
|
56
|
+
state: 'Colorado',
|
|
57
|
+
managerId: '08m6rx',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: 'wzxj9m',
|
|
61
|
+
firstName: 'Mckenna',
|
|
62
|
+
lastName: 'Friesen',
|
|
63
|
+
email: 'Veda_Feeney@yahoo.com',
|
|
64
|
+
state: 'New York',
|
|
65
|
+
managerId: null, //top of a tree
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
id: '21dwtz',
|
|
69
|
+
firstName: 'Wyman',
|
|
70
|
+
lastName: 'Jast',
|
|
71
|
+
email: 'Melvin.Pacocha@yahoo.com',
|
|
72
|
+
state: 'Montana',
|
|
73
|
+
managerId: 'wzxj9m',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: 'o8oe4k',
|
|
77
|
+
firstName: 'Janick',
|
|
78
|
+
lastName: 'Willms',
|
|
79
|
+
email: 'Delfina12@gmail.com',
|
|
80
|
+
state: 'Nebraska',
|
|
81
|
+
managerId: 'wzxj9m',
|
|
82
|
+
},
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
const Example = () => {
|
|
86
|
+
const columns = useMemo<MRT_ColumnDef<Employee>[]>(
|
|
87
|
+
//column definitions...
|
|
88
|
+
() => [
|
|
89
|
+
{
|
|
90
|
+
accessorKey: 'firstName',
|
|
91
|
+
header: 'First Name',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
accessorKey: 'lastName',
|
|
95
|
+
header: 'Last Name',
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
{
|
|
99
|
+
accessorKey: 'email',
|
|
100
|
+
header: 'Email',
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
accessorKey: 'state',
|
|
104
|
+
header: 'State',
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
[],
|
|
108
|
+
//end
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
//only root rows with no managerId
|
|
112
|
+
const rootData = useMemo(() => data.filter((r) => !r.managerId), [data]);
|
|
113
|
+
|
|
114
|
+
const table = useMaterialReactTable({
|
|
115
|
+
columns,
|
|
116
|
+
data: rootData,
|
|
117
|
+
enableExpanding: true,
|
|
118
|
+
//note: performance of this example should be improved with hash maps. This is currently 0(n^2)
|
|
119
|
+
getSubRows: (row) => data.filter((r) => r.managerId === row.id),
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
return <MaterialReactTable table={table} />;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export default Example;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MaterialReactTable,
|
|
4
|
+
type MRT_ExpandedState,
|
|
5
|
+
type MRT_ColumnDef,
|
|
6
|
+
useMaterialReactTable,
|
|
7
|
+
} from 'material-react-table';
|
|
8
|
+
import { Button } from '@mui/material';
|
|
9
|
+
|
|
10
|
+
export type Person = {
|
|
11
|
+
id: string;
|
|
12
|
+
firstName: string;
|
|
13
|
+
lastName: string;
|
|
14
|
+
address: string;
|
|
15
|
+
city: string;
|
|
16
|
+
state: string;
|
|
17
|
+
subRows?: Person[]; //Each person can have sub rows of more people
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//data definitions...
|
|
21
|
+
export const data: Person[] = [
|
|
22
|
+
{
|
|
23
|
+
id: '1',
|
|
24
|
+
firstName: 'Dylan',
|
|
25
|
+
lastName: 'Murray',
|
|
26
|
+
address: '261 Erdman Ford',
|
|
27
|
+
city: 'East Daphne',
|
|
28
|
+
state: 'Kentucky',
|
|
29
|
+
subRows: [
|
|
30
|
+
{
|
|
31
|
+
id: '2',
|
|
32
|
+
firstName: 'Ervin',
|
|
33
|
+
lastName: 'Reinger',
|
|
34
|
+
address: '566 Brakus Inlet',
|
|
35
|
+
city: 'South Linda',
|
|
36
|
+
state: 'West Virginia',
|
|
37
|
+
subRows: [
|
|
38
|
+
{
|
|
39
|
+
id: '3',
|
|
40
|
+
firstName: 'Jordane',
|
|
41
|
+
lastName: 'Homenick',
|
|
42
|
+
address: '1234 Brakus Inlet',
|
|
43
|
+
city: 'South Linda',
|
|
44
|
+
state: 'West Virginia',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: '4',
|
|
48
|
+
firstName: 'Jordan',
|
|
49
|
+
lastName: 'Clarkson',
|
|
50
|
+
address: '4882 Palm Rd',
|
|
51
|
+
city: 'San Francisco',
|
|
52
|
+
state: 'California',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: '5',
|
|
58
|
+
firstName: 'Brittany',
|
|
59
|
+
lastName: 'McCullough',
|
|
60
|
+
address: '722 Emie Stream',
|
|
61
|
+
city: 'Lincoln',
|
|
62
|
+
state: 'Nebraska',
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: '6',
|
|
68
|
+
firstName: 'Raquel',
|
|
69
|
+
lastName: 'Kohler',
|
|
70
|
+
address: '769 Dominic Grove',
|
|
71
|
+
city: 'Columbus',
|
|
72
|
+
state: 'Ohio',
|
|
73
|
+
subRows: [
|
|
74
|
+
{
|
|
75
|
+
id: '7',
|
|
76
|
+
firstName: 'Branson',
|
|
77
|
+
lastName: 'Frami',
|
|
78
|
+
address: '32188 Larkin Turnpike',
|
|
79
|
+
city: 'Charleston',
|
|
80
|
+
state: 'South Carolina',
|
|
81
|
+
subRows: [
|
|
82
|
+
{
|
|
83
|
+
id: '8',
|
|
84
|
+
firstName: 'Henry',
|
|
85
|
+
lastName: 'Ford',
|
|
86
|
+
address: '1234 Brakus Inlet',
|
|
87
|
+
city: 'Nashville',
|
|
88
|
+
state: 'Tennessee',
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
//end
|
|
96
|
+
|
|
97
|
+
const Example = () => {
|
|
98
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
99
|
+
//column definitions...
|
|
100
|
+
() => [
|
|
101
|
+
{
|
|
102
|
+
accessorKey: 'firstName',
|
|
103
|
+
header: 'First Name',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
accessorKey: 'lastName',
|
|
107
|
+
header: 'Last Name',
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
{
|
|
111
|
+
accessorKey: 'address',
|
|
112
|
+
header: 'Address',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
accessorKey: 'city',
|
|
116
|
+
header: 'City',
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
{
|
|
120
|
+
accessorKey: 'state',
|
|
121
|
+
enableColumnOrdering: false,
|
|
122
|
+
header: 'State',
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
[],
|
|
126
|
+
//end
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const initialExpandedRootRows = useMemo<MRT_ExpandedState>(
|
|
130
|
+
() =>
|
|
131
|
+
data
|
|
132
|
+
.map((originalRow) => originalRow.id) //get all the root row ids, use recursion for additional levels
|
|
133
|
+
.reduce((a, v) => ({ ...a, [v]: true }), {}), //convert to an object with all the ids as keys and `true` as values
|
|
134
|
+
[],
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
const table = useMaterialReactTable({
|
|
138
|
+
columns,
|
|
139
|
+
data,
|
|
140
|
+
enableExpanding: true,
|
|
141
|
+
getRowId: (originalRow) => originalRow.id,
|
|
142
|
+
initialState: { expanded: initialExpandedRootRows }, //only expand the root rows by default
|
|
143
|
+
renderTopToolbarCustomActions: ({ table }) => (
|
|
144
|
+
<Button onClick={() => table.resetExpanded()}>Reset Expanded</Button>
|
|
145
|
+
),
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
return <MaterialReactTable table={table} />;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export default Example;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MaterialReactTable,
|
|
3
|
+
useMaterialReactTable,
|
|
4
|
+
type MRT_Row,
|
|
5
|
+
createMRTColumnHelper,
|
|
6
|
+
} from 'material-react-table';
|
|
7
|
+
import { Box, Button } from '@mui/material';
|
|
8
|
+
import FileDownloadIcon from '@mui/icons-material/FileDownload';
|
|
9
|
+
import { mkConfig, generateCsv, download } from 'export-to-csv'; //or use your library of choice here
|
|
10
|
+
import { data, type Person } from './makeData';
|
|
11
|
+
|
|
12
|
+
const columnHelper = createMRTColumnHelper<Person>();
|
|
13
|
+
|
|
14
|
+
const columns = [
|
|
15
|
+
columnHelper.accessor('id', {
|
|
16
|
+
header: 'ID',
|
|
17
|
+
size: 40,
|
|
18
|
+
}),
|
|
19
|
+
columnHelper.accessor('firstName', {
|
|
20
|
+
header: 'First Name',
|
|
21
|
+
size: 120,
|
|
22
|
+
}),
|
|
23
|
+
columnHelper.accessor('lastName', {
|
|
24
|
+
header: 'Last Name',
|
|
25
|
+
size: 120,
|
|
26
|
+
}),
|
|
27
|
+
columnHelper.accessor('company', {
|
|
28
|
+
header: 'Company',
|
|
29
|
+
size: 300,
|
|
30
|
+
}),
|
|
31
|
+
columnHelper.accessor('city', {
|
|
32
|
+
header: 'City',
|
|
33
|
+
}),
|
|
34
|
+
columnHelper.accessor('country', {
|
|
35
|
+
header: 'Country',
|
|
36
|
+
size: 220,
|
|
37
|
+
}),
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
const csvConfig = mkConfig({
|
|
41
|
+
fieldSeparator: ',',
|
|
42
|
+
decimalSeparator: '.',
|
|
43
|
+
useKeysAsHeaders: true,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const Example = () => {
|
|
47
|
+
const handleExportRows = (rows: MRT_Row<Person>[]) => {
|
|
48
|
+
const rowData = rows.map((row) => row.original);
|
|
49
|
+
const csv = generateCsv(csvConfig)(rowData);
|
|
50
|
+
download(csvConfig)(csv);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const handleExportData = () => {
|
|
54
|
+
const csv = generateCsv(csvConfig)(data);
|
|
55
|
+
download(csvConfig)(csv);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const table = useMaterialReactTable({
|
|
59
|
+
columns,
|
|
60
|
+
data,
|
|
61
|
+
enableRowSelection: true,
|
|
62
|
+
columnFilterDisplayMode: 'popover',
|
|
63
|
+
paginationDisplayMode: 'pages',
|
|
64
|
+
positionToolbarAlertBanner: 'bottom',
|
|
65
|
+
renderTopToolbarCustomActions: ({ table }) => (
|
|
66
|
+
<Box
|
|
67
|
+
sx={{
|
|
68
|
+
display: 'flex',
|
|
69
|
+
gap: '16px',
|
|
70
|
+
padding: '8px',
|
|
71
|
+
flexWrap: 'wrap',
|
|
72
|
+
}}
|
|
73
|
+
>
|
|
74
|
+
<Button
|
|
75
|
+
//export all data that is currently in the table (ignore pagination, sorting, filtering, etc.)
|
|
76
|
+
onClick={handleExportData}
|
|
77
|
+
startIcon={<FileDownloadIcon />}
|
|
78
|
+
>
|
|
79
|
+
Export All Data
|
|
80
|
+
</Button>
|
|
81
|
+
<Button
|
|
82
|
+
disabled={table.getPrePaginatedRowModel().rows.length === 0}
|
|
83
|
+
//export all rows, including from the next page, (still respects filtering and sorting)
|
|
84
|
+
onClick={() => handleExportRows(table.getPrePaginatedRowModel().rows)}
|
|
85
|
+
startIcon={<FileDownloadIcon />}
|
|
86
|
+
>
|
|
87
|
+
Export All Rows
|
|
88
|
+
</Button>
|
|
89
|
+
<Button
|
|
90
|
+
disabled={table.getRowModel().rows.length === 0}
|
|
91
|
+
//export all rows as seen on the screen (respects pagination, sorting, filtering, etc.)
|
|
92
|
+
onClick={() => handleExportRows(table.getRowModel().rows)}
|
|
93
|
+
startIcon={<FileDownloadIcon />}
|
|
94
|
+
>
|
|
95
|
+
Export Page Rows
|
|
96
|
+
</Button>
|
|
97
|
+
<Button
|
|
98
|
+
disabled={
|
|
99
|
+
!table.getIsSomeRowsSelected() && !table.getIsAllRowsSelected()
|
|
100
|
+
}
|
|
101
|
+
//only export selected rows
|
|
102
|
+
onClick={() => handleExportRows(table.getSelectedRowModel().rows)}
|
|
103
|
+
startIcon={<FileDownloadIcon />}
|
|
104
|
+
>
|
|
105
|
+
Export Selected Rows
|
|
106
|
+
</Button>
|
|
107
|
+
</Box>
|
|
108
|
+
),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return <MaterialReactTable table={table} />;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export default Example;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MaterialReactTable,
|
|
3
|
+
useMaterialReactTable,
|
|
4
|
+
type MRT_Row,
|
|
5
|
+
createMRTColumnHelper,
|
|
6
|
+
} from 'material-react-table';
|
|
7
|
+
import { Box, Button } from '@mui/material';
|
|
8
|
+
import FileDownloadIcon from '@mui/icons-material/FileDownload';
|
|
9
|
+
import { jsPDF } from 'jspdf'; //or use your library of choice here
|
|
10
|
+
import autoTable from 'jspdf-autotable';
|
|
11
|
+
import { data, type Person } from './makeData';
|
|
12
|
+
|
|
13
|
+
const columnHelper = createMRTColumnHelper<Person>();
|
|
14
|
+
|
|
15
|
+
const columns = [
|
|
16
|
+
columnHelper.accessor('id', {
|
|
17
|
+
header: 'ID',
|
|
18
|
+
size: 40,
|
|
19
|
+
}),
|
|
20
|
+
columnHelper.accessor('firstName', {
|
|
21
|
+
header: 'First Name',
|
|
22
|
+
size: 120,
|
|
23
|
+
}),
|
|
24
|
+
columnHelper.accessor('lastName', {
|
|
25
|
+
header: 'Last Name',
|
|
26
|
+
size: 120,
|
|
27
|
+
}),
|
|
28
|
+
columnHelper.accessor('company', {
|
|
29
|
+
header: 'Company',
|
|
30
|
+
size: 300,
|
|
31
|
+
}),
|
|
32
|
+
columnHelper.accessor('city', {
|
|
33
|
+
header: 'City',
|
|
34
|
+
}),
|
|
35
|
+
columnHelper.accessor('country', {
|
|
36
|
+
header: 'Country',
|
|
37
|
+
size: 220,
|
|
38
|
+
}),
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
const Example = () => {
|
|
42
|
+
const handleExportRows = (rows: MRT_Row<Person>[]) => {
|
|
43
|
+
const doc = new jsPDF();
|
|
44
|
+
const tableData = rows.map((row) => Object.values(row.original));
|
|
45
|
+
const tableHeaders = columns.map((c) => c.header);
|
|
46
|
+
|
|
47
|
+
autoTable(doc, {
|
|
48
|
+
head: [tableHeaders],
|
|
49
|
+
body: tableData,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
doc.save('mrt-pdf-example.pdf');
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const table = useMaterialReactTable({
|
|
56
|
+
columns,
|
|
57
|
+
data,
|
|
58
|
+
enableRowSelection: true,
|
|
59
|
+
columnFilterDisplayMode: 'popover',
|
|
60
|
+
paginationDisplayMode: 'pages',
|
|
61
|
+
positionToolbarAlertBanner: 'bottom',
|
|
62
|
+
renderTopToolbarCustomActions: ({ table }) => (
|
|
63
|
+
<Box
|
|
64
|
+
sx={{
|
|
65
|
+
display: 'flex',
|
|
66
|
+
gap: '16px',
|
|
67
|
+
padding: '8px',
|
|
68
|
+
flexWrap: 'wrap',
|
|
69
|
+
}}
|
|
70
|
+
>
|
|
71
|
+
<Button
|
|
72
|
+
disabled={table.getPrePaginatedRowModel().rows.length === 0}
|
|
73
|
+
//export all rows, including from the next page, (still respects filtering and sorting)
|
|
74
|
+
onClick={() => handleExportRows(table.getPrePaginatedRowModel().rows)}
|
|
75
|
+
startIcon={<FileDownloadIcon />}
|
|
76
|
+
>
|
|
77
|
+
Export All Rows
|
|
78
|
+
</Button>
|
|
79
|
+
<Button
|
|
80
|
+
disabled={table.getRowModel().rows.length === 0}
|
|
81
|
+
//export all rows as seen on the screen (respects pagination, sorting, filtering, etc.)
|
|
82
|
+
onClick={() => handleExportRows(table.getRowModel().rows)}
|
|
83
|
+
startIcon={<FileDownloadIcon />}
|
|
84
|
+
>
|
|
85
|
+
Export Page Rows
|
|
86
|
+
</Button>
|
|
87
|
+
<Button
|
|
88
|
+
disabled={
|
|
89
|
+
!table.getIsSomeRowsSelected() && !table.getIsAllRowsSelected()
|
|
90
|
+
}
|
|
91
|
+
//only export selected rows
|
|
92
|
+
onClick={() => handleExportRows(table.getSelectedRowModel().rows)}
|
|
93
|
+
startIcon={<FileDownloadIcon />}
|
|
94
|
+
>
|
|
95
|
+
Export Selected Rows
|
|
96
|
+
</Button>
|
|
97
|
+
</Box>
|
|
98
|
+
),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return <MaterialReactTable table={table} />;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export default Example;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MRT_GlobalFilterTextField,
|
|
3
|
+
MRT_ShowHideColumnsButton,
|
|
4
|
+
MRT_TablePagination,
|
|
5
|
+
MRT_ToggleDensePaddingButton,
|
|
6
|
+
MRT_ToggleFiltersButton,
|
|
7
|
+
MRT_ToolbarAlertBanner,
|
|
8
|
+
useMaterialReactTable,
|
|
9
|
+
type MRT_ColumnDef,
|
|
10
|
+
MRT_TableContainer,
|
|
11
|
+
} from 'material-react-table';
|
|
12
|
+
import { IconButton, Box, Button, Typography, Tooltip } from '@mui/material';
|
|
13
|
+
import PrintIcon from '@mui/icons-material/Print';
|
|
14
|
+
import { data, type Person } from './makeData';
|
|
15
|
+
|
|
16
|
+
const columns: MRT_ColumnDef<Person>[] = [
|
|
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
|
+
const Example = () => {
|
|
36
|
+
const table = useMaterialReactTable({
|
|
37
|
+
columns,
|
|
38
|
+
data,
|
|
39
|
+
enableRowSelection: true,
|
|
40
|
+
initialState: { showGlobalFilter: true },
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<Box sx={{ border: 'gray 2px dashed', padding: '16px' }}>
|
|
45
|
+
{/* Our Custom External Top Toolbar */}
|
|
46
|
+
<Box
|
|
47
|
+
sx={(theme) => ({
|
|
48
|
+
display: 'flex',
|
|
49
|
+
backgroundColor: 'inherit',
|
|
50
|
+
borderRadius: '4px',
|
|
51
|
+
flexDirection: 'row',
|
|
52
|
+
gap: '16px',
|
|
53
|
+
justifyContent: 'space-between',
|
|
54
|
+
padding: '24px 16px',
|
|
55
|
+
'@media max-width: 768px': {
|
|
56
|
+
flexDirection: 'column',
|
|
57
|
+
},
|
|
58
|
+
})}
|
|
59
|
+
>
|
|
60
|
+
<Box>
|
|
61
|
+
<Button
|
|
62
|
+
color="primary"
|
|
63
|
+
onClick={() => {
|
|
64
|
+
alert('Add User');
|
|
65
|
+
}}
|
|
66
|
+
variant="contained"
|
|
67
|
+
>
|
|
68
|
+
Create New Account
|
|
69
|
+
</Button>
|
|
70
|
+
</Box>
|
|
71
|
+
<MRT_GlobalFilterTextField table={table} />
|
|
72
|
+
<Box sx={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
|
|
73
|
+
<MRT_ToggleFiltersButton table={table} />
|
|
74
|
+
<MRT_ShowHideColumnsButton table={table} />
|
|
75
|
+
<MRT_ToggleDensePaddingButton table={table} />
|
|
76
|
+
<Tooltip title="Print">
|
|
77
|
+
<IconButton onClick={() => window.print()}>
|
|
78
|
+
<PrintIcon />
|
|
79
|
+
</IconButton>
|
|
80
|
+
</Tooltip>
|
|
81
|
+
</Box>
|
|
82
|
+
</Box>
|
|
83
|
+
{/* Some Page Content */}
|
|
84
|
+
<Typography
|
|
85
|
+
sx={{
|
|
86
|
+
p: '16px 4px',
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
{
|
|
90
|
+
"Hey I'm some page content. I'm just one of your normal components between your custom toolbar and the MRT Table below"
|
|
91
|
+
}
|
|
92
|
+
</Typography>
|
|
93
|
+
{/* The MRT Table with no toolbars built-in */}
|
|
94
|
+
<MRT_TableContainer table={table} />
|
|
95
|
+
{/* Our Custom Bottom Toolbar */}
|
|
96
|
+
<Box>
|
|
97
|
+
<Box sx={{ display: 'flex', justifyContent: 'flex-end' }}>
|
|
98
|
+
<MRT_TablePagination table={table} />
|
|
99
|
+
</Box>
|
|
100
|
+
<Box sx={{ display: 'grid', width: '100%' }}>
|
|
101
|
+
<MRT_ToolbarAlertBanner stackAlertBanner table={table} />
|
|
102
|
+
</Box>
|
|
103
|
+
</Box>
|
|
104
|
+
</Box>
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export default Example;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MaterialReactTable,
|
|
4
|
+
type MRT_ColumnDef,
|
|
5
|
+
type MRT_Icons,
|
|
6
|
+
} from 'material-react-table';
|
|
7
|
+
import { data, type Person } from './makeData';
|
|
8
|
+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
9
|
+
import {
|
|
10
|
+
faArrowDownWideShort,
|
|
11
|
+
faBars,
|
|
12
|
+
faBarsStaggered,
|
|
13
|
+
faColumns,
|
|
14
|
+
faCompress,
|
|
15
|
+
faEllipsisH,
|
|
16
|
+
faEllipsisVertical,
|
|
17
|
+
faExpand,
|
|
18
|
+
faEyeSlash,
|
|
19
|
+
faFilter,
|
|
20
|
+
faFilterCircleXmark,
|
|
21
|
+
faGripLines,
|
|
22
|
+
faSearch,
|
|
23
|
+
faSearchMinus,
|
|
24
|
+
faSortDown,
|
|
25
|
+
faThumbTack,
|
|
26
|
+
} from '@fortawesome/free-solid-svg-icons';
|
|
27
|
+
import '@fortawesome/fontawesome-svg-core/styles.css';
|
|
28
|
+
import { config } from '@fortawesome/fontawesome-svg-core';
|
|
29
|
+
config.autoAddCss = false;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* These are just some of the icons visible in this table's feature set.
|
|
33
|
+
* If you skip customizing some icons, those particular icons will fallback the the default Material UI icons.
|
|
34
|
+
*/
|
|
35
|
+
const fontAwesomeIcons: Partial<MRT_Icons> = {
|
|
36
|
+
ArrowDownwardIcon: (props: any) => (
|
|
37
|
+
<FontAwesomeIcon icon={faSortDown} {...props} />
|
|
38
|
+
),
|
|
39
|
+
ClearAllIcon: () => <FontAwesomeIcon icon={faBarsStaggered} />,
|
|
40
|
+
DensityLargeIcon: () => <FontAwesomeIcon icon={faGripLines} />,
|
|
41
|
+
DensityMediumIcon: () => <FontAwesomeIcon icon={faBars} />,
|
|
42
|
+
DensitySmallIcon: () => <FontAwesomeIcon icon={faBars} />,
|
|
43
|
+
DragHandleIcon: () => <FontAwesomeIcon icon={faGripLines} />,
|
|
44
|
+
FilterListIcon: (props: any) => (
|
|
45
|
+
<FontAwesomeIcon icon={faFilter} {...props} />
|
|
46
|
+
),
|
|
47
|
+
FilterListOffIcon: () => <FontAwesomeIcon icon={faFilterCircleXmark} />,
|
|
48
|
+
FullscreenExitIcon: () => <FontAwesomeIcon icon={faCompress} />,
|
|
49
|
+
FullscreenIcon: () => <FontAwesomeIcon icon={faExpand} />,
|
|
50
|
+
SearchIcon: (props: any) => <FontAwesomeIcon icon={faSearch} {...props} />,
|
|
51
|
+
SearchOffIcon: () => <FontAwesomeIcon icon={faSearchMinus} />,
|
|
52
|
+
ViewColumnIcon: () => <FontAwesomeIcon icon={faColumns} />,
|
|
53
|
+
MoreVertIcon: () => <FontAwesomeIcon icon={faEllipsisVertical} />,
|
|
54
|
+
MoreHorizIcon: () => <FontAwesomeIcon icon={faEllipsisH} />,
|
|
55
|
+
SortIcon: (props: any) => (
|
|
56
|
+
<FontAwesomeIcon icon={faArrowDownWideShort} {...props} /> //props so that style rotation transforms are applied
|
|
57
|
+
),
|
|
58
|
+
PushPinIcon: (props: any) => (
|
|
59
|
+
<FontAwesomeIcon icon={faThumbTack} {...props} /> //props so that style rotation transforms are applied
|
|
60
|
+
),
|
|
61
|
+
VisibilityOffIcon: () => <FontAwesomeIcon icon={faEyeSlash} />,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const Example = () => {
|
|
65
|
+
const columns = useMemo(
|
|
66
|
+
//column definitions...
|
|
67
|
+
() =>
|
|
68
|
+
[
|
|
69
|
+
{
|
|
70
|
+
accessorKey: 'firstName',
|
|
71
|
+
header: 'First Name',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
accessorKey: 'lastName',
|
|
75
|
+
header: 'Last Name',
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
{
|
|
79
|
+
accessorKey: 'address',
|
|
80
|
+
header: 'Address',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
accessorKey: 'city',
|
|
84
|
+
header: 'City',
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
{
|
|
88
|
+
accessorKey: 'state',
|
|
89
|
+
header: 'State',
|
|
90
|
+
},
|
|
91
|
+
] as MRT_ColumnDef<Person>[],
|
|
92
|
+
[], //end
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<MaterialReactTable
|
|
97
|
+
columns={columns}
|
|
98
|
+
data={data}
|
|
99
|
+
enableColumnOrdering
|
|
100
|
+
enableColumnPinning
|
|
101
|
+
icons={fontAwesomeIcons}
|
|
102
|
+
/>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export default Example;
|