@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,48 @@
|
|
|
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: 'address',
|
|
23
|
+
header: 'Address',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
accessorKey: 'city',
|
|
27
|
+
header: 'City',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
accessorKey: 'state',
|
|
31
|
+
header: 'State',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
[],
|
|
35
|
+
//end
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const table = useMaterialReactTable({
|
|
39
|
+
columns,
|
|
40
|
+
data,
|
|
41
|
+
enableRowNumbers: true,
|
|
42
|
+
rowNumberDisplayMode: 'static', // default
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return <MaterialReactTable table={table} />;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default Example;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useMemo, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
useMaterialReactTable,
|
|
4
|
+
type MRT_ColumnDef,
|
|
5
|
+
type MRT_Row,
|
|
6
|
+
MRT_TableContainer,
|
|
7
|
+
} from 'material-react-table';
|
|
8
|
+
import { data as initData, 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: 'city',
|
|
24
|
+
header: 'City',
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
[],
|
|
28
|
+
//end
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const [data, setData] = useState(() => initData);
|
|
32
|
+
|
|
33
|
+
const table = useMaterialReactTable({
|
|
34
|
+
autoResetPageIndex: false,
|
|
35
|
+
columns,
|
|
36
|
+
data,
|
|
37
|
+
enableRowOrdering: true,
|
|
38
|
+
enableSorting: false,
|
|
39
|
+
muiRowDragHandleProps: ({ table }) => ({
|
|
40
|
+
onDragEnd: () => {
|
|
41
|
+
const { draggingRow, hoveredRow } = table.getState();
|
|
42
|
+
if (hoveredRow && draggingRow) {
|
|
43
|
+
data.splice(
|
|
44
|
+
(hoveredRow as MRT_Row<Person>).index,
|
|
45
|
+
0,
|
|
46
|
+
data.splice(draggingRow.index, 1)[0],
|
|
47
|
+
);
|
|
48
|
+
setData([...data]);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return <MRT_TableContainer table={table} />;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default Example;
|
|
@@ -0,0 +1,76 @@
|
|
|
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: 'email',
|
|
23
|
+
header: 'Email',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
accessorKey: 'city',
|
|
27
|
+
header: 'City',
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
[],
|
|
31
|
+
//end
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const table = useMaterialReactTable({
|
|
35
|
+
columns,
|
|
36
|
+
data,
|
|
37
|
+
enablePagination: false,
|
|
38
|
+
enableRowPinning: true,
|
|
39
|
+
enableRowSelection: true,
|
|
40
|
+
enableStickyHeader: true,
|
|
41
|
+
rowPinningDisplayMode: 'select-sticky',
|
|
42
|
+
getRowId: (row) => row.email,
|
|
43
|
+
initialState: {
|
|
44
|
+
rowPinning: {
|
|
45
|
+
bottom: [],
|
|
46
|
+
top: ['ereinger@mailinator.com'],
|
|
47
|
+
},
|
|
48
|
+
rowSelection: {
|
|
49
|
+
'ereinger@mailinator.com': true,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
muiTableContainerProps: {
|
|
53
|
+
sx: {
|
|
54
|
+
maxHeight: '400px',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
muiTableBodyRowProps: ({ row, table }) => {
|
|
58
|
+
const { density } = table.getState();
|
|
59
|
+
return {
|
|
60
|
+
sx: {
|
|
61
|
+
//Set a fixed height for pinned rows
|
|
62
|
+
height: row.getIsPinned()
|
|
63
|
+
? `${
|
|
64
|
+
//Default mrt row height estimates. Adjust as needed.
|
|
65
|
+
density === 'compact' ? 37 : density === 'comfortable' ? 53 : 69
|
|
66
|
+
}px`
|
|
67
|
+
: undefined,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return <MaterialReactTable table={table} />;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export default Example;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MaterialReactTable,
|
|
4
|
+
useMaterialReactTable,
|
|
5
|
+
type MRT_ColumnDef,
|
|
6
|
+
} from 'material-react-table';
|
|
7
|
+
import { data, type Person } from './makeData';
|
|
8
|
+
|
|
9
|
+
const Example = () => {
|
|
10
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
11
|
+
() => [
|
|
12
|
+
{
|
|
13
|
+
accessorKey: 'firstName',
|
|
14
|
+
header: 'First Name',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
accessorKey: 'lastName',
|
|
18
|
+
header: 'Last Name',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
accessorKey: 'email',
|
|
22
|
+
header: 'Email',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
accessorKey: 'city',
|
|
26
|
+
header: 'City',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
[],
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const table = useMaterialReactTable({
|
|
33
|
+
columns,
|
|
34
|
+
data,
|
|
35
|
+
enableRowPinning: true,
|
|
36
|
+
enablePagination: false,
|
|
37
|
+
enableStickyHeader: true,
|
|
38
|
+
rowPinningDisplayMode: 'top-and-bottom',
|
|
39
|
+
getRowId: (row) => row.email,
|
|
40
|
+
muiTableContainerProps: {
|
|
41
|
+
sx: {
|
|
42
|
+
maxHeight: '400px',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return <MaterialReactTable table={table} />;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default Example;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MaterialReactTable,
|
|
4
|
+
useMaterialReactTable,
|
|
5
|
+
type MRT_ColumnDef,
|
|
6
|
+
} from 'material-react-table';
|
|
7
|
+
import { data, type Person } from './makeData';
|
|
8
|
+
|
|
9
|
+
const Example = () => {
|
|
10
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
11
|
+
() => [
|
|
12
|
+
{
|
|
13
|
+
accessorKey: 'firstName',
|
|
14
|
+
header: 'First Name',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
accessorKey: 'lastName',
|
|
18
|
+
header: 'Last Name',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
accessorKey: 'email',
|
|
22
|
+
header: 'Email',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
accessorKey: 'city',
|
|
26
|
+
header: 'City',
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
[],
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const table = useMaterialReactTable({
|
|
33
|
+
columns,
|
|
34
|
+
data,
|
|
35
|
+
enableRowPinning: true,
|
|
36
|
+
enablePagination: false,
|
|
37
|
+
enableStickyHeader: true,
|
|
38
|
+
getRowId: (row) => row.email,
|
|
39
|
+
initialState: {
|
|
40
|
+
rowPinning: {
|
|
41
|
+
top: ['rkholer33@yopmail.com', 'egarcia@yopmail.com'],
|
|
42
|
+
bottom: [],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
muiTableContainerProps: {
|
|
46
|
+
sx: {
|
|
47
|
+
maxHeight: '400px',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
muiTableBodyRowProps: ({ row, table }) => {
|
|
51
|
+
const { density } = table.getState();
|
|
52
|
+
return {
|
|
53
|
+
sx: {
|
|
54
|
+
//Set a fixed height for pinned rows
|
|
55
|
+
height: row.getIsPinned()
|
|
56
|
+
? `${
|
|
57
|
+
//Default mrt row height estimates. Adjust as needed.
|
|
58
|
+
density === 'compact' ? 37 : density === 'comfortable' ? 53 : 69
|
|
59
|
+
}px`
|
|
60
|
+
: undefined,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return <MaterialReactTable table={table} />;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export default Example;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MaterialReactTable,
|
|
4
|
+
useMaterialReactTable,
|
|
5
|
+
type MRT_ColumnDef,
|
|
6
|
+
type MRT_RowSelectionState,
|
|
7
|
+
} from 'material-react-table';
|
|
8
|
+
|
|
9
|
+
//data definitions...
|
|
10
|
+
interface Person {
|
|
11
|
+
userId: string;
|
|
12
|
+
firstName: string;
|
|
13
|
+
lastName: string;
|
|
14
|
+
age: number;
|
|
15
|
+
address: string;
|
|
16
|
+
city: string;
|
|
17
|
+
state: string;
|
|
18
|
+
}
|
|
19
|
+
//end
|
|
20
|
+
|
|
21
|
+
const data = [
|
|
22
|
+
{
|
|
23
|
+
userId: '3f25309c-8fa1-470f-811e-cdb082ab9017', //we'll use this as a unique row id
|
|
24
|
+
firstName: 'Dylan',
|
|
25
|
+
lastName: 'Murray',
|
|
26
|
+
age: 22,
|
|
27
|
+
address: '261 Erdman Ford',
|
|
28
|
+
city: 'East Daphne',
|
|
29
|
+
state: 'Kentucky',
|
|
30
|
+
}, //data definitions...
|
|
31
|
+
{
|
|
32
|
+
userId: 'be731030-df83-419c-b3d6-9ef04e7f4a9f',
|
|
33
|
+
firstName: 'Raquel',
|
|
34
|
+
lastName: 'Kohler',
|
|
35
|
+
age: 18,
|
|
36
|
+
address: '769 Dominic Grove',
|
|
37
|
+
city: 'Columbus',
|
|
38
|
+
state: 'Ohio',
|
|
39
|
+
},
|
|
40
|
+
//end
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const Example = () => {
|
|
44
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
45
|
+
//column definitions...
|
|
46
|
+
() => [
|
|
47
|
+
{
|
|
48
|
+
accessorKey: 'firstName',
|
|
49
|
+
header: 'First Name',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
accessorKey: 'lastName',
|
|
53
|
+
header: 'Last Name',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
accessorKey: 'age',
|
|
57
|
+
header: 'Age',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
accessorKey: 'address',
|
|
61
|
+
header: 'Address',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
accessorKey: 'city',
|
|
65
|
+
header: 'City',
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
accessorKey: 'state',
|
|
69
|
+
header: 'State',
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
[], //end
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
//optionally, you can manage the row selection state yourself
|
|
76
|
+
const [rowSelection, setRowSelection] = useState<MRT_RowSelectionState>({});
|
|
77
|
+
|
|
78
|
+
const table = useMaterialReactTable({
|
|
79
|
+
columns,
|
|
80
|
+
data,
|
|
81
|
+
enableRowSelection: true,
|
|
82
|
+
getRowId: (row) => row.userId, //give each row a more useful id
|
|
83
|
+
onRowSelectionChange: setRowSelection, //connect internal row selection state to your own
|
|
84
|
+
state: { rowSelection }, //pass our managed row selection state to the table to use
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
//do something when the row selection changes...
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
console.info({ rowSelection }); //read your managed row selection state
|
|
90
|
+
// console.info(table.getState().rowSelection); //alternate way to get the row selection state
|
|
91
|
+
}, [rowSelection]);
|
|
92
|
+
|
|
93
|
+
return <MaterialReactTable table={table} />;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export default Example;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
MaterialReactTable,
|
|
4
|
+
useMaterialReactTable,
|
|
5
|
+
type MRT_ColumnDef,
|
|
6
|
+
type MRT_SortingState,
|
|
7
|
+
type MRT_RowVirtualizer,
|
|
8
|
+
} from 'material-react-table';
|
|
9
|
+
import { makeData, type Person } from './makeData';
|
|
10
|
+
|
|
11
|
+
const Example = () => {
|
|
12
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
13
|
+
//column definitions...
|
|
14
|
+
() => [
|
|
15
|
+
{
|
|
16
|
+
accessorKey: 'firstName',
|
|
17
|
+
header: 'First Name',
|
|
18
|
+
size: 150,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
accessorKey: 'middleName',
|
|
22
|
+
header: 'Middle Name',
|
|
23
|
+
size: 150,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
accessorKey: 'lastName',
|
|
27
|
+
header: 'Last Name',
|
|
28
|
+
size: 150,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
accessorKey: 'email',
|
|
32
|
+
header: 'Email Address',
|
|
33
|
+
size: 300,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
accessorKey: 'address',
|
|
37
|
+
header: 'Address',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
accessorKey: 'zipCode',
|
|
41
|
+
header: 'Zip Code',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
accessorKey: 'city',
|
|
45
|
+
header: 'City',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
accessorKey: 'state',
|
|
49
|
+
header: 'State',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
accessorKey: 'country',
|
|
53
|
+
header: 'Country',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
[],
|
|
57
|
+
//end
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
//optionally access the underlying virtualizer instance
|
|
61
|
+
const rowVirtualizerInstanceRef = useRef<MRT_RowVirtualizer>(null);
|
|
62
|
+
|
|
63
|
+
const [data, setData] = useState<Person[]>([]);
|
|
64
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
65
|
+
const [sorting, setSorting] = useState<MRT_SortingState>([]);
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (typeof window !== 'undefined') {
|
|
69
|
+
setData(makeData(10_000));
|
|
70
|
+
setIsLoading(false);
|
|
71
|
+
}
|
|
72
|
+
}, []);
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
//scroll to the top of the table when the sorting changes
|
|
76
|
+
try {
|
|
77
|
+
rowVirtualizerInstanceRef.current?.scrollToIndex?.(0);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error(error);
|
|
80
|
+
}
|
|
81
|
+
}, [sorting]);
|
|
82
|
+
|
|
83
|
+
const table = useMaterialReactTable({
|
|
84
|
+
columns,
|
|
85
|
+
data, //10,000 rows
|
|
86
|
+
enableBottomToolbar: false,
|
|
87
|
+
enableGlobalFilterModes: true,
|
|
88
|
+
enablePagination: false,
|
|
89
|
+
enableRowNumbers: true,
|
|
90
|
+
enableRowVirtualization: true,
|
|
91
|
+
muiTableContainerProps: { sx: { maxHeight: '600px' } },
|
|
92
|
+
onSortingChange: setSorting,
|
|
93
|
+
state: { isLoading, sorting },
|
|
94
|
+
rowVirtualizerInstanceRef, //optional
|
|
95
|
+
rowVirtualizerOptions: { overscan: 5 }, //optionally customize the row virtualizer
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
return <MaterialReactTable table={table} />;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export default Example;
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
footer: 'First Name',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
accessorKey: 'lastName',
|
|
20
|
+
header: 'Last Name',
|
|
21
|
+
footer: 'Last Name',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
accessorKey: 'email',
|
|
25
|
+
header: 'Email',
|
|
26
|
+
footer: 'Email',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
accessorKey: 'city',
|
|
30
|
+
header: 'City',
|
|
31
|
+
footer: 'City',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
[],
|
|
35
|
+
//end
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const table = useMaterialReactTable({
|
|
39
|
+
columns,
|
|
40
|
+
data,
|
|
41
|
+
enableBottomToolbar: false,
|
|
42
|
+
enableStickyHeader: true,
|
|
43
|
+
enableStickyFooter: true,
|
|
44
|
+
enablePagination: false,
|
|
45
|
+
muiTableContainerProps: { sx: { maxHeight: '400px' } },
|
|
46
|
+
muiTableBodyCellProps: {
|
|
47
|
+
sx: (theme) => ({
|
|
48
|
+
backgroundColor:
|
|
49
|
+
theme.palette.mode === 'dark'
|
|
50
|
+
? theme.palette.grey[900]
|
|
51
|
+
: theme.palette.grey[50],
|
|
52
|
+
}),
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return <MaterialReactTable table={table} />;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default Example;
|
|
@@ -0,0 +1,121 @@
|
|
|
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
|
+
firstName: string;
|
|
10
|
+
lastName: string;
|
|
11
|
+
address: string;
|
|
12
|
+
city: string;
|
|
13
|
+
state: string;
|
|
14
|
+
subRows?: Person[]; //Each person can have sub rows of more people
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const data: Person[] = [
|
|
18
|
+
{
|
|
19
|
+
firstName: 'Dylan',
|
|
20
|
+
lastName: 'Murray',
|
|
21
|
+
address: '261 Erdman Ford',
|
|
22
|
+
city: 'East Daphne',
|
|
23
|
+
state: 'Kentucky',
|
|
24
|
+
subRows: [
|
|
25
|
+
{
|
|
26
|
+
firstName: 'Ervin',
|
|
27
|
+
lastName: 'Reinger',
|
|
28
|
+
address: '566 Brakus Inlet',
|
|
29
|
+
city: 'South Linda',
|
|
30
|
+
state: 'West Virginia',
|
|
31
|
+
subRows: [
|
|
32
|
+
{
|
|
33
|
+
firstName: 'Jordane',
|
|
34
|
+
lastName: 'Homenick',
|
|
35
|
+
address: '1234 Brakus Inlet',
|
|
36
|
+
city: 'South Linda',
|
|
37
|
+
state: 'West Virginia',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
firstName: 'Jordan',
|
|
41
|
+
lastName: 'Clarkson',
|
|
42
|
+
address: '4882 Palm Rd',
|
|
43
|
+
city: 'San Francisco',
|
|
44
|
+
state: 'California',
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
firstName: 'Brittany',
|
|
50
|
+
lastName: 'McCullough',
|
|
51
|
+
address: '722 Emie Stream',
|
|
52
|
+
city: 'Lincoln',
|
|
53
|
+
state: 'Nebraska',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
firstName: 'Raquel',
|
|
59
|
+
lastName: 'Kohler',
|
|
60
|
+
address: '769 Dominic Grove',
|
|
61
|
+
city: 'Columbus',
|
|
62
|
+
state: 'Ohio',
|
|
63
|
+
subRows: [
|
|
64
|
+
{
|
|
65
|
+
firstName: 'Branson',
|
|
66
|
+
lastName: 'Frami',
|
|
67
|
+
address: '32188 Larkin Turnpike',
|
|
68
|
+
city: 'Charleston',
|
|
69
|
+
state: 'South Carolina',
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
const Example = () => {
|
|
76
|
+
const columns = useMemo<MRT_ColumnDef<Person>[]>(
|
|
77
|
+
//column definitions...
|
|
78
|
+
() => [
|
|
79
|
+
{
|
|
80
|
+
accessorKey: 'firstName',
|
|
81
|
+
header: 'First Name',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
accessorKey: 'lastName',
|
|
85
|
+
header: 'Last Name',
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
{
|
|
89
|
+
accessorKey: 'address',
|
|
90
|
+
header: 'Address',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
accessorKey: 'city',
|
|
94
|
+
header: 'City',
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
{
|
|
98
|
+
accessorKey: 'state',
|
|
99
|
+
enableColumnOrdering: false,
|
|
100
|
+
header: 'State',
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
[],
|
|
104
|
+
//end
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const table = useMaterialReactTable({
|
|
108
|
+
columns,
|
|
109
|
+
data,
|
|
110
|
+
enableExpandAll: false, //hide expand all double arrow in column header
|
|
111
|
+
enableExpanding: true,
|
|
112
|
+
filterFromLeafRows: true, //apply filtering to all rows instead of just parent rows
|
|
113
|
+
getSubRows: (row) => row.subRows, //default
|
|
114
|
+
initialState: { expanded: true }, //expand all rows by default
|
|
115
|
+
paginateExpandedRows: false, //When rows are expanded, do not count sub-rows as number of rows on the page towards pagination
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
return <MaterialReactTable table={table} />;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export default Example;
|