material-react-table 0.7.0-alpha.8 → 0.7.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 +3 -5
- package/dist/MaterialReactTable.d.ts +65 -46
- package/dist/buttons/{MRT_ToggleSearchButton.d.ts → MRT_ToggleGlobalFilterButton.d.ts} +1 -1
- package/dist/localization.d.ts +3 -0
- package/dist/material-react-table.cjs.development.js +228 -167
- 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 +231 -170
- 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 +5 -5
- package/src/MaterialReactTable.tsx +103 -57
- package/src/body/MRT_TableBodyCell.tsx +5 -3
- package/src/buttons/MRT_EditActionButtons.tsx +1 -1
- package/src/buttons/MRT_FullScreenToggleButton.tsx +13 -4
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +0 -1
- package/src/buttons/MRT_ToggleDensePaddingButton.tsx +13 -4
- package/src/buttons/MRT_ToggleFiltersButton.tsx +13 -4
- package/src/buttons/{MRT_ToggleSearchButton.tsx → MRT_ToggleGlobalFilterButton.tsx} +14 -8
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +1 -1
- package/src/head/MRT_TableHeadCell.tsx +8 -9
- package/src/inputs/MRT_EditCellTextField.tsx +2 -5
- package/src/inputs/MRT_FilterTextField.tsx +2 -2
- package/src/inputs/MRT_SearchTextField.tsx +6 -6
- package/src/localization.ts +6 -0
- package/src/menus/MRT_ColumnActionMenu.tsx +4 -4
- package/src/menus/MRT_FilterTypeMenu.tsx +5 -8
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +7 -7
- package/src/table/MRT_Table.tsx +5 -5
- package/src/table/MRT_TableContainer.tsx +4 -4
- package/src/table/MRT_TablePaper.tsx +9 -13
- package/src/table/MRT_TableRoot.tsx +96 -79
- package/src/toolbar/MRT_ToolbarBottom.tsx +2 -2
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +8 -9
- package/src/toolbar/MRT_ToolbarTop.tsx +2 -2
- package/src/utils.ts +10 -10
|
@@ -30,8 +30,8 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
30
30
|
icons: { FilterAltIcon, FilterAltOff },
|
|
31
31
|
localization,
|
|
32
32
|
muiTableHeadCellProps,
|
|
33
|
-
setShowFilters,
|
|
34
33
|
},
|
|
34
|
+
setShowFilters,
|
|
35
35
|
} = tableInstance;
|
|
36
36
|
|
|
37
37
|
const { isDensePadding, showFilters } = getState();
|
|
@@ -56,9 +56,9 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
56
56
|
|
|
57
57
|
const sortTooltip = !!column.getIsSorted()
|
|
58
58
|
? column.getIsSorted() === 'desc'
|
|
59
|
-
? localization.
|
|
60
|
-
: localization.
|
|
61
|
-
: localization.
|
|
59
|
+
? localization.sortedByColumnDesc.replace('{column}', column.header)
|
|
60
|
+
: localization.sortedByColumnAsc.replace('{column}', column.header)
|
|
61
|
+
: localization.unsorted;
|
|
62
62
|
|
|
63
63
|
const filterType = getState()?.currentFilterTypes?.[header.id];
|
|
64
64
|
|
|
@@ -135,7 +135,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
135
135
|
}}
|
|
136
136
|
>
|
|
137
137
|
<Box
|
|
138
|
-
{
|
|
138
|
+
onClick={() => column.toggleSorting()}
|
|
139
139
|
sx={{
|
|
140
140
|
alignItems: 'center',
|
|
141
141
|
cursor:
|
|
@@ -144,9 +144,8 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
144
144
|
: undefined,
|
|
145
145
|
display: 'flex',
|
|
146
146
|
flexWrap: 'nowrap',
|
|
147
|
-
whiteSpace: column.header.length <
|
|
147
|
+
whiteSpace: column.header.length < 24 ? 'nowrap' : 'normal',
|
|
148
148
|
}}
|
|
149
|
-
title={undefined}
|
|
150
149
|
>
|
|
151
150
|
{headerElement}
|
|
152
151
|
{column.columnDefType !== 'group' && column.getCanSort() && (
|
|
@@ -185,9 +184,9 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
185
184
|
}}
|
|
186
185
|
>
|
|
187
186
|
{showFilters && !column.getColumnFilterValue() ? (
|
|
188
|
-
<FilterAltOff
|
|
187
|
+
<FilterAltOff />
|
|
189
188
|
) : (
|
|
190
|
-
<FilterAltIcon
|
|
189
|
+
<FilterAltIcon />
|
|
191
190
|
)}
|
|
192
191
|
</IconButton>
|
|
193
192
|
</Tooltip>
|
|
@@ -16,11 +16,8 @@ interface Props {
|
|
|
16
16
|
export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
17
17
|
const {
|
|
18
18
|
getState,
|
|
19
|
-
options: {
|
|
20
|
-
|
|
21
|
-
muiTableBodyCellEditTextFieldProps,
|
|
22
|
-
setCurrentEditingRow,
|
|
23
|
-
},
|
|
19
|
+
options: { enableEditing, muiTableBodyCellEditTextFieldProps },
|
|
20
|
+
setCurrentEditingRow,
|
|
24
21
|
} = tableInstance;
|
|
25
22
|
|
|
26
23
|
const [value, setValue] = useState(cell.value);
|
|
@@ -32,8 +32,8 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
|
|
|
32
32
|
idPrefix,
|
|
33
33
|
localization,
|
|
34
34
|
muiTableHeadCellFilterTextFieldProps,
|
|
35
|
-
setCurrentFilterTypes,
|
|
36
35
|
},
|
|
36
|
+
setCurrentFilterTypes,
|
|
37
37
|
} = tableInstance;
|
|
38
38
|
|
|
39
39
|
const { column } = header;
|
|
@@ -206,7 +206,7 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
|
|
|
206
206
|
width: '1.75rem',
|
|
207
207
|
}}
|
|
208
208
|
>
|
|
209
|
-
<CloseIcon
|
|
209
|
+
<CloseIcon />
|
|
210
210
|
</IconButton>
|
|
211
211
|
</span>
|
|
212
212
|
</Tooltip>
|
|
@@ -29,11 +29,11 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
29
29
|
idPrefix,
|
|
30
30
|
localization,
|
|
31
31
|
muiSearchTextFieldProps,
|
|
32
|
-
|
|
32
|
+
onGlobalSearchFilterChange,
|
|
33
33
|
},
|
|
34
34
|
} = tableInstance;
|
|
35
35
|
|
|
36
|
-
const { globalFilter,
|
|
36
|
+
const { globalFilter, showGlobalFilter } = getState();
|
|
37
37
|
|
|
38
38
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
39
39
|
const [searchValue, setSearchValue] = useState(globalFilter ?? '');
|
|
@@ -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
|
+
onGlobalSearchFilterChange?.({ event, tableInstance });
|
|
45
45
|
}, 200),
|
|
46
46
|
[],
|
|
47
47
|
);
|
|
@@ -61,7 +61,7 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
61
61
|
: muiSearchTextFieldProps;
|
|
62
62
|
|
|
63
63
|
return (
|
|
64
|
-
<Collapse in={
|
|
64
|
+
<Collapse in={showGlobalFilter} orientation="horizontal">
|
|
65
65
|
<TextField
|
|
66
66
|
id={`mrt-${idPrefix}-search-text-field`}
|
|
67
67
|
placeholder={localization.search}
|
|
@@ -82,7 +82,7 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
82
82
|
size="small"
|
|
83
83
|
sx={{ height: '1.75rem', width: '1.75rem' }}
|
|
84
84
|
>
|
|
85
|
-
<SearchIcon
|
|
85
|
+
<SearchIcon />
|
|
86
86
|
</IconButton>
|
|
87
87
|
</span>
|
|
88
88
|
</Tooltip>
|
|
@@ -97,7 +97,7 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
97
97
|
size="small"
|
|
98
98
|
title={localization.clearSearch}
|
|
99
99
|
>
|
|
100
|
-
<CloseIcon
|
|
100
|
+
<CloseIcon />
|
|
101
101
|
</IconButton>
|
|
102
102
|
</InputAdornment>
|
|
103
103
|
),
|
package/src/localization.ts
CHANGED
|
@@ -46,6 +46,8 @@ export interface MRT_Localization {
|
|
|
46
46
|
showHideSearch: string;
|
|
47
47
|
sortByColumnAsc: string;
|
|
48
48
|
sortByColumnDesc: string;
|
|
49
|
+
sortedByColumnAsc: string;
|
|
50
|
+
sortedByColumnDesc: string;
|
|
49
51
|
thenBy: string;
|
|
50
52
|
toggleDensePadding: string;
|
|
51
53
|
toggleFullScreen: string;
|
|
@@ -53,6 +55,7 @@ export interface MRT_Localization {
|
|
|
53
55
|
toggleSelectRow: string;
|
|
54
56
|
ungroupByColumn: string;
|
|
55
57
|
unpin: string;
|
|
58
|
+
unsorted: string;
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
@@ -104,6 +107,8 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
|
104
107
|
showHideSearch: 'Show/Hide search',
|
|
105
108
|
sortByColumnAsc: 'Sort by {column} ascending',
|
|
106
109
|
sortByColumnDesc: 'Sort by {column} descending',
|
|
110
|
+
sortedByColumnAsc: 'Sorted by {column} ascending',
|
|
111
|
+
sortedByColumnDesc: 'Sorted by {column} descending',
|
|
107
112
|
thenBy: ', then by ',
|
|
108
113
|
toggleDensePadding: 'Toggle dense padding',
|
|
109
114
|
toggleFullScreen: 'Toggle full screen',
|
|
@@ -111,4 +116,5 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
|
111
116
|
toggleSelectRow: 'Toggle select row',
|
|
112
117
|
ungroupByColumn: 'Ungroup by {column}',
|
|
113
118
|
unpin: 'Unpin',
|
|
119
|
+
unsorted: 'Unsorted',
|
|
114
120
|
};
|
|
@@ -35,7 +35,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
35
35
|
setColumnOrder,
|
|
36
36
|
options: {
|
|
37
37
|
enableColumnFilters,
|
|
38
|
-
|
|
38
|
+
enablePinning,
|
|
39
39
|
enableGrouping,
|
|
40
40
|
enableHiding,
|
|
41
41
|
enableSorting,
|
|
@@ -52,8 +52,8 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
52
52
|
},
|
|
53
53
|
idPrefix,
|
|
54
54
|
localization,
|
|
55
|
-
setShowFilters,
|
|
56
55
|
},
|
|
56
|
+
setShowFilters,
|
|
57
57
|
} = tableInstance;
|
|
58
58
|
|
|
59
59
|
const { column } = header;
|
|
@@ -245,7 +245,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
245
245
|
{enableGrouping &&
|
|
246
246
|
column.getCanGroup() && [
|
|
247
247
|
<MenuItem
|
|
248
|
-
divider={
|
|
248
|
+
divider={enablePinning}
|
|
249
249
|
key={0}
|
|
250
250
|
onClick={handleGroupByColumn}
|
|
251
251
|
sx={commonMenuItemStyles}
|
|
@@ -260,7 +260,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
260
260
|
</Box>
|
|
261
261
|
</MenuItem>,
|
|
262
262
|
]}
|
|
263
|
-
{
|
|
263
|
+
{enablePinning &&
|
|
264
264
|
column.getCanPin() && [
|
|
265
265
|
<MenuItem
|
|
266
266
|
disabled={column.getIsPinned() === 'left'}
|
|
@@ -39,12 +39,9 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
|
|
|
39
39
|
}) => {
|
|
40
40
|
const {
|
|
41
41
|
getState,
|
|
42
|
-
options: {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
setCurrentFilterTypes,
|
|
46
|
-
setCurrentGlobalFilterType,
|
|
47
|
-
},
|
|
42
|
+
options: { enabledGlobalFilterTypes, localization },
|
|
43
|
+
setCurrentFilterTypes,
|
|
44
|
+
setCurrentGlobalFilterType,
|
|
48
45
|
} = tableInstance;
|
|
49
46
|
|
|
50
47
|
const { isDensePadding, currentFilterTypes, currentGlobalFilterType } =
|
|
@@ -126,8 +123,8 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
|
|
|
126
123
|
},
|
|
127
124
|
].filter((filterType) =>
|
|
128
125
|
header
|
|
129
|
-
? !header.column.
|
|
130
|
-
header.column.
|
|
126
|
+
? !header.column.enabledColumnFilterTypes ||
|
|
127
|
+
header.column.enabledColumnFilterTypes.includes(filterType.type)
|
|
131
128
|
: (!enabledGlobalFilterTypes ||
|
|
132
129
|
enabledGlobalFilterTypes.includes(filterType.type)) &&
|
|
133
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
|
}
|
|
@@ -16,7 +16,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
16
16
|
}) => {
|
|
17
17
|
const {
|
|
18
18
|
getState,
|
|
19
|
-
options: {
|
|
19
|
+
options: { onToggleColumnVisibility },
|
|
20
20
|
} = tableInstance;
|
|
21
21
|
|
|
22
22
|
const { columnVisibility } = getState();
|
|
@@ -26,15 +26,15 @@ 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 {
|
|
35
35
|
column.toggleVisibility();
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
onToggleColumnVisibility?.({
|
|
38
38
|
column,
|
|
39
39
|
columnVisibility,
|
|
40
40
|
tableInstance,
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
import React, { FC,
|
|
1
|
+
import React, { FC, useEffect, useState } from 'react';
|
|
2
2
|
import { alpha, Box, TableContainer, Theme } from '@mui/material';
|
|
3
3
|
import { SystemStyleObject } from '@mui/material/node_modules/@mui/system';
|
|
4
4
|
import { MRT_TableInstance } from '..';
|
|
@@ -36,7 +36,7 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
36
36
|
getRightTableWidth,
|
|
37
37
|
getState,
|
|
38
38
|
options: {
|
|
39
|
-
|
|
39
|
+
enablePinning,
|
|
40
40
|
enableStickyHeader,
|
|
41
41
|
idPrefix,
|
|
42
42
|
muiTableContainerProps,
|
|
@@ -52,7 +52,7 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
52
52
|
? muiTableContainerProps({ tableInstance })
|
|
53
53
|
: muiTableContainerProps;
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
useEffect(() => {
|
|
56
56
|
const topToolbarHeight =
|
|
57
57
|
typeof document !== 'undefined'
|
|
58
58
|
? document?.getElementById(`mrt-${idPrefix}-toolbar-top`)
|
|
@@ -85,7 +85,7 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
85
85
|
: undefined,
|
|
86
86
|
}}
|
|
87
87
|
>
|
|
88
|
-
{
|
|
88
|
+
{enablePinning && getIsSomeColumnsPinned() ? (
|
|
89
89
|
<Box
|
|
90
90
|
sx={{
|
|
91
91
|
display: 'grid',
|
|
@@ -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,23 +1,20 @@
|
|
|
1
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
1
2
|
import {
|
|
2
|
-
columnFilterRowsFn,
|
|
3
|
-
createTable,
|
|
4
|
-
expandRowsFn,
|
|
5
|
-
functionalUpdate,
|
|
6
|
-
globalFilterRowsFn,
|
|
7
|
-
groupRowsFn,
|
|
8
|
-
paginateRowsFn,
|
|
9
3
|
PaginationState,
|
|
10
|
-
sortRowsFn,
|
|
11
4
|
Table,
|
|
12
|
-
|
|
5
|
+
createTable,
|
|
6
|
+
functionalUpdate,
|
|
7
|
+
getColumnFilteredRowModelSync,
|
|
8
|
+
getExpandedRowModel,
|
|
9
|
+
getGlobalFilteredRowModelSync,
|
|
10
|
+
getGroupedRowModelSync,
|
|
11
|
+
getPaginationRowModel,
|
|
12
|
+
getSortedRowModelSync,
|
|
13
|
+
useTableInstance,
|
|
14
|
+
getCoreRowModelSync,
|
|
15
|
+
ColumnDef,
|
|
13
16
|
} from '@tanstack/react-table';
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
16
|
-
MRT_ColumnInterface,
|
|
17
|
-
MRT_FilterType,
|
|
18
|
-
MRT_Row,
|
|
19
|
-
MRT_TableInstance,
|
|
20
|
-
} from '..';
|
|
17
|
+
import { MRT_ColumnDef, MRT_FilterType, MRT_Row, MRT_TableInstance } from '..';
|
|
21
18
|
import { MRT_ExpandAllButton } from '../buttons/MRT_ExpandAllButton';
|
|
22
19
|
import { MRT_ExpandButton } from '../buttons/MRT_ExpandButton';
|
|
23
20
|
import { MRT_ToggleRowActionMenuButton } from '../buttons/MRT_ToggleRowActionMenuButton';
|
|
@@ -32,14 +29,18 @@ import {
|
|
|
32
29
|
} from '../utils';
|
|
33
30
|
import { defaultFilterFNs } from '../filtersFNs';
|
|
34
31
|
import { MRT_FILTER_TYPE } from '../enums';
|
|
32
|
+
import { Box, Dialog, Grow } from '@mui/material';
|
|
35
33
|
|
|
36
34
|
export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
37
35
|
props: MaterialReactTableProps<D>,
|
|
38
36
|
) => {
|
|
39
|
-
const idPrefix =
|
|
40
|
-
|
|
37
|
+
const [idPrefix, setIdPrefix] = useState(props.idPrefix);
|
|
38
|
+
useEffect(
|
|
39
|
+
() =>
|
|
40
|
+
setIdPrefix(props.idPrefix ?? Math.random().toString(36).substring(2, 9)),
|
|
41
41
|
[props.idPrefix],
|
|
42
42
|
);
|
|
43
|
+
|
|
43
44
|
const [currentEditingRow, setCurrentEditingRow] = useState<MRT_Row | null>(
|
|
44
45
|
null,
|
|
45
46
|
);
|
|
@@ -52,10 +53,9 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
52
53
|
const [showFilters, setShowFilters] = useState(
|
|
53
54
|
props.initialState?.showFilters ?? false,
|
|
54
55
|
);
|
|
55
|
-
const [
|
|
56
|
-
props.initialState?.
|
|
56
|
+
const [showGlobalFilter, setShowGlobalFilter] = useState(
|
|
57
|
+
props.initialState?.showGlobalFilter ?? false,
|
|
57
58
|
);
|
|
58
|
-
|
|
59
59
|
const [pagination, setPagination] = useState<PaginationState>({
|
|
60
60
|
pageIndex: props.initialState?.pagination?.pageIndex ?? 0,
|
|
61
61
|
pageSize: props.initialState?.pagination?.pageSize ?? 10,
|
|
@@ -67,16 +67,14 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
67
67
|
}>(() =>
|
|
68
68
|
Object.assign(
|
|
69
69
|
{},
|
|
70
|
-
...getAllLeafColumnDefs(props.columns as
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}),
|
|
79
|
-
),
|
|
70
|
+
...getAllLeafColumnDefs(props.columns as MRT_ColumnDef[]).map((c) => ({
|
|
71
|
+
[c.id as string]:
|
|
72
|
+
c.filter ??
|
|
73
|
+
props?.initialState?.columnFilters?.find((cf) => cf.id === c.id) ??
|
|
74
|
+
(!!c.filterSelectOptions?.length
|
|
75
|
+
? MRT_FILTER_TYPE.EQUALS
|
|
76
|
+
: MRT_FILTER_TYPE.BEST_MATCH),
|
|
77
|
+
})),
|
|
80
78
|
),
|
|
81
79
|
);
|
|
82
80
|
|
|
@@ -96,7 +94,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
96
94
|
createDisplayColumn(table, {
|
|
97
95
|
Cell: ({ cell }) => (
|
|
98
96
|
<MRT_ToggleRowActionMenuButton
|
|
99
|
-
row={cell.row as
|
|
97
|
+
row={cell.row as MRT_Row}
|
|
100
98
|
tableInstance={tableInstance}
|
|
101
99
|
/>
|
|
102
100
|
),
|
|
@@ -109,7 +107,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
109
107
|
createDisplayColumn(table, {
|
|
110
108
|
Cell: ({ cell }) => (
|
|
111
109
|
<MRT_ExpandButton
|
|
112
|
-
row={cell.row as
|
|
110
|
+
row={cell.row as MRT_Row}
|
|
113
111
|
tableInstance={tableInstance}
|
|
114
112
|
/>
|
|
115
113
|
),
|
|
@@ -126,7 +124,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
126
124
|
createDisplayColumn(table, {
|
|
127
125
|
Cell: ({ cell }) => (
|
|
128
126
|
<MRT_SelectCheckbox
|
|
129
|
-
row={cell.row as
|
|
127
|
+
row={cell.row as MRT_Row}
|
|
130
128
|
tableInstance={tableInstance}
|
|
131
129
|
/>
|
|
132
130
|
),
|
|
@@ -151,16 +149,16 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
151
149
|
}),
|
|
152
150
|
].filter(Boolean),
|
|
153
151
|
[
|
|
154
|
-
|
|
152
|
+
props.enableEditing,
|
|
155
153
|
props.enableExpandAll,
|
|
156
154
|
props.enableExpanded,
|
|
157
|
-
props.enableRowActions,
|
|
158
155
|
props.enableGrouping,
|
|
159
|
-
props.
|
|
156
|
+
props.enableRowActions,
|
|
160
157
|
props.enableRowNumbers,
|
|
161
158
|
props.enableRowSelection,
|
|
162
159
|
props.enableSelectAll,
|
|
163
160
|
props.localization,
|
|
161
|
+
table,
|
|
164
162
|
],
|
|
165
163
|
);
|
|
166
164
|
|
|
@@ -173,21 +171,21 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
173
171
|
? createGroup(table, column, currentFilterTypes)
|
|
174
172
|
: createDataColumn(table, column, currentFilterTypes),
|
|
175
173
|
),
|
|
176
|
-
] as
|
|
174
|
+
] as ColumnDef<D>[]),
|
|
177
175
|
[table, props.columns, currentFilterTypes],
|
|
178
176
|
);
|
|
179
177
|
|
|
180
|
-
const data = useMemo(
|
|
178
|
+
const data: D['Row'][] = useMemo(
|
|
181
179
|
() =>
|
|
182
180
|
props.isLoading && !props.data.length
|
|
183
|
-
? [...Array(10).fill(null)].map((
|
|
181
|
+
? [...Array(10).fill(null)].map(() =>
|
|
184
182
|
Object.assign(
|
|
185
183
|
{},
|
|
186
|
-
...getAllLeafColumnDefs(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
184
|
+
...getAllLeafColumnDefs(props.columns as MRT_ColumnDef[]).map(
|
|
185
|
+
(c) => ({
|
|
186
|
+
[c.id]: null,
|
|
187
|
+
}),
|
|
188
|
+
),
|
|
191
189
|
),
|
|
192
190
|
)
|
|
193
191
|
: props.data,
|
|
@@ -195,45 +193,64 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
195
193
|
);
|
|
196
194
|
|
|
197
195
|
//@ts-ignore
|
|
198
|
-
const tableInstance: MRT_TableInstance<{}> =
|
|
199
|
-
...
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
196
|
+
const tableInstance: MRT_TableInstance<{}> = {
|
|
197
|
+
...useTableInstance(table, {
|
|
198
|
+
//@ts-ignore
|
|
199
|
+
filterTypes: defaultFilterFNs,
|
|
200
|
+
getColumnFilteredRowModel: getColumnFilteredRowModelSync(),
|
|
201
|
+
getCoreRowModel: getCoreRowModelSync(),
|
|
202
|
+
getExpandedRowModel: getExpandedRowModel(),
|
|
203
|
+
getGlobalFilteredRowModel: getGlobalFilteredRowModelSync(),
|
|
204
|
+
getGroupedRowModel: getGroupedRowModelSync(),
|
|
205
|
+
getPaginationRowModel: getPaginationRowModel(),
|
|
206
|
+
getSortedRowModel: getSortedRowModelSync(),
|
|
207
|
+
getSubRows: (originalRow: D) => originalRow.subRows,
|
|
208
|
+
globalFilterType: currentGlobalFilterType,
|
|
209
|
+
idPrefix,
|
|
210
|
+
onPaginationChange: (updater: any) =>
|
|
211
|
+
setPagination((old) => functionalUpdate(updater, old)),
|
|
212
|
+
...props,
|
|
213
|
+
columns,
|
|
214
|
+
data,
|
|
215
|
+
state: {
|
|
216
|
+
currentEditingRow,
|
|
217
|
+
currentFilterTypes,
|
|
218
|
+
currentGlobalFilterType,
|
|
219
|
+
isDensePadding,
|
|
220
|
+
isFullScreen,
|
|
221
|
+
//@ts-ignore
|
|
222
|
+
pagination,
|
|
223
|
+
showFilters,
|
|
224
|
+
showGlobalFilter,
|
|
225
|
+
...props.state,
|
|
226
|
+
},
|
|
227
|
+
}),
|
|
215
228
|
setCurrentEditingRow,
|
|
216
229
|
setCurrentFilterTypes,
|
|
217
230
|
setCurrentGlobalFilterType,
|
|
218
231
|
setIsDensePadding,
|
|
219
232
|
setIsFullScreen,
|
|
220
233
|
setShowFilters,
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
state: {
|
|
224
|
-
...props.initialState,
|
|
225
|
-
currentEditingRow,
|
|
226
|
-
currentFilterTypes,
|
|
227
|
-
currentGlobalFilterType,
|
|
228
|
-
isDensePadding,
|
|
229
|
-
isFullScreen,
|
|
230
|
-
//@ts-ignore
|
|
231
|
-
pagination,
|
|
232
|
-
showFilters,
|
|
233
|
-
showSearch,
|
|
234
|
-
...props.state,
|
|
235
|
-
},
|
|
236
|
-
});
|
|
234
|
+
setShowGlobalFilter,
|
|
235
|
+
};
|
|
237
236
|
|
|
238
|
-
return
|
|
237
|
+
return (
|
|
238
|
+
<>
|
|
239
|
+
<Dialog
|
|
240
|
+
TransitionComponent={Grow}
|
|
241
|
+
PaperComponent={Box}
|
|
242
|
+
disablePortal
|
|
243
|
+
fullScreen
|
|
244
|
+
keepMounted={false}
|
|
245
|
+
onClose={() => tableInstance.setIsFullScreen(false)}
|
|
246
|
+
open={tableInstance.getState().isFullScreen}
|
|
247
|
+
transitionDuration={400}
|
|
248
|
+
>
|
|
249
|
+
<MRT_TablePaper tableInstance={tableInstance} />
|
|
250
|
+
</Dialog>
|
|
251
|
+
{!tableInstance.getState().isFullScreen && (
|
|
252
|
+
<MRT_TablePaper tableInstance={tableInstance} />
|
|
253
|
+
)}
|
|
254
|
+
</>
|
|
255
|
+
);
|
|
239
256
|
};
|