material-react-table 0.6.9 → 0.7.0-alpha.10
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 +29 -19
- package/dist/MaterialReactTable.d.ts +314 -108
- package/dist/body/MRT_TableBody.d.ts +3 -0
- package/dist/body/MRT_TableBodyCell.d.ts +2 -11
- package/dist/body/MRT_TableBodyRow.d.ts +3 -1
- package/dist/body/MRT_TableDetailPanel.d.ts +2 -1
- package/dist/buttons/MRT_CopyButton.d.ts +2 -1
- package/dist/buttons/MRT_EditActionButtons.d.ts +2 -1
- package/dist/buttons/MRT_ExpandAllButton.d.ts +2 -0
- package/dist/buttons/MRT_ExpandButton.d.ts +2 -1
- package/dist/buttons/MRT_FullScreenToggleButton.d.ts +2 -0
- package/dist/buttons/MRT_ShowHideColumnsButton.d.ts +2 -0
- package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +3 -2
- package/dist/buttons/MRT_ToggleDensePaddingButton.d.ts +2 -0
- package/dist/buttons/MRT_ToggleFiltersButton.d.ts +2 -0
- package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +2 -1
- package/dist/buttons/MRT_ToggleSearchButton.d.ts +2 -0
- package/dist/enums.d.ts +2 -1
- package/dist/filtersFNs.d.ts +13 -5
- package/dist/footer/MRT_TableFooter.d.ts +3 -0
- package/dist/footer/MRT_TableFooterCell.d.ts +3 -2
- package/dist/footer/MRT_TableFooterRow.d.ts +2 -1
- package/dist/head/MRT_TableHead.d.ts +3 -0
- package/dist/head/MRT_TableHeadCell.d.ts +4 -18
- package/dist/head/MRT_TableHeadRow.d.ts +2 -1
- package/dist/icons.d.ts +1 -1
- package/dist/inputs/MRT_EditCellTextField.d.ts +2 -1
- package/dist/inputs/MRT_FilterTextField.d.ts +3 -2
- package/dist/inputs/MRT_SearchTextField.d.ts +2 -0
- package/dist/inputs/MRT_SelectCheckbox.d.ts +2 -1
- package/dist/localization.d.ts +10 -2
- package/dist/material-react-table.cjs.development.js +2286 -2459
- 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 +2288 -2461
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ColumnActionMenu.d.ts +3 -2
- package/dist/menus/MRT_FilterTypeMenu.d.ts +4 -3
- package/dist/menus/MRT_RowActionMenu.d.ts +3 -2
- package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +2 -0
- package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +2 -1
- package/dist/table/MRT_Table.d.ts +3 -0
- package/dist/table/MRT_TableContainer.d.ts +2 -0
- package/dist/table/MRT_TablePaper.d.ts +7 -0
- package/dist/table/MRT_TableRoot.d.ts +3 -0
- package/dist/toolbar/MRT_LinearProgressBar.d.ts +2 -0
- package/dist/toolbar/MRT_TablePagination.d.ts +2 -0
- package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +2 -0
- package/dist/toolbar/MRT_ToolbarBottom.d.ts +2 -0
- package/dist/toolbar/MRT_ToolbarInternalButtons.d.ts +2 -0
- package/dist/toolbar/MRT_ToolbarTop.d.ts +4 -2
- package/dist/utils.d.ts +12 -2
- package/package.json +29 -30
- package/src/MaterialReactTable.tsx +614 -297
- package/src/body/MRT_TableBody.tsx +26 -22
- package/src/body/MRT_TableBodyCell.tsx +79 -55
- package/src/body/MRT_TableBodyRow.tsx +37 -67
- package/src/body/MRT_TableDetailPanel.tsx +21 -17
- package/src/buttons/MRT_CopyButton.tsx +34 -10
- package/src/buttons/MRT_EditActionButtons.tsx +16 -13
- package/src/buttons/MRT_ExpandAllButton.tsx +36 -28
- package/src/buttons/MRT_ExpandButton.tsx +35 -41
- package/src/buttons/MRT_FullScreenToggleButton.tsx +18 -11
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +18 -7
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +22 -11
- package/src/buttons/MRT_ToggleDensePaddingButton.tsx +18 -11
- package/src/buttons/MRT_ToggleFiltersButton.tsx +16 -9
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +31 -26
- package/src/buttons/MRT_ToggleSearchButton.tsx +24 -12
- package/src/enums.ts +2 -1
- package/src/filtersFNs.ts +17 -3
- package/src/footer/MRT_TableFooter.tsx +24 -8
- package/src/footer/MRT_TableFooterCell.tsx +34 -26
- package/src/footer/MRT_TableFooterRow.tsx +21 -39
- package/src/head/MRT_TableHead.tsx +24 -8
- package/src/head/MRT_TableHeadCell.tsx +185 -142
- package/src/head/MRT_TableHeadRow.tsx +16 -93
- package/src/icons.ts +3 -3
- package/src/inputs/MRT_EditCellTextField.tsx +39 -24
- package/src/inputs/MRT_FilterTextField.tsx +53 -39
- package/src/inputs/MRT_SearchTextField.tsx +71 -25
- package/src/inputs/MRT_SelectCheckbox.tsx +42 -30
- package/src/localization.ts +20 -4
- package/src/menus/MRT_ColumnActionMenu.tsx +129 -69
- package/src/menus/MRT_FilterTypeMenu.tsx +55 -23
- package/src/menus/MRT_RowActionMenu.tsx +22 -15
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +52 -20
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +27 -17
- package/src/table/MRT_Table.tsx +25 -15
- package/src/table/MRT_TableContainer.tsx +106 -45
- package/src/table/MRT_TablePaper.tsx +65 -0
- package/src/table/MRT_TableRoot.tsx +239 -0
- package/src/toolbar/MRT_LinearProgressBar.tsx +10 -7
- package/src/toolbar/MRT_TablePagination.tsx +33 -19
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +33 -20
- package/src/toolbar/MRT_ToolbarBottom.tsx +32 -21
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +34 -20
- package/src/toolbar/MRT_ToolbarTop.tsx +36 -29
- package/src/utils.ts +37 -8
- package/dist/head/MRT_TableHeadCellActions.d.ts +0 -5
- package/dist/table/MRT_TableSpacerCell.d.ts +0 -6
- package/dist/useMRT.d.ts +0 -27
- package/src/@types/faker.d.ts +0 -4
- package/src/@types/react-table-config.d.ts +0 -53
- package/src/head/MRT_TableHeadCellActions.tsx +0 -29
- package/src/table/MRT_TableSpacerCell.tsx +0 -20
- package/src/useMRT.tsx +0 -215
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import React, { FC, useMemo } from 'react';
|
|
2
2
|
import { Menu, MenuItem } from '@mui/material';
|
|
3
|
-
import {
|
|
4
|
-
import type { MRT_FilterType, MRT_HeaderGroup } from '..';
|
|
3
|
+
import type { MRT_FilterType, MRT_Header, MRT_TableInstance } from '..';
|
|
5
4
|
import { MRT_FILTER_TYPE } from '../enums';
|
|
6
5
|
import {
|
|
6
|
+
bestMatch,
|
|
7
|
+
bestMatchFirst,
|
|
7
8
|
contains,
|
|
8
9
|
empty,
|
|
9
10
|
endsWith,
|
|
10
11
|
equals,
|
|
11
|
-
fuzzy,
|
|
12
12
|
greaterThan,
|
|
13
13
|
lessThan,
|
|
14
14
|
notEmpty,
|
|
@@ -24,18 +24,31 @@ const commonMenuItemStyles = {
|
|
|
24
24
|
|
|
25
25
|
interface Props {
|
|
26
26
|
anchorEl: HTMLElement | null;
|
|
27
|
-
|
|
28
|
-
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
27
|
+
header?: MRT_Header;
|
|
29
28
|
onSelect?: () => void;
|
|
29
|
+
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
30
|
+
tableInstance: MRT_TableInstance;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
export const MRT_FilterTypeMenu: FC<Props> = ({
|
|
33
34
|
anchorEl,
|
|
34
|
-
|
|
35
|
+
header,
|
|
35
36
|
onSelect,
|
|
36
37
|
setAnchorEl,
|
|
38
|
+
tableInstance,
|
|
37
39
|
}) => {
|
|
38
|
-
const {
|
|
40
|
+
const {
|
|
41
|
+
getState,
|
|
42
|
+
options: {
|
|
43
|
+
enabledGlobalFilterTypes,
|
|
44
|
+
localization,
|
|
45
|
+
setCurrentFilterTypes,
|
|
46
|
+
setCurrentGlobalFilterType,
|
|
47
|
+
},
|
|
48
|
+
} = tableInstance;
|
|
49
|
+
|
|
50
|
+
const { isDensePadding, currentFilterTypes, currentGlobalFilterType } =
|
|
51
|
+
getState();
|
|
39
52
|
|
|
40
53
|
const filterTypes: {
|
|
41
54
|
type: MRT_FILTER_TYPE;
|
|
@@ -46,15 +59,21 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
|
|
|
46
59
|
() =>
|
|
47
60
|
[
|
|
48
61
|
{
|
|
49
|
-
type: MRT_FILTER_TYPE.
|
|
50
|
-
label: localization.
|
|
62
|
+
type: MRT_FILTER_TYPE.BEST_MATCH_FIRST,
|
|
63
|
+
label: localization.filterBestMatchFirst,
|
|
51
64
|
divider: false,
|
|
52
|
-
fn:
|
|
65
|
+
fn: bestMatchFirst,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
type: MRT_FILTER_TYPE.BEST_MATCH,
|
|
69
|
+
label: localization.filterBestMatch,
|
|
70
|
+
divider: !!header,
|
|
71
|
+
fn: bestMatch,
|
|
53
72
|
},
|
|
54
73
|
{
|
|
55
74
|
type: MRT_FILTER_TYPE.CONTAINS,
|
|
56
75
|
label: localization.filterContains,
|
|
57
|
-
divider:
|
|
76
|
+
divider: false,
|
|
58
77
|
fn: contains,
|
|
59
78
|
},
|
|
60
79
|
{
|
|
@@ -105,26 +124,39 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
|
|
|
105
124
|
divider: false,
|
|
106
125
|
fn: notEmpty,
|
|
107
126
|
},
|
|
108
|
-
].filter(
|
|
109
|
-
|
|
110
|
-
!column.
|
|
127
|
+
].filter((filterType) =>
|
|
128
|
+
header
|
|
129
|
+
? !header.column.enabledFilterTypes ||
|
|
130
|
+
header.column.enabledFilterTypes.includes(filterType.type)
|
|
131
|
+
: (!enabledGlobalFilterTypes ||
|
|
132
|
+
enabledGlobalFilterTypes.includes(filterType.type)) &&
|
|
133
|
+
[
|
|
134
|
+
MRT_FILTER_TYPE.BEST_MATCH_FIRST,
|
|
135
|
+
MRT_FILTER_TYPE.BEST_MATCH,
|
|
136
|
+
].includes(filterType.type),
|
|
111
137
|
),
|
|
112
138
|
[],
|
|
113
139
|
);
|
|
114
140
|
|
|
115
141
|
const handleSelectFilterType = (value: MRT_FILTER_TYPE) => {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
142
|
+
if (header) {
|
|
143
|
+
setCurrentFilterTypes((prev: { [key: string]: MRT_FilterType }) => ({
|
|
144
|
+
...prev,
|
|
145
|
+
[header.id]: value,
|
|
146
|
+
}));
|
|
147
|
+
if ([MRT_FILTER_TYPE.EMPTY, MRT_FILTER_TYPE.NOT_EMPTY].includes(value)) {
|
|
148
|
+
header.column.setColumnFilterValue(' ');
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
setCurrentGlobalFilterType(value);
|
|
123
152
|
}
|
|
153
|
+
setAnchorEl(null);
|
|
124
154
|
onSelect?.();
|
|
125
155
|
};
|
|
126
156
|
|
|
127
|
-
const filterType =
|
|
157
|
+
const filterType = !!header
|
|
158
|
+
? currentFilterTypes[header.id]
|
|
159
|
+
: currentGlobalFilterType;
|
|
128
160
|
|
|
129
161
|
return (
|
|
130
162
|
<Menu
|
|
@@ -133,7 +165,7 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
|
|
|
133
165
|
onClose={() => setAnchorEl(null)}
|
|
134
166
|
open={!!anchorEl}
|
|
135
167
|
MenuListProps={{
|
|
136
|
-
dense:
|
|
168
|
+
dense: isDensePadding,
|
|
137
169
|
}}
|
|
138
170
|
>
|
|
139
171
|
{filterTypes.map(({ type, label, divider, fn }, index) => (
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { Box, ListItemIcon, Menu, MenuItem } from '@mui/material';
|
|
3
|
-
import {
|
|
4
|
-
import type { MRT_Row } from '..';
|
|
3
|
+
import type { MRT_Row, MRT_TableInstance } from '..';
|
|
5
4
|
import {
|
|
6
5
|
commonListItemStyles,
|
|
7
6
|
commonMenuItemStyles,
|
|
@@ -9,24 +8,30 @@ import {
|
|
|
9
8
|
|
|
10
9
|
interface Props {
|
|
11
10
|
anchorEl: HTMLElement | null;
|
|
11
|
+
handleEdit: () => void;
|
|
12
12
|
row: MRT_Row;
|
|
13
13
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
14
|
-
|
|
14
|
+
tableInstance: MRT_TableInstance;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export const MRT_RowActionMenu: FC<Props> = ({
|
|
18
18
|
anchorEl,
|
|
19
|
-
row,
|
|
20
19
|
handleEdit,
|
|
20
|
+
row,
|
|
21
21
|
setAnchorEl,
|
|
22
|
+
tableInstance,
|
|
22
23
|
}) => {
|
|
23
24
|
const {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
getState,
|
|
26
|
+
options: {
|
|
27
|
+
icons: { EditIcon },
|
|
28
|
+
enableEditing,
|
|
29
|
+
localization,
|
|
30
|
+
renderRowActionMenuItems,
|
|
31
|
+
},
|
|
32
|
+
} = tableInstance;
|
|
33
|
+
|
|
34
|
+
const { isDensePadding } = getState();
|
|
30
35
|
|
|
31
36
|
return (
|
|
32
37
|
<Menu
|
|
@@ -34,10 +39,10 @@ export const MRT_RowActionMenu: FC<Props> = ({
|
|
|
34
39
|
open={!!anchorEl}
|
|
35
40
|
onClose={() => setAnchorEl(null)}
|
|
36
41
|
MenuListProps={{
|
|
37
|
-
dense:
|
|
42
|
+
dense: isDensePadding,
|
|
38
43
|
}}
|
|
39
44
|
>
|
|
40
|
-
{
|
|
45
|
+
{enableEditing && (
|
|
41
46
|
<MenuItem onClick={handleEdit} sx={commonMenuItemStyles}>
|
|
42
47
|
<Box sx={commonListItemStyles}>
|
|
43
48
|
<ListItemIcon>
|
|
@@ -47,9 +52,11 @@ export const MRT_RowActionMenu: FC<Props> = ({
|
|
|
47
52
|
</Box>
|
|
48
53
|
</MenuItem>
|
|
49
54
|
)}
|
|
50
|
-
{renderRowActionMenuItems?.(
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
{renderRowActionMenuItems?.({
|
|
56
|
+
row,
|
|
57
|
+
tableInstance,
|
|
58
|
+
closeMenu: () => setAnchorEl(null),
|
|
59
|
+
})}
|
|
53
60
|
</Menu>
|
|
54
61
|
);
|
|
55
62
|
};
|
|
@@ -1,40 +1,65 @@
|
|
|
1
|
-
import React, { FC } from 'react';
|
|
1
|
+
import React, { FC, useMemo } from 'react';
|
|
2
2
|
import { Button, Menu, Divider, Box } from '@mui/material';
|
|
3
|
-
import type { MRT_ColumnInstance } from '..';
|
|
4
|
-
import { useMRT } from '../useMRT';
|
|
5
3
|
import { MRT_ShowHideColumnsMenuItems } from './MRT_ShowHideColumnsMenuItems';
|
|
6
|
-
import {
|
|
4
|
+
import { MRT_TableInstance } from '..';
|
|
7
5
|
|
|
8
6
|
interface Props {
|
|
9
7
|
anchorEl: HTMLElement | null;
|
|
10
8
|
isSubMenu?: boolean;
|
|
11
9
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
10
|
+
tableInstance: MRT_TableInstance;
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
15
14
|
anchorEl,
|
|
16
15
|
isSubMenu,
|
|
17
16
|
setAnchorEl,
|
|
17
|
+
tableInstance,
|
|
18
18
|
}) => {
|
|
19
|
-
const {
|
|
19
|
+
const {
|
|
20
|
+
getAllColumns,
|
|
21
|
+
getIsAllColumnsVisible,
|
|
22
|
+
getIsSomeColumnsVisible,
|
|
23
|
+
getIsSomeColumnsPinned,
|
|
24
|
+
getState,
|
|
25
|
+
toggleAllColumnsVisible,
|
|
26
|
+
getAllLeafColumns,
|
|
27
|
+
options: { localization },
|
|
28
|
+
} = tableInstance;
|
|
29
|
+
|
|
30
|
+
const { isDensePadding } = getState();
|
|
20
31
|
|
|
21
32
|
const hideAllColumns = () => {
|
|
22
|
-
(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
) as MRT_ColumnInstance[]
|
|
26
|
-
)
|
|
27
|
-
.filter((col: MRT_ColumnInstance) => !col.disableColumnHiding)
|
|
28
|
-
.forEach((col: MRT_ColumnInstance) => col.toggleHidden(true));
|
|
33
|
+
getAllLeafColumns()
|
|
34
|
+
.filter((col) => col.enableHiding !== false)
|
|
35
|
+
.forEach((col) => col.toggleVisibility(false));
|
|
29
36
|
};
|
|
30
37
|
|
|
38
|
+
const allDisplayColumns = useMemo(
|
|
39
|
+
() => getAllColumns().filter((col) => col.columnDefType === 'display'),
|
|
40
|
+
[getAllColumns()],
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const allDataColumns = useMemo(() => {
|
|
44
|
+
const dataColumns = getAllColumns().filter(
|
|
45
|
+
(col) => col.columnDefType !== 'display',
|
|
46
|
+
);
|
|
47
|
+
return getIsSomeColumnsPinned()
|
|
48
|
+
? [
|
|
49
|
+
...dataColumns.filter((c) => c.getIsPinned() === 'left'),
|
|
50
|
+
...dataColumns.filter((c) => c.getIsPinned() === false),
|
|
51
|
+
...dataColumns.filter((c) => c.getIsPinned() === 'right'),
|
|
52
|
+
]
|
|
53
|
+
: dataColumns;
|
|
54
|
+
}, [getAllColumns(), getState().columnPinning, getIsSomeColumnsPinned()]);
|
|
55
|
+
|
|
31
56
|
return (
|
|
32
57
|
<Menu
|
|
33
58
|
anchorEl={anchorEl}
|
|
34
59
|
open={!!anchorEl}
|
|
35
60
|
onClose={() => setAnchorEl(null)}
|
|
36
61
|
MenuListProps={{
|
|
37
|
-
dense:
|
|
62
|
+
dense: isDensePadding,
|
|
38
63
|
}}
|
|
39
64
|
>
|
|
40
65
|
<Box
|
|
@@ -47,28 +72,35 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
47
72
|
>
|
|
48
73
|
{!isSubMenu && (
|
|
49
74
|
<Button
|
|
50
|
-
disabled={
|
|
51
|
-
!tableInstance.getToggleHideAllColumnsProps().checked &&
|
|
52
|
-
!tableInstance.getToggleHideAllColumnsProps().indeterminate
|
|
53
|
-
}
|
|
75
|
+
disabled={!getIsSomeColumnsVisible()}
|
|
54
76
|
onClick={hideAllColumns}
|
|
55
77
|
>
|
|
56
78
|
{localization.hideAll}
|
|
57
79
|
</Button>
|
|
58
80
|
)}
|
|
59
81
|
<Button
|
|
60
|
-
disabled={
|
|
61
|
-
onClick={() =>
|
|
82
|
+
disabled={getIsAllColumnsVisible()}
|
|
83
|
+
onClick={() => toggleAllColumnsVisible(true)}
|
|
62
84
|
>
|
|
63
85
|
{localization.showAll}
|
|
64
86
|
</Button>
|
|
65
87
|
</Box>
|
|
66
88
|
<Divider />
|
|
67
|
-
{
|
|
89
|
+
{allDisplayColumns.map((column, index) => (
|
|
90
|
+
<MRT_ShowHideColumnsMenuItems
|
|
91
|
+
column={column}
|
|
92
|
+
isSubMenu={isSubMenu}
|
|
93
|
+
key={`${index}-${column.id}`}
|
|
94
|
+
tableInstance={tableInstance}
|
|
95
|
+
/>
|
|
96
|
+
))}
|
|
97
|
+
<Divider />
|
|
98
|
+
{allDataColumns.map((column, index) => (
|
|
68
99
|
<MRT_ShowHideColumnsMenuItems
|
|
69
100
|
column={column}
|
|
70
101
|
isSubMenu={isSubMenu}
|
|
71
102
|
key={`${index}-${column.id}`}
|
|
103
|
+
tableInstance={tableInstance}
|
|
72
104
|
/>
|
|
73
105
|
))}
|
|
74
106
|
</Menu>
|
|
@@ -1,37 +1,44 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { FormControlLabel, MenuItem, Switch } from '@mui/material';
|
|
3
|
-
import {
|
|
4
|
-
import type { MRT_ColumnInstance } from '..';
|
|
3
|
+
import type { MRT_ColumnInstance, MRT_TableInstance } from '..';
|
|
5
4
|
import { commonMenuItemStyles } from './MRT_ColumnActionMenu';
|
|
6
|
-
import { useMRT } from '../useMRT';
|
|
7
5
|
|
|
8
6
|
interface Props {
|
|
9
7
|
column: MRT_ColumnInstance;
|
|
10
8
|
isSubMenu?: boolean;
|
|
9
|
+
tableInstance: MRT_TableInstance;
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
14
13
|
column,
|
|
15
14
|
isSubMenu,
|
|
15
|
+
tableInstance,
|
|
16
16
|
}) => {
|
|
17
|
-
const {
|
|
18
|
-
|
|
17
|
+
const {
|
|
18
|
+
getState,
|
|
19
|
+
options: { onColumnHide },
|
|
20
|
+
} = tableInstance;
|
|
19
21
|
|
|
20
|
-
const
|
|
21
|
-
isParentHeader &&
|
|
22
|
-
!!column.columns?.every((childColumn) => childColumn.isVisible);
|
|
22
|
+
const { columnVisibility } = getState();
|
|
23
23
|
|
|
24
|
-
const switchChecked =
|
|
24
|
+
const switchChecked =
|
|
25
|
+
(column.columnDefType !== 'group' && column.getIsVisible()) ||
|
|
26
|
+
(column.columnDefType === 'group' &&
|
|
27
|
+
column.getLeafColumns().some((col) => col.getIsVisible()));
|
|
25
28
|
|
|
26
|
-
const handleToggleColumnHidden = (column:
|
|
27
|
-
if (
|
|
28
|
-
column?.columns?.forEach?.((childColumn) => {
|
|
29
|
-
childColumn.
|
|
29
|
+
const handleToggleColumnHidden = (column: MRT_ColumnInstance) => {
|
|
30
|
+
if (column.columnDefType === 'group') {
|
|
31
|
+
column?.columns?.forEach?.((childColumn: MRT_ColumnInstance) => {
|
|
32
|
+
childColumn.toggleVisibility(!switchChecked);
|
|
30
33
|
});
|
|
31
34
|
} else {
|
|
32
|
-
column.
|
|
35
|
+
column.toggleVisibility();
|
|
33
36
|
}
|
|
34
|
-
onColumnHide?.(
|
|
37
|
+
onColumnHide?.({
|
|
38
|
+
column,
|
|
39
|
+
columnVisibility,
|
|
40
|
+
tableInstance,
|
|
41
|
+
});
|
|
35
42
|
};
|
|
36
43
|
|
|
37
44
|
return (
|
|
@@ -43,8 +50,10 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
43
50
|
componentsProps={{ typography: { sx: { marginBottom: 0 } } }}
|
|
44
51
|
checked={switchChecked}
|
|
45
52
|
control={<Switch />}
|
|
46
|
-
disabled={
|
|
47
|
-
|
|
53
|
+
disabled={
|
|
54
|
+
(isSubMenu && switchChecked) || column.enableHiding === false
|
|
55
|
+
}
|
|
56
|
+
label={column.header}
|
|
48
57
|
onChange={() => handleToggleColumnHidden(column)}
|
|
49
58
|
/>
|
|
50
59
|
</MenuItem>
|
|
@@ -53,6 +62,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
53
62
|
key={`${i}-${c.id}`}
|
|
54
63
|
column={c}
|
|
55
64
|
isSubMenu={isSubMenu}
|
|
65
|
+
tableInstance={tableInstance}
|
|
56
66
|
/>
|
|
57
67
|
))}
|
|
58
68
|
</>
|
package/src/table/MRT_Table.tsx
CHANGED
|
@@ -3,33 +3,43 @@ import { Table } from '@mui/material';
|
|
|
3
3
|
import { MRT_TableHead } from '../head/MRT_TableHead';
|
|
4
4
|
import { MRT_TableBody } from '../body/MRT_TableBody';
|
|
5
5
|
import { MRT_TableFooter } from '../footer/MRT_TableFooter';
|
|
6
|
-
import {
|
|
6
|
+
import { MRT_TableInstance } from '..';
|
|
7
7
|
|
|
8
|
-
interface Props {
|
|
8
|
+
interface Props {
|
|
9
|
+
pinned: 'left' | 'center' | 'right' | 'none';
|
|
10
|
+
tableInstance: MRT_TableInstance;
|
|
11
|
+
}
|
|
9
12
|
|
|
10
|
-
export const MRT_Table: FC<Props> = () => {
|
|
11
|
-
const {
|
|
12
|
-
|
|
13
|
+
export const MRT_Table: FC<Props> = ({ pinned, tableInstance }) => {
|
|
14
|
+
const {
|
|
15
|
+
getTableProps,
|
|
16
|
+
options: {
|
|
17
|
+
enableStickyHeader,
|
|
18
|
+
hideTableFooter,
|
|
19
|
+
hideTableHead,
|
|
20
|
+
muiTableProps,
|
|
21
|
+
},
|
|
22
|
+
} = tableInstance;
|
|
13
23
|
|
|
14
24
|
const mTableProps =
|
|
15
25
|
muiTableProps instanceof Function
|
|
16
|
-
? muiTableProps(tableInstance)
|
|
26
|
+
? muiTableProps({ tableInstance })
|
|
17
27
|
: muiTableProps;
|
|
18
28
|
|
|
19
29
|
const tableProps = {
|
|
30
|
+
...getTableProps(),
|
|
20
31
|
...mTableProps,
|
|
21
|
-
...tableInstance.getTableProps(),
|
|
22
|
-
style: {
|
|
23
|
-
...tableInstance.getTableProps().style,
|
|
24
|
-
...mTableProps?.style,
|
|
25
|
-
},
|
|
26
32
|
};
|
|
27
33
|
|
|
28
34
|
return (
|
|
29
|
-
<Table {...tableProps}>
|
|
30
|
-
{!hideTableHead &&
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
<Table stickyHeader={enableStickyHeader} {...tableProps}>
|
|
36
|
+
{!hideTableHead && (
|
|
37
|
+
<MRT_TableHead pinned={pinned} tableInstance={tableInstance} />
|
|
38
|
+
)}
|
|
39
|
+
<MRT_TableBody pinned={pinned} tableInstance={tableInstance} />
|
|
40
|
+
{!hideTableFooter && (
|
|
41
|
+
<MRT_TableFooter pinned={pinned} tableInstance={tableInstance} />
|
|
42
|
+
)}
|
|
33
43
|
</Table>
|
|
34
44
|
);
|
|
35
45
|
};
|
|
@@ -1,65 +1,126 @@
|
|
|
1
|
-
import React, { FC,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import React, { FC, useLayoutEffect, useState } from 'react';
|
|
2
|
+
import { alpha, Box, TableContainer, Theme } from '@mui/material';
|
|
3
|
+
import { SystemStyleObject } from '@mui/material/node_modules/@mui/system';
|
|
4
|
+
import { MRT_TableInstance } from '..';
|
|
4
5
|
import { MRT_Table } from './MRT_Table';
|
|
5
|
-
import { MRT_ToolbarTop } from '../toolbar/MRT_ToolbarTop';
|
|
6
|
-
import { MRT_ToolbarBottom } from '../toolbar/MRT_ToolbarBottom';
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
const commonBoxStyles = ({
|
|
8
|
+
pinned,
|
|
9
|
+
theme,
|
|
10
|
+
visible,
|
|
11
|
+
}: {
|
|
12
|
+
pinned?: 'left' | 'right';
|
|
13
|
+
theme: Theme;
|
|
14
|
+
visible?: boolean;
|
|
15
|
+
}): SystemStyleObject<Theme> => ({
|
|
16
|
+
display: 'grid',
|
|
17
|
+
minWidth: visible ? '200px' : 0,
|
|
18
|
+
overflowX: 'auto',
|
|
19
|
+
boxShadow:
|
|
20
|
+
pinned === 'left'
|
|
21
|
+
? `0 1px 12px ${alpha(theme.palette.common.black, 0.5)}`
|
|
22
|
+
: pinned === 'right'
|
|
23
|
+
? `0 -1px 12px ${alpha(theme.palette.common.black, 0.5)}`
|
|
24
|
+
: 'none',
|
|
25
|
+
});
|
|
9
26
|
|
|
10
|
-
|
|
27
|
+
interface Props {
|
|
28
|
+
tableInstance: MRT_TableInstance;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
11
32
|
const {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
33
|
+
getCenterTableWidth,
|
|
34
|
+
getIsSomeColumnsPinned,
|
|
35
|
+
getLeftTableWidth,
|
|
36
|
+
getRightTableWidth,
|
|
37
|
+
getState,
|
|
38
|
+
options: {
|
|
39
|
+
enableColumnPinning,
|
|
40
|
+
enableStickyHeader,
|
|
41
|
+
idPrefix,
|
|
42
|
+
muiTableContainerProps,
|
|
43
|
+
},
|
|
44
|
+
} = tableInstance;
|
|
45
|
+
|
|
46
|
+
const { isFullScreen, columnPinning } = getState();
|
|
18
47
|
|
|
19
|
-
|
|
20
|
-
if (typeof window !== 'undefined') {
|
|
21
|
-
if (fullScreen) {
|
|
22
|
-
document.body.style.overflow = 'hidden';
|
|
23
|
-
} else {
|
|
24
|
-
document.body.style.overflow = 'auto';
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}, [fullScreen]);
|
|
48
|
+
const [totalToolbarHeight, setTotalToolbarHeight] = useState(0);
|
|
28
49
|
|
|
29
50
|
const tableContainerProps =
|
|
30
51
|
muiTableContainerProps instanceof Function
|
|
31
|
-
? muiTableContainerProps(tableInstance)
|
|
52
|
+
? muiTableContainerProps({ tableInstance })
|
|
32
53
|
: muiTableContainerProps;
|
|
33
54
|
|
|
55
|
+
useLayoutEffect(() => {
|
|
56
|
+
const topToolbarHeight =
|
|
57
|
+
typeof document !== 'undefined'
|
|
58
|
+
? document?.getElementById(`mrt-${idPrefix}-toolbar-top`)
|
|
59
|
+
?.offsetHeight ?? 0
|
|
60
|
+
: 0;
|
|
61
|
+
|
|
62
|
+
const bottomToolbarHeight =
|
|
63
|
+
typeof document !== 'undefined'
|
|
64
|
+
? document?.getElementById(`mrt-${idPrefix}-toolbar-bottom`)
|
|
65
|
+
?.offsetHeight ?? 0
|
|
66
|
+
: 0;
|
|
67
|
+
|
|
68
|
+
setTotalToolbarHeight(topToolbarHeight + bottomToolbarHeight);
|
|
69
|
+
});
|
|
70
|
+
|
|
34
71
|
return (
|
|
35
72
|
<TableContainer
|
|
36
|
-
component={Paper}
|
|
37
73
|
{...tableContainerProps}
|
|
38
74
|
sx={{
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
position: fullScreen ? 'fixed' : undefined,
|
|
45
|
-
right: fullScreen ? '0' : undefined,
|
|
46
|
-
top: fullScreen ? '0' : undefined,
|
|
47
|
-
transition: 'all 0.2s ease-in-out',
|
|
48
|
-
width: fullScreen ? '100vw' : undefined,
|
|
49
|
-
zIndex: fullScreen ? 1200 : 1,
|
|
75
|
+
maxWidth: '100%',
|
|
76
|
+
maxHeight: enableStickyHeader
|
|
77
|
+
? `clamp(350px, calc(100vh - ${totalToolbarHeight}px), 2000px)`
|
|
78
|
+
: undefined,
|
|
79
|
+
overflow: 'auto',
|
|
50
80
|
...tableContainerProps?.sx,
|
|
51
81
|
}}
|
|
82
|
+
style={{
|
|
83
|
+
maxHeight: isFullScreen
|
|
84
|
+
? `calc(100vh - ${totalToolbarHeight}px)`
|
|
85
|
+
: undefined,
|
|
86
|
+
}}
|
|
52
87
|
>
|
|
53
|
-
{
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
88
|
+
{enableColumnPinning && getIsSomeColumnsPinned() ? (
|
|
89
|
+
<Box
|
|
90
|
+
sx={{
|
|
91
|
+
display: 'grid',
|
|
92
|
+
gridTemplateColumns: `${getLeftTableWidth()}fr ${getCenterTableWidth()}fr ${getRightTableWidth()}fr`,
|
|
93
|
+
}}
|
|
94
|
+
>
|
|
95
|
+
<Box
|
|
96
|
+
sx={(theme: Theme) =>
|
|
97
|
+
commonBoxStyles({
|
|
98
|
+
pinned: 'left',
|
|
99
|
+
theme,
|
|
100
|
+
visible: !!columnPinning.left?.length,
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
>
|
|
104
|
+
<MRT_Table pinned="left" tableInstance={tableInstance} />
|
|
105
|
+
</Box>
|
|
106
|
+
<Box sx={(theme: Theme) => commonBoxStyles({ theme })}>
|
|
107
|
+
<MRT_Table pinned="center" tableInstance={tableInstance} />
|
|
108
|
+
</Box>
|
|
109
|
+
<Box
|
|
110
|
+
sx={(theme: Theme) =>
|
|
111
|
+
commonBoxStyles({
|
|
112
|
+
pinned: 'right',
|
|
113
|
+
theme,
|
|
114
|
+
visible: !!columnPinning.right?.length,
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
>
|
|
118
|
+
<MRT_Table pinned="right" tableInstance={tableInstance} />
|
|
119
|
+
</Box>
|
|
120
|
+
</Box>
|
|
121
|
+
) : (
|
|
122
|
+
<MRT_Table pinned="none" tableInstance={tableInstance} />
|
|
123
|
+
)}
|
|
63
124
|
</TableContainer>
|
|
64
125
|
);
|
|
65
126
|
};
|