material-react-table 0.7.0 → 0.7.3
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 -2
- package/dist/MaterialReactTable.d.ts +45 -26
- package/dist/icons.d.ts +1 -0
- package/dist/localization.d.ts +1 -0
- package/dist/material-react-table.cjs.development.js +218 -103
- 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 +219 -104
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +2 -2
- package/dist/utils.d.ts +5 -5
- package/package.json +2 -2
- package/src/MaterialReactTable.tsx +73 -25
- package/src/body/MRT_TableBodyCell.tsx +39 -5
- package/src/buttons/MRT_CopyButton.tsx +1 -0
- package/src/footer/MRT_TableFooterCell.tsx +3 -0
- package/src/head/MRT_TableHeadCell.tsx +53 -54
- package/src/head/MRT_TableHeadRow.tsx +12 -3
- package/src/icons.ts +3 -0
- package/src/inputs/MRT_EditCellTextField.tsx +12 -1
- package/src/localization.ts +2 -0
- package/src/menus/MRT_ColumnActionMenu.tsx +26 -4
- package/src/menus/MRT_FilterTypeMenu.tsx +2 -2
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +5 -5
- package/src/table/MRT_Table.tsx +5 -5
- package/src/table/MRT_TableContainer.tsx +3 -4
- package/src/table/MRT_TablePaper.tsx +9 -13
- package/src/table/MRT_TableRoot.tsx +59 -33
- package/src/toolbar/MRT_ToolbarBottom.tsx +2 -2
- package/src/toolbar/MRT_ToolbarTop.tsx +2 -2
- package/src/utils.ts +15 -11
|
@@ -16,7 +16,14 @@ interface Props {
|
|
|
16
16
|
export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
17
17
|
const {
|
|
18
18
|
getState,
|
|
19
|
-
options: {
|
|
19
|
+
options: {
|
|
20
|
+
idPrefix,
|
|
21
|
+
enableEditing,
|
|
22
|
+
muiTableBodyCellEditTextFieldProps,
|
|
23
|
+
onCellEditBlur,
|
|
24
|
+
onCellEditChange,
|
|
25
|
+
},
|
|
26
|
+
setCurrentEditingCell,
|
|
20
27
|
setCurrentEditingRow,
|
|
21
28
|
} = tableInstance;
|
|
22
29
|
|
|
@@ -27,6 +34,7 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
27
34
|
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
28
35
|
setValue(event.target.value);
|
|
29
36
|
column.onCellEditChange?.({ event, cell, tableInstance });
|
|
37
|
+
onCellEditChange?.({ event, cell, tableInstance });
|
|
30
38
|
};
|
|
31
39
|
|
|
32
40
|
const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
|
|
@@ -34,7 +42,9 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
34
42
|
row.values[column.id] = value;
|
|
35
43
|
setCurrentEditingRow({ ...getState().currentEditingRow } as MRT_Row);
|
|
36
44
|
}
|
|
45
|
+
setCurrentEditingCell(null);
|
|
37
46
|
column.onCellEditBlur?.({ event, cell, tableInstance });
|
|
47
|
+
onCellEditBlur?.({ event, cell, tableInstance });
|
|
38
48
|
};
|
|
39
49
|
|
|
40
50
|
const mTableBodyCellEditTextFieldProps =
|
|
@@ -58,6 +68,7 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
58
68
|
|
|
59
69
|
return (
|
|
60
70
|
<TextField
|
|
71
|
+
id={`mrt-${idPrefix}-edit-cell-text-field-${cell.id}`}
|
|
61
72
|
margin="dense"
|
|
62
73
|
onBlur={handleBlur}
|
|
63
74
|
onChange={handleChange}
|
package/src/localization.ts
CHANGED
|
@@ -32,6 +32,7 @@ export interface MRT_Localization {
|
|
|
32
32
|
hideColumn: string;
|
|
33
33
|
pinToLeft: string;
|
|
34
34
|
pinToRight: string;
|
|
35
|
+
resetColumnSize: string;
|
|
35
36
|
rowActions: string;
|
|
36
37
|
rowNumber: string;
|
|
37
38
|
rowNumbers: string;
|
|
@@ -92,6 +93,7 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
|
92
93
|
hideColumn: 'Hide {column} column',
|
|
93
94
|
pinToLeft: 'Pin to left',
|
|
94
95
|
pinToRight: 'Pin to right',
|
|
96
|
+
resetColumnSize: 'Reset column size',
|
|
95
97
|
rowActions: 'Row Actions',
|
|
96
98
|
rowNumber: '#',
|
|
97
99
|
rowNumbers: 'Row Numbers',
|
|
@@ -35,9 +35,10 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
35
35
|
setColumnOrder,
|
|
36
36
|
options: {
|
|
37
37
|
enableColumnFilters,
|
|
38
|
-
|
|
38
|
+
enableColumnResizing,
|
|
39
39
|
enableGrouping,
|
|
40
40
|
enableHiding,
|
|
41
|
+
enablePinning,
|
|
41
42
|
enableSorting,
|
|
42
43
|
icons: {
|
|
43
44
|
ArrowRightIcon,
|
|
@@ -48,6 +49,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
48
49
|
FilterListOffIcon,
|
|
49
50
|
PushPinIcon,
|
|
50
51
|
SortIcon,
|
|
52
|
+
RestartAltIcon,
|
|
51
53
|
VisibilityOffIcon,
|
|
52
54
|
},
|
|
53
55
|
idPrefix,
|
|
@@ -58,7 +60,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
58
60
|
|
|
59
61
|
const { column } = header;
|
|
60
62
|
|
|
61
|
-
const {
|
|
63
|
+
const { columnSizing, columnVisibility, isDensePadding } = getState();
|
|
62
64
|
|
|
63
65
|
const [filterMenuAnchorEl, setFilterMenuAnchorEl] =
|
|
64
66
|
useState<null | HTMLElement>(null);
|
|
@@ -81,6 +83,11 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
81
83
|
setAnchorEl(null);
|
|
82
84
|
};
|
|
83
85
|
|
|
86
|
+
const handleResetColumnSize = () => {
|
|
87
|
+
column.resetSize();
|
|
88
|
+
setAnchorEl(null);
|
|
89
|
+
};
|
|
90
|
+
|
|
84
91
|
const handleHideColumn = () => {
|
|
85
92
|
column.toggleVisibility(false);
|
|
86
93
|
setAnchorEl(null);
|
|
@@ -263,7 +270,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
263
270
|
{enablePinning &&
|
|
264
271
|
column.getCanPin() && [
|
|
265
272
|
<MenuItem
|
|
266
|
-
disabled={column.getIsPinned() === 'left'}
|
|
273
|
+
disabled={column.getIsPinned() === 'left' || !column.getCanPin()}
|
|
267
274
|
key={0}
|
|
268
275
|
onClick={() => handlePinColumn('left')}
|
|
269
276
|
sx={commonMenuItemStyles}
|
|
@@ -276,7 +283,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
276
283
|
</Box>
|
|
277
284
|
</MenuItem>,
|
|
278
285
|
<MenuItem
|
|
279
|
-
disabled={column.getIsPinned() === 'right'}
|
|
286
|
+
disabled={column.getIsPinned() === 'right' || !column.getCanPin()}
|
|
280
287
|
key={0}
|
|
281
288
|
onClick={() => handlePinColumn('right')}
|
|
282
289
|
sx={commonMenuItemStyles}
|
|
@@ -303,6 +310,21 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
303
310
|
</Box>
|
|
304
311
|
</MenuItem>,
|
|
305
312
|
]}
|
|
313
|
+
{enableColumnResizing && [
|
|
314
|
+
<MenuItem
|
|
315
|
+
disabled={!column.getCanResize() || !columnSizing[column.id]}
|
|
316
|
+
key={0}
|
|
317
|
+
onClick={handleResetColumnSize}
|
|
318
|
+
sx={commonMenuItemStyles}
|
|
319
|
+
>
|
|
320
|
+
<Box sx={commonListItemStyles}>
|
|
321
|
+
<ListItemIcon>
|
|
322
|
+
<RestartAltIcon />
|
|
323
|
+
</ListItemIcon>
|
|
324
|
+
{localization.resetColumnSize}
|
|
325
|
+
</Box>
|
|
326
|
+
</MenuItem>,
|
|
327
|
+
]}
|
|
306
328
|
{enableHiding && [
|
|
307
329
|
<MenuItem
|
|
308
330
|
disabled={column.enableHiding === false}
|
|
@@ -123,8 +123,8 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
|
|
|
123
123
|
},
|
|
124
124
|
].filter((filterType) =>
|
|
125
125
|
header
|
|
126
|
-
? !header.column.
|
|
127
|
-
header.column.
|
|
126
|
+
? !header.column.enabledColumnFilterTypes ||
|
|
127
|
+
header.column.enabledColumnFilterTypes.includes(filterType.type)
|
|
128
128
|
: (!enabledGlobalFilterTypes ||
|
|
129
129
|
enabledGlobalFilterTypes.includes(filterType.type)) &&
|
|
130
130
|
[
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { FormControlLabel, MenuItem, Switch } from '@mui/material';
|
|
3
|
-
import type {
|
|
3
|
+
import type { MRT_Column, MRT_TableInstance } from '..';
|
|
4
4
|
import { commonMenuItemStyles } from './MRT_ColumnActionMenu';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
|
-
column:
|
|
7
|
+
column: MRT_Column;
|
|
8
8
|
isSubMenu?: boolean;
|
|
9
9
|
tableInstance: MRT_TableInstance;
|
|
10
10
|
}
|
|
@@ -26,9 +26,9 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
26
26
|
(column.columnDefType === 'group' &&
|
|
27
27
|
column.getLeafColumns().some((col) => col.getIsVisible()));
|
|
28
28
|
|
|
29
|
-
const handleToggleColumnHidden = (column:
|
|
29
|
+
const handleToggleColumnHidden = (column: MRT_Column) => {
|
|
30
30
|
if (column.columnDefType === 'group') {
|
|
31
|
-
column?.columns?.forEach?.((childColumn:
|
|
31
|
+
column?.columns?.forEach?.((childColumn: MRT_Column) => {
|
|
32
32
|
childColumn.toggleVisibility(!switchChecked);
|
|
33
33
|
});
|
|
34
34
|
} else {
|
|
@@ -57,7 +57,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
57
57
|
onChange={() => handleToggleColumnHidden(column)}
|
|
58
58
|
/>
|
|
59
59
|
</MenuItem>
|
|
60
|
-
{column.columns?.map((c:
|
|
60
|
+
{column.columns?.map((c: MRT_Column, i) => (
|
|
61
61
|
<MRT_ShowHideColumnsMenuItems
|
|
62
62
|
key={`${i}-${c.id}`}
|
|
63
63
|
column={c}
|
package/src/table/MRT_Table.tsx
CHANGED
|
@@ -14,10 +14,10 @@ export const MRT_Table: FC<Props> = ({ pinned, tableInstance }) => {
|
|
|
14
14
|
const {
|
|
15
15
|
getTableProps,
|
|
16
16
|
options: {
|
|
17
|
-
enableStickyHeader,
|
|
18
|
-
hideTableFooter,
|
|
19
|
-
hideTableHead,
|
|
20
17
|
muiTableProps,
|
|
18
|
+
enableTableHead,
|
|
19
|
+
enableTableFooter,
|
|
20
|
+
enableStickyHeader,
|
|
21
21
|
},
|
|
22
22
|
} = tableInstance;
|
|
23
23
|
|
|
@@ -33,11 +33,11 @@ export const MRT_Table: FC<Props> = ({ pinned, tableInstance }) => {
|
|
|
33
33
|
|
|
34
34
|
return (
|
|
35
35
|
<Table stickyHeader={enableStickyHeader} {...tableProps}>
|
|
36
|
-
{
|
|
36
|
+
{enableTableHead && (
|
|
37
37
|
<MRT_TableHead pinned={pinned} tableInstance={tableInstance} />
|
|
38
38
|
)}
|
|
39
39
|
<MRT_TableBody pinned={pinned} tableInstance={tableInstance} />
|
|
40
|
-
{
|
|
40
|
+
{enableTableFooter && (
|
|
41
41
|
<MRT_TableFooter pinned={pinned} tableInstance={tableInstance} />
|
|
42
42
|
)}
|
|
43
43
|
</Table>
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import React, { FC, useEffect, useState } from 'react';
|
|
1
|
+
import React, { CSSProperties, FC, useEffect, useState } from 'react';
|
|
2
2
|
import { alpha, Box, TableContainer, Theme } from '@mui/material';
|
|
3
|
-
import { SystemStyleObject } from '@mui/material/node_modules/@mui/system';
|
|
4
3
|
import { MRT_TableInstance } from '..';
|
|
5
4
|
import { MRT_Table } from './MRT_Table';
|
|
6
5
|
|
|
@@ -12,10 +11,10 @@ const commonBoxStyles = ({
|
|
|
12
11
|
pinned?: 'left' | 'right';
|
|
13
12
|
theme: Theme;
|
|
14
13
|
visible?: boolean;
|
|
15
|
-
}):
|
|
14
|
+
}): CSSProperties => ({
|
|
16
15
|
display: 'grid',
|
|
17
16
|
minWidth: visible ? '200px' : 0,
|
|
18
|
-
overflowX: 'auto',
|
|
17
|
+
overflowX: pinned ? 'scroll' : 'auto',
|
|
19
18
|
boxShadow:
|
|
20
19
|
pinned === 'left'
|
|
21
20
|
? `0 1px 12px ${alpha(theme.palette.common.black, 0.5)}`
|
|
@@ -12,7 +12,7 @@ interface Props {
|
|
|
12
12
|
export const MRT_TablePaper: FC<Props> = ({ tableInstance }) => {
|
|
13
13
|
const {
|
|
14
14
|
getState,
|
|
15
|
-
options: {
|
|
15
|
+
options: { enableToolbarBottom, enableToolbarTop, muiTablePaperProps },
|
|
16
16
|
} = tableInstance;
|
|
17
17
|
|
|
18
18
|
const { isFullScreen } = getState();
|
|
@@ -21,8 +21,10 @@ export const MRT_TablePaper: FC<Props> = ({ tableInstance }) => {
|
|
|
21
21
|
if (typeof window !== 'undefined') {
|
|
22
22
|
if (isFullScreen) {
|
|
23
23
|
document.body.style.overflow = 'hidden';
|
|
24
|
+
document.body.style.height = '100vh';
|
|
24
25
|
} else {
|
|
25
26
|
document.body.style.overflow = 'auto';
|
|
27
|
+
document.body.style.height = 'auto';
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
}, [isFullScreen]);
|
|
@@ -41,23 +43,17 @@ export const MRT_TablePaper: FC<Props> = ({ tableInstance }) => {
|
|
|
41
43
|
...tablePaperProps?.sx,
|
|
42
44
|
}}
|
|
43
45
|
style={{
|
|
44
|
-
height: isFullScreen ? '
|
|
45
|
-
left: isFullScreen ? '0' : undefined,
|
|
46
|
+
height: isFullScreen ? '100vh' : undefined,
|
|
46
47
|
margin: isFullScreen ? '0' : undefined,
|
|
47
|
-
maxHeight: isFullScreen ? '
|
|
48
|
-
maxWidth: isFullScreen ? '
|
|
49
|
-
|
|
50
|
-
position: isFullScreen ? 'fixed' : undefined,
|
|
51
|
-
right: isFullScreen ? '0' : undefined,
|
|
52
|
-
top: isFullScreen ? '0' : undefined,
|
|
48
|
+
maxHeight: isFullScreen ? '100vh' : undefined,
|
|
49
|
+
maxWidth: isFullScreen ? '100vw' : undefined,
|
|
50
|
+
padding: isFullScreen ? '0' : undefined,
|
|
53
51
|
width: isFullScreen ? '100vw' : undefined,
|
|
54
|
-
zIndex: isFullScreen ? 1200 : 1,
|
|
55
|
-
bottom: isFullScreen ? '0' : undefined,
|
|
56
52
|
}}
|
|
57
53
|
>
|
|
58
|
-
{
|
|
54
|
+
{enableToolbarTop && <MRT_ToolbarTop tableInstance={tableInstance} />}
|
|
59
55
|
<MRT_TableContainer tableInstance={tableInstance} />
|
|
60
|
-
{
|
|
56
|
+
{enableToolbarBottom && (
|
|
61
57
|
<MRT_ToolbarBottom tableInstance={tableInstance} />
|
|
62
58
|
)}
|
|
63
59
|
</Paper>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useMemo, useState } from 'react';
|
|
1
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
PaginationState,
|
|
4
4
|
Table,
|
|
@@ -15,7 +15,8 @@ import {
|
|
|
15
15
|
ColumnDef,
|
|
16
16
|
} from '@tanstack/react-table';
|
|
17
17
|
import {
|
|
18
|
-
|
|
18
|
+
MRT_Cell,
|
|
19
|
+
MRT_ColumnDef,
|
|
19
20
|
MRT_FilterType,
|
|
20
21
|
MRT_Row,
|
|
21
22
|
MRT_TableInstance,
|
|
@@ -34,16 +35,24 @@ import {
|
|
|
34
35
|
} from '../utils';
|
|
35
36
|
import { defaultFilterFNs } from '../filtersFNs';
|
|
36
37
|
import { MRT_FILTER_TYPE } from '../enums';
|
|
38
|
+
import { Box, Dialog, Grow } from '@mui/material';
|
|
37
39
|
|
|
38
40
|
export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
39
41
|
props: MaterialReactTableProps<D>,
|
|
40
42
|
) => {
|
|
41
|
-
const idPrefix =
|
|
42
|
-
|
|
43
|
+
const [idPrefix, setIdPrefix] = useState(props.idPrefix);
|
|
44
|
+
useEffect(
|
|
45
|
+
() =>
|
|
46
|
+
setIdPrefix(props.idPrefix ?? Math.random().toString(36).substring(2, 9)),
|
|
43
47
|
[props.idPrefix],
|
|
44
48
|
);
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
|
|
50
|
+
const [currentEditingCell, setCurrentEditingCell] =
|
|
51
|
+
useState<MRT_Cell<D> | null>(
|
|
52
|
+
props.initialState?.currentEditingCell ?? null,
|
|
53
|
+
);
|
|
54
|
+
const [currentEditingRow, setCurrentEditingRow] = useState<MRT_Row<D> | null>(
|
|
55
|
+
props.initialState?.currentEditingRow ?? null,
|
|
47
56
|
);
|
|
48
57
|
const [isDensePadding, setIsDensePadding] = useState(
|
|
49
58
|
props.initialState?.isDensePadding ?? false,
|
|
@@ -68,16 +77,14 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
68
77
|
}>(() =>
|
|
69
78
|
Object.assign(
|
|
70
79
|
{},
|
|
71
|
-
...getAllLeafColumnDefs(props.columns as
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}),
|
|
80
|
-
),
|
|
80
|
+
...getAllLeafColumnDefs(props.columns as MRT_ColumnDef[]).map((c) => ({
|
|
81
|
+
[c.id as string]:
|
|
82
|
+
c.filter ??
|
|
83
|
+
props?.initialState?.columnFilters?.find((cf) => cf.id === c.id) ??
|
|
84
|
+
(!!c.filterSelectOptions?.length
|
|
85
|
+
? MRT_FILTER_TYPE.EQUALS
|
|
86
|
+
: MRT_FILTER_TYPE.BEST_MATCH),
|
|
87
|
+
})),
|
|
81
88
|
),
|
|
82
89
|
);
|
|
83
90
|
|
|
@@ -85,15 +92,13 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
85
92
|
props.globalFilterType ?? MRT_FILTER_TYPE.BEST_MATCH_FIRST,
|
|
86
93
|
);
|
|
87
94
|
|
|
88
|
-
const table = useMemo(
|
|
89
|
-
() => createTable<{ Row: D }>(),
|
|
90
|
-
[],
|
|
91
|
-
) as unknown as Table<D>;
|
|
95
|
+
const table = useMemo(() => createTable() as unknown as Table<D>, []);
|
|
92
96
|
|
|
93
97
|
const displayColumns = useMemo(
|
|
94
98
|
() =>
|
|
95
99
|
[
|
|
96
|
-
(props.enableRowActions ||
|
|
100
|
+
(props.enableRowActions ||
|
|
101
|
+
(props.enableEditing && props.editingMode === 'row')) &&
|
|
97
102
|
createDisplayColumn(table, {
|
|
98
103
|
Cell: ({ cell }) => (
|
|
99
104
|
<MRT_ToggleRowActionMenuButton
|
|
@@ -152,6 +157,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
152
157
|
}),
|
|
153
158
|
].filter(Boolean),
|
|
154
159
|
[
|
|
160
|
+
props.editingMode,
|
|
155
161
|
props.enableEditing,
|
|
156
162
|
props.enableExpandAll,
|
|
157
163
|
props.enableExpanded,
|
|
@@ -184,11 +190,11 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
184
190
|
? [...Array(10).fill(null)].map(() =>
|
|
185
191
|
Object.assign(
|
|
186
192
|
{},
|
|
187
|
-
...getAllLeafColumnDefs(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
...getAllLeafColumnDefs(props.columns as MRT_ColumnDef[]).map(
|
|
194
|
+
(c) => ({
|
|
195
|
+
[c.id]: null,
|
|
196
|
+
}),
|
|
197
|
+
),
|
|
192
198
|
),
|
|
193
199
|
)
|
|
194
200
|
: props.data,
|
|
@@ -198,9 +204,6 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
198
204
|
//@ts-ignore
|
|
199
205
|
const tableInstance: MRT_TableInstance<{}> = {
|
|
200
206
|
...useTableInstance(table, {
|
|
201
|
-
...props,
|
|
202
|
-
columns,
|
|
203
|
-
data,
|
|
204
207
|
//@ts-ignore
|
|
205
208
|
filterTypes: defaultFilterFNs,
|
|
206
209
|
getColumnFilteredRowModel: getColumnFilteredRowModelSync(),
|
|
@@ -210,14 +213,16 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
210
213
|
getGroupedRowModel: getGroupedRowModelSync(),
|
|
211
214
|
getPaginationRowModel: getPaginationRowModel(),
|
|
212
215
|
getSortedRowModel: getSortedRowModelSync(),
|
|
213
|
-
getSubRows:
|
|
216
|
+
getSubRows: (originalRow: D) => originalRow.subRows,
|
|
214
217
|
globalFilterType: currentGlobalFilterType,
|
|
215
218
|
idPrefix,
|
|
216
|
-
//@ts-ignore
|
|
217
|
-
initialState: props.initialState,
|
|
218
219
|
onPaginationChange: (updater: any) =>
|
|
219
220
|
setPagination((old) => functionalUpdate(updater, old)),
|
|
221
|
+
...props,
|
|
222
|
+
columns,
|
|
223
|
+
data,
|
|
220
224
|
state: {
|
|
225
|
+
currentEditingCell,
|
|
221
226
|
currentEditingRow,
|
|
222
227
|
currentFilterTypes,
|
|
223
228
|
currentGlobalFilterType,
|
|
@@ -230,6 +235,9 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
230
235
|
...props.state,
|
|
231
236
|
},
|
|
232
237
|
}),
|
|
238
|
+
//@ts-ignore
|
|
239
|
+
setCurrentEditingCell,
|
|
240
|
+
//@ts-ignore
|
|
233
241
|
setCurrentEditingRow,
|
|
234
242
|
setCurrentFilterTypes,
|
|
235
243
|
setCurrentGlobalFilterType,
|
|
@@ -239,5 +247,23 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
239
247
|
setShowGlobalFilter,
|
|
240
248
|
};
|
|
241
249
|
|
|
242
|
-
return
|
|
250
|
+
return (
|
|
251
|
+
<>
|
|
252
|
+
<Dialog
|
|
253
|
+
TransitionComponent={Grow}
|
|
254
|
+
PaperComponent={Box}
|
|
255
|
+
disablePortal
|
|
256
|
+
fullScreen
|
|
257
|
+
keepMounted={false}
|
|
258
|
+
onClose={() => tableInstance.setIsFullScreen(false)}
|
|
259
|
+
open={tableInstance.getState().isFullScreen}
|
|
260
|
+
transitionDuration={400}
|
|
261
|
+
>
|
|
262
|
+
<MRT_TablePaper tableInstance={tableInstance} />
|
|
263
|
+
</Dialog>
|
|
264
|
+
{!tableInstance.getState().isFullScreen && (
|
|
265
|
+
<MRT_TablePaper tableInstance={tableInstance} />
|
|
266
|
+
)}
|
|
267
|
+
</>
|
|
268
|
+
);
|
|
243
269
|
};
|
|
@@ -15,7 +15,7 @@ export const MRT_ToolbarBottom: FC<Props> = ({ tableInstance }) => {
|
|
|
15
15
|
const {
|
|
16
16
|
getState,
|
|
17
17
|
options: {
|
|
18
|
-
|
|
18
|
+
enableToolbarInternalActions,
|
|
19
19
|
idPrefix,
|
|
20
20
|
enablePagination,
|
|
21
21
|
muiTableToolbarBottomProps,
|
|
@@ -51,7 +51,7 @@ export const MRT_ToolbarBottom: FC<Props> = ({ tableInstance }) => {
|
|
|
51
51
|
<Box
|
|
52
52
|
sx={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}
|
|
53
53
|
>
|
|
54
|
-
{
|
|
54
|
+
{enableToolbarInternalActions && positionToolbarActions === 'bottom' ? (
|
|
55
55
|
<MRT_ToolbarInternalButtons tableInstance={tableInstance} />
|
|
56
56
|
) : (
|
|
57
57
|
<span />
|
|
@@ -29,7 +29,7 @@ export const MRT_ToolbarTop: FC<Props> = ({ tableInstance }) => {
|
|
|
29
29
|
options: {
|
|
30
30
|
enableGlobalFilter,
|
|
31
31
|
enablePagination,
|
|
32
|
-
|
|
32
|
+
enableToolbarInternalActions,
|
|
33
33
|
idPrefix,
|
|
34
34
|
muiTableToolbarTopProps,
|
|
35
35
|
positionPagination,
|
|
@@ -82,7 +82,7 @@ export const MRT_ToolbarTop: FC<Props> = ({ tableInstance }) => {
|
|
|
82
82
|
{enableGlobalFilter && (
|
|
83
83
|
<MRT_SearchTextField tableInstance={tableInstance} />
|
|
84
84
|
)}
|
|
85
|
-
{
|
|
85
|
+
{enableToolbarInternalActions && positionToolbarActions === 'top' && (
|
|
86
86
|
<MRT_ToolbarInternalButtons tableInstance={tableInstance} />
|
|
87
87
|
)}
|
|
88
88
|
</Box>
|
package/src/utils.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { ColumnDef, Table } from '@tanstack/react-table';
|
|
2
|
-
import {
|
|
2
|
+
import { MRT_ColumnDef, MRT_FilterType } from '.';
|
|
3
3
|
import { MRT_FILTER_TYPE } from './enums';
|
|
4
|
+
import { defaultFilterFNs } from './filtersFNs';
|
|
4
5
|
|
|
5
6
|
export const getAllLeafColumnDefs = (
|
|
6
|
-
columns:
|
|
7
|
-
):
|
|
8
|
-
let lowestLevelColumns:
|
|
9
|
-
let currentCols:
|
|
7
|
+
columns: MRT_ColumnDef[],
|
|
8
|
+
): MRT_ColumnDef[] => {
|
|
9
|
+
let lowestLevelColumns: MRT_ColumnDef[] = columns;
|
|
10
|
+
let currentCols: MRT_ColumnDef[] | undefined = columns;
|
|
10
11
|
while (!!currentCols?.length && currentCols.some((col) => col.columns)) {
|
|
11
|
-
const nextCols:
|
|
12
|
+
const nextCols: MRT_ColumnDef[] = currentCols
|
|
12
13
|
.filter((col) => !!col.columns)
|
|
13
14
|
.map((col) => col.columns)
|
|
14
|
-
.flat() as
|
|
15
|
+
.flat() as MRT_ColumnDef[];
|
|
15
16
|
if (nextCols.every((col) => !col?.columns)) {
|
|
16
17
|
lowestLevelColumns = [...lowestLevelColumns, ...nextCols];
|
|
17
18
|
}
|
|
@@ -22,7 +23,7 @@ export const getAllLeafColumnDefs = (
|
|
|
22
23
|
|
|
23
24
|
export const createGroup = <D extends Record<string, any> = {}>(
|
|
24
25
|
table: Table<D>,
|
|
25
|
-
column:
|
|
26
|
+
column: MRT_ColumnDef<D>,
|
|
26
27
|
currentFilterTypes: { [key: string]: MRT_FilterType },
|
|
27
28
|
): ColumnDef<D> =>
|
|
28
29
|
table.createGroup({
|
|
@@ -36,15 +37,18 @@ export const createGroup = <D extends Record<string, any> = {}>(
|
|
|
36
37
|
|
|
37
38
|
export const createDataColumn = <D extends Record<string, any> = {}>(
|
|
38
39
|
table: Table<D>,
|
|
39
|
-
column:
|
|
40
|
+
column: MRT_ColumnDef<D>,
|
|
40
41
|
currentFilterTypes: { [key: string]: MRT_FilterType },
|
|
41
42
|
): ColumnDef<D> => // @ts-ignore
|
|
42
43
|
table.createDataColumn(column.id, {
|
|
43
|
-
|
|
44
|
+
filterFn:
|
|
45
|
+
currentFilterTypes[column.id] instanceof Function
|
|
46
|
+
? currentFilterTypes[column.id]
|
|
47
|
+
: defaultFilterFNs[currentFilterTypes[column.id] as MRT_FILTER_TYPE],
|
|
44
48
|
...column,
|
|
45
49
|
}) as any;
|
|
46
50
|
|
|
47
51
|
export const createDisplayColumn = <D extends Record<string, any> = {}>(
|
|
48
52
|
table: Table<D>,
|
|
49
|
-
column: Omit<
|
|
53
|
+
column: Omit<MRT_ColumnDef<D>, 'header'> & { header?: string },
|
|
50
54
|
): ColumnDef<D> => table.createDisplayColumn(column);
|