@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.
Files changed (117) hide show
  1. package/README.md +1 -1
  2. package/data/examples/advanced.js +215 -0
  3. package/data/examples/aggregation-and-grouping.js +116 -0
  4. package/data/examples/aggregation-multi.js +89 -0
  5. package/data/examples/alternate-column-filtering.js +38 -0
  6. package/data/examples/alternate-detail-panel.js +65 -0
  7. package/data/examples/alternate-pagination.js +17 -0
  8. package/data/examples/basic.js +86 -0
  9. package/data/examples/chart-detail-panel.js +69 -0
  10. package/data/examples/column-actions-space.js +34 -0
  11. package/data/examples/column-alignment.js +58 -0
  12. package/data/examples/custom-column-actions.js +74 -0
  13. package/data/examples/custom-column-filtering-ui.js +59 -0
  14. package/data/examples/custom-headless.js +85 -0
  15. package/data/examples/custom-top-toolbar.js +60 -0
  16. package/data/examples/customize-display-columns.js +72 -0
  17. package/data/examples/customize-filter-components.js +78 -0
  18. package/data/examples/customize-filter-modes.js +59 -0
  19. package/data/examples/customize-filter-variants.js +98 -0
  20. package/data/examples/customize-global-filter-component.js +37 -0
  21. package/data/examples/customize-remove-column-grouping.js +75 -0
  22. package/data/examples/customize-row-selection.js +43 -0
  23. package/data/examples/customize-table-styles.js +81 -0
  24. package/data/examples/disable-column-actions.js +26 -0
  25. package/data/examples/disable-column-hiding.js +74 -0
  26. package/data/examples/disable-density-toggle.js +37 -0
  27. package/data/examples/dynamic-columns.js +124 -0
  28. package/data/examples/editing-crud-cell.js +288 -0
  29. package/data/examples/editing-crud-modal.js +275 -0
  30. package/data/examples/editing-crud-row.js +255 -0
  31. package/data/examples/editing-crud-table.js +280 -0
  32. package/data/examples/editing-crud-tree.js +328 -0
  33. package/data/examples/enable-cell-actions.js +52 -0
  34. package/data/examples/enable-click-to-copy.js +33 -0
  35. package/data/examples/enable-column-grouping.js +69 -0
  36. package/data/examples/enable-column-ordering.js +37 -0
  37. package/data/examples/enable-column-pinning.js +58 -0
  38. package/data/examples/enable-column-resizing.js +45 -0
  39. package/data/examples/enable-column-virtualization.js +19 -0
  40. package/data/examples/enable-detail-panel-conditionally.js +61 -0
  41. package/data/examples/enable-detail-panel-virtualized.js +64 -0
  42. package/data/examples/enable-expanding-tree.js +87 -0
  43. package/data/examples/enable-filter-facet-values.js +52 -0
  44. package/data/examples/enable-row-dragging.js +102 -0
  45. package/data/examples/enable-row-numbers-original.js +37 -0
  46. package/data/examples/enable-row-numbers-static.js +37 -0
  47. package/data/examples/enable-row-ordering.js +40 -0
  48. package/data/examples/enable-row-pinning-select.js +64 -0
  49. package/data/examples/enable-row-pinning-static.js +39 -0
  50. package/data/examples/enable-row-pinning-sticky.js +57 -0
  51. package/data/examples/enable-row-selection.js +71 -0
  52. package/data/examples/enable-row-virtualization.js +85 -0
  53. package/data/examples/enable-sticky-header.js +47 -0
  54. package/data/examples/expanding-tree-expanded.js +98 -0
  55. package/data/examples/expanding-tree-flat-parse.js +102 -0
  56. package/data/examples/expanding-tree-root-expanded.js +120 -0
  57. package/data/examples/export-to-csv.js +84 -0
  58. package/data/examples/export-to-pdf.js +76 -0
  59. package/data/examples/external-toolbar.js +82 -0
  60. package/data/examples/font-awesome-icons.js +62 -0
  61. package/data/examples/infinite-scrolling.js +137 -0
  62. package/data/examples/lazy-detail-panel.js +164 -0
  63. package/data/examples/lazy-sub-rows.js +118 -0
  64. package/data/examples/linear-progress.js +48 -0
  65. package/data/examples/loading.js +34 -0
  66. package/data/examples/localization-i18n-ar.js +40 -0
  67. package/data/examples/localization-i18n-az.js +38 -0
  68. package/data/examples/localization-i18n-bg.js +38 -0
  69. package/data/examples/localization-i18n-cs.js +38 -0
  70. package/data/examples/localization-i18n-da.js +38 -0
  71. package/data/examples/localization-i18n-de.js +38 -0
  72. package/data/examples/localization-i18n-el.js +38 -0
  73. package/data/examples/localization-i18n-en.js +38 -0
  74. package/data/examples/localization-i18n-es.js +38 -0
  75. package/data/examples/localization-i18n-et.js +38 -0
  76. package/data/examples/localization-i18n-fa.js +40 -0
  77. package/data/examples/localization-i18n-fi.js +38 -0
  78. package/data/examples/localization-i18n-fr.js +38 -0
  79. package/data/examples/localization-i18n-he.js +40 -0
  80. package/data/examples/localization-i18n-hr.js +38 -0
  81. package/data/examples/localization-i18n-hu.js +38 -0
  82. package/data/examples/localization-i18n-hy.js +40 -0
  83. package/data/examples/localization-i18n-id.js +38 -0
  84. package/data/examples/localization-i18n-it.js +38 -0
  85. package/data/examples/localization-i18n-ja.js +38 -0
  86. package/data/examples/localization-i18n-ko.js +38 -0
  87. package/data/examples/localization-i18n-nl.js +38 -0
  88. package/data/examples/localization-i18n-no.js +38 -0
  89. package/data/examples/localization-i18n-np.js +38 -0
  90. package/data/examples/localization-i18n-pl.js +38 -0
  91. package/data/examples/localization-i18n-pt-BR.js +38 -0
  92. package/data/examples/localization-i18n-pt.js +38 -0
  93. package/data/examples/localization-i18n-ro.js +38 -0
  94. package/data/examples/localization-i18n-ru.js +38 -0
  95. package/data/examples/localization-i18n-sk.js +38 -0
  96. package/data/examples/localization-i18n-sr-Cyrl-RS.js +38 -0
  97. package/data/examples/localization-i18n-sr-Latn-RS.js +38 -0
  98. package/data/examples/localization-i18n-sv.js +38 -0
  99. package/data/examples/localization-i18n-tr.js +38 -0
  100. package/data/examples/localization-i18n-uk.js +38 -0
  101. package/data/examples/localization-i18n-vi.js +38 -0
  102. package/data/examples/localization-i18n-zh-hans.js +38 -0
  103. package/data/examples/localization-i18n-zh-hant.js +38 -0
  104. package/data/examples/manual-selection.js +81 -0
  105. package/data/examples/minimal.js +66 -0
  106. package/data/examples/mui-theme.js +109 -0
  107. package/data/examples/multi-sorting.js +48 -0
  108. package/data/examples/persistent-state.js +126 -0
  109. package/data/examples/react-query.js +122 -0
  110. package/data/examples/remote.js +113 -0
  111. package/data/examples/row-actions-buttons.js +54 -0
  112. package/data/examples/row-actions-menu-items.js +36 -0
  113. package/data/examples/single-row-selection.js +74 -0
  114. package/data/examples/virtualized.js +122 -0
  115. package/dist/data.js +31 -9
  116. package/dist/index.js +18 -6
  117. package/package.json +1 -1
