material-react-table 0.8.14 → 0.9.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 +2 -1
- package/dist/MaterialReactTable.d.ts +41 -37
- package/dist/material-react-table.cjs.development.js +223 -185
- 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 +223 -185
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/table/MRT_TableRoot.d.ts +1 -0
- package/dist/toolbar/MRT_LinearProgressBar.d.ts +1 -0
- package/dist/utils.d.ts +4 -3
- package/package.json +9 -9
- package/src/MaterialReactTable.tsx +56 -47
- package/src/body/MRT_TableBodyCell.tsx +28 -10
- package/src/body/MRT_TableBodyRow.tsx +4 -3
- 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 +4 -4
- 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 +24 -13
- 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
|
@@ -59,12 +59,12 @@ export const MRT_TableFooterCell: FC<Props> = ({ footer, tableInstance }) => {
|
|
|
59
59
|
<>
|
|
60
60
|
{footer.isPlaceholder
|
|
61
61
|
? null
|
|
62
|
-
: columnDef.Footer instanceof Function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
: (columnDef.Footer instanceof Function
|
|
63
|
+
? columnDef.Footer?.({
|
|
64
|
+
footer,
|
|
65
|
+
tableInstance,
|
|
66
|
+
})
|
|
67
|
+
: columnDef.Footer) ??
|
|
68
68
|
columnDef.footer ??
|
|
69
69
|
footer.renderFooter() ??
|
|
70
70
|
null}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { useDrag, useDrop } from 'react-dnd';
|
|
3
3
|
import { MRT_TableHeadCell } from './MRT_TableHeadCell';
|
|
4
|
-
import type { MRT_Header, MRT_TableInstance } from '..';
|
|
4
|
+
import type { MRT_Column, MRT_Header, MRT_TableInstance } from '..';
|
|
5
|
+
import { reorderColumn } from '../utils';
|
|
5
6
|
|
|
6
7
|
interface Props {
|
|
7
8
|
header: MRT_Header;
|
|
@@ -20,29 +21,20 @@ export const MRT_DraggableTableHeadCell: FC<Props> = ({
|
|
|
20
21
|
|
|
21
22
|
const { columnOrder } = getState();
|
|
22
23
|
|
|
23
|
-
const
|
|
24
|
-
if (movingHeader.column.getCanPin()) {
|
|
25
|
-
movingHeader.column.pin(receivingHeader.column.getIsPinned());
|
|
26
|
-
}
|
|
27
|
-
columnOrder.splice(
|
|
28
|
-
receivingHeader.index,
|
|
29
|
-
0,
|
|
30
|
-
columnOrder.splice(movingHeader.index, 1)[0],
|
|
31
|
-
);
|
|
32
|
-
setColumnOrder([...columnOrder]);
|
|
33
|
-
};
|
|
24
|
+
const { column } = header;
|
|
34
25
|
|
|
35
26
|
const [, dropRef] = useDrop({
|
|
36
|
-
accept: '
|
|
37
|
-
drop: (
|
|
27
|
+
accept: 'column',
|
|
28
|
+
drop: (movingColumn: MRT_Column) =>
|
|
29
|
+
reorderColumn(movingColumn, column, columnOrder, setColumnOrder),
|
|
38
30
|
});
|
|
39
31
|
|
|
40
32
|
const [{ isDragging }, dragRef, previewRef] = useDrag({
|
|
41
33
|
collect: (monitor) => ({
|
|
42
34
|
isDragging: monitor.isDragging(),
|
|
43
35
|
}),
|
|
44
|
-
item: () =>
|
|
45
|
-
type: '
|
|
36
|
+
item: () => column,
|
|
37
|
+
type: 'column',
|
|
46
38
|
});
|
|
47
39
|
|
|
48
40
|
return (
|
|
@@ -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,8 @@ export const MRT_SelectCheckbox: FC<Props> = ({
|
|
|
20
20
|
options: {
|
|
21
21
|
localization,
|
|
22
22
|
muiSelectCheckboxProps,
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
onMrtSelectRowChange,
|
|
24
|
+
onMrtSelectAllChange,
|
|
25
25
|
selectAllMode,
|
|
26
26
|
},
|
|
27
27
|
} = tableInstance;
|
|
@@ -35,14 +35,14 @@ export const MRT_SelectCheckbox: FC<Props> = ({
|
|
|
35
35
|
} else if (selectAllMode === 'page') {
|
|
36
36
|
tableInstance.getToggleAllPageRowsSelectedHandler()(event as any);
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
onMrtSelectAllChange?.({
|
|
39
39
|
event,
|
|
40
40
|
selectedRows: event.target.checked ? getRowModel().flatRows : [],
|
|
41
41
|
tableInstance,
|
|
42
42
|
});
|
|
43
43
|
} else if (row) {
|
|
44
44
|
row?.getToggleSelectedHandler()(event as any);
|
|
45
|
-
|
|
45
|
+
onMrtSelectRowChange?.({
|
|
46
46
|
event,
|
|
47
47
|
row,
|
|
48
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);
|
|
@@ -135,6 +137,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
135
137
|
|
|
136
138
|
const table = useMemo(
|
|
137
139
|
() =>
|
|
140
|
+
// @ts-ignore
|
|
138
141
|
createTable().setOptions({
|
|
139
142
|
//@ts-ignore
|
|
140
143
|
filterFns: defaultFilterFNs,
|
|
@@ -146,9 +149,9 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
146
149
|
getPaginationRowModel: getPaginationRowModel(),
|
|
147
150
|
getSortedRowModel: getSortedRowModel(),
|
|
148
151
|
getSubRows: (row) => (row as MRT_Row)?.subRows,
|
|
149
|
-
|
|
152
|
+
tableId,
|
|
150
153
|
initialState,
|
|
151
|
-
})
|
|
154
|
+
}) as Table<D>,
|
|
152
155
|
[],
|
|
153
156
|
);
|
|
154
157
|
|
|
@@ -165,6 +168,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
165
168
|
),
|
|
166
169
|
header: props.localization?.actions,
|
|
167
170
|
id: 'mrt-row-actions',
|
|
171
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
172
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
168
173
|
size: 60,
|
|
169
174
|
}),
|
|
170
175
|
showExpandColumn &&
|
|
@@ -181,6 +186,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
181
186
|
) : null,
|
|
182
187
|
header: props.localization?.expand,
|
|
183
188
|
id: 'mrt-expand',
|
|
189
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
190
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
184
191
|
size: 50,
|
|
185
192
|
}),
|
|
186
193
|
props.enableRowSelection &&
|
|
@@ -197,6 +204,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
197
204
|
) : null,
|
|
198
205
|
header: props.localization?.select,
|
|
199
206
|
id: 'mrt-select',
|
|
207
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
208
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
200
209
|
size: 50,
|
|
201
210
|
}),
|
|
202
211
|
props.enableRowNumbers &&
|
|
@@ -205,6 +214,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
205
214
|
Header: () => props.localization?.rowNumber,
|
|
206
215
|
header: props.localization?.rowNumbers,
|
|
207
216
|
id: 'mrt-row-numbers',
|
|
217
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
218
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
208
219
|
size: 50,
|
|
209
220
|
}),
|
|
210
221
|
].filter(Boolean),
|
|
@@ -289,14 +300,14 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
289
300
|
if (typeof window === 'undefined' || !props.enablePersistentState) {
|
|
290
301
|
return;
|
|
291
302
|
}
|
|
292
|
-
if (!props.
|
|
303
|
+
if (!props.tableId && process.env.NODE_ENV !== 'production') {
|
|
293
304
|
console.warn(
|
|
294
|
-
'a unique
|
|
305
|
+
'a unique tableId prop is required for persistent table state to work',
|
|
295
306
|
);
|
|
296
307
|
return;
|
|
297
308
|
}
|
|
298
309
|
const itemArgs: [string, string] = [
|
|
299
|
-
`mrt-${
|
|
310
|
+
`mrt-${tableId}-table-state`,
|
|
300
311
|
JSON.stringify(tableInstance.getState()),
|
|
301
312
|
];
|
|
302
313
|
if (props.persistentStateMode === 'localStorage') {
|
|
@@ -306,7 +317,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
306
317
|
}
|
|
307
318
|
}, [
|
|
308
319
|
props.enablePersistentState,
|
|
309
|
-
props.
|
|
320
|
+
props.tableId,
|
|
310
321
|
props.persistentStateMode,
|
|
311
322
|
tableInstance,
|
|
312
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 && (
|