@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,69 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { MaterialReactTable, useMaterialReactTable, } from 'material-react-table';
|
|
3
|
+
import { useTheme } from '@mui/material/styles';
|
|
4
|
+
import { LineChart } from '@mui/x-charts/LineChart';
|
|
5
|
+
import { data } from './makeData';
|
|
6
|
+
const Example = () => {
|
|
7
|
+
const theme = useTheme();
|
|
8
|
+
const columns = useMemo(
|
|
9
|
+
//column definitions...
|
|
10
|
+
() => [
|
|
11
|
+
{
|
|
12
|
+
accessorKey: 'id',
|
|
13
|
+
header: 'ID',
|
|
14
|
+
size: 50,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
accessorKey: 'firstName',
|
|
18
|
+
header: 'First Name',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
accessorKey: 'middleName',
|
|
22
|
+
header: 'Middle Name',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
accessorKey: 'lastName',
|
|
26
|
+
header: 'Last Name',
|
|
27
|
+
},
|
|
28
|
+
], []);
|
|
29
|
+
const table = useMaterialReactTable({
|
|
30
|
+
columns,
|
|
31
|
+
data,
|
|
32
|
+
initialState: { expanded: { 0: true } },
|
|
33
|
+
muiTableBodyRowProps: {
|
|
34
|
+
sx: {
|
|
35
|
+
'.Mui-TableBodyCell-DetailPanel': {
|
|
36
|
+
backgroundColor: theme.palette.mode === 'dark'
|
|
37
|
+
? theme.palette.grey[900]
|
|
38
|
+
: theme.palette.grey[100],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
renderDetailPanel: ({ row }) => (<LineChart xAxis={[
|
|
43
|
+
{
|
|
44
|
+
data: row.original.gamesPlayed,
|
|
45
|
+
label: 'Games Played',
|
|
46
|
+
valueFormatter: (value) => `#${value}`,
|
|
47
|
+
tickLabelInterval: (value) => value % 1 === 0,
|
|
48
|
+
},
|
|
49
|
+
]} yAxis={[{ min: 0, max: 60 }]} series={[
|
|
50
|
+
{
|
|
51
|
+
color: theme.palette.primary.dark,
|
|
52
|
+
data: row.original.points,
|
|
53
|
+
label: 'Points',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
color: theme.palette.secondary.main,
|
|
57
|
+
data: row.original.assists,
|
|
58
|
+
label: 'Assists',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
color: theme.palette.error.main,
|
|
62
|
+
data: row.original.turnovers,
|
|
63
|
+
label: 'Turnovers',
|
|
64
|
+
},
|
|
65
|
+
]} height={250}/>),
|
|
66
|
+
});
|
|
67
|
+
return <MaterialReactTable table={table}/>;
|
|
68
|
+
};
|
|
69
|
+
export default Example;
|
|
@@ -0,0 +1,34 @@
|
|
|
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: 'id',
|
|
10
|
+
header: 'ID',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
accessorKey: 'firstName',
|
|
14
|
+
header: 'First Name',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
accessorKey: 'lastName',
|
|
18
|
+
header: 'Last Name',
|
|
19
|
+
},
|
|
20
|
+
], []);
|
|
21
|
+
const table = useMaterialReactTable({
|
|
22
|
+
columns,
|
|
23
|
+
data,
|
|
24
|
+
muiTableHeadCellProps: {
|
|
25
|
+
sx: {
|
|
26
|
+
'& .Mui-TableHeadCell-Content': {
|
|
27
|
+
justifyContent: 'space-between',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
return <MaterialReactTable table={table}/>;
|
|
33
|
+
};
|
|
34
|
+
export default Example;
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
{
|
|
7
|
+
accessorKey: 'firstName',
|
|
8
|
+
header: 'First Name',
|
|
9
|
+
size: 100,
|
|
10
|
+
muiTableHeadCellProps: {
|
|
11
|
+
align: 'center',
|
|
12
|
+
},
|
|
13
|
+
muiTableBodyCellProps: {
|
|
14
|
+
align: 'center',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
accessorKey: 'lastName',
|
|
19
|
+
header: 'Last Name',
|
|
20
|
+
size: 100,
|
|
21
|
+
muiTableHeadCellProps: {
|
|
22
|
+
align: 'center',
|
|
23
|
+
},
|
|
24
|
+
muiTableBodyCellProps: {
|
|
25
|
+
align: 'center',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
accessorKey: 'age',
|
|
30
|
+
header: 'Age',
|
|
31
|
+
muiTableHeadCellProps: {
|
|
32
|
+
align: 'right',
|
|
33
|
+
},
|
|
34
|
+
muiTableBodyCellProps: {
|
|
35
|
+
align: 'right',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
accessorKey: 'salary',
|
|
40
|
+
header: 'Salary',
|
|
41
|
+
muiTableHeadCellProps: {
|
|
42
|
+
align: 'right',
|
|
43
|
+
},
|
|
44
|
+
muiTableBodyCellProps: {
|
|
45
|
+
align: 'right',
|
|
46
|
+
},
|
|
47
|
+
Cell: ({ cell }) => cell
|
|
48
|
+
.getValue()
|
|
49
|
+
.toLocaleString('en-US', { style: 'currency', currency: 'USD' }),
|
|
50
|
+
},
|
|
51
|
+
], []);
|
|
52
|
+
const table = useMaterialReactTable({
|
|
53
|
+
columns,
|
|
54
|
+
data,
|
|
55
|
+
});
|
|
56
|
+
return <MaterialReactTable table={table}/>;
|
|
57
|
+
};
|
|
58
|
+
export default Example;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { MaterialReactTable, useMaterialReactTable, } from 'material-react-table';
|
|
3
|
+
import { Divider, MenuItem } from '@mui/material';
|
|
4
|
+
import { data } from './makeData';
|
|
5
|
+
const Example = () => {
|
|
6
|
+
const columns = useMemo(() => [
|
|
7
|
+
{
|
|
8
|
+
accessorKey: 'id',
|
|
9
|
+
header: 'ID',
|
|
10
|
+
renderColumnActionsMenuItems: ({ closeMenu }) => [
|
|
11
|
+
<MenuItem key={1} onClick={() => {
|
|
12
|
+
console.log('Item 1 clicked');
|
|
13
|
+
closeMenu();
|
|
14
|
+
}}>
|
|
15
|
+
Item 1
|
|
16
|
+
</MenuItem>,
|
|
17
|
+
<MenuItem key={2} onClick={() => {
|
|
18
|
+
console.log('Item 2 clicked');
|
|
19
|
+
closeMenu();
|
|
20
|
+
}}>
|
|
21
|
+
Item 2
|
|
22
|
+
</MenuItem>,
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
accessorKey: 'firstName',
|
|
27
|
+
header: 'First Name',
|
|
28
|
+
renderColumnActionsMenuItems: ({ closeMenu, internalColumnMenuItems, }) => [
|
|
29
|
+
...internalColumnMenuItems,
|
|
30
|
+
<Divider key="divider-1"/>,
|
|
31
|
+
<MenuItem key={'item-1'} onClick={() => {
|
|
32
|
+
console.log('Item 1 clicked');
|
|
33
|
+
closeMenu();
|
|
34
|
+
}}>
|
|
35
|
+
Item 1
|
|
36
|
+
</MenuItem>,
|
|
37
|
+
<MenuItem key={'item-2'} onClick={() => {
|
|
38
|
+
console.log('Item 2 clicked');
|
|
39
|
+
closeMenu();
|
|
40
|
+
}}>
|
|
41
|
+
Item 2
|
|
42
|
+
</MenuItem>,
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
accessorKey: 'lastName',
|
|
47
|
+
header: 'Last Name',
|
|
48
|
+
renderColumnActionsMenuItems: ({ closeMenu, internalColumnMenuItems, }) => [
|
|
49
|
+
<MenuItem key={'item-1'} onClick={() => {
|
|
50
|
+
console.log('Item 1 clicked');
|
|
51
|
+
closeMenu();
|
|
52
|
+
}}>
|
|
53
|
+
Item 1
|
|
54
|
+
</MenuItem>,
|
|
55
|
+
<MenuItem key={'item-2'} onClick={() => {
|
|
56
|
+
console.log('Item 2 clicked');
|
|
57
|
+
closeMenu();
|
|
58
|
+
}}>
|
|
59
|
+
Item 2
|
|
60
|
+
</MenuItem>,
|
|
61
|
+
<Divider key="divider-1"/>,
|
|
62
|
+
...internalColumnMenuItems.splice(0, 3),
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
], []);
|
|
66
|
+
const table = useMaterialReactTable({
|
|
67
|
+
columns,
|
|
68
|
+
data,
|
|
69
|
+
//or you could define the menu items here for all columns
|
|
70
|
+
// renderColumnActionsMenuItems: ({ closeMenu }) => [],
|
|
71
|
+
});
|
|
72
|
+
return <MaterialReactTable table={table}/>;
|
|
73
|
+
};
|
|
74
|
+
export default Example;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useMaterialReactTable, MRT_TableContainer, MRT_TableHeadCellFilterContainer, } from 'material-react-table';
|
|
3
|
+
import { data } from './makeData';
|
|
4
|
+
import { Paper, Stack, useMediaQuery } from '@mui/material';
|
|
5
|
+
const Example = () => {
|
|
6
|
+
const isMobile = useMediaQuery('(max-width: 1000px)');
|
|
7
|
+
const columns = useMemo(() => [
|
|
8
|
+
{
|
|
9
|
+
accessorKey: 'id',
|
|
10
|
+
header: 'ID',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
accessorKey: 'firstName',
|
|
14
|
+
header: 'First Name',
|
|
15
|
+
filterVariant: 'autocomplete',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
accessorKey: 'lastName',
|
|
19
|
+
header: 'Last Name',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
accessorKey: 'gender',
|
|
23
|
+
header: 'Gender',
|
|
24
|
+
filterFn: 'equals',
|
|
25
|
+
filterSelectOptions: ['Male', 'Female', 'Other'],
|
|
26
|
+
filterVariant: 'select',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
accessorKey: 'age',
|
|
30
|
+
header: 'Age',
|
|
31
|
+
filterVariant: 'range',
|
|
32
|
+
},
|
|
33
|
+
], []);
|
|
34
|
+
const table = useMaterialReactTable({
|
|
35
|
+
columns,
|
|
36
|
+
data,
|
|
37
|
+
columnFilterDisplayMode: 'custom', //we will render our own filtering UI
|
|
38
|
+
enableFacetedValues: true,
|
|
39
|
+
muiFilterTextFieldProps: ({ column }) => ({
|
|
40
|
+
label: `Filter by ${column.columnDef.header}`,
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
return (<Stack direction={isMobile ? 'column-reverse' : 'row'} sx={{
|
|
44
|
+
gap: '8px',
|
|
45
|
+
}}>
|
|
46
|
+
<MRT_TableContainer table={table}/>
|
|
47
|
+
<Paper>
|
|
48
|
+
<Stack sx={{
|
|
49
|
+
p: '8px',
|
|
50
|
+
gap: '8px',
|
|
51
|
+
}}>
|
|
52
|
+
{table
|
|
53
|
+
.getLeafHeaders()
|
|
54
|
+
.map((header) => header.column.getCanFilter() && (<MRT_TableHeadCellFilterContainer key={header.id} header={header} table={table} in/>))}
|
|
55
|
+
</Stack>
|
|
56
|
+
</Paper>
|
|
57
|
+
</Stack>);
|
|
58
|
+
};
|
|
59
|
+
export default Example;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { MRT_GlobalFilterTextField, MRT_TableBodyCellValue, MRT_TablePagination, MRT_ToolbarAlertBanner, flexRender, useMaterialReactTable, } from 'material-react-table';
|
|
2
|
+
import { Box, Stack, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Typography, } from '@mui/material';
|
|
3
|
+
import { data } from './makeData';
|
|
4
|
+
const columns = [
|
|
5
|
+
{
|
|
6
|
+
accessorKey: 'name.firstName',
|
|
7
|
+
header: 'First Name',
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
accessorKey: 'name.lastName',
|
|
11
|
+
header: 'Last Name',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
accessorKey: 'address',
|
|
15
|
+
header: 'Address',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
accessorKey: 'city',
|
|
19
|
+
header: 'City',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
accessorKey: 'state',
|
|
23
|
+
header: 'State',
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
const Example = () => {
|
|
27
|
+
const table = useMaterialReactTable({
|
|
28
|
+
columns,
|
|
29
|
+
data, //must be memoized or stable (useState, useMemo, defined outside of this component, etc.)
|
|
30
|
+
//MRT display columns can still work, optionally override cell renders with `displayColumnDefOptions`
|
|
31
|
+
enableRowSelection: true,
|
|
32
|
+
initialState: {
|
|
33
|
+
pagination: { pageSize: 5, pageIndex: 0 },
|
|
34
|
+
showGlobalFilter: true,
|
|
35
|
+
},
|
|
36
|
+
//customize the MRT components
|
|
37
|
+
muiPaginationProps: {
|
|
38
|
+
rowsPerPageOptions: [5, 10, 15],
|
|
39
|
+
variant: 'outlined',
|
|
40
|
+
},
|
|
41
|
+
paginationDisplayMode: 'pages',
|
|
42
|
+
});
|
|
43
|
+
return (<Stack sx={{ m: '2rem 0' }}>
|
|
44
|
+
<Typography variant="h4">My Custom Headless Table</Typography>
|
|
45
|
+
<Box sx={{
|
|
46
|
+
display: 'flex',
|
|
47
|
+
justifyContent: 'space-between',
|
|
48
|
+
alignItems: 'center',
|
|
49
|
+
}}>
|
|
50
|
+
{/**
|
|
51
|
+
* Use MRT components along side your own markup.
|
|
52
|
+
* They just need the `table` instance passed as a prop to work!
|
|
53
|
+
*/}
|
|
54
|
+
<MRT_GlobalFilterTextField table={table}/>
|
|
55
|
+
<MRT_TablePagination table={table}/>
|
|
56
|
+
</Box>
|
|
57
|
+
{/* Using Vanilla Material-UI Table components here */}
|
|
58
|
+
<TableContainer>
|
|
59
|
+
<Table>
|
|
60
|
+
{/* Use your own markup, customize however you want using the power of TanStack Table */}
|
|
61
|
+
<TableHead>
|
|
62
|
+
{table.getHeaderGroups().map((headerGroup) => (<TableRow key={headerGroup.id}>
|
|
63
|
+
{headerGroup.headers.map((header) => (<TableCell align="center" variant="head" key={header.id}>
|
|
64
|
+
{header.isPlaceholder
|
|
65
|
+
? null
|
|
66
|
+
: flexRender(header.column.columnDef.Header ??
|
|
67
|
+
header.column.columnDef.header, header.getContext())}
|
|
68
|
+
</TableCell>))}
|
|
69
|
+
</TableRow>))}
|
|
70
|
+
</TableHead>
|
|
71
|
+
<TableBody>
|
|
72
|
+
{table.getRowModel().rows.map((row, rowIndex) => (<TableRow key={row.id} selected={row.getIsSelected()}>
|
|
73
|
+
{row.getVisibleCells().map((cell, _columnIndex) => (<TableCell align="center" variant="body" key={cell.id}>
|
|
74
|
+
{/* Use MRT's cell renderer that provides better logic than flexRender */}
|
|
75
|
+
<MRT_TableBodyCellValue cell={cell} table={table} staticRowIndex={rowIndex} //just for batch row selection to work
|
|
76
|
+
/>
|
|
77
|
+
</TableCell>))}
|
|
78
|
+
</TableRow>))}
|
|
79
|
+
</TableBody>
|
|
80
|
+
</Table>
|
|
81
|
+
</TableContainer>
|
|
82
|
+
<MRT_ToolbarAlertBanner stackAlertBanner table={table}/>
|
|
83
|
+
</Stack>);
|
|
84
|
+
};
|
|
85
|
+
export default Example;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { MaterialReactTable, MRT_ToggleDensePaddingButton, MRT_ToggleFullScreenButton, useMaterialReactTable, } from 'material-react-table';
|
|
3
|
+
import { Box, Button, IconButton } from '@mui/material';
|
|
4
|
+
import PrintIcon from '@mui/icons-material/Print';
|
|
5
|
+
import { data } from './makeData';
|
|
6
|
+
const Example = () => {
|
|
7
|
+
const columns = useMemo(
|
|
8
|
+
//column definitions...
|
|
9
|
+
() => [
|
|
10
|
+
{
|
|
11
|
+
accessorKey: 'firstName',
|
|
12
|
+
header: 'First Name',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
accessorKey: 'lastName',
|
|
16
|
+
header: 'Last Name',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
accessorKey: 'age',
|
|
20
|
+
header: 'Age',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
accessorKey: 'salary',
|
|
24
|
+
header: 'Salary',
|
|
25
|
+
},
|
|
26
|
+
], []);
|
|
27
|
+
const table = useMaterialReactTable({
|
|
28
|
+
columns,
|
|
29
|
+
data,
|
|
30
|
+
enableRowSelection: true,
|
|
31
|
+
positionToolbarAlertBanner: 'bottom', //show selected rows count on bottom toolbar
|
|
32
|
+
//add custom action buttons to top-left of top toolbar
|
|
33
|
+
renderTopToolbarCustomActions: ({ table }) => (<Box sx={{ display: 'flex', gap: '1rem', p: '4px' }}>
|
|
34
|
+
<Button color="secondary" onClick={() => {
|
|
35
|
+
alert('Create New Account');
|
|
36
|
+
}} variant="contained">
|
|
37
|
+
Create Account
|
|
38
|
+
</Button>
|
|
39
|
+
<Button color="error" disabled={!table.getIsSomeRowsSelected()} onClick={() => {
|
|
40
|
+
alert('Delete Selected Accounts');
|
|
41
|
+
}} variant="contained">
|
|
42
|
+
Delete Selected Accounts
|
|
43
|
+
</Button>
|
|
44
|
+
</Box>),
|
|
45
|
+
//customize built-in buttons in the top-right of top toolbar
|
|
46
|
+
renderToolbarInternalActions: ({ table }) => (<Box>
|
|
47
|
+
{/* add custom button to print table */}
|
|
48
|
+
<IconButton onClick={() => {
|
|
49
|
+
window.print();
|
|
50
|
+
}}>
|
|
51
|
+
<PrintIcon />
|
|
52
|
+
</IconButton>
|
|
53
|
+
{/* along-side built-in buttons in whatever order you want them */}
|
|
54
|
+
<MRT_ToggleDensePaddingButton table={table}/>
|
|
55
|
+
<MRT_ToggleFullScreenButton table={table}/>
|
|
56
|
+
</Box>),
|
|
57
|
+
});
|
|
58
|
+
return <MaterialReactTable table={table}/>;
|
|
59
|
+
};
|
|
60
|
+
export default Example;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { Box, Button } from '@mui/material';
|
|
3
|
+
import { MaterialReactTable, useMaterialReactTable, } from 'material-react-table';
|
|
4
|
+
import { data } from './makeData';
|
|
5
|
+
const Example = () => {
|
|
6
|
+
const columns = useMemo(
|
|
7
|
+
//column definitions...
|
|
8
|
+
() => [
|
|
9
|
+
{
|
|
10
|
+
accessorKey: 'firstName',
|
|
11
|
+
header: 'First Name',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
accessorKey: 'lastName',
|
|
15
|
+
header: 'Last Name',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
accessorKey: 'address',
|
|
19
|
+
header: 'Address',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
accessorKey: 'city',
|
|
23
|
+
header: 'City',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
accessorKey: 'state',
|
|
27
|
+
header: 'State',
|
|
28
|
+
},
|
|
29
|
+
], []);
|
|
30
|
+
const table = useMaterialReactTable({
|
|
31
|
+
columns,
|
|
32
|
+
data,
|
|
33
|
+
defaultDisplayColumn: {
|
|
34
|
+
enableResizing: true, //turn on some features that are usually off for all display columns
|
|
35
|
+
},
|
|
36
|
+
displayColumnDefOptions: {
|
|
37
|
+
'mrt-row-actions': {
|
|
38
|
+
size: 350, //set custom width
|
|
39
|
+
muiTableHeadCellProps: {
|
|
40
|
+
align: 'center', //change head cell props
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
'mrt-row-numbers': {
|
|
44
|
+
enableColumnDragging: true,
|
|
45
|
+
enableColumnOrdering: true, //turn on some features that are usually off
|
|
46
|
+
enableResizing: true,
|
|
47
|
+
muiTableHeadCellProps: {
|
|
48
|
+
sx: {
|
|
49
|
+
fontSize: '1.2rem',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
'mrt-row-select': {
|
|
54
|
+
enableColumnActions: true,
|
|
55
|
+
enableHiding: true,
|
|
56
|
+
size: 100,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
enableColumnResizing: true,
|
|
60
|
+
enableColumnOrdering: true,
|
|
61
|
+
enableRowNumbers: true,
|
|
62
|
+
enableRowSelection: true,
|
|
63
|
+
enableRowActions: true,
|
|
64
|
+
renderRowActions: ({ row }) => (<Box sx={{ display: 'flex', gap: '1rem' }}>
|
|
65
|
+
<Button>Button 1</Button>
|
|
66
|
+
<Button>Button 2</Button>
|
|
67
|
+
<Button>Button 3</Button>
|
|
68
|
+
</Box>),
|
|
69
|
+
});
|
|
70
|
+
return <MaterialReactTable table={table}/>;
|
|
71
|
+
};
|
|
72
|
+
export default Example;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { MaterialReactTable, useMaterialReactTable, } from 'material-react-table';
|
|
3
|
+
const Example = () => {
|
|
4
|
+
const columns = useMemo(() => [
|
|
5
|
+
{
|
|
6
|
+
accessorKey: 'id',
|
|
7
|
+
header: 'ID',
|
|
8
|
+
muiFilterTextFieldProps: { placeholder: 'ID' },
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
accessorKey: 'firstName',
|
|
12
|
+
header: 'First Name',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
accessorKey: 'lastName',
|
|
16
|
+
header: 'Last Name',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
accessorKey: 'gender',
|
|
20
|
+
header: 'Gender',
|
|
21
|
+
filterFn: 'equals',
|
|
22
|
+
filterSelectOptions: [
|
|
23
|
+
{ label: 'Male', value: 'Male' },
|
|
24
|
+
{ label: 'Female', value: 'Female' },
|
|
25
|
+
{ label: 'Other', value: 'Other' },
|
|
26
|
+
],
|
|
27
|
+
filterVariant: 'select',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
accessorKey: 'age',
|
|
31
|
+
header: 'Age',
|
|
32
|
+
filterVariant: 'range',
|
|
33
|
+
},
|
|
34
|
+
], []);
|
|
35
|
+
const data = useMemo(
|
|
36
|
+
//data definitions...
|
|
37
|
+
() => [
|
|
38
|
+
{
|
|
39
|
+
id: 1,
|
|
40
|
+
firstName: 'Hugh',
|
|
41
|
+
lastName: 'Mungus',
|
|
42
|
+
gender: 'Male',
|
|
43
|
+
age: 42,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: 2,
|
|
47
|
+
firstName: 'Leroy',
|
|
48
|
+
lastName: 'Jenkins',
|
|
49
|
+
gender: 'Male',
|
|
50
|
+
age: 51,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: 3,
|
|
54
|
+
firstName: 'Candice',
|
|
55
|
+
lastName: 'Nutella',
|
|
56
|
+
gender: 'Female',
|
|
57
|
+
age: 27,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: 4,
|
|
61
|
+
firstName: 'Micah',
|
|
62
|
+
lastName: 'Johnson',
|
|
63
|
+
gender: 'Other',
|
|
64
|
+
age: 32,
|
|
65
|
+
},
|
|
66
|
+
], []);
|
|
67
|
+
const table = useMaterialReactTable({
|
|
68
|
+
columns,
|
|
69
|
+
data,
|
|
70
|
+
initialState: { showColumnFilters: true },
|
|
71
|
+
muiFilterTextFieldProps: {
|
|
72
|
+
sx: { m: '0.5rem 0', width: '100%' },
|
|
73
|
+
variant: 'outlined',
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
return <MaterialReactTable table={table}/>;
|
|
77
|
+
};
|
|
78
|
+
export default Example;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { MaterialReactTable, useMaterialReactTable, } from 'material-react-table';
|
|
3
|
+
import { MenuItem } from '@mui/material';
|
|
4
|
+
import { data } from './makeData';
|
|
5
|
+
const Example = () => {
|
|
6
|
+
const columns = useMemo(() => [
|
|
7
|
+
{
|
|
8
|
+
accessorKey: 'id',
|
|
9
|
+
enableColumnFilterModes: false, //disable changing filter mode for this column
|
|
10
|
+
filterFn: 'equals', //set filter mode to equals
|
|
11
|
+
header: 'ID',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
accessorKey: 'firstName', //normal, all filter modes are enabled
|
|
15
|
+
header: 'First Name',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
accessorKey: 'middleName',
|
|
19
|
+
enableColumnFilterModes: false, //disable changing filter mode for this column
|
|
20
|
+
filterFn: 'startsWith', //even though changing the mode is disabled, you can still set the default filter mode
|
|
21
|
+
header: 'Middle Name',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
accessorKey: 'lastName',
|
|
25
|
+
header: 'Last Name',
|
|
26
|
+
//if you do not want to use the default filter modes, you can provide your own and render your own menu
|
|
27
|
+
renderColumnFilterModeMenuItems: ({ onSelectFilterMode }) => [
|
|
28
|
+
<MenuItem key="0" onClick={() => onSelectFilterMode('contains')}>
|
|
29
|
+
<div>Contains</div>
|
|
30
|
+
</MenuItem>,
|
|
31
|
+
<MenuItem key="1" onClick={() => onSelectFilterMode('customFilterFn')}>
|
|
32
|
+
<div>Custom Filter Fn</div>
|
|
33
|
+
</MenuItem>,
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
accessorKey: 'age',
|
|
38
|
+
columnFilterModeOptions: ['between', 'greaterThan', 'lessThan'], //only allow these filter modes
|
|
39
|
+
filterFn: 'between',
|
|
40
|
+
header: 'Age',
|
|
41
|
+
},
|
|
42
|
+
], []);
|
|
43
|
+
const table = useMaterialReactTable({
|
|
44
|
+
columns,
|
|
45
|
+
data,
|
|
46
|
+
enableColumnFilterModes: true, //enable changing filter mode for all columns unless explicitly disabled in a column def
|
|
47
|
+
initialState: { showColumnFilters: true }, //show filters by default
|
|
48
|
+
filterFns: {
|
|
49
|
+
customFilterFn: (row, id, filterValue) => {
|
|
50
|
+
return row.getValue(id) === filterValue;
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
localization: {
|
|
54
|
+
filterCustomFilterFn: 'Custom Filter Fn',
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
return <MaterialReactTable table={table}/>;
|
|
58
|
+
};
|
|
59
|
+
export default Example;
|