@@ -0,0 +1,38 @@
1
+ //Import Material React Table and its Types
2
+ import { MaterialReactTable } from 'material-react-table';
3
+ //Import Material React Table Translations
4
+ import { MRT_Localization_UK } from 'material-react-table/locales/uk';
5
+ //mock data
6
+ import { data } from './makeData';
7
+ const columns = [
8
+ //column definitions...
9
+ {
10
+ accessorKey: 'firstName',
11
+ header: "Ім'я",
12
+ },
13
+ {
14
+ accessorKey: 'lastName',
15
+ header: 'Прізвище',
16
+ enableClickToCopy: true,
17
+ },
18
+ {
19
+ accessorKey: 'age',
20
+ header: 'Вік',
21
+ },
22
+ //end
23
+ ];
24
+ const Example = () => {
25
+ return (<MaterialReactTable columns={columns} data={data} enableColumnFilterModes enableColumnOrdering enableEditing enableColumnPinning enableRowActions enableRowSelection enableSelectAll={false} initialState={{ showColumnFilters: true, showGlobalFilter: true }} localization={MRT_Localization_UK}/>);
26
+ };
27
+ //App.tsx or similar
28
+ import { createTheme, ThemeProvider, useTheme } from '@mui/material';
29
+ import { ukUA } from '@mui/material/locale';
30
+ const ExampleWithThemeProvider = () => {
31
+ const theme = useTheme(); //replace with your theme/createTheme
32
+ return (
33
+ //Setting Material UI locale as best practice to result in better accessibility
34
+ <ThemeProvider theme={createTheme(theme, ukUA)}>
35
+ <Example />
36
+ </ThemeProvider>);
37
+ };
38
+ export default ExampleWithThemeProvider;
@@ -0,0 +1,38 @@
1
+ //Import Material React Table and its Types
2
+ import { MaterialReactTable } from 'material-react-table';
3
+ //Import Material React Table Translations
4
+ import { MRT_Localization_VI } from 'material-react-table/locales/vi';
5
+ //mock data
6
+ import { data } from './makeData';
7
+ const columns = [
8
+ //column definitions...
9
+ {
10
+ accessorKey: 'firstName',
11
+ header: 'Họ của người nào',
12
+ },
13
+ {
14
+ accessorKey: 'lastName',
15
+ header: 'Tên họ',
16
+ enableClickToCopy: true,
17
+ },
18
+ {
19
+ accessorKey: 'age',
20
+ header: 'Tuổi tác',
21
+ },
22
+ //end
23
+ ];
24
+ const Example = () => {
25
+ return (<MaterialReactTable columns={columns} data={data} enableColumnFilterModes enableColumnOrdering enableEditing enableColumnPinning enableRowActions enableRowSelection enableSelectAll={false} initialState={{ showColumnFilters: true, showGlobalFilter: true }} localization={MRT_Localization_VI}/>);
26
+ };
27
+ //App.tsx or similar
28
+ import { createTheme, ThemeProvider, useTheme } from '@mui/material';
29
+ import { trTR } from '@mui/material/locale';
30
+ const ExampleWithThemeProvider = () => {
31
+ const theme = useTheme(); //replace with your theme/createTheme
32
+ return (
33
+ //Setting Material UI locale as best practice to result in better accessibility
34
+ <ThemeProvider theme={createTheme(theme, trTR)}>
35
+ <Example />
36
+ </ThemeProvider>);
37
+ };
38
+ export default ExampleWithThemeProvider;
@@ -0,0 +1,38 @@
1
+ //Import Material React Table and its Types
2
+ import { MaterialReactTable } from 'material-react-table';
3
+ //Import Material React Table Translations
4
+ import { MRT_Localization_ZH_HANS } from 'material-react-table/locales/zh-Hans';
5
+ //mock data
6
+ import { data } from './makeData';
7
+ const columns = [
8
+ //column definitions...
9
+ {
10
+ accessorKey: 'firstName',
11
+ header: '名',
12
+ },
13
+ {
14
+ accessorKey: 'lastName',
15
+ header: '姓',
16
+ enableClickToCopy: true,
17
+ },
18
+ {
19
+ accessorKey: 'age',
20
+ header: '年龄',
21
+ },
22
+ //end
23
+ ];
24
+ const Example = () => {
25
+ return (<MaterialReactTable columns={columns} data={data} enableColumnFilterModes enableColumnOrdering enableEditing enableColumnPinning enableRowActions enableRowSelection enableSelectAll={false} initialState={{ showColumnFilters: true, showGlobalFilter: true }} localization={MRT_Localization_ZH_HANS}/>);
26
+ };
27
+ //App.tsx or similar
28
+ import { createTheme, ThemeProvider, useTheme } from '@mui/material';
29
+ import { zhCN } from '@mui/material/locale';
30
+ const ExampleWithThemeProvider = () => {
31
+ const theme = useTheme(); //replace with your theme/createTheme
32
+ return (
33
+ //Setting Material UI locale as best practice to result in better accessibility
34
+ <ThemeProvider theme={createTheme(theme, zhCN)}>
35
+ <Example />
36
+ </ThemeProvider>);
37
+ };
38
+ export default ExampleWithThemeProvider;
@@ -0,0 +1,38 @@
1
+ //Import Material React Table and its Types
2
+ import { MaterialReactTable } from 'material-react-table';
3
+ //Import Material React Table Translations
4
+ import { MRT_Localization_ZH_HANT } from 'material-react-table/locales/zh-Hant';
5
+ //mock data
6
+ import { data } from './makeData';
7
+ const columns = [
8
+ //column definitions...
9
+ {
10
+ accessorKey: 'firstName',
11
+ header: '名',
12
+ },
13
+ {
14
+ accessorKey: 'lastName',
15
+ header: '姓',
16
+ enableClickToCopy: true,
17
+ },
18
+ {
19
+ accessorKey: 'age',
20
+ header: '年齡',
21
+ },
22
+ //end
23
+ ];
24
+ const Example = () => {
25
+ return (<MaterialReactTable columns={columns} data={data} enableColumnFilterModes enableColumnOrdering enableEditing enableColumnPinning enableRowActions enableRowSelection enableSelectAll={false} initialState={{ showColumnFilters: true, showGlobalFilter: true }} localization={MRT_Localization_ZH_HANT}/>);
26
+ };
27
+ //App.tsx or similar
28
+ import { createTheme, ThemeProvider, useTheme } from '@mui/material';
29
+ import { zhHK } from '@mui/material/locale';
30
+ const ExampleWithThemeProvider = () => {
31
+ const theme = useTheme(); //replace with your theme/createTheme
32
+ return (
33
+ //Setting Material UI locale as best practice to result in better accessibility
34
+ <ThemeProvider theme={createTheme(theme, zhHK)}>
35
+ <Example />
36
+ </ThemeProvider>);
37
+ };
38
+ export default ExampleWithThemeProvider;
@@ -0,0 +1,81 @@
1
+ import { useMemo, useState } from 'react';
2
+ import { MaterialReactTable, useMaterialReactTable, } from 'material-react-table';
3
+ //end
4
+ const data = [
5
+ //data definitions...
6
+ {
7
+ userId: '3f25309c-8fa1-470f-811e-cdb082ab9017', //we'll use this as a unique row id
8
+ firstName: 'Dylan',
9
+ lastName: 'Murray',
10
+ age: 22,
11
+ address: '261 Erdman Ford',
12
+ city: 'East Daphne',
13
+ state: 'Kentucky',
14
+ },
15
+ {
16
+ userId: 'be731030-df83-419c-b3d6-9ef04e7f4a9f',
17
+ firstName: 'Raquel',
18
+ lastName: 'Kohler',
19
+ age: 18,
20
+ address: '769 Dominic Grove',
21
+ city: 'Columbus',
22
+ state: 'Ohio',
23
+ },
24
+ //end
25
+ ];
26
+ const Example = () => {
27
+ const columns = useMemo(
28
+ //column definitions...
29
+ () => [
30
+ {
31
+ accessorKey: 'firstName',
32
+ header: 'First Name',
33
+ },
34
+ {
35
+ accessorKey: 'lastName',
36
+ header: 'Last Name',
37
+ },
38
+ {
39
+ accessorKey: 'age',
40
+ header: 'Age',
41
+ },
42
+ {
43
+ accessorKey: 'address',
44
+ header: 'Address',
45
+ },
46
+ {
47
+ accessorKey: 'city',
48
+ header: 'City',
49
+ },
50
+ {
51
+ accessorKey: 'state',
52
+ header: 'State',
53
+ },
54
+ ], []);
55
+ const [rowSelection, setRowSelection] = useState({});
56
+ const table = useMaterialReactTable({
57
+ columns,
58
+ data,
59
+ getRowId: (row) => row.userId,
60
+ muiTableBodyRowProps: ({ row }) => ({
61
+ //implement row selection click events manually
62
+ onClick: () => setRowSelection((prev) => {
63
+ //this is a simple toggle implementation
64
+ const next = { ...prev };
65
+ if (next[row.id])
66
+ delete next[row.id];
67
+ else
68
+ next[row.id] = true;
69
+ return next;
70
+ }),
71
+ selected: rowSelection[row.id],
72
+ sx: {
73
+ cursor: 'pointer',
74
+ },
75
+ }),
76
+ onRowSelectionChange: setRowSelection,
77
+ state: { rowSelection },
78
+ });
79
+ return <MaterialReactTable table={table}/>;
80
+ };
81
+ export default Example;
@@ -0,0 +1,66 @@
1
+ import { useMemo } from 'react';
2
+ import { MRT_Table, useMaterialReactTable, } from 'material-react-table';
3
+ import { data } from './makeData';
4
+ export const Example = () => {
5
+ const columns = useMemo(
6
+ //column definitions...
7
+ () => [
8
+ {
9
+ accessorKey: 'firstName',
10
+ header: 'First Name',
11
+ },
12
+ {
13
+ accessorKey: 'lastName',
14
+ header: 'Last Name',
15
+ },
16
+ {
17
+ accessorKey: 'address',
18
+ header: 'Address',
19
+ },
20
+ {
21
+ accessorKey: 'city',
22
+ header: 'City',
23
+ },
24
+ {
25
+ accessorKey: 'state',
26
+ header: 'State',
27
+ },
28
+ ], []);
29
+ const table = useMaterialReactTable({
30
+ columns,
31
+ data, //data must be memoized or stable (useState, useMemo, defined outside of this component, etc.)
32
+ enableKeyboardShortcuts: false,
33
+ enableColumnActions: false,
34
+ enableColumnFilters: false,
35
+ enablePagination: false,
36
+ enableSorting: false,
37
+ mrtTheme: (theme) => ({
38
+ baseBackgroundColor: theme.palette.background.default, //change default background color
39
+ }),
40
+ muiTableBodyRowProps: { hover: false },
41
+ muiTableProps: {
42
+ sx: {
43
+ border: '1px solid rgba(81, 81, 81, .5)',
44
+ caption: {
45
+ captionSide: 'top',
46
+ },
47
+ },
48
+ },
49
+ muiTableHeadCellProps: {
50
+ sx: {
51
+ border: '1px solid rgba(81, 81, 81, .5)',
52
+ fontStyle: 'italic',
53
+ fontWeight: 'normal',
54
+ },
55
+ },
56
+ muiTableBodyCellProps: {
57
+ sx: {
58
+ border: '1px solid rgba(81, 81, 81, .5)',
59
+ },
60
+ },
61
+ renderCaption: ({ table }) => `Here is a table rendered with the lighter weight MRT_Table sub-component, rendering ${table.getRowModel().rows.length} rows.`,
62
+ });
63
+ //using MRT_Table instead of MaterialReactTable if we do not need any of the toolbar components or features
64
+ return <MRT_Table table={table}/>;
65
+ };
66
+ export default Example;
@@ -0,0 +1,109 @@
1
+ import { useMemo } from 'react';
2
+ import { MaterialReactTable } from 'material-react-table';
3
+ import { createTheme, ThemeProvider, useTheme } from '@mui/material';
4
+ //column definitions...
5
+ const columns = [
6
+ {
7
+ accessorKey: 'firstName',
8
+ header: 'First Name',
9
+ },
10
+ {
11
+ accessorKey: 'lastName',
12
+ header: 'Last Name',
13
+ },
14
+ {
15
+ accessorKey: 'address',
16
+ header: 'Address',
17
+ },
18
+ {
19
+ accessorKey: 'city',
20
+ header: 'City',
21
+ },
22
+ {
23
+ accessorKey: 'state',
24
+ header: 'State',
25
+ },
26
+ ];
27
+ //end
28
+ //data definitions...
29
+ const data = [
30
+ {
31
+ firstName: 'Dylan',
32
+ lastName: 'Murray',
33
+ address: '261 Erdman Ford',
34
+ city: 'East Daphne',
35
+ state: 'Kentucky',
36
+ },
37
+ {
38
+ firstName: 'Raquel',
39
+ lastName: 'Kohler',
40
+ address: '769 Dominic Grove',
41
+ city: 'Columbus',
42
+ state: 'Ohio',
43
+ },
44
+ {
45
+ firstName: 'Ervin',
46
+ lastName: 'Reinger',
47
+ address: '566 Brakus Inlet',
48
+ city: 'South Linda',
49
+ state: 'West Virginia',
50
+ },
51
+ {
52
+ firstName: 'Brittany',
53
+ lastName: 'McCullough',
54
+ address: '722 Emie Stream',
55
+ city: 'Lincoln',
56
+ state: 'Nebraska',
57
+ },
58
+ {
59
+ firstName: 'Branson',
60
+ lastName: 'Frami',
61
+ address: '32188 Larkin Turnpike',
62
+ city: 'Charleston',
63
+ state: 'South Carolina',
64
+ },
65
+ ];
66
+ //end
67
+ const Example = () => {
68
+ const globalTheme = useTheme(); //(optional) if you already have a theme defined in your app root, you can import here
69
+ const tableTheme = useMemo(() => createTheme({
70
+ palette: {
71
+ mode: globalTheme.palette.mode, //let's use the same dark/light mode as the global theme
72
+ primary: globalTheme.palette.secondary, //swap in the secondary color as the primary for the table
73
+ info: {
74
+ main: 'rgb(255,122,0)', //add in a custom color for the toolbar alert background stuff
75
+ },
76
+ background: {
77
+ default: globalTheme.palette.mode === 'light'
78
+ ? 'rgb(254,255,244)' //random light yellow color for the background in light mode
79
+ : '#000', //pure black table in dark mode for fun
80
+ },
81
+ },
82
+ typography: {
83
+ button: {
84
+ textTransform: 'none', //customize typography styles for all buttons in table by default
85
+ fontSize: '1.2rem',
86
+ },
87
+ },
88
+ components: {
89
+ MuiTooltip: {
90
+ styleOverrides: {
91
+ tooltip: {
92
+ fontSize: '1.1rem', //override to make tooltip font size larger
93
+ },
94
+ },
95
+ },
96
+ MuiSwitch: {
97
+ styleOverrides: {
98
+ thumb: {
99
+ color: 'pink', //change the color of the switch thumb in the columns show/hide menu to pink
100
+ },
101
+ },
102
+ },
103
+ },
104
+ }), [globalTheme]);
105
+ return (<ThemeProvider theme={tableTheme}>
106
+ <MaterialReactTable columns={columns} data={data} enableRowSelection enableColumnOrdering enableColumnPinning/>
107
+ </ThemeProvider>);
108
+ };
109
+ export default Example;
@@ -0,0 +1,48 @@
1
+ import { MaterialReactTable, useMaterialReactTable, } from 'material-react-table';
2
+ import { data } from './makeData';
3
+ import { Button } from '@mui/material';
4
+ const columns = [
5
+ {
6
+ accessorKey: 'firstName',
7
+ header: 'First Name',
8
+ sortDescFirst: false, //sort first name in ascending order by default on first sort click (default for non-numeric columns)
9
+ },
10
+ //column definitions...
11
+ {
12
+ accessorKey: 'lastName',
13
+ header: 'Last Name',
14
+ },
15
+ {
16
+ accessorKey: 'city',
17
+ header: 'City',
18
+ },
19
+ {
20
+ accessorKey: 'state',
21
+ header: 'State',
22
+ },
23
+ //end
24
+ {
25
+ accessorKey: 'salary',
26
+ header: 'Salary',
27
+ sortDescFirst: true, //sort salary in descending order by default on first sort click (default for numeric columns)
28
+ },
29
+ ];
30
+ const Example = () => {
31
+ const table = useMaterialReactTable({
32
+ columns,
33
+ data,
34
+ isMultiSortEvent: () => true, //now no need to hold `shift` key to multi-sort
35
+ maxMultiSortColCount: 3, //prevent more than 3 columns from being sorted at once
36
+ initialState: {
37
+ sorting: [
38
+ { id: 'state', desc: false }, //sort by state in ascending order by default
39
+ { id: 'city', desc: true }, //then sort by city in descending order by default
40
+ ],
41
+ },
42
+ renderTopToolbarCustomActions: ({ table }) => (<Button onClick={() => table.resetSorting(true)}>
43
+ Clear All Sorting
44
+ </Button>),
45
+ });
46
+ return <MaterialReactTable table={table}/>;
47
+ };
48
+ export default Example;
@@ -0,0 +1,126 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ import { Button } from '@mui/material';
3
+ import { MaterialReactTable, } from 'material-react-table';
4
+ import { data } from './makeData';
5
+ //column definitions...
6
+ const columns = [
7
+ {
8
+ accessorKey: 'firstName',
9
+ header: 'First Name',
10
+ },
11
+ {
12
+ accessorKey: 'lastName',
13
+ header: 'Last Name',
14
+ },
15
+ {
16
+ accessorKey: 'city',
17
+ header: 'City',
18
+ },
19
+ {
20
+ accessorKey: 'state',
21
+ header: 'State',
22
+ },
23
+ {
24
+ accessorKey: 'salary',
25
+ header: 'Salary',
26
+ },
27
+ ];
28
+ //end
29
+ const Example = () => {
30
+ const isFirstRender = useRef(true);
31
+ const [columnFilters, setColumnFilters] = useState([]);
32
+ const [columnVisibility, setColumnVisibility] = useState({});
33
+ const [density, setDensity] = useState('comfortable');
34
+ const [globalFilter, setGlobalFilter] = useState(undefined);
35
+ const [showGlobalFilter, setShowGlobalFilter] = useState(false);
36
+ const [showColumnFilters, setShowColumnFilters] = useState(false);
37
+ const [sorting, setSorting] = useState([]);
38
+ //load state from local storage
39
+ useEffect(() => {
40
+ const columnFilters = sessionStorage.getItem('mrt_columnFilters_table_1');
41
+ const columnVisibility = sessionStorage.getItem('mrt_columnVisibility_table_1');
42
+ const density = sessionStorage.getItem('mrt_density_table_1');
43
+ const globalFilter = sessionStorage.getItem('mrt_globalFilter_table_1');
44
+ const showGlobalFilter = sessionStorage.getItem('mrt_showGlobalFilter_table_1');
45
+ const showColumnFilters = sessionStorage.getItem('mrt_showColumnFilters_table_1');
46
+ const sorting = sessionStorage.getItem('mrt_sorting_table_1');
47
+ if (columnFilters) {
48
+ setColumnFilters(JSON.parse(columnFilters));
49
+ }
50
+ if (columnVisibility) {
51
+ setColumnVisibility(JSON.parse(columnVisibility));
52
+ }
53
+ if (density) {
54
+ setDensity(JSON.parse(density));
55
+ }
56
+ if (globalFilter) {
57
+ setGlobalFilter(JSON.parse(globalFilter) || undefined);
58
+ }
59
+ if (showGlobalFilter) {
60
+ setShowGlobalFilter(JSON.parse(showGlobalFilter));
61
+ }
62
+ if (showColumnFilters) {
63
+ setShowColumnFilters(JSON.parse(showColumnFilters));
64
+ }
65
+ if (sorting) {
66
+ setSorting(JSON.parse(sorting));
67
+ }
68
+ isFirstRender.current = false;
69
+ }, []);
70
+ //save states to local storage
71
+ useEffect(() => {
72
+ if (isFirstRender.current)
73
+ return;
74
+ sessionStorage.setItem('mrt_columnFilters_table_1', JSON.stringify(columnFilters));
75
+ }, [columnFilters]);
76
+ useEffect(() => {
77
+ if (isFirstRender.current)
78
+ return;
79
+ sessionStorage.setItem('mrt_columnVisibility_table_1', JSON.stringify(columnVisibility));
80
+ }, [columnVisibility]);
81
+ useEffect(() => {
82
+ if (isFirstRender.current)
83
+ return;
84
+ sessionStorage.setItem('mrt_density_table_1', JSON.stringify(density));
85
+ }, [density]);
86
+ useEffect(() => {
87
+ if (isFirstRender.current)
88
+ return;
89
+ sessionStorage.setItem('mrt_globalFilter_table_1', JSON.stringify(globalFilter ?? ''));
90
+ }, [globalFilter]);
91
+ useEffect(() => {
92
+ if (isFirstRender.current)
93
+ return;
94
+ sessionStorage.setItem('mrt_showGlobalFilter_table_1', JSON.stringify(showGlobalFilter));
95
+ }, [showGlobalFilter]);
96
+ useEffect(() => {
97
+ if (isFirstRender.current)
98
+ return;
99
+ sessionStorage.setItem('mrt_showColumnFilters_table_1', JSON.stringify(showColumnFilters));
100
+ }, [showColumnFilters]);
101
+ useEffect(() => {
102
+ if (isFirstRender.current)
103
+ return;
104
+ sessionStorage.setItem('mrt_sorting_table_1', JSON.stringify(sorting));
105
+ }, [sorting]);
106
+ const resetState = () => {
107
+ sessionStorage.removeItem('mrt_columnFilters_table_1');
108
+ sessionStorage.removeItem('mrt_columnVisibility_table_1');
109
+ sessionStorage.removeItem('mrt_density_table_1');
110
+ sessionStorage.removeItem('mrt_globalFilter_table_1');
111
+ sessionStorage.removeItem('mrt_showGlobalFilter_table_1');
112
+ sessionStorage.removeItem('mrt_showColumnFilters_table_1');
113
+ sessionStorage.removeItem('mrt_sorting_table_1');
114
+ window.location.reload();
115
+ };
116
+ return (<MaterialReactTable columns={columns} data={data} onColumnFiltersChange={setColumnFilters} onColumnVisibilityChange={setColumnVisibility} onDensityChange={setDensity} onGlobalFilterChange={setGlobalFilter} onShowColumnFiltersChange={setShowColumnFilters} onShowGlobalFilterChange={setShowGlobalFilter} onSortingChange={setSorting} state={{
117
+ columnFilters,
118
+ columnVisibility,
119
+ density,
120
+ globalFilter,
121
+ showColumnFilters,
122
+ showGlobalFilter,
123
+ sorting,
124
+ }} renderTopToolbarCustomActions={() => (<Button onClick={resetState}>Reset State</Button>)}/>);
125
+ };
126
+ export default Example;