material-react-table 0.8.13 → 0.9.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 +2 -1
- package/dist/MaterialReactTable.d.ts +42 -37
- package/dist/material-react-table.cjs.development.js +233 -186
- 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 +234 -187
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/toolbar/MRT_LinearProgressBar.d.ts +1 -0
- package/dist/utils.d.ts +4 -3
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +59 -47
- package/src/body/MRT_TableBodyCell.tsx +19 -5
- package/src/body/MRT_TableBodyRow.tsx +2 -2
- package/src/body/MRT_TableDetailPanel.tsx +2 -2
- package/src/buttons/MRT_ColumnPinningButtons.tsx +1 -1
- package/src/buttons/MRT_EditActionButtons.tsx +2 -2
- package/src/buttons/MRT_ExpandButton.tsx +2 -2
- package/src/buttons/MRT_FullScreenToggleButton.tsx +2 -2
- package/src/buttons/MRT_ToggleDensePaddingButton.tsx +2 -2
- package/src/buttons/MRT_ToggleFiltersButton.tsx +2 -2
- package/src/buttons/MRT_ToggleGlobalFilterButton.tsx +4 -4
- package/src/footer/MRT_TableFooterCell.tsx +6 -6
- package/src/head/MRT_DraggableTableHeadCell.tsx +8 -16
- package/src/head/MRT_TableHeadCell.tsx +12 -10
- package/src/head/MRT_TableHeadCellFilterLabel.tsx +1 -0
- package/src/inputs/MRT_EditCellTextField.tsx +8 -8
- package/src/inputs/MRT_FilterTextField.tsx +2 -2
- package/src/inputs/MRT_SearchTextField.tsx +4 -4
- package/src/inputs/MRT_SelectCheckbox.tsx +10 -5
- package/src/menus/MRT_ColumnActionMenu.tsx +2 -2
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +18 -5
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +18 -18
- package/src/table/MRT_TableContainer.tsx +3 -3
- package/src/table/MRT_TableRoot.tsx +43 -25
- package/src/toolbar/MRT_LinearProgressBar.tsx +17 -2
- package/src/toolbar/MRT_ToolbarBottom.tsx +4 -4
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +2 -1
- package/src/toolbar/MRT_ToolbarTop.tsx +13 -6
- package/src/utils.ts +24 -2
|
@@ -58,14 +58,14 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
58
58
|
...mcTableHeadCellProps,
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
const headerElement = (
|
|
62
|
-
columnDef?.Header
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
const headerElement = ((columnDef?.Header instanceof Function
|
|
62
|
+
? columnDef?.Header?.({
|
|
63
|
+
header,
|
|
64
|
+
tableInstance,
|
|
65
|
+
})
|
|
66
|
+
: columnDef?.Header) ??
|
|
67
|
+
header.renderHeader() ??
|
|
68
|
+
columnDef.header) as ReactNode;
|
|
69
69
|
|
|
70
70
|
const getIsLastLeftPinnedColumn = () => {
|
|
71
71
|
return (
|
|
@@ -92,7 +92,9 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
92
92
|
align={columnDefType === 'group' ? 'center' : 'left'}
|
|
93
93
|
colSpan={header.colSpan}
|
|
94
94
|
{...tableCellProps}
|
|
95
|
-
ref={
|
|
95
|
+
ref={
|
|
96
|
+
columnDefType === 'data' && enableColumnOrdering ? dropRef : undefined
|
|
97
|
+
}
|
|
96
98
|
sx={(theme: Theme) => ({
|
|
97
99
|
backgroundColor:
|
|
98
100
|
column.getIsPinned() && columnDefType !== 'group'
|
|
@@ -123,7 +125,7 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
123
125
|
column.getIsPinned() && columnDefType !== 'group'
|
|
124
126
|
? 'sticky'
|
|
125
127
|
: undefined,
|
|
126
|
-
pt: columnDefType !== 'data' ? 0 : isDensePadding ? '0.25' : '.
|
|
128
|
+
pt: columnDefType !== 'data' ? 0 : isDensePadding ? '0.25' : '.75rem',
|
|
127
129
|
right:
|
|
128
130
|
column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
|
|
129
131
|
transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
|
|
@@ -67,6 +67,7 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({
|
|
|
67
67
|
opacity: !!column.getFilterValue() || showFilters ? 0.8 : 0,
|
|
68
68
|
p: '2px',
|
|
69
69
|
transition: 'all 0.2s ease-in-out',
|
|
70
|
+
transform: 'scale(0.66)',
|
|
70
71
|
'&:hover': {
|
|
71
72
|
backgroundColor: 'transparent',
|
|
72
73
|
opacity: 0.8,
|
|
@@ -17,11 +17,11 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
17
17
|
const {
|
|
18
18
|
getState,
|
|
19
19
|
options: {
|
|
20
|
-
|
|
20
|
+
tableId,
|
|
21
21
|
enableEditing,
|
|
22
22
|
muiTableBodyCellEditTextFieldProps,
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
onMrtCellEditBlur,
|
|
24
|
+
onMrtCellEditChange,
|
|
25
25
|
},
|
|
26
26
|
setCurrentEditingCell,
|
|
27
27
|
setCurrentEditingRow,
|
|
@@ -35,8 +35,8 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
35
35
|
|
|
36
36
|
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
37
37
|
setValue(event.target.value);
|
|
38
|
-
columnDef.
|
|
39
|
-
|
|
38
|
+
columnDef.onMrtCellEditChange?.({ event, cell, tableInstance });
|
|
39
|
+
onMrtCellEditChange?.({ event, cell, tableInstance });
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
|
|
@@ -46,8 +46,8 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
46
46
|
setCurrentEditingRow({ ...getState().currentEditingRow } as MRT_Row);
|
|
47
47
|
}
|
|
48
48
|
setCurrentEditingCell(null);
|
|
49
|
-
columnDef.
|
|
50
|
-
|
|
49
|
+
columnDef.onMrtCellEditBlur?.({ event, cell, tableInstance });
|
|
50
|
+
onMrtCellEditBlur?.({ event, cell, tableInstance });
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
const mTableBodyCellEditTextFieldProps =
|
|
@@ -74,7 +74,7 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
74
74
|
|
|
75
75
|
return (
|
|
76
76
|
<TextField
|
|
77
|
-
id={`mrt-${
|
|
77
|
+
id={`mrt-${tableId}-edit-cell-text-field-${cell.id}`}
|
|
78
78
|
margin="dense"
|
|
79
79
|
onBlur={handleBlur}
|
|
80
80
|
onChange={handleChange}
|
|
@@ -34,7 +34,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
34
34
|
getState,
|
|
35
35
|
options: {
|
|
36
36
|
icons: { FilterListIcon, CloseIcon },
|
|
37
|
-
|
|
37
|
+
tableId,
|
|
38
38
|
localization,
|
|
39
39
|
muiTableHeadCellFilterTextFieldProps,
|
|
40
40
|
},
|
|
@@ -118,7 +118,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
118
118
|
return <>{columnDef.Filter?.({ header, tableInstance })}</>;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
const filterId = `mrt-${
|
|
121
|
+
const filterId = `mrt-${tableId}-${header.id}-filter-text-field${
|
|
122
122
|
inputIndex ?? ''
|
|
123
123
|
}`;
|
|
124
124
|
const filterFn = currentFilterFns?.[header.id];
|
|
@@ -26,10 +26,10 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
26
26
|
setGlobalFilter,
|
|
27
27
|
options: {
|
|
28
28
|
icons: { SearchIcon, CloseIcon },
|
|
29
|
-
|
|
29
|
+
tableId,
|
|
30
30
|
localization,
|
|
31
31
|
muiSearchTextFieldProps,
|
|
32
|
-
|
|
32
|
+
onMrtGlobalFilterValueChange,
|
|
33
33
|
},
|
|
34
34
|
} = tableInstance;
|
|
35
35
|
|
|
@@ -41,7 +41,7 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
41
41
|
const handleChange = useCallback(
|
|
42
42
|
debounce((event: ChangeEvent<HTMLInputElement>) => {
|
|
43
43
|
setGlobalFilter(event.target.value ?? undefined);
|
|
44
|
-
|
|
44
|
+
onMrtGlobalFilterValueChange?.({ event, tableInstance });
|
|
45
45
|
}, 200),
|
|
46
46
|
[],
|
|
47
47
|
);
|
|
@@ -63,7 +63,7 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
63
63
|
return (
|
|
64
64
|
<Collapse in={showGlobalFilter} orientation="horizontal">
|
|
65
65
|
<TextField
|
|
66
|
-
id={`mrt-${
|
|
66
|
+
id={`mrt-${tableId}-search-text-field`}
|
|
67
67
|
placeholder={localization.search}
|
|
68
68
|
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
69
69
|
setSearchValue(event.target.value);
|
|
@@ -20,8 +20,9 @@ export const MRT_SelectCheckbox: FC<Props> = ({
|
|
|
20
20
|
options: {
|
|
21
21
|
localization,
|
|
22
22
|
muiSelectCheckboxProps,
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
onMrtSelectRowChange,
|
|
24
|
+
onMrtSelectAllChange,
|
|
25
|
+
selectAllMode,
|
|
25
26
|
},
|
|
26
27
|
} = tableInstance;
|
|
27
28
|
|
|
@@ -29,15 +30,19 @@ export const MRT_SelectCheckbox: FC<Props> = ({
|
|
|
29
30
|
|
|
30
31
|
const handleSelectChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
31
32
|
if (selectAll) {
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
if (selectAllMode === 'all') {
|
|
34
|
+
tableInstance.getToggleAllRowsSelectedHandler()(event as any);
|
|
35
|
+
} else if (selectAllMode === 'page') {
|
|
36
|
+
tableInstance.getToggleAllPageRowsSelectedHandler()(event as any);
|
|
37
|
+
}
|
|
38
|
+
onMrtSelectAllChange?.({
|
|
34
39
|
event,
|
|
35
40
|
selectedRows: event.target.checked ? getRowModel().flatRows : [],
|
|
36
41
|
tableInstance,
|
|
37
42
|
});
|
|
38
43
|
} else if (row) {
|
|
39
44
|
row?.getToggleSelectedHandler()(event as any);
|
|
40
|
-
|
|
45
|
+
onMrtSelectRowChange?.({
|
|
41
46
|
event,
|
|
42
47
|
row,
|
|
43
48
|
selectedRows: event.target.checked
|
|
@@ -52,7 +52,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
52
52
|
RestartAltIcon,
|
|
53
53
|
VisibilityOffIcon,
|
|
54
54
|
},
|
|
55
|
-
|
|
55
|
+
tableId,
|
|
56
56
|
localization,
|
|
57
57
|
},
|
|
58
58
|
setShowFilters,
|
|
@@ -119,7 +119,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
119
119
|
.getElementById(
|
|
120
120
|
// @ts-ignore
|
|
121
121
|
header.muiTableHeadCellFilterTextFieldProps?.id ??
|
|
122
|
-
`mrt-${
|
|
122
|
+
`mrt-${tableId}-${header.id}-filter-text-field`,
|
|
123
123
|
)
|
|
124
124
|
?.focus(),
|
|
125
125
|
200,
|
|
@@ -19,9 +19,12 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
19
19
|
const {
|
|
20
20
|
getAllColumns,
|
|
21
21
|
getAllLeafColumns,
|
|
22
|
+
getCenterLeafColumns,
|
|
22
23
|
getIsAllColumnsVisible,
|
|
23
24
|
getIsSomeColumnsPinned,
|
|
24
25
|
getIsSomeColumnsVisible,
|
|
26
|
+
getLeftLeafColumns,
|
|
27
|
+
getRightLeafColumns,
|
|
25
28
|
getState,
|
|
26
29
|
toggleAllColumnsVisible,
|
|
27
30
|
options: { localization, enablePinning, enableColumnOrdering },
|
|
@@ -41,13 +44,23 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
41
44
|
columnOrder.length > 0 &&
|
|
42
45
|
!columns.some((col) => col.columnDefType === 'group')
|
|
43
46
|
) {
|
|
44
|
-
return
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
return [
|
|
48
|
+
...getLeftLeafColumns(),
|
|
49
|
+
...Array.from(new Set(columnOrder)).map((colId) =>
|
|
50
|
+
getCenterLeafColumns().find((col) => col?.id === colId),
|
|
51
|
+
),
|
|
52
|
+
...getRightLeafColumns(),
|
|
53
|
+
].filter(Boolean);
|
|
48
54
|
}
|
|
49
55
|
return columns;
|
|
50
|
-
}, [
|
|
56
|
+
}, [
|
|
57
|
+
columnOrder,
|
|
58
|
+
columnPinning,
|
|
59
|
+
getAllColumns(),
|
|
60
|
+
getCenterLeafColumns(),
|
|
61
|
+
getLeftLeafColumns(),
|
|
62
|
+
getRightLeafColumns(),
|
|
63
|
+
]) as MRT_Column[];
|
|
51
64
|
|
|
52
65
|
return (
|
|
53
66
|
<Menu
|
|
@@ -3,6 +3,7 @@ import { useDrag, useDrop } from 'react-dnd';
|
|
|
3
3
|
import { Box, FormControlLabel, MenuItem, Switch } from '@mui/material';
|
|
4
4
|
import { MRT_ColumnPinningButtons } from '../buttons/MRT_ColumnPinningButtons';
|
|
5
5
|
import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
|
|
6
|
+
import { reorderColumn } from '../utils';
|
|
6
7
|
import type { MRT_Column, MRT_TableInstance } from '..';
|
|
7
8
|
|
|
8
9
|
interface Props {
|
|
@@ -20,7 +21,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
20
21
|
}) => {
|
|
21
22
|
const {
|
|
22
23
|
getState,
|
|
23
|
-
options: { enableColumnOrdering,
|
|
24
|
+
options: { enableColumnOrdering, onMrtToggleColumnVisibility },
|
|
24
25
|
setColumnOrder,
|
|
25
26
|
} = tableInstance;
|
|
26
27
|
|
|
@@ -28,21 +29,10 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
28
29
|
|
|
29
30
|
const { columnDef, columnDefType } = column;
|
|
30
31
|
|
|
31
|
-
const reorder = (movingColumn: MRT_Column, receivingColumn: MRT_Column) => {
|
|
32
|
-
if (movingColumn.getCanPin()) {
|
|
33
|
-
movingColumn.pin(receivingColumn.getIsPinned());
|
|
34
|
-
}
|
|
35
|
-
columnOrder.splice(
|
|
36
|
-
columnOrder.indexOf(receivingColumn.id),
|
|
37
|
-
0,
|
|
38
|
-
columnOrder.splice(columnOrder.indexOf(movingColumn.id), 1)[0],
|
|
39
|
-
);
|
|
40
|
-
setColumnOrder([...columnOrder]);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
32
|
const [, dropRef] = useDrop({
|
|
44
33
|
accept: 'column',
|
|
45
|
-
drop: (movingColumn: MRT_Column) =>
|
|
34
|
+
drop: (movingColumn: MRT_Column) =>
|
|
35
|
+
reorderColumn(movingColumn, column, columnOrder, setColumnOrder),
|
|
46
36
|
});
|
|
47
37
|
|
|
48
38
|
const [, dragRef, previewRef] = useDrag({
|
|
@@ -66,7 +56,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
66
56
|
} else {
|
|
67
57
|
column.toggleVisibility();
|
|
68
58
|
}
|
|
69
|
-
|
|
59
|
+
onMrtToggleColumnVisibility?.({
|
|
70
60
|
column,
|
|
71
61
|
columnVisibility,
|
|
72
62
|
tableInstance,
|
|
@@ -85,7 +75,14 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
85
75
|
py: '6px',
|
|
86
76
|
}}
|
|
87
77
|
>
|
|
88
|
-
<Box
|
|
78
|
+
<Box
|
|
79
|
+
ref={previewRef}
|
|
80
|
+
sx={{
|
|
81
|
+
display: 'flex',
|
|
82
|
+
flexWrap: 'nowrap',
|
|
83
|
+
gap: '8px',
|
|
84
|
+
}}
|
|
85
|
+
>
|
|
89
86
|
{columnDefType !== 'group' &&
|
|
90
87
|
enableColumnOrdering &&
|
|
91
88
|
columnDef.enableColumnOrdering !== false &&
|
|
@@ -112,10 +109,13 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
112
109
|
}}
|
|
113
110
|
checked={switchChecked}
|
|
114
111
|
control={<Switch />}
|
|
115
|
-
disabled={
|
|
112
|
+
disabled={
|
|
113
|
+
(isSubMenu && switchChecked) ||
|
|
114
|
+
!column.getCanHide() ||
|
|
115
|
+
column.getIsGrouped()
|
|
116
|
+
}
|
|
116
117
|
label={columnDef.header}
|
|
117
118
|
onChange={() => handleToggleColumnHidden(column)}
|
|
118
|
-
sx={{ ml: '4px' }}
|
|
119
119
|
/>
|
|
120
120
|
</Box>
|
|
121
121
|
</MenuItem>
|
|
@@ -13,7 +13,7 @@ interface Props {
|
|
|
13
13
|
export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
14
14
|
const {
|
|
15
15
|
getState,
|
|
16
|
-
options: { enableStickyHeader,
|
|
16
|
+
options: { enableStickyHeader, tableId, muiTableContainerProps },
|
|
17
17
|
} = tableInstance;
|
|
18
18
|
|
|
19
19
|
const { isFullScreen } = getState();
|
|
@@ -28,13 +28,13 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
28
28
|
useIsomorphicLayoutEffect(() => {
|
|
29
29
|
const topToolbarHeight =
|
|
30
30
|
typeof document !== 'undefined'
|
|
31
|
-
? document?.getElementById(`mrt-${
|
|
31
|
+
? document?.getElementById(`mrt-${tableId}-toolbar-top`)
|
|
32
32
|
?.offsetHeight ?? 0
|
|
33
33
|
: 0;
|
|
34
34
|
|
|
35
35
|
const bottomToolbarHeight =
|
|
36
36
|
typeof document !== 'undefined'
|
|
37
|
-
? document?.getElementById(`mrt-${
|
|
37
|
+
? document?.getElementById(`mrt-${tableId}-toolbar-bottom`)
|
|
38
38
|
?.offsetHeight ?? 0
|
|
39
39
|
: 0;
|
|
40
40
|
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
ReactTableGenerics,
|
|
13
13
|
getFacetedRowModel,
|
|
14
14
|
TableState,
|
|
15
|
+
Table,
|
|
15
16
|
} from '@tanstack/react-table';
|
|
16
17
|
import {
|
|
17
18
|
MRT_Cell,
|
|
@@ -40,11 +41,11 @@ import { Box, Dialog, Grow } from '@mui/material';
|
|
|
40
41
|
export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
41
42
|
props: MaterialReactTableProps<D>,
|
|
42
43
|
) => {
|
|
43
|
-
const [
|
|
44
|
+
const [tableId, setIdPrefix] = useState(props.tableId);
|
|
44
45
|
useEffect(
|
|
45
46
|
() =>
|
|
46
|
-
setIdPrefix(props.
|
|
47
|
-
[props.
|
|
47
|
+
setIdPrefix(props.tableId ?? Math.random().toString(36).substring(2, 9)),
|
|
48
|
+
[props.tableId],
|
|
48
49
|
);
|
|
49
50
|
|
|
50
51
|
const showActionColumn =
|
|
@@ -57,7 +58,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
57
58
|
const initState = props.initialState ?? {};
|
|
58
59
|
|
|
59
60
|
initState.columnOrder =
|
|
60
|
-
initState?.columnOrder ??
|
|
61
|
+
initState?.columnOrder ??
|
|
62
|
+
(props.enableColumnOrdering || props.enableGrouping)
|
|
61
63
|
? ([
|
|
62
64
|
showActionColumn && 'mrt-row-actions',
|
|
63
65
|
showExpandColumn && 'mrt-expand',
|
|
@@ -69,7 +71,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
69
71
|
].filter(Boolean) as string[])
|
|
70
72
|
: [];
|
|
71
73
|
|
|
72
|
-
if (!props.enablePersistentState || !props.
|
|
74
|
+
if (!props.enablePersistentState || !props.tableId) {
|
|
73
75
|
return initState;
|
|
74
76
|
}
|
|
75
77
|
if (typeof window === 'undefined') {
|
|
@@ -82,9 +84,9 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
82
84
|
}
|
|
83
85
|
const storedState =
|
|
84
86
|
props.persistentStateMode === 'localStorage'
|
|
85
|
-
? localStorage.getItem(`mrt-${
|
|
87
|
+
? localStorage.getItem(`mrt-${tableId}-table-state`)
|
|
86
88
|
: props.persistentStateMode === 'sessionStorage'
|
|
87
|
-
? sessionStorage.getItem(`mrt-${
|
|
89
|
+
? sessionStorage.getItem(`mrt-${tableId}-table-state`)
|
|
88
90
|
: '{}';
|
|
89
91
|
if (storedState) {
|
|
90
92
|
const parsedState = JSON.parse(storedState);
|
|
@@ -133,7 +135,25 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
133
135
|
MRT_FILTER_OPTION | FilterFn<ReactTableGenerics> | string | number | symbol
|
|
134
136
|
>(props.globalFilterFn ?? MRT_FILTER_OPTION.FUZZY);
|
|
135
137
|
|
|
136
|
-
const table = useMemo(
|
|
138
|
+
const table = useMemo(
|
|
139
|
+
() =>
|
|
140
|
+
// @ts-ignore
|
|
141
|
+
createTable().setOptions({
|
|
142
|
+
//@ts-ignore
|
|
143
|
+
filterFns: defaultFilterFNs,
|
|
144
|
+
getCoreRowModel: getCoreRowModel(),
|
|
145
|
+
getExpandedRowModel: getExpandedRowModel(),
|
|
146
|
+
getFacetedRowModel: getFacetedRowModel(),
|
|
147
|
+
getFilteredRowModel: getFilteredRowModel(),
|
|
148
|
+
getGroupedRowModel: getGroupedRowModel(),
|
|
149
|
+
getPaginationRowModel: getPaginationRowModel(),
|
|
150
|
+
getSortedRowModel: getSortedRowModel(),
|
|
151
|
+
getSubRows: (row) => (row as MRT_Row)?.subRows,
|
|
152
|
+
tableId,
|
|
153
|
+
initialState,
|
|
154
|
+
}) as Table<D>,
|
|
155
|
+
[],
|
|
156
|
+
);
|
|
137
157
|
|
|
138
158
|
const displayColumns = useMemo(
|
|
139
159
|
() =>
|
|
@@ -148,6 +168,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
148
168
|
),
|
|
149
169
|
header: props.localization?.actions,
|
|
150
170
|
id: 'mrt-row-actions',
|
|
171
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
172
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
151
173
|
size: 60,
|
|
152
174
|
}),
|
|
153
175
|
showExpandColumn &&
|
|
@@ -164,6 +186,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
164
186
|
) : null,
|
|
165
187
|
header: props.localization?.expand,
|
|
166
188
|
id: 'mrt-expand',
|
|
189
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
190
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
167
191
|
size: 50,
|
|
168
192
|
}),
|
|
169
193
|
props.enableRowSelection &&
|
|
@@ -180,6 +204,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
180
204
|
) : null,
|
|
181
205
|
header: props.localization?.select,
|
|
182
206
|
id: 'mrt-select',
|
|
207
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
208
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
183
209
|
size: 50,
|
|
184
210
|
}),
|
|
185
211
|
props.enableRowNumbers &&
|
|
@@ -188,6 +214,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
188
214
|
Header: () => props.localization?.rowNumber,
|
|
189
215
|
header: props.localization?.rowNumbers,
|
|
190
216
|
id: 'mrt-row-numbers',
|
|
217
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
218
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
191
219
|
size: 50,
|
|
192
220
|
}),
|
|
193
221
|
].filter(Boolean),
|
|
@@ -238,24 +266,14 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
238
266
|
|
|
239
267
|
//@ts-ignore
|
|
240
268
|
const tableInstance = {
|
|
269
|
+
//@ts-ignore
|
|
241
270
|
...useTableInstance(table, {
|
|
242
|
-
filterFns: defaultFilterFNs,
|
|
243
|
-
getCoreRowModel: getCoreRowModel(),
|
|
244
|
-
getExpandedRowModel: getExpandedRowModel(),
|
|
245
|
-
getFacetedRowModel: getFacetedRowModel(),
|
|
246
|
-
getFilteredRowModel: getFilteredRowModel(),
|
|
247
|
-
getGroupedRowModel: getGroupedRowModel(),
|
|
248
|
-
getPaginationRowModel: getPaginationRowModel(),
|
|
249
|
-
getSortedRowModel: getSortedRowModel(),
|
|
250
|
-
getSubRows: (row) => (row as MRT_Row)?.subRows,
|
|
251
|
-
//@ts-ignore
|
|
252
|
-
globalFilterFn: currentGlobalFilterFn,
|
|
253
271
|
...props,
|
|
254
272
|
//@ts-ignore
|
|
255
273
|
columns,
|
|
256
274
|
data,
|
|
257
|
-
|
|
258
|
-
|
|
275
|
+
//@ts-ignore
|
|
276
|
+
globalFilterFn: currentGlobalFilterFn,
|
|
259
277
|
state: {
|
|
260
278
|
currentEditingCell,
|
|
261
279
|
currentEditingRow,
|
|
@@ -282,14 +300,14 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
282
300
|
if (typeof window === 'undefined' || !props.enablePersistentState) {
|
|
283
301
|
return;
|
|
284
302
|
}
|
|
285
|
-
if (!props.
|
|
303
|
+
if (!props.tableId && process.env.NODE_ENV !== 'production') {
|
|
286
304
|
console.warn(
|
|
287
|
-
'a unique
|
|
305
|
+
'a unique tableId prop is required for persistent table state to work',
|
|
288
306
|
);
|
|
289
307
|
return;
|
|
290
308
|
}
|
|
291
309
|
const itemArgs: [string, string] = [
|
|
292
|
-
`mrt-${
|
|
310
|
+
`mrt-${tableId}-table-state`,
|
|
293
311
|
JSON.stringify(tableInstance.getState()),
|
|
294
312
|
];
|
|
295
313
|
if (props.persistentStateMode === 'localStorage') {
|
|
@@ -299,7 +317,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
299
317
|
}
|
|
300
318
|
}, [
|
|
301
319
|
props.enablePersistentState,
|
|
302
|
-
props.
|
|
320
|
+
props.tableId,
|
|
303
321
|
props.persistentStateMode,
|
|
304
322
|
tableInstance,
|
|
305
323
|
]);
|
|
@@ -3,10 +3,14 @@ import { Collapse, LinearProgress } from '@mui/material';
|
|
|
3
3
|
import { MRT_TableInstance } from '..';
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
6
|
+
alignTo: 'bottom' | 'top';
|
|
6
7
|
tableInstance: MRT_TableInstance;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
export const MRT_LinearProgressBar: FC<Props> = ({
|
|
10
|
+
export const MRT_LinearProgressBar: FC<Props> = ({
|
|
11
|
+
alignTo,
|
|
12
|
+
tableInstance,
|
|
13
|
+
}) => {
|
|
10
14
|
const {
|
|
11
15
|
options: { muiLinearProgressProps },
|
|
12
16
|
getState,
|
|
@@ -20,10 +24,21 @@ export const MRT_LinearProgressBar: FC<Props> = ({ tableInstance }) => {
|
|
|
20
24
|
: muiLinearProgressProps;
|
|
21
25
|
|
|
22
26
|
return (
|
|
23
|
-
<Collapse
|
|
27
|
+
<Collapse
|
|
28
|
+
in={isLoading || showProgressBars}
|
|
29
|
+
mountOnEnter
|
|
30
|
+
unmountOnExit
|
|
31
|
+
sx={{
|
|
32
|
+
bottom: alignTo === 'bottom' ? 0 : undefined,
|
|
33
|
+
position: 'absolute',
|
|
34
|
+
top: alignTo === 'top' ? 0 : undefined,
|
|
35
|
+
width: '100%',
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
24
38
|
<LinearProgress
|
|
25
39
|
aria-label="Loading"
|
|
26
40
|
aria-busy="true"
|
|
41
|
+
sx={{ position: 'relative' }}
|
|
27
42
|
{...linearProgressProps}
|
|
28
43
|
/>
|
|
29
44
|
</Collapse>
|
|
@@ -16,7 +16,7 @@ export const MRT_ToolbarBottom: FC<Props> = ({ tableInstance }) => {
|
|
|
16
16
|
getState,
|
|
17
17
|
options: {
|
|
18
18
|
enableToolbarInternalActions,
|
|
19
|
-
|
|
19
|
+
tableId,
|
|
20
20
|
enablePagination,
|
|
21
21
|
muiTableToolbarBottomProps,
|
|
22
22
|
positionPagination,
|
|
@@ -45,20 +45,20 @@ export const MRT_ToolbarBottom: FC<Props> = ({ tableInstance }) => {
|
|
|
45
45
|
|
|
46
46
|
return (
|
|
47
47
|
<Toolbar
|
|
48
|
-
id={`mrt-${
|
|
48
|
+
id={`mrt-${tableId}-toolbar-bottom`}
|
|
49
49
|
variant="dense"
|
|
50
50
|
{...toolbarProps}
|
|
51
51
|
sx={(theme) =>
|
|
52
52
|
({
|
|
53
53
|
...commonToolbarStyles({ theme }),
|
|
54
54
|
bottom: isFullScreen ? '0' : undefined,
|
|
55
|
-
position: isFullScreen ? 'fixed' : undefined,
|
|
56
55
|
boxShadow: `-3px 0 6px ${alpha(theme.palette.common.black, 0.1)}`,
|
|
56
|
+
position: isFullScreen ? 'fixed' : 'relative',
|
|
57
57
|
...toolbarProps?.sx,
|
|
58
58
|
} as any)
|
|
59
59
|
}
|
|
60
60
|
>
|
|
61
|
-
<MRT_LinearProgressBar tableInstance={tableInstance} />
|
|
61
|
+
<MRT_LinearProgressBar alignTo='top' tableInstance={tableInstance} />
|
|
62
62
|
{positionToolbarAlertBanner === 'bottom' && (
|
|
63
63
|
<MRT_ToolbarAlertBanner tableInstance={tableInstance} />
|
|
64
64
|
)}
|
|
@@ -21,6 +21,7 @@ export const MRT_ToolbarInternalButtons: FC<Props> = ({ tableInstance }) => {
|
|
|
21
21
|
enableFullScreenToggle,
|
|
22
22
|
enableGlobalFilter,
|
|
23
23
|
enableHiding,
|
|
24
|
+
positionGlobalFilter,
|
|
24
25
|
renderToolbarInternalActions,
|
|
25
26
|
},
|
|
26
27
|
} = tableInstance;
|
|
@@ -42,7 +43,7 @@ export const MRT_ToolbarInternalButtons: FC<Props> = ({ tableInstance }) => {
|
|
|
42
43
|
tableInstance,
|
|
43
44
|
}) ?? (
|
|
44
45
|
<>
|
|
45
|
-
{enableGlobalFilter && (
|
|
46
|
+
{enableGlobalFilter && positionGlobalFilter === 'right' && (
|
|
46
47
|
<MRT_SearchTextField tableInstance={tableInstance} />
|
|
47
48
|
)}
|
|
48
49
|
{enableFilters && enableGlobalFilter && (
|
|
@@ -5,6 +5,7 @@ import { MRT_TablePagination } from './MRT_TablePagination';
|
|
|
5
5
|
import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
|
|
6
6
|
import { MRT_LinearProgressBar } from './MRT_LinearProgressBar';
|
|
7
7
|
import { MRT_TableInstance } from '..';
|
|
8
|
+
import { MRT_SearchTextField } from '../inputs/MRT_SearchTextField';
|
|
8
9
|
|
|
9
10
|
export const commonToolbarStyles = ({ theme }: { theme: Theme }) => ({
|
|
10
11
|
backgroundColor: lighten(theme.palette.background.default, 0.04),
|
|
@@ -26,18 +27,20 @@ export const MRT_ToolbarTop: FC<Props> = ({ tableInstance }) => {
|
|
|
26
27
|
const {
|
|
27
28
|
getState,
|
|
28
29
|
options: {
|
|
30
|
+
enableGlobalFilter,
|
|
29
31
|
enablePagination,
|
|
30
32
|
enableToolbarInternalActions,
|
|
31
|
-
|
|
33
|
+
tableId,
|
|
32
34
|
muiTableToolbarTopProps,
|
|
33
35
|
positionPagination,
|
|
36
|
+
positionGlobalFilter,
|
|
34
37
|
positionToolbarActions,
|
|
35
38
|
positionToolbarAlertBanner,
|
|
36
39
|
renderToolbarCustomActions,
|
|
37
40
|
},
|
|
38
41
|
} = tableInstance;
|
|
39
42
|
|
|
40
|
-
const { isFullScreen } = getState();
|
|
43
|
+
const { isFullScreen, showGlobalFilter } = getState();
|
|
41
44
|
|
|
42
45
|
const isMobile = useMediaQuery('(max-width:720px)');
|
|
43
46
|
|
|
@@ -48,11 +51,12 @@ export const MRT_ToolbarTop: FC<Props> = ({ tableInstance }) => {
|
|
|
48
51
|
|
|
49
52
|
const stackAlertBanner =
|
|
50
53
|
isMobile ||
|
|
51
|
-
(positionToolbarAlertBanner === 'top' &&
|
|
54
|
+
(positionToolbarAlertBanner === 'top' &&
|
|
55
|
+
(!!renderToolbarCustomActions || showGlobalFilter));
|
|
52
56
|
|
|
53
57
|
return (
|
|
54
58
|
<Toolbar
|
|
55
|
-
id={`mrt-${
|
|
59
|
+
id={`mrt-${tableId}-toolbar-top`}
|
|
56
60
|
variant="dense"
|
|
57
61
|
{...toolbarProps}
|
|
58
62
|
sx={(theme) =>
|
|
@@ -78,9 +82,12 @@ export const MRT_ToolbarTop: FC<Props> = ({ tableInstance }) => {
|
|
|
78
82
|
position: stackAlertBanner ? 'relative' : 'absolute',
|
|
79
83
|
right: 0,
|
|
80
84
|
top: 0,
|
|
81
|
-
width: '
|
|
85
|
+
width: renderToolbarCustomActions ? '100%' : undefined,
|
|
82
86
|
}}
|
|
83
87
|
>
|
|
88
|
+
{enableGlobalFilter && positionGlobalFilter === 'left' && (
|
|
89
|
+
<MRT_SearchTextField tableInstance={tableInstance} />
|
|
90
|
+
)}
|
|
84
91
|
{renderToolbarCustomActions?.({ tableInstance }) ?? <span />}
|
|
85
92
|
{enableToolbarInternalActions && positionToolbarActions === 'top' && (
|
|
86
93
|
<MRT_ToolbarInternalButtons tableInstance={tableInstance} />
|
|
@@ -92,7 +99,7 @@ export const MRT_ToolbarTop: FC<Props> = ({ tableInstance }) => {
|
|
|
92
99
|
<MRT_TablePagination tableInstance={tableInstance} />
|
|
93
100
|
)}
|
|
94
101
|
</div>
|
|
95
|
-
<MRT_LinearProgressBar tableInstance={tableInstance} />
|
|
102
|
+
<MRT_LinearProgressBar alignTo="bottom" tableInstance={tableInstance} />
|
|
96
103
|
</Toolbar>
|
|
97
104
|
);
|
|
98
105
|
};
|