material-react-table 0.5.2 → 0.5.5
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/dist/MaterialReactTable.d.ts +10 -5
- package/dist/filtersFNs.d.ts +67 -0
- package/dist/icons.d.ts +3 -0
- package/dist/localization.d.ts +14 -1
- package/dist/material-react-table.cjs.development.js +448 -85
- 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 +449 -86
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_FilterTypeMenu.d.ts +10 -0
- package/dist/useMRT.d.ts +13 -9
- package/package.json +6 -2
- package/src/MaterialReactTable.tsx +25 -5
- package/src/body/MRT_TableBody.tsx +7 -2
- package/src/buttons/MRT_EditActionButtons.tsx +3 -1
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +34 -31
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +4 -3
- package/src/buttons/MRT_ToggleFiltersButton.tsx +3 -1
- package/src/buttons/MRT_ToggleSearchButton.tsx +5 -2
- package/src/filtersFNs.ts +112 -0
- package/src/footer/MRT_TableFooter.tsx +6 -1
- package/src/footer/MRT_TableFooterCell.tsx +1 -1
- package/src/head/MRT_TableHeadCell.tsx +91 -44
- package/src/{icons.tsx → icons.ts} +9 -0
- package/src/index.tsx +0 -2
- package/src/inputs/MRT_FilterTextField.tsx +121 -52
- package/src/inputs/MRT_SearchTextField.tsx +2 -1
- package/src/inputs/MRT_SelectCheckbox.tsx +5 -7
- package/src/localization.ts +30 -4
- package/src/menus/MRT_ColumnActionMenu.tsx +145 -78
- package/src/menus/MRT_FilterTypeMenu.tsx +107 -0
- package/src/menus/MRT_RowActionMenu.tsx +20 -9
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +1 -1
- package/src/table/MRT_Table.tsx +7 -2
- package/src/table/MRT_TableContainer.tsx +15 -2
- package/src/useMRT.tsx +67 -13
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import ArrowRightIcon from '@mui/icons-material/ArrowRight';
|
|
1
2
|
import CancelIcon from '@mui/icons-material/Cancel';
|
|
2
3
|
import ClearAllIcon from '@mui/icons-material/ClearAll';
|
|
3
4
|
import CloseIcon from '@mui/icons-material/Close';
|
|
@@ -8,6 +9,8 @@ import DynamicFeedIcon from '@mui/icons-material/DynamicFeed';
|
|
|
8
9
|
import EditIcon from '@mui/icons-material/Edit';
|
|
9
10
|
import ExpandLessIcon from '@mui/icons-material/ExpandLess';
|
|
10
11
|
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
|
12
|
+
import FilterAltIcon from '@mui/icons-material/FilterAlt';
|
|
13
|
+
import FilterAltOff from '@mui/icons-material/FilterAltOff';
|
|
11
14
|
import FilterListIcon from '@mui/icons-material/FilterList';
|
|
12
15
|
import FilterListOffIcon from '@mui/icons-material/FilterListOff';
|
|
13
16
|
import FullscreenExitIcon from '@mui/icons-material/FullscreenExit';
|
|
@@ -22,6 +25,7 @@ import ViewColumnIcon from '@mui/icons-material/ViewColumn';
|
|
|
22
25
|
import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
|
|
23
26
|
|
|
24
27
|
export interface MRT_Icons {
|
|
28
|
+
ArrowRightIcon: any;
|
|
25
29
|
CancelIcon: any;
|
|
26
30
|
ClearAllIcon: any;
|
|
27
31
|
CloseIcon: any;
|
|
@@ -32,6 +36,8 @@ export interface MRT_Icons {
|
|
|
32
36
|
EditIcon: any;
|
|
33
37
|
ExpandLessIcon: any;
|
|
34
38
|
ExpandMoreIcon: any;
|
|
39
|
+
FilterAltIcon: any;
|
|
40
|
+
FilterAltOff: any;
|
|
35
41
|
FilterListIcon: any;
|
|
36
42
|
FilterListOffIcon: any;
|
|
37
43
|
FullscreenExitIcon: any;
|
|
@@ -47,6 +53,7 @@ export interface MRT_Icons {
|
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
export const MRT_Default_Icons: MRT_Icons = {
|
|
56
|
+
ArrowRightIcon,
|
|
50
57
|
CancelIcon,
|
|
51
58
|
ClearAllIcon,
|
|
52
59
|
CloseIcon,
|
|
@@ -57,6 +64,8 @@ export const MRT_Default_Icons: MRT_Icons = {
|
|
|
57
64
|
EditIcon,
|
|
58
65
|
ExpandLessIcon,
|
|
59
66
|
ExpandMoreIcon,
|
|
67
|
+
FilterAltIcon,
|
|
68
|
+
FilterAltOff,
|
|
60
69
|
FilterListIcon,
|
|
61
70
|
FilterListOffIcon,
|
|
62
71
|
FullscreenExitIcon,
|
package/src/index.tsx
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import React, { ChangeEvent, FC, useState } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { ChangeEvent, FC, MouseEvent, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Chip,
|
|
4
|
+
IconButton,
|
|
5
|
+
InputAdornment,
|
|
6
|
+
TextField,
|
|
7
|
+
TextFieldProps,
|
|
8
|
+
Tooltip,
|
|
9
|
+
} from '@mui/material';
|
|
3
10
|
import { useAsyncDebounce } from 'react-table';
|
|
4
11
|
import { useMRT } from '../useMRT';
|
|
5
12
|
import { MRT_HeaderGroup } from '..';
|
|
13
|
+
import { MRT_FilterTypeMenu } from '../menus/MRT_FilterTypeMenu';
|
|
6
14
|
|
|
7
15
|
interface Props {
|
|
8
16
|
column: MRT_HeaderGroup;
|
|
@@ -11,79 +19,140 @@ interface Props {
|
|
|
11
19
|
export const MRT_FilterTextField: FC<Props> = ({ column }) => {
|
|
12
20
|
const {
|
|
13
21
|
icons: { FilterListIcon, CloseIcon },
|
|
22
|
+
idPrefix,
|
|
14
23
|
localization,
|
|
24
|
+
muiTableHeadCellFilterTextFieldProps,
|
|
25
|
+
setCurrentFilterTypes,
|
|
26
|
+
tableInstance,
|
|
15
27
|
} = useMRT();
|
|
16
28
|
|
|
29
|
+
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
30
|
+
|
|
31
|
+
const mTableHeadCellFilterTextFieldProps =
|
|
32
|
+
muiTableHeadCellFilterTextFieldProps instanceof Function
|
|
33
|
+
? muiTableHeadCellFilterTextFieldProps(column)
|
|
34
|
+
: muiTableHeadCellFilterTextFieldProps;
|
|
35
|
+
|
|
36
|
+
const mcTableHeadCellFilterTextFieldProps =
|
|
37
|
+
column.muiTableHeadCellFilterTextFieldProps instanceof Function
|
|
38
|
+
? column.muiTableHeadCellFilterTextFieldProps(column)
|
|
39
|
+
: column.muiTableHeadCellFilterTextFieldProps;
|
|
40
|
+
|
|
41
|
+
const textFieldProps = {
|
|
42
|
+
...mTableHeadCellFilterTextFieldProps,
|
|
43
|
+
...mcTableHeadCellFilterTextFieldProps,
|
|
44
|
+
style: {
|
|
45
|
+
...mTableHeadCellFilterTextFieldProps?.style,
|
|
46
|
+
...mcTableHeadCellFilterTextFieldProps?.style,
|
|
47
|
+
},
|
|
48
|
+
} as TextFieldProps;
|
|
49
|
+
|
|
17
50
|
const [filterValue, setFilterValue] = useState('');
|
|
18
51
|
|
|
19
52
|
const handleChange = useAsyncDebounce((value) => {
|
|
20
53
|
column.setFilter(value ?? undefined);
|
|
21
54
|
}, 150);
|
|
22
55
|
|
|
56
|
+
const handleFilterMenuOpen = (event: MouseEvent<HTMLElement>) => {
|
|
57
|
+
setAnchorEl(event.currentTarget);
|
|
58
|
+
};
|
|
59
|
+
|
|
23
60
|
const handleClear = () => {
|
|
24
61
|
setFilterValue('');
|
|
25
62
|
column.setFilter(undefined);
|
|
26
63
|
};
|
|
27
64
|
|
|
65
|
+
const handleClearFilterChip = () => {
|
|
66
|
+
setFilterValue('');
|
|
67
|
+
column.setFilter(undefined);
|
|
68
|
+
setCurrentFilterTypes((prev) => ({ ...prev, [column.id]: 'fuzzy' }));
|
|
69
|
+
};
|
|
70
|
+
|
|
28
71
|
if (column.Filter) {
|
|
29
72
|
return <>{column.Filter?.({ column })}</>;
|
|
30
73
|
}
|
|
31
74
|
|
|
75
|
+
const filterType = tableInstance.state.currentFilterTypes[column.id];
|
|
76
|
+
const filterChipLabel = ['empty', 'notEmpty'].includes(filterType);
|
|
77
|
+
const filterPlaceholder = localization.filterTextFieldPlaceholder?.replace(
|
|
78
|
+
'{column}',
|
|
79
|
+
String(column.Header),
|
|
80
|
+
);
|
|
81
|
+
|
|
32
82
|
return (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
arrow
|
|
57
|
-
title={localization.filterTextFieldPlaceholder?.replace(
|
|
58
|
-
'{column}',
|
|
59
|
-
String(column.Header),
|
|
60
|
-
)}
|
|
61
|
-
>
|
|
83
|
+
<>
|
|
84
|
+
<TextField
|
|
85
|
+
fullWidth
|
|
86
|
+
id={`mrt-${idPrefix}-${column.id}-filter-text-field`}
|
|
87
|
+
inputProps={{
|
|
88
|
+
disabled: !!filterChipLabel,
|
|
89
|
+
sx: {
|
|
90
|
+
textOverflow: 'ellipsis',
|
|
91
|
+
width: filterChipLabel ? 0 : 'auto',
|
|
92
|
+
},
|
|
93
|
+
title: filterPlaceholder,
|
|
94
|
+
}}
|
|
95
|
+
margin="none"
|
|
96
|
+
placeholder={filterChipLabel ? '' : filterPlaceholder}
|
|
97
|
+
onChange={(e: ChangeEvent<HTMLInputElement>) => {
|
|
98
|
+
setFilterValue(e.target.value);
|
|
99
|
+
handleChange(e.target.value);
|
|
100
|
+
}}
|
|
101
|
+
onClick={(e) => e.stopPropagation()}
|
|
102
|
+
value={filterValue ?? ''}
|
|
103
|
+
variant="standard"
|
|
104
|
+
InputProps={{
|
|
105
|
+
startAdornment: (
|
|
62
106
|
<InputAdornment position="start">
|
|
63
|
-
<
|
|
64
|
-
</InputAdornment>
|
|
65
|
-
</Tooltip>
|
|
66
|
-
),
|
|
67
|
-
endAdornment: (
|
|
68
|
-
<InputAdornment position="end">
|
|
69
|
-
<Tooltip
|
|
70
|
-
arrow
|
|
71
|
-
title={localization.filterTextFieldClearButtonTitle ?? ''}
|
|
72
|
-
>
|
|
73
|
-
<span>
|
|
107
|
+
<Tooltip arrow title="Change Filter Mode">
|
|
74
108
|
<IconButton
|
|
75
|
-
|
|
76
|
-
disabled={filterValue?.length === 0}
|
|
77
|
-
onClick={handleClear}
|
|
109
|
+
onClick={handleFilterMenuOpen}
|
|
78
110
|
size="small"
|
|
111
|
+
sx={{ height: '1.75rem', width: '1.75rem' }}
|
|
79
112
|
>
|
|
80
|
-
<
|
|
113
|
+
<FilterListIcon />
|
|
81
114
|
</IconButton>
|
|
82
|
-
</
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
115
|
+
</Tooltip>
|
|
116
|
+
{filterChipLabel && (
|
|
117
|
+
<Chip onDelete={handleClearFilterChip} label={filterType} />
|
|
118
|
+
)}
|
|
119
|
+
</InputAdornment>
|
|
120
|
+
),
|
|
121
|
+
endAdornment: !filterChipLabel && (
|
|
122
|
+
<InputAdornment position="end">
|
|
123
|
+
<Tooltip
|
|
124
|
+
arrow
|
|
125
|
+
placement="right"
|
|
126
|
+
title={localization.filterTextFieldClearButtonTitle ?? ''}
|
|
127
|
+
>
|
|
128
|
+
<span>
|
|
129
|
+
<IconButton
|
|
130
|
+
aria-label={localization.filterTextFieldClearButtonTitle}
|
|
131
|
+
disabled={filterValue?.length === 0}
|
|
132
|
+
onClick={handleClear}
|
|
133
|
+
size="small"
|
|
134
|
+
sx={{ height: '1.75rem', width: '1.75rem' }}
|
|
135
|
+
>
|
|
136
|
+
<CloseIcon fontSize="small" />
|
|
137
|
+
</IconButton>
|
|
138
|
+
</span>
|
|
139
|
+
</Tooltip>
|
|
140
|
+
</InputAdornment>
|
|
141
|
+
),
|
|
142
|
+
}}
|
|
143
|
+
{...textFieldProps}
|
|
144
|
+
sx={{
|
|
145
|
+
m: '0 -0.25rem',
|
|
146
|
+
minWidth: !filterChipLabel ? '5rem' : 'auto',
|
|
147
|
+
width: 'calc(100% + 0.5rem)',
|
|
148
|
+
...textFieldProps?.sx,
|
|
149
|
+
}}
|
|
150
|
+
/>
|
|
151
|
+
<MRT_FilterTypeMenu
|
|
152
|
+
anchorEl={anchorEl}
|
|
153
|
+
column={column}
|
|
154
|
+
setAnchorEl={setAnchorEl}
|
|
155
|
+
/>
|
|
156
|
+
</>
|
|
88
157
|
);
|
|
89
158
|
};
|
|
@@ -8,6 +8,7 @@ interface Props {}
|
|
|
8
8
|
export const MRT_SearchTextField: FC<Props> = () => {
|
|
9
9
|
const {
|
|
10
10
|
icons: { SearchIcon, CloseIcon },
|
|
11
|
+
idPrefix,
|
|
11
12
|
localization,
|
|
12
13
|
muiSearchTextFieldProps,
|
|
13
14
|
onGlobalFilterChange,
|
|
@@ -32,7 +33,7 @@ export const MRT_SearchTextField: FC<Props> = () => {
|
|
|
32
33
|
return (
|
|
33
34
|
<Collapse in={tableInstance.state.showSearch} orientation="horizontal">
|
|
34
35
|
<TextField
|
|
35
|
-
id=
|
|
36
|
+
id={`mrt-${idPrefix}-search-text-field`}
|
|
36
37
|
placeholder={localization.searchTextFieldPlaceholder}
|
|
37
38
|
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
38
39
|
setSearchValue(event.target.value);
|
|
@@ -10,12 +10,8 @@ interface Props {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll }) => {
|
|
13
|
-
const {
|
|
14
|
-
|
|
15
|
-
onRowSelectChange,
|
|
16
|
-
onSelectAllChange,
|
|
17
|
-
tableInstance,
|
|
18
|
-
} = useMRT();
|
|
13
|
+
const { localization, onRowSelectChange, onSelectAllChange, tableInstance } =
|
|
14
|
+
useMRT();
|
|
19
15
|
|
|
20
16
|
const onSelectChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
21
17
|
if (selectAll) {
|
|
@@ -32,7 +28,9 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll }) => {
|
|
|
32
28
|
: row?.getToggleRowSelectedProps();
|
|
33
29
|
|
|
34
30
|
return (
|
|
35
|
-
<TableCell
|
|
31
|
+
<TableCell
|
|
32
|
+
sx={commonTableBodyButtonCellStyles(tableInstance.state.densePadding)}
|
|
33
|
+
>
|
|
36
34
|
<Tooltip
|
|
37
35
|
arrow
|
|
38
36
|
enterDelay={1000}
|
package/src/localization.ts
CHANGED
|
@@ -11,6 +11,19 @@ export interface MRT_Localization {
|
|
|
11
11
|
columnShowHideMenuShowAll: string;
|
|
12
12
|
expandAllButtonTitle: string;
|
|
13
13
|
expandButtonTitle: string;
|
|
14
|
+
filterApplied: string;
|
|
15
|
+
filterMenuItemContains: string;
|
|
16
|
+
filterMenuItemEmpty: string;
|
|
17
|
+
filterMenuItemEndsWith: string;
|
|
18
|
+
filterMenuItemEquals: string;
|
|
19
|
+
filterMenuItemFuzzy: string;
|
|
20
|
+
filterMenuItemNotEmpty: string;
|
|
21
|
+
filterMenuItemNotEquals: string;
|
|
22
|
+
filterMenuItemStartsWith: string;
|
|
23
|
+
filterMenuTitle: string;
|
|
24
|
+
filterTextFieldChangeFilterButtonTitle: string;
|
|
25
|
+
filterTextFieldChipLabelEmpty: string;
|
|
26
|
+
filterTextFieldChipLabelNotEmpty: string;
|
|
14
27
|
filterTextFieldClearButtonTitle: string;
|
|
15
28
|
filterTextFieldPlaceholder: string;
|
|
16
29
|
rowActionButtonCancel: string;
|
|
@@ -27,9 +40,9 @@ export interface MRT_Localization {
|
|
|
27
40
|
toggleFilterButtonTitle: string;
|
|
28
41
|
toggleFullScreenButtonTitle: string;
|
|
29
42
|
toggleSearchButtonTitle: string;
|
|
30
|
-
toolbarAlertSelectionMessage: string;
|
|
31
43
|
toolbarAlertGroupedByMessage: string;
|
|
32
44
|
toolbarAlertGroupedThenByMessage: string;
|
|
45
|
+
toolbarAlertSelectionMessage: string;
|
|
33
46
|
}
|
|
34
47
|
|
|
35
48
|
export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
@@ -45,6 +58,19 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
|
45
58
|
columnShowHideMenuShowAll: 'Show all',
|
|
46
59
|
expandAllButtonTitle: 'Expand all',
|
|
47
60
|
expandButtonTitle: 'Expand',
|
|
61
|
+
filterApplied: 'Filtering by {column} - ({filterType})',
|
|
62
|
+
filterMenuItemContains: 'Contains Exact',
|
|
63
|
+
filterMenuItemEmpty: 'Empty',
|
|
64
|
+
filterMenuItemEndsWith: 'Ends With',
|
|
65
|
+
filterMenuItemEquals: 'Equals',
|
|
66
|
+
filterMenuItemFuzzy: 'Fuzzy Match (Default)',
|
|
67
|
+
filterMenuItemNotEmpty: 'Not Empty',
|
|
68
|
+
filterMenuItemNotEquals: 'Not Equals',
|
|
69
|
+
filterMenuItemStartsWith: 'Starts With',
|
|
70
|
+
filterMenuTitle: 'Filter Mode',
|
|
71
|
+
filterTextFieldChangeFilterButtonTitle: 'Change Filter Mode',
|
|
72
|
+
filterTextFieldChipLabelEmpty: 'Empty',
|
|
73
|
+
filterTextFieldChipLabelNotEmpty: 'Not Empty',
|
|
48
74
|
filterTextFieldClearButtonTitle: 'Clear filter',
|
|
49
75
|
filterTextFieldPlaceholder: 'Filter by {column}',
|
|
50
76
|
rowActionButtonCancel: 'Cancel',
|
|
@@ -58,10 +84,10 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
|
58
84
|
selectCheckboxTitle: 'Toggle select row',
|
|
59
85
|
showHideColumnsButtonTitle: 'Show/Hide columns',
|
|
60
86
|
toggleDensePaddingSwitchTitle: 'Toggle dense padding',
|
|
61
|
-
toggleFilterButtonTitle: '
|
|
87
|
+
toggleFilterButtonTitle: 'Show/Hide filters',
|
|
62
88
|
toggleFullScreenButtonTitle: 'Toggle full screen',
|
|
63
|
-
toggleSearchButtonTitle: '
|
|
64
|
-
toolbarAlertSelectionMessage: '{selectedCount} of {rowCount} row(s) selected',
|
|
89
|
+
toggleSearchButtonTitle: 'Show/Hide search',
|
|
65
90
|
toolbarAlertGroupedByMessage: 'Grouped by ',
|
|
66
91
|
toolbarAlertGroupedThenByMessage: ', then by ',
|
|
92
|
+
toolbarAlertSelectionMessage: '{selectedCount} of {rowCount} row(s) selected',
|
|
67
93
|
};
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import React, { FC } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { FC, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
IconButton,
|
|
4
|
+
ListItemIcon,
|
|
5
|
+
ListItemText,
|
|
6
|
+
Menu,
|
|
7
|
+
MenuItem,
|
|
8
|
+
MenuList,
|
|
9
|
+
} from '@mui/material';
|
|
3
10
|
import { useMRT } from '../useMRT';
|
|
4
11
|
import { MRT_HeaderGroup } from '..';
|
|
12
|
+
import { MRT_FilterTypeMenu } from './MRT_FilterTypeMenu';
|
|
5
13
|
|
|
6
14
|
const commonMenuItemStyles = {
|
|
7
15
|
display: 'flex',
|
|
8
|
-
|
|
16
|
+
alignItems: 'center',
|
|
9
17
|
};
|
|
10
18
|
|
|
11
19
|
interface Props {
|
|
@@ -24,17 +32,23 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
24
32
|
disableFilters,
|
|
25
33
|
disableSortBy,
|
|
26
34
|
enableColumnGrouping,
|
|
27
|
-
localization,
|
|
28
|
-
setShowFilters,
|
|
29
35
|
icons: {
|
|
30
|
-
|
|
31
|
-
SortIcon,
|
|
36
|
+
ArrowRightIcon,
|
|
32
37
|
ClearAllIcon,
|
|
33
38
|
DynamicFeedIcon,
|
|
39
|
+
FilterListIcon,
|
|
40
|
+
SortIcon,
|
|
34
41
|
VisibilityOffIcon,
|
|
35
42
|
},
|
|
43
|
+
idPrefix,
|
|
44
|
+
localization,
|
|
45
|
+
setShowFilters,
|
|
46
|
+
tableInstance,
|
|
36
47
|
} = useMRT();
|
|
37
48
|
|
|
49
|
+
const [filterMenuAnchorEl, setFilterMenuAnchorEl] =
|
|
50
|
+
useState<null | HTMLElement>(null);
|
|
51
|
+
|
|
38
52
|
const handleClearSort = () => {
|
|
39
53
|
column.clearSortBy();
|
|
40
54
|
setAnchorEl(null);
|
|
@@ -68,7 +82,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
68
82
|
.getElementById(
|
|
69
83
|
// @ts-ignore
|
|
70
84
|
column.muiTableHeadCellFilterTextFieldProps?.id ??
|
|
71
|
-
`
|
|
85
|
+
`mrt-${idPrefix}-${column.id}-filter-text-field`,
|
|
72
86
|
)
|
|
73
87
|
?.focus(),
|
|
74
88
|
200,
|
|
@@ -76,88 +90,141 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
76
90
|
setAnchorEl(null);
|
|
77
91
|
};
|
|
78
92
|
|
|
93
|
+
const handleOpenFilterModeMenu = (event: React.MouseEvent<HTMLElement>) => {
|
|
94
|
+
event.stopPropagation();
|
|
95
|
+
setFilterMenuAnchorEl(event.currentTarget);
|
|
96
|
+
};
|
|
97
|
+
|
|
79
98
|
return (
|
|
80
99
|
<Menu
|
|
81
100
|
anchorEl={anchorEl}
|
|
82
101
|
open={!!anchorEl}
|
|
83
102
|
onClose={() => setAnchorEl(null)}
|
|
84
103
|
>
|
|
85
|
-
{
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
<
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
104
|
+
<MenuList dense={tableInstance.state.densePadding} disablePadding>
|
|
105
|
+
{!disableSortBy &&
|
|
106
|
+
column.canSort && [
|
|
107
|
+
<MenuItem
|
|
108
|
+
key={1}
|
|
109
|
+
disabled={!column.isSorted}
|
|
110
|
+
onClick={handleClearSort}
|
|
111
|
+
sx={commonMenuItemStyles}
|
|
112
|
+
>
|
|
113
|
+
<ListItemIcon>
|
|
114
|
+
<ClearAllIcon />
|
|
115
|
+
</ListItemIcon>
|
|
116
|
+
<ListItemText>
|
|
117
|
+
{localization.columnActionMenuItemClearSort}
|
|
118
|
+
</ListItemText>
|
|
119
|
+
</MenuItem>,
|
|
120
|
+
<MenuItem
|
|
121
|
+
disabled={column.isSorted && !column.isSortedDesc}
|
|
122
|
+
key={2}
|
|
123
|
+
onClick={handleSortAsc}
|
|
124
|
+
sx={commonMenuItemStyles}
|
|
125
|
+
>
|
|
126
|
+
<ListItemIcon>
|
|
127
|
+
<SortIcon />
|
|
128
|
+
</ListItemIcon>
|
|
129
|
+
<ListItemText>
|
|
130
|
+
{localization.columnActionMenuItemSortAsc?.replace(
|
|
131
|
+
'{column}',
|
|
132
|
+
String(column.Header),
|
|
133
|
+
)}
|
|
134
|
+
</ListItemText>
|
|
135
|
+
</MenuItem>,
|
|
136
|
+
<MenuItem
|
|
137
|
+
divider={
|
|
138
|
+
!disableFilters || enableColumnGrouping || !disableColumnHiding
|
|
139
|
+
}
|
|
140
|
+
key={3}
|
|
141
|
+
disabled={column.isSorted && column.isSortedDesc}
|
|
142
|
+
onClick={handleSortDesc}
|
|
143
|
+
sx={commonMenuItemStyles}
|
|
144
|
+
>
|
|
145
|
+
<ListItemIcon>
|
|
146
|
+
<SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />
|
|
147
|
+
</ListItemIcon>
|
|
148
|
+
<ListItemText>
|
|
149
|
+
{localization.columnActionMenuItemSortDesc?.replace(
|
|
150
|
+
'{column}',
|
|
151
|
+
String(column.Header),
|
|
152
|
+
)}
|
|
153
|
+
</ListItemText>
|
|
154
|
+
</MenuItem>,
|
|
155
|
+
]}
|
|
156
|
+
{!disableFilters &&
|
|
157
|
+
column.canFilter && [
|
|
158
|
+
<MenuItem
|
|
159
|
+
divider={enableColumnGrouping || !disableColumnHiding}
|
|
160
|
+
key={1}
|
|
161
|
+
onClick={handleFilterByColumn}
|
|
162
|
+
sx={commonMenuItemStyles}
|
|
163
|
+
>
|
|
164
|
+
<ListItemIcon>
|
|
165
|
+
<FilterListIcon />
|
|
166
|
+
</ListItemIcon>
|
|
167
|
+
<ListItemText>
|
|
168
|
+
{localization.filterTextFieldPlaceholder?.replace(
|
|
169
|
+
'{column}',
|
|
170
|
+
String(column.Header),
|
|
171
|
+
)}
|
|
172
|
+
</ListItemText>
|
|
173
|
+
<IconButton
|
|
174
|
+
onClick={handleOpenFilterModeMenu}
|
|
175
|
+
onMouseEnter={handleOpenFilterModeMenu}
|
|
176
|
+
size="small"
|
|
177
|
+
sx={{ p: 0 }}
|
|
178
|
+
>
|
|
179
|
+
<ArrowRightIcon />
|
|
180
|
+
</IconButton>
|
|
181
|
+
</MenuItem>,
|
|
182
|
+
<MRT_FilterTypeMenu
|
|
183
|
+
anchorEl={filterMenuAnchorEl}
|
|
184
|
+
column={column}
|
|
185
|
+
key={2}
|
|
186
|
+
setAnchorEl={setFilterMenuAnchorEl}
|
|
187
|
+
onSelect={handleFilterByColumn}
|
|
188
|
+
/>,
|
|
189
|
+
]}
|
|
190
|
+
{enableColumnGrouping &&
|
|
191
|
+
column.canGroupBy && [
|
|
192
|
+
<MenuItem
|
|
193
|
+
divider={!disableColumnHiding}
|
|
194
|
+
key={2}
|
|
195
|
+
onClick={handleGroupByColumn}
|
|
196
|
+
sx={commonMenuItemStyles}
|
|
197
|
+
>
|
|
198
|
+
<ListItemIcon>
|
|
199
|
+
<DynamicFeedIcon />
|
|
200
|
+
</ListItemIcon>
|
|
201
|
+
<ListItemText>
|
|
202
|
+
{localization[
|
|
203
|
+
column.isGrouped
|
|
204
|
+
? 'columnActionMenuItemUnGroupBy'
|
|
205
|
+
: 'columnActionMenuItemGroupBy'
|
|
206
|
+
]?.replace('{column}', String(column.Header))}
|
|
207
|
+
</ListItemText>
|
|
208
|
+
</MenuItem>,
|
|
209
|
+
]}
|
|
210
|
+
{!disableColumnHiding && [
|
|
123
211
|
<MenuItem
|
|
124
212
|
key={1}
|
|
125
|
-
onClick={
|
|
126
|
-
sx={commonMenuItemStyles}
|
|
127
|
-
>
|
|
128
|
-
<FilterListIcon />{' '}
|
|
129
|
-
{localization.filterTextFieldPlaceholder?.replace(
|
|
130
|
-
'{column}',
|
|
131
|
-
String(column.Header),
|
|
132
|
-
)}
|
|
133
|
-
</MenuItem>,
|
|
134
|
-
]}
|
|
135
|
-
{enableColumnGrouping &&
|
|
136
|
-
column.canGroupBy && [
|
|
137
|
-
<Divider key={1} />,
|
|
138
|
-
<MenuItem
|
|
139
|
-
key={2}
|
|
140
|
-
onClick={handleGroupByColumn}
|
|
213
|
+
onClick={handleHideColumn}
|
|
141
214
|
sx={commonMenuItemStyles}
|
|
142
215
|
>
|
|
143
|
-
<
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
216
|
+
<ListItemIcon>
|
|
217
|
+
<VisibilityOffIcon />
|
|
218
|
+
</ListItemIcon>
|
|
219
|
+
<ListItemText>
|
|
220
|
+
{localization.columnActionMenuItemHideColumn?.replace(
|
|
221
|
+
'{column}',
|
|
222
|
+
String(column.Header),
|
|
223
|
+
)}
|
|
224
|
+
</ListItemText>
|
|
149
225
|
</MenuItem>,
|
|
150
226
|
]}
|
|
151
|
-
|
|
152
|
-
<Divider key={0} />,
|
|
153
|
-
<MenuItem key={1} onClick={handleHideColumn} sx={commonMenuItemStyles}>
|
|
154
|
-
<VisibilityOffIcon />{' '}
|
|
155
|
-
{localization.columnActionMenuItemHideColumn?.replace(
|
|
156
|
-
'{column}',
|
|
157
|
-
String(column.Header),
|
|
158
|
-
)}
|
|
159
|
-
</MenuItem>,
|
|
160
|
-
]}
|
|
227
|
+
</MenuList>
|
|
161
228
|
</Menu>
|
|
162
229
|
);
|
|
163
230
|
};
|