material-react-table 0.3.0 → 0.3.4
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 +32 -162
- package/dist/MaterialReactTable.d.ts +52 -45
- package/dist/body/MRT_TableBodyRow.d.ts +16 -1
- package/dist/buttons/MRT_EditActionButtons.d.ts +7 -0
- package/dist/buttons/MRT_ToggleFiltersButton.d.ts +4 -0
- package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +7 -0
- package/dist/buttons/MRT_ToggleSearchButton.d.ts +4 -0
- package/dist/head/MRT_TableHeadCell.d.ts +4 -0
- package/dist/index.d.ts +2 -2
- package/dist/inputs/MRT_DensePaddingSwitch.d.ts +5 -0
- package/dist/inputs/MRT_EditCellTextField.d.ts +7 -0
- package/dist/inputs/MRT_FilterTextField.d.ts +1 -1
- package/dist/material-react-table.cjs.development.js +1732 -466
- package/dist/material-react-table.cjs.development.js.map +1 -1
- package/dist/material-react-table.cjs.production.min.js +1 -1
- package/dist/material-react-table.cjs.production.min.js.map +1 -1
- package/dist/material-react-table.esm.js +1743 -477
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ColumnActionMenu.d.ts +2 -2
- package/dist/menus/MRT_RowActionMenu.d.ts +10 -0
- package/dist/table/MRT_TableButtonCell.d.ts +3 -0
- package/dist/{footer → toolbar}/MRT_TablePagination.d.ts +0 -0
- package/dist/toolbar/MRT_ToolbarBottom.d.ts +5 -0
- package/dist/toolbar/MRT_ToolbarButtons.d.ts +5 -0
- package/dist/toolbar/{MRT_Toolbar.d.ts → MRT_ToolbarTop.d.ts} +1 -1
- package/dist/useMaterialReactTable.d.ts +10 -2
- package/dist/utils/localization.d.ts +25 -14
- package/dist/utils/useMRTCalcs.d.ts +1 -1
- package/package.json +26 -21
- package/src/@types/faker.d.ts +4 -0
- package/src/@types/react-table-config.d.ts +131 -0
- package/src/MaterialReactTable.tsx +92 -101
- package/src/body/MRT_TableBody.tsx +17 -40
- package/src/body/MRT_TableBodyCell.tsx +36 -11
- package/src/body/MRT_TableBodyRow.tsx +35 -26
- package/src/body/MRT_TableDetailPanel.tsx +41 -15
- package/src/buttons/MRT_EditActionButtons.tsx +49 -0
- package/src/buttons/MRT_ExpandAllButton.tsx +15 -19
- package/src/buttons/MRT_ExpandButton.tsx +23 -21
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +14 -21
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +5 -9
- package/src/buttons/MRT_ToggleFiltersButton.tsx +23 -0
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +83 -0
- package/src/buttons/MRT_ToggleSearchButton.tsx +29 -0
- package/src/footer/MRT_TableFooter.tsx +4 -22
- package/src/footer/MRT_TableFooterCell.tsx +35 -10
- package/src/footer/MRT_TableFooterRow.tsx +24 -16
- package/src/head/MRT_TableHead.tsx +6 -23
- package/src/head/MRT_TableHeadCell.tsx +65 -28
- package/src/head/MRT_TableHeadRow.tsx +44 -17
- package/src/index.tsx +2 -5
- package/src/inputs/MRT_DensePaddingSwitch.tsx +23 -0
- package/src/inputs/MRT_EditCellTextField.tsx +64 -0
- package/src/inputs/MRT_FilterTextField.tsx +42 -15
- package/src/inputs/MRT_SearchTextField.tsx +40 -43
- package/src/inputs/MRT_SelectAllCheckbox.tsx +9 -6
- package/src/inputs/MRT_SelectCheckbox.tsx +9 -5
- package/src/menus/MRT_ColumnActionMenu.tsx +69 -48
- package/src/menus/MRT_RowActionMenu.tsx +33 -0
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +2 -2
- package/src/table/MRT_Table.tsx +13 -5
- package/src/table/MRT_TableButtonCell.tsx +9 -0
- package/src/table/MRT_TableContainer.tsx +32 -5
- package/src/table/MRT_TableSpacerCell.tsx +15 -1
- package/src/toolbar/MRT_TablePagination.tsx +34 -0
- package/src/toolbar/MRT_ToolbarBottom.tsx +41 -0
- package/src/toolbar/MRT_ToolbarButtons.tsx +29 -0
- package/src/toolbar/MRT_ToolbarTop.tsx +59 -0
- package/src/useMaterialReactTable.tsx +40 -44
- package/src/utils/localization.ts +42 -20
- package/src/utils/useMRTCalcs.tsx +1 -3
- package/dist/utils/overrideWarnings.d.ts +0 -1
- package/src/footer/MRT_TablePagination.tsx +0 -42
- package/src/toolbar/MRT_Toolbar.tsx +0 -39
- package/src/utils/overrideWarnings.ts +0 -41
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { ChangeEvent, FC, useState } from 'react';
|
|
2
2
|
import {
|
|
3
|
+
Collapse,
|
|
3
4
|
IconButton,
|
|
4
5
|
InputAdornment,
|
|
5
6
|
styled,
|
|
@@ -17,22 +18,15 @@ const TextField = styled(MuiTextField)({
|
|
|
17
18
|
interface Props {}
|
|
18
19
|
|
|
19
20
|
export const MRT_SearchTextField: FC<Props> = () => {
|
|
20
|
-
const {
|
|
21
|
-
|
|
22
|
-
tableSearchTextfieldProps,
|
|
23
|
-
localization,
|
|
24
|
-
onSearchChange,
|
|
25
|
-
} = useMaterialReactTable();
|
|
21
|
+
const { showSearch, localization, muiSearchTextFieldProps, onGlobalFilterChange, tableInstance } =
|
|
22
|
+
useMaterialReactTable();
|
|
26
23
|
|
|
27
24
|
const [searchValue, setSearchValue] = useState('');
|
|
28
25
|
|
|
29
|
-
const handleChange = useAsyncDebounce(
|
|
30
|
-
(event
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},
|
|
34
|
-
200,
|
|
35
|
-
);
|
|
26
|
+
const handleChange = useAsyncDebounce((event: ChangeEvent<HTMLInputElement>) => {
|
|
27
|
+
tableInstance.setGlobalFilter(event.target.value ?? undefined);
|
|
28
|
+
onGlobalFilterChange?.(event);
|
|
29
|
+
}, 200);
|
|
36
30
|
|
|
37
31
|
const handleClear = () => {
|
|
38
32
|
setSearchValue('');
|
|
@@ -40,35 +34,38 @@ export const MRT_SearchTextField: FC<Props> = () => {
|
|
|
40
34
|
};
|
|
41
35
|
|
|
42
36
|
return (
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
37
|
+
<Collapse in={showSearch} orientation="horizontal">
|
|
38
|
+
<TextField
|
|
39
|
+
id="global-search-text-field"
|
|
40
|
+
placeholder={localization?.searchTextFieldPlaceholder}
|
|
41
|
+
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
42
|
+
setSearchValue(event.target.value);
|
|
43
|
+
handleChange(event);
|
|
44
|
+
}}
|
|
45
|
+
value={searchValue ?? ''}
|
|
46
|
+
variant="standard"
|
|
47
|
+
InputProps={{
|
|
48
|
+
startAdornment: (
|
|
49
|
+
<InputAdornment position="start">
|
|
50
|
+
<SearchIcon fontSize="small" />
|
|
51
|
+
</InputAdornment>
|
|
52
|
+
),
|
|
53
|
+
endAdornment: (
|
|
54
|
+
<InputAdornment position="end">
|
|
55
|
+
<IconButton
|
|
56
|
+
aria-label={localization?.searchTextFieldClearButtonTitle}
|
|
57
|
+
disabled={searchValue?.length === 0}
|
|
58
|
+
onClick={handleClear}
|
|
59
|
+
size="small"
|
|
60
|
+
title={localization?.searchTextFieldClearButtonTitle}
|
|
61
|
+
>
|
|
62
|
+
<CloseIcon fontSize="small" />
|
|
63
|
+
</IconButton>
|
|
64
|
+
</InputAdornment>
|
|
65
|
+
),
|
|
66
|
+
}}
|
|
67
|
+
{...muiSearchTextFieldProps}
|
|
68
|
+
/>
|
|
69
|
+
</Collapse>
|
|
73
70
|
);
|
|
74
71
|
};
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Checkbox
|
|
2
|
+
import { Checkbox } from '@mui/material';
|
|
3
3
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
4
|
+
import { MRT_TableButtonCell } from '../table/MRT_TableButtonCell';
|
|
4
5
|
|
|
5
6
|
export const MRT_SelectAllCheckbox = () => {
|
|
6
|
-
const { tableInstance,
|
|
7
|
+
const { tableInstance, disableSelectAll, densePadding, localization } = useMaterialReactTable();
|
|
7
8
|
|
|
8
9
|
return (
|
|
9
|
-
<
|
|
10
|
-
{
|
|
10
|
+
<MRT_TableButtonCell densePadding={densePadding} variant="head">
|
|
11
|
+
{!disableSelectAll ? (
|
|
11
12
|
<Checkbox
|
|
12
|
-
|
|
13
|
+
inputProps={{
|
|
14
|
+
'aria-label': localization?.selectAllCheckboxTitle ?? '',
|
|
15
|
+
}}
|
|
13
16
|
{...tableInstance.getToggleAllPageRowsSelectedProps()}
|
|
14
17
|
/>
|
|
15
18
|
) : null}
|
|
16
|
-
</
|
|
19
|
+
</MRT_TableButtonCell>
|
|
17
20
|
);
|
|
18
21
|
};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import React, { ChangeEvent, FC } from 'react';
|
|
2
|
-
import { Checkbox
|
|
2
|
+
import { Checkbox } from '@mui/material';
|
|
3
3
|
import { Row } from 'react-table';
|
|
4
4
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
|
+
import { MRT_TableButtonCell } from '../table/MRT_TableButtonCell';
|
|
5
6
|
|
|
6
7
|
interface Props {
|
|
7
8
|
row: Row;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
export const MRT_SelectCheckbox: FC<Props> = ({ row }) => {
|
|
11
|
-
const { tableInstance, onRowSelectChange } = useMaterialReactTable();
|
|
12
|
+
const { tableInstance, onRowSelectChange, densePadding, localization } = useMaterialReactTable();
|
|
12
13
|
|
|
13
14
|
const onSelectChange = (event: ChangeEvent) => {
|
|
14
15
|
row.getToggleRowSelectedProps()?.onChange?.(event);
|
|
@@ -16,11 +17,14 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row }) => {
|
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
return (
|
|
19
|
-
<
|
|
20
|
+
<MRT_TableButtonCell densePadding={densePadding}>
|
|
20
21
|
<Checkbox
|
|
21
|
-
{
|
|
22
|
+
inputProps={{
|
|
23
|
+
'aria-label': localization?.selectCheckboxTitle,
|
|
24
|
+
}}
|
|
22
25
|
onChange={onSelectChange}
|
|
26
|
+
{...row.getToggleRowSelectedProps()}
|
|
23
27
|
/>
|
|
24
|
-
</
|
|
28
|
+
</MRT_TableButtonCell>
|
|
25
29
|
);
|
|
26
30
|
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { Divider, Menu, MenuItem as MuiMenuItem, styled } from '@mui/material';
|
|
3
3
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
4
|
-
import {
|
|
4
|
+
import { HeaderGroup } from 'react-table';
|
|
5
5
|
import ClearAllIcon from '@mui/icons-material/ClearAll';
|
|
6
6
|
import SortIcon from '@mui/icons-material/Sort';
|
|
7
7
|
import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
|
|
8
8
|
import DynamicFeedIcon from '@mui/icons-material/DynamicFeed';
|
|
9
|
+
import FilterIcon from '@mui/icons-material/FilterList';
|
|
9
10
|
|
|
10
11
|
const MenuItem = styled(MuiMenuItem)({
|
|
11
12
|
display: 'flex',
|
|
@@ -14,20 +15,18 @@ const MenuItem = styled(MuiMenuItem)({
|
|
|
14
15
|
|
|
15
16
|
interface Props {
|
|
16
17
|
anchorEl: HTMLElement | null;
|
|
17
|
-
column:
|
|
18
|
+
column: HeaderGroup;
|
|
18
19
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
22
|
-
anchorEl,
|
|
23
|
-
column,
|
|
24
|
-
setAnchorEl,
|
|
25
|
-
}) => {
|
|
22
|
+
export const MRT_ColumnActionMenu: FC<Props> = ({ anchorEl, column, setAnchorEl }) => {
|
|
26
23
|
const {
|
|
27
|
-
|
|
24
|
+
disableColumnHiding,
|
|
28
25
|
enableColumnGrouping,
|
|
29
|
-
|
|
26
|
+
disableSortBy,
|
|
30
27
|
localization,
|
|
28
|
+
disableFilters,
|
|
29
|
+
setShowFilters,
|
|
31
30
|
} = useMaterialReactTable();
|
|
32
31
|
|
|
33
32
|
const handleClearSort = () => {
|
|
@@ -55,48 +54,70 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
55
54
|
setAnchorEl(null);
|
|
56
55
|
};
|
|
57
56
|
|
|
57
|
+
const handleFilterByColumn = () => {
|
|
58
|
+
setShowFilters(true);
|
|
59
|
+
setTimeout(
|
|
60
|
+
() =>
|
|
61
|
+
document
|
|
62
|
+
.getElementById(
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
column.muiTableHeadCellFilterTextFieldProps?.id ?? `filter-${column.id}-column`,
|
|
65
|
+
)
|
|
66
|
+
?.focus(),
|
|
67
|
+
200,
|
|
68
|
+
);
|
|
69
|
+
setAnchorEl(null);
|
|
70
|
+
};
|
|
71
|
+
|
|
58
72
|
return (
|
|
59
|
-
<Menu
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
<
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
<Menu anchorEl={anchorEl} open={!!anchorEl} onClose={() => setAnchorEl(null)}>
|
|
74
|
+
{!disableSortBy &&
|
|
75
|
+
column.canSort && [
|
|
76
|
+
<MenuItem key={1} disabled={!column.isSorted} onClick={handleClearSort}>
|
|
77
|
+
<ClearAllIcon /> {localization?.columnActionMenuItemClearSort}
|
|
78
|
+
</MenuItem>,
|
|
79
|
+
<MenuItem
|
|
80
|
+
key={2}
|
|
81
|
+
disabled={column.isSorted && !column.isSortedDesc}
|
|
82
|
+
onClick={handleSortAsc}
|
|
83
|
+
>
|
|
84
|
+
<SortIcon />{' '}
|
|
85
|
+
{localization?.columnActionMenuItemSortAsc?.replace('{column}', String(column.Header))}
|
|
86
|
+
</MenuItem>,
|
|
87
|
+
<MenuItem
|
|
88
|
+
key={3}
|
|
89
|
+
disabled={column.isSorted && column.isSortedDesc}
|
|
90
|
+
onClick={handleSortDesc}
|
|
91
|
+
>
|
|
92
|
+
<SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />{' '}
|
|
93
|
+
{localization?.columnActionMenuItemSortDesc?.replace('{column}', String(column.Header))}
|
|
94
|
+
</MenuItem>,
|
|
95
|
+
]}
|
|
96
|
+
{!disableFilters &&
|
|
97
|
+
column.canFilter && [
|
|
98
|
+
<Divider key={0} />,
|
|
99
|
+
<MenuItem key={1} onClick={handleFilterByColumn}>
|
|
100
|
+
<FilterIcon />{' '}
|
|
101
|
+
{localization?.filterTextFieldPlaceholder?.replace('{column}', String(column.Header))}
|
|
102
|
+
</MenuItem>,
|
|
103
|
+
]}
|
|
104
|
+
{enableColumnGrouping &&
|
|
105
|
+
column.canGroupBy && [
|
|
106
|
+
<Divider key={1} />,
|
|
107
|
+
<MenuItem key={2} onClick={handleGroupByColumn}>
|
|
108
|
+
<DynamicFeedIcon />{' '}
|
|
109
|
+
{localization?.[
|
|
110
|
+
column.isGrouped ? 'columnActionMenuItemUnGroupBy' : 'columnActionMenuItemGroupBy'
|
|
111
|
+
]?.replace('{column}', String(column.Header))}
|
|
112
|
+
</MenuItem>,
|
|
113
|
+
]}
|
|
114
|
+
{!disableColumnHiding && [
|
|
115
|
+
<Divider key={0} />,
|
|
116
|
+
<MenuItem key={1} onClick={handleHideColumn}>
|
|
117
|
+
<VisibilityOffIcon />{' '}
|
|
118
|
+
{localization?.columnActionMenuItemHideColumn?.replace('{column}', String(column.Header))}
|
|
82
119
|
</MenuItem>,
|
|
83
|
-
<Divider key={4} />,
|
|
84
120
|
]}
|
|
85
|
-
{enableColumnHiding && (
|
|
86
|
-
<MenuItem onClick={handleHideColumn}>
|
|
87
|
-
<VisibilityOffIcon /> {localization?.columnActionMenuItemHideColumn}
|
|
88
|
-
</MenuItem>
|
|
89
|
-
)}
|
|
90
|
-
{enableColumnGrouping && column.canGroupBy && (
|
|
91
|
-
<MenuItem disabled={column.isGrouped} onClick={handleGroupByColumn}>
|
|
92
|
-
<DynamicFeedIcon /> {localization?.columnActionMenuItemGroupBy}
|
|
93
|
-
</MenuItem>
|
|
94
|
-
)}
|
|
95
|
-
{enableColumnGrouping && column.canGroupBy && (
|
|
96
|
-
<MenuItem disabled={!column.isGrouped} onClick={handleGroupByColumn}>
|
|
97
|
-
<DynamicFeedIcon /> {localization?.columnActionMenuItemUnGroupBy}
|
|
98
|
-
</MenuItem>
|
|
99
|
-
)}
|
|
100
121
|
</Menu>
|
|
101
122
|
);
|
|
102
123
|
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { Menu, MenuItem as MuiMenuItem, styled } from '@mui/material';
|
|
3
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
4
|
+
import { Row } from 'react-table';
|
|
5
|
+
import EditIcon from '@mui/icons-material/Edit';
|
|
6
|
+
|
|
7
|
+
const MenuItem = styled(MuiMenuItem)({
|
|
8
|
+
display: 'flex',
|
|
9
|
+
gap: '0.75rem',
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
anchorEl: HTMLElement | null;
|
|
14
|
+
row: Row;
|
|
15
|
+
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
16
|
+
handleEdit: () => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const MRT_RowActionMenu: FC<Props> = ({ anchorEl, row, handleEdit, setAnchorEl }) => {
|
|
20
|
+
const { enableRowEditing, localization, renderRowActionMenuItems, tableInstance } =
|
|
21
|
+
useMaterialReactTable();
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Menu anchorEl={anchorEl} open={!!anchorEl} onClose={() => setAnchorEl(null)}>
|
|
25
|
+
{enableRowEditing && (
|
|
26
|
+
<MenuItem onClick={handleEdit}>
|
|
27
|
+
<EditIcon /> {localization?.rowActionMenuItemEdit}
|
|
28
|
+
</MenuItem>
|
|
29
|
+
)}
|
|
30
|
+
{renderRowActionMenuItems?.(row, tableInstance, () => setAnchorEl(null)) ?? null}
|
|
31
|
+
</Menu>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
@@ -17,10 +17,10 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({ column }) => {
|
|
|
17
17
|
<MenuItem style={{ paddingLeft: `${column.depth + 1}rem` }}>
|
|
18
18
|
{isMaxDepth ? (
|
|
19
19
|
<FormControlLabel
|
|
20
|
-
onChange={() => isMaxDepth && column.toggleHidden()}
|
|
21
|
-
label={column.Header as string}
|
|
22
20
|
checked={column.isVisible}
|
|
23
21
|
control={<Switch />}
|
|
22
|
+
label={column.Header as string}
|
|
23
|
+
onChange={() => isMaxDepth && column.toggleHidden()}
|
|
24
24
|
/>
|
|
25
25
|
) : (
|
|
26
26
|
<Typography>{column.Header}</Typography>
|
package/src/table/MRT_Table.tsx
CHANGED
|
@@ -8,14 +8,22 @@ import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
|
8
8
|
interface Props {}
|
|
9
9
|
|
|
10
10
|
export const MRT_Table: FC<Props> = () => {
|
|
11
|
-
const { tableInstance,
|
|
12
|
-
|
|
11
|
+
const { tableInstance, muiTableProps, hideTableHead, hideTableFooter } = useMaterialReactTable();
|
|
12
|
+
|
|
13
|
+
const tableProps = {
|
|
14
|
+
...muiTableProps,
|
|
15
|
+
...tableInstance.getTableProps(),
|
|
16
|
+
style: {
|
|
17
|
+
...tableInstance.getTableProps().style,
|
|
18
|
+
...(muiTableProps?.style ?? {}),
|
|
19
|
+
},
|
|
20
|
+
};
|
|
13
21
|
|
|
14
22
|
return (
|
|
15
|
-
<Table {...tableProps}
|
|
16
|
-
{
|
|
23
|
+
<Table {...tableProps}>
|
|
24
|
+
{!hideTableHead && <MRT_TableHead />}
|
|
17
25
|
<MRT_TableBody />
|
|
18
|
-
{
|
|
26
|
+
{!hideTableFooter && <MRT_TableFooter />}
|
|
19
27
|
</Table>
|
|
20
28
|
);
|
|
21
29
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { styled, TableCell as MuiTableCell } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
export const MRT_TableButtonCell = styled(MuiTableCell, {
|
|
4
|
+
shouldForwardProp: (prop) => prop !== 'densePadding',
|
|
5
|
+
})<{ densePadding?: boolean }>(({ densePadding }) => ({
|
|
6
|
+
padding: densePadding ? '1px' : '0.6rem',
|
|
7
|
+
textAlign: 'center',
|
|
8
|
+
transition: 'all 0.2s ease-in-out',
|
|
9
|
+
}));
|
|
@@ -1,18 +1,45 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
alpha,
|
|
4
|
+
CircularProgress,
|
|
5
|
+
LinearProgress,
|
|
6
|
+
Paper,
|
|
7
|
+
styled,
|
|
8
|
+
TableContainer,
|
|
9
|
+
} from '@mui/material';
|
|
3
10
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
4
11
|
import { MRT_Table } from './MRT_Table';
|
|
5
|
-
import {
|
|
12
|
+
import { MRT_ToolbarTop } from '../toolbar/MRT_ToolbarTop';
|
|
13
|
+
import { MRT_ToolbarBottom } from '../toolbar/MRT_ToolbarBottom';
|
|
14
|
+
|
|
15
|
+
const CircularProgressWrapper = styled('div')(({ theme }) => ({
|
|
16
|
+
alignItems: 'center',
|
|
17
|
+
backgroundColor: alpha(theme.palette.background.paper, 0.5),
|
|
18
|
+
display: 'grid',
|
|
19
|
+
height: '100%',
|
|
20
|
+
justifyContent: 'center',
|
|
21
|
+
margin: 'auto',
|
|
22
|
+
position: 'absolute',
|
|
23
|
+
width: 'calc(100% - 2rem)',
|
|
24
|
+
}));
|
|
6
25
|
|
|
7
26
|
interface Props {}
|
|
8
27
|
|
|
9
28
|
export const MRT_TableContainer: FC<Props> = () => {
|
|
10
|
-
const {
|
|
29
|
+
const { muiTableContainerProps, hideToolbarTop, hideToolbarBottom, isLoading, isFetching } =
|
|
30
|
+
useMaterialReactTable();
|
|
11
31
|
|
|
12
32
|
return (
|
|
13
|
-
<TableContainer component={Paper} {...
|
|
14
|
-
{
|
|
33
|
+
<TableContainer component={Paper} {...muiTableContainerProps}>
|
|
34
|
+
{!hideToolbarTop && <MRT_ToolbarTop />}
|
|
35
|
+
{isFetching && <LinearProgress />}
|
|
36
|
+
{isLoading && (
|
|
37
|
+
<CircularProgressWrapper>
|
|
38
|
+
<CircularProgress aria-busy="true" aria-label="Loading data" />
|
|
39
|
+
</CircularProgressWrapper>
|
|
40
|
+
)}
|
|
15
41
|
<MRT_Table />
|
|
42
|
+
{!hideToolbarBottom && <MRT_ToolbarBottom />}
|
|
16
43
|
</TableContainer>
|
|
17
44
|
);
|
|
18
45
|
};
|
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
import React, { CSSProperties, FC } from 'react';
|
|
2
2
|
import { TableCell } from '@mui/material';
|
|
3
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
3
4
|
|
|
4
5
|
interface Props {
|
|
5
6
|
width?: CSSProperties['width'];
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
export const MRT_TableSpacerCell: FC<Props> = ({ width }) => {
|
|
9
|
-
|
|
10
|
+
const { muiTableBodyCellProps } = useMaterialReactTable();
|
|
11
|
+
|
|
12
|
+
const mTableBodyCellrops =
|
|
13
|
+
muiTableBodyCellProps instanceof Function ? muiTableBodyCellProps() : muiTableBodyCellProps;
|
|
14
|
+
|
|
15
|
+
const tableCellProps = {
|
|
16
|
+
...mTableBodyCellrops,
|
|
17
|
+
style: {
|
|
18
|
+
width,
|
|
19
|
+
...(mTableBodyCellrops?.style ?? {}),
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return <TableCell {...tableCellProps} />;
|
|
10
24
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React, { ChangeEvent, FC } from 'react';
|
|
2
|
+
import { TablePagination } from '@mui/material';
|
|
3
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
4
|
+
|
|
5
|
+
interface Props {}
|
|
6
|
+
|
|
7
|
+
export const MRT_TablePagination: FC<Props> = () => {
|
|
8
|
+
const { tableInstance, muiTablePaginationProps } = useMaterialReactTable();
|
|
9
|
+
|
|
10
|
+
const tablePaginationProps =
|
|
11
|
+
muiTablePaginationProps instanceof Function
|
|
12
|
+
? muiTablePaginationProps(tableInstance)
|
|
13
|
+
: muiTablePaginationProps;
|
|
14
|
+
|
|
15
|
+
const handleChangeRowsPerPage = (event: ChangeEvent<HTMLInputElement>) => {
|
|
16
|
+
tableInstance.setPageSize(+event.target.value);
|
|
17
|
+
tableInstance.gotoPage(0);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<TablePagination
|
|
22
|
+
component={'div'}
|
|
23
|
+
count={tableInstance.rows.length}
|
|
24
|
+
onPageChange={(_, newPage) => tableInstance.gotoPage(newPage)}
|
|
25
|
+
onRowsPerPageChange={handleChangeRowsPerPage}
|
|
26
|
+
page={tableInstance.state.pageIndex}
|
|
27
|
+
rowsPerPage={tableInstance.state.pageSize}
|
|
28
|
+
showFirstButton={tableInstance.rows.length / tableInstance.state.pageSize > 2}
|
|
29
|
+
showLastButton={tableInstance.rows.length / tableInstance.state.pageSize > 2}
|
|
30
|
+
style={{ padding: 0 }}
|
|
31
|
+
{...tablePaginationProps}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { styled, Toolbar as MuiToolbar } from '@mui/material';
|
|
3
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
4
|
+
import { MRT_TablePagination } from './MRT_TablePagination';
|
|
5
|
+
import { MRT_ToolbarButtons } from './MRT_ToolbarButtons';
|
|
6
|
+
|
|
7
|
+
const Toolbar = styled(MuiToolbar)({
|
|
8
|
+
display: 'flex',
|
|
9
|
+
justifyContent: 'space-between',
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
interface Props {}
|
|
13
|
+
|
|
14
|
+
export const MRT_ToolbarBottom: FC<Props> = () => {
|
|
15
|
+
const {
|
|
16
|
+
hideToolbarActions,
|
|
17
|
+
manualPagination,
|
|
18
|
+
muiTableToolbarBottomProps,
|
|
19
|
+
positionPagination,
|
|
20
|
+
positionToolbarActions,
|
|
21
|
+
tableInstance,
|
|
22
|
+
} = useMaterialReactTable();
|
|
23
|
+
|
|
24
|
+
const toolbarProps =
|
|
25
|
+
muiTableToolbarBottomProps instanceof Function
|
|
26
|
+
? muiTableToolbarBottomProps(tableInstance)
|
|
27
|
+
: muiTableToolbarBottomProps;
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<Toolbar style={{ padding: 0 }} variant="dense" {...toolbarProps}>
|
|
31
|
+
{!hideToolbarActions && positionToolbarActions === 'bottom' ? (
|
|
32
|
+
<MRT_ToolbarButtons />
|
|
33
|
+
) : (
|
|
34
|
+
<span />
|
|
35
|
+
)}
|
|
36
|
+
{!manualPagination && ['bottom', 'both'].includes(positionPagination ?? '') && (
|
|
37
|
+
<MRT_TablePagination />
|
|
38
|
+
)}
|
|
39
|
+
</Toolbar>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { styled } from '@mui/material';
|
|
3
|
+
import { MRT_ToggleFiltersButton } from '../buttons/MRT_ToggleFiltersButton';
|
|
4
|
+
import { MRT_ShowHideColumnsButton } from '../buttons/MRT_ShowHideColumnsButton';
|
|
5
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
6
|
+
import { MRT_DensePaddingSwitch } from '../inputs/MRT_DensePaddingSwitch';
|
|
7
|
+
import { MRT_ToggleSearchButton } from '../buttons/MRT_ToggleSearchButton';
|
|
8
|
+
|
|
9
|
+
const ToolbarButtonsContainer = styled('div')({
|
|
10
|
+
display: 'flex',
|
|
11
|
+
gap: '0.5rem',
|
|
12
|
+
alignItems: 'center',
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
interface Props {}
|
|
16
|
+
|
|
17
|
+
export const MRT_ToolbarButtons: FC<Props> = () => {
|
|
18
|
+
const { disableFilters, disableColumnHiding, disableDensePaddingToggle, disableGlobalFilter } =
|
|
19
|
+
useMaterialReactTable();
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<ToolbarButtonsContainer>
|
|
23
|
+
{!disableGlobalFilter && <MRT_ToggleSearchButton />}
|
|
24
|
+
{!disableFilters && <MRT_ToggleFiltersButton />}
|
|
25
|
+
{!disableColumnHiding && <MRT_ShowHideColumnsButton />}
|
|
26
|
+
{!disableDensePaddingToggle && <MRT_DensePaddingSwitch />}
|
|
27
|
+
</ToolbarButtonsContainer>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { styled, Toolbar as MuiToolbar } from '@mui/material';
|
|
3
|
+
import { MRT_SearchTextField } from '../inputs/MRT_SearchTextField';
|
|
4
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
|
+
import { MRT_ToolbarButtons } from './MRT_ToolbarButtons';
|
|
6
|
+
import { MRT_TablePagination } from './MRT_TablePagination';
|
|
7
|
+
|
|
8
|
+
const Toolbar = styled(MuiToolbar)({
|
|
9
|
+
display: 'grid',
|
|
10
|
+
padding: '0.5rem !important',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const ToolbarTopRow = styled('div')({
|
|
14
|
+
padding: '0.5rem',
|
|
15
|
+
display: 'flex',
|
|
16
|
+
justifyContent: 'space-between',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const ToolbarActionsContainer = styled('div')({
|
|
20
|
+
display: 'flex',
|
|
21
|
+
gap: '0.5rem',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
interface Props {}
|
|
25
|
+
|
|
26
|
+
export const MRT_ToolbarTop: FC<Props> = () => {
|
|
27
|
+
const {
|
|
28
|
+
disableGlobalFilter,
|
|
29
|
+
hideToolbarActions,
|
|
30
|
+
manualPagination,
|
|
31
|
+
muiTableToolbarTopProps,
|
|
32
|
+
positionPagination,
|
|
33
|
+
positionToolbarActions,
|
|
34
|
+
renderToolbarActions,
|
|
35
|
+
tableInstance,
|
|
36
|
+
} = useMaterialReactTable();
|
|
37
|
+
|
|
38
|
+
const toolbarProps =
|
|
39
|
+
muiTableToolbarTopProps instanceof Function
|
|
40
|
+
? muiTableToolbarTopProps(tableInstance)
|
|
41
|
+
: muiTableToolbarTopProps;
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<Toolbar variant="dense" {...toolbarProps}>
|
|
45
|
+
<ToolbarTopRow>
|
|
46
|
+
{renderToolbarActions?.(tableInstance) ?? <span />}
|
|
47
|
+
<ToolbarActionsContainer>
|
|
48
|
+
{!disableGlobalFilter && <MRT_SearchTextField />}
|
|
49
|
+
{!hideToolbarActions && positionToolbarActions === 'top' && <MRT_ToolbarButtons />}
|
|
50
|
+
</ToolbarActionsContainer>
|
|
51
|
+
</ToolbarTopRow>
|
|
52
|
+
<div>
|
|
53
|
+
{!manualPagination && ['top', 'both'].includes(positionPagination ?? '') && (
|
|
54
|
+
<MRT_TablePagination />
|
|
55
|
+
)}
|
|
56
|
+
</div>
|
|
57
|
+
</Toolbar>
|
|
58
|
+
);
|
|
59
|
+
};
|