material-react-table 0.5.7 → 0.6.0
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 +8 -2
- package/dist/body/MRT_TableBodyCell.d.ts +1 -1
- package/dist/body/MRT_TableBodyRow.d.ts +1 -1
- package/dist/body/MRT_TableDetailPanel.d.ts +1 -1
- package/dist/buttons/MRT_EditActionButtons.d.ts +1 -1
- package/dist/buttons/MRT_ExpandButton.d.ts +1 -1
- package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +1 -1
- package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +1 -1
- package/dist/enums.d.ts +12 -0
- package/dist/filtersFNs.d.ts +20 -0
- package/dist/footer/MRT_TableFooterCell.d.ts +1 -1
- package/dist/footer/MRT_TableFooterRow.d.ts +1 -1
- package/dist/head/MRT_TableHeadCell.d.ts +1 -1
- package/dist/head/MRT_TableHeadRow.d.ts +1 -1
- package/dist/inputs/MRT_EditCellTextField.d.ts +1 -1
- package/dist/inputs/MRT_FilterTextField.d.ts +1 -1
- package/dist/inputs/MRT_SelectCheckbox.d.ts +1 -1
- package/dist/localization.d.ts +44 -44
- package/dist/material-react-table.cjs.development.js +569 -360
- 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 +570 -361
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ColumnActionMenu.d.ts +9 -2
- package/dist/menus/MRT_FilterTypeMenu.d.ts +1 -1
- package/dist/menus/MRT_RowActionMenu.d.ts +1 -1
- package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +3 -2
- package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +8 -0
- package/dist/useMRT.d.ts +1 -1
- package/package.json +2 -2
- package/src/MaterialReactTable.tsx +5 -9
- package/src/body/MRT_TableBody.tsx +1 -1
- package/src/body/MRT_TableBodyCell.tsx +1 -1
- package/src/body/MRT_TableBodyRow.tsx +1 -1
- package/src/body/MRT_TableDetailPanel.tsx +1 -1
- package/src/buttons/MRT_EditActionButtons.tsx +5 -8
- package/src/buttons/MRT_ExpandAllButton.tsx +2 -2
- package/src/buttons/MRT_ExpandButton.tsx +3 -3
- package/src/buttons/MRT_FullScreenToggleButton.tsx +2 -2
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +4 -55
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +4 -3
- package/src/buttons/MRT_ToggleDensePaddingButton.tsx +2 -2
- package/src/buttons/MRT_ToggleFiltersButton.tsx +2 -2
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +4 -8
- package/src/buttons/MRT_ToggleSearchButton.tsx +1 -1
- package/src/enums.ts +12 -0
- package/src/filtersFNs.ts +42 -0
- package/src/footer/MRT_TableFooter.tsx +1 -1
- package/src/footer/MRT_TableFooterCell.tsx +1 -1
- package/src/footer/MRT_TableFooterRow.tsx +1 -1
- package/src/head/MRT_TableHead.tsx +1 -1
- package/src/head/MRT_TableHeadCell.tsx +22 -18
- package/src/head/MRT_TableHeadCellActions.tsx +1 -1
- package/src/head/MRT_TableHeadRow.tsx +1 -1
- package/src/inputs/MRT_EditCellTextField.tsx +1 -1
- package/src/inputs/MRT_FilterTextField.tsx +99 -21
- package/src/inputs/MRT_SearchTextField.tsx +3 -3
- package/src/inputs/MRT_SelectCheckbox.tsx +5 -5
- package/src/localization.ts +89 -88
- package/src/menus/MRT_ColumnActionMenu.tsx +109 -56
- package/src/menus/MRT_FilterTypeMenu.tsx +63 -26
- package/src/menus/MRT_RowActionMenu.tsx +4 -10
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +54 -33
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +57 -0
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +3 -3
- package/src/useMRT.tsx +36 -14
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import React, { FC, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
IconButton,
|
|
4
|
-
ListItemIcon,
|
|
5
|
-
ListItemText,
|
|
6
|
-
Menu,
|
|
7
|
-
MenuItem,
|
|
8
|
-
} from '@mui/material';
|
|
2
|
+
import { Box, IconButton, Menu, MenuItem } from '@mui/material';
|
|
9
3
|
import { useMRT } from '../useMRT';
|
|
10
|
-
import { MRT_HeaderGroup } from '..';
|
|
4
|
+
import type { MRT_HeaderGroup } from '..';
|
|
11
5
|
import { MRT_FilterTypeMenu } from './MRT_FilterTypeMenu';
|
|
6
|
+
import { MRT_ShowHideColumnsMenu } from './MRT_ShowHideColumnsMenu';
|
|
12
7
|
|
|
13
8
|
export const commonMenuItemStyles = {
|
|
14
|
-
py: '
|
|
15
|
-
my:
|
|
9
|
+
py: '6px',
|
|
10
|
+
my: 0,
|
|
11
|
+
justifyContent: 'space-between',
|
|
12
|
+
alignItems: 'center',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const commonListItemStyles = {
|
|
16
|
+
display: 'flex',
|
|
17
|
+
gap: '0.75rem',
|
|
18
|
+
alignItems: 'center',
|
|
16
19
|
};
|
|
17
20
|
|
|
18
21
|
interface Props {
|
|
@@ -34,8 +37,10 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
34
37
|
icons: {
|
|
35
38
|
ArrowRightIcon,
|
|
36
39
|
ClearAllIcon,
|
|
40
|
+
ViewColumnIcon,
|
|
37
41
|
DynamicFeedIcon,
|
|
38
42
|
FilterListIcon,
|
|
43
|
+
FilterListOffIcon,
|
|
39
44
|
SortIcon,
|
|
40
45
|
VisibilityOffIcon,
|
|
41
46
|
},
|
|
@@ -48,6 +53,9 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
48
53
|
const [filterMenuAnchorEl, setFilterMenuAnchorEl] =
|
|
49
54
|
useState<null | HTMLElement>(null);
|
|
50
55
|
|
|
56
|
+
const [showHideColumnsMenuAnchorEl, setShowHideColumnsMenuAnchorEl] =
|
|
57
|
+
useState<null | HTMLElement>(null);
|
|
58
|
+
|
|
51
59
|
const handleClearSort = () => {
|
|
52
60
|
column.clearSortBy();
|
|
53
61
|
setAnchorEl(null);
|
|
@@ -73,6 +81,11 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
73
81
|
setAnchorEl(null);
|
|
74
82
|
};
|
|
75
83
|
|
|
84
|
+
const handleClearFilter = () => {
|
|
85
|
+
column.setFilter('');
|
|
86
|
+
setAnchorEl(null);
|
|
87
|
+
};
|
|
88
|
+
|
|
76
89
|
const handleFilterByColumn = () => {
|
|
77
90
|
setShowFilters(true);
|
|
78
91
|
setTimeout(
|
|
@@ -94,6 +107,17 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
94
107
|
setFilterMenuAnchorEl(event.currentTarget);
|
|
95
108
|
};
|
|
96
109
|
|
|
110
|
+
const handleShowAllColumns = () => {
|
|
111
|
+
tableInstance.toggleHideAllColumns(false);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const handleOpenShowHideColumnsMenu = (
|
|
115
|
+
event: React.MouseEvent<HTMLElement>,
|
|
116
|
+
) => {
|
|
117
|
+
event.stopPropagation();
|
|
118
|
+
setShowHideColumnsMenuAnchorEl(event.currentTarget);
|
|
119
|
+
};
|
|
120
|
+
|
|
97
121
|
return (
|
|
98
122
|
<Menu
|
|
99
123
|
anchorEl={anchorEl}
|
|
@@ -101,85 +125,89 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
101
125
|
onClose={() => setAnchorEl(null)}
|
|
102
126
|
MenuListProps={{
|
|
103
127
|
dense: tableInstance.state.densePadding,
|
|
104
|
-
disablePadding: true,
|
|
105
128
|
}}
|
|
106
129
|
>
|
|
107
130
|
{!disableSortBy &&
|
|
108
131
|
column.canSort && [
|
|
109
132
|
<MenuItem
|
|
110
|
-
key={1}
|
|
111
133
|
disabled={!column.isSorted}
|
|
134
|
+
key={0}
|
|
112
135
|
onClick={handleClearSort}
|
|
113
136
|
sx={commonMenuItemStyles}
|
|
114
137
|
>
|
|
115
|
-
<
|
|
138
|
+
<Box sx={commonListItemStyles}>
|
|
116
139
|
<ClearAllIcon />
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
{localization.columnActionMenuItemClearSort}
|
|
120
|
-
</ListItemText>
|
|
140
|
+
{localization.clearSort}
|
|
141
|
+
</Box>
|
|
121
142
|
</MenuItem>,
|
|
122
143
|
<MenuItem
|
|
123
144
|
disabled={column.isSorted && !column.isSortedDesc}
|
|
124
|
-
key={
|
|
145
|
+
key={1}
|
|
125
146
|
onClick={handleSortAsc}
|
|
126
147
|
sx={commonMenuItemStyles}
|
|
127
148
|
>
|
|
128
|
-
<
|
|
149
|
+
<Box sx={commonListItemStyles}>
|
|
129
150
|
<SortIcon />
|
|
130
|
-
|
|
131
|
-
<ListItemText sx={commonMenuItemStyles}>
|
|
132
|
-
{localization.columnActionMenuItemSortAsc?.replace(
|
|
151
|
+
{localization.sortByColumnAsc?.replace(
|
|
133
152
|
'{column}',
|
|
134
153
|
String(column.Header),
|
|
135
154
|
)}
|
|
136
|
-
</
|
|
155
|
+
</Box>
|
|
137
156
|
</MenuItem>,
|
|
138
157
|
<MenuItem
|
|
139
158
|
divider={
|
|
140
159
|
!disableFilters || enableColumnGrouping || !disableColumnHiding
|
|
141
160
|
}
|
|
142
|
-
key={
|
|
161
|
+
key={2}
|
|
143
162
|
disabled={column.isSorted && column.isSortedDesc}
|
|
144
163
|
onClick={handleSortDesc}
|
|
145
164
|
sx={commonMenuItemStyles}
|
|
146
165
|
>
|
|
147
|
-
<
|
|
166
|
+
<Box sx={commonListItemStyles}>
|
|
148
167
|
<SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />
|
|
149
|
-
|
|
150
|
-
<ListItemText sx={commonMenuItemStyles}>
|
|
151
|
-
{localization.columnActionMenuItemSortDesc?.replace(
|
|
168
|
+
{localization.sortByColumnDesc?.replace(
|
|
152
169
|
'{column}',
|
|
153
170
|
String(column.Header),
|
|
154
171
|
)}
|
|
155
|
-
</
|
|
172
|
+
</Box>
|
|
156
173
|
</MenuItem>,
|
|
157
174
|
]}
|
|
158
175
|
{!disableFilters &&
|
|
159
176
|
column.canFilter && [
|
|
177
|
+
<MenuItem
|
|
178
|
+
disabled={!column.filterValue}
|
|
179
|
+
key={0}
|
|
180
|
+
onClick={handleClearFilter}
|
|
181
|
+
sx={commonMenuItemStyles}
|
|
182
|
+
>
|
|
183
|
+
<Box sx={commonListItemStyles}>
|
|
184
|
+
<FilterListOffIcon />
|
|
185
|
+
{localization.clearFilter}
|
|
186
|
+
</Box>
|
|
187
|
+
</MenuItem>,
|
|
160
188
|
<MenuItem
|
|
161
189
|
divider={enableColumnGrouping || !disableColumnHiding}
|
|
162
190
|
key={1}
|
|
163
191
|
onClick={handleFilterByColumn}
|
|
164
192
|
sx={commonMenuItemStyles}
|
|
165
193
|
>
|
|
166
|
-
<
|
|
194
|
+
<Box sx={commonListItemStyles}>
|
|
167
195
|
<FilterListIcon />
|
|
168
|
-
|
|
169
|
-
<ListItemText sx={commonMenuItemStyles}>
|
|
170
|
-
{localization.filterTextFieldPlaceholder?.replace(
|
|
196
|
+
{localization.filterByColumn?.replace(
|
|
171
197
|
'{column}',
|
|
172
198
|
String(column.Header),
|
|
173
199
|
)}
|
|
174
|
-
</
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
200
|
+
</Box>
|
|
201
|
+
{!column.filterSelectOptions && (
|
|
202
|
+
<IconButton
|
|
203
|
+
onClick={handleOpenFilterModeMenu}
|
|
204
|
+
onMouseEnter={handleOpenFilterModeMenu}
|
|
205
|
+
size="small"
|
|
206
|
+
sx={{ p: 0 }}
|
|
207
|
+
>
|
|
208
|
+
<ArrowRightIcon />
|
|
209
|
+
</IconButton>
|
|
210
|
+
)}
|
|
183
211
|
</MenuItem>,
|
|
184
212
|
<MRT_FilterTypeMenu
|
|
185
213
|
anchorEl={filterMenuAnchorEl}
|
|
@@ -193,34 +221,59 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
193
221
|
column.canGroupBy && [
|
|
194
222
|
<MenuItem
|
|
195
223
|
divider={!disableColumnHiding}
|
|
196
|
-
key={
|
|
224
|
+
key={0}
|
|
197
225
|
onClick={handleGroupByColumn}
|
|
198
226
|
sx={commonMenuItemStyles}
|
|
199
227
|
>
|
|
200
|
-
<
|
|
228
|
+
<Box sx={commonListItemStyles}>
|
|
201
229
|
<DynamicFeedIcon />
|
|
202
|
-
</ListItemIcon>
|
|
203
|
-
<ListItemText sx={commonMenuItemStyles}>
|
|
204
230
|
{localization[
|
|
205
|
-
column.isGrouped
|
|
206
|
-
? 'columnActionMenuItemUnGroupBy'
|
|
207
|
-
: 'columnActionMenuItemGroupBy'
|
|
231
|
+
column.isGrouped ? 'ungroupByColumn' : 'groupByColumn'
|
|
208
232
|
]?.replace('{column}', String(column.Header))}
|
|
209
|
-
</
|
|
233
|
+
</Box>
|
|
210
234
|
</MenuItem>,
|
|
211
235
|
]}
|
|
212
236
|
{!disableColumnHiding && [
|
|
213
|
-
<MenuItem key={
|
|
214
|
-
<
|
|
237
|
+
<MenuItem key={0} onClick={handleHideColumn} sx={commonMenuItemStyles}>
|
|
238
|
+
<Box sx={commonListItemStyles}>
|
|
215
239
|
<VisibilityOffIcon />
|
|
216
|
-
|
|
217
|
-
<ListItemText sx={commonMenuItemStyles}>
|
|
218
|
-
{localization.columnActionMenuItemHideColumn?.replace(
|
|
240
|
+
{localization.hideColumn?.replace(
|
|
219
241
|
'{column}',
|
|
220
242
|
String(column.Header),
|
|
221
243
|
)}
|
|
222
|
-
</
|
|
244
|
+
</Box>
|
|
245
|
+
</MenuItem>,
|
|
246
|
+
<MenuItem
|
|
247
|
+
disabled={!tableInstance.state.hiddenColumns?.length}
|
|
248
|
+
key={1}
|
|
249
|
+
onClick={handleShowAllColumns}
|
|
250
|
+
sx={commonMenuItemStyles}
|
|
251
|
+
>
|
|
252
|
+
<Box sx={commonListItemStyles}>
|
|
253
|
+
<ViewColumnIcon />
|
|
254
|
+
|
|
255
|
+
{localization.showAllColumns?.replace(
|
|
256
|
+
'{column}',
|
|
257
|
+
String(column.Header),
|
|
258
|
+
)}
|
|
259
|
+
</Box>
|
|
260
|
+
{!column.filterSelectOptions && (
|
|
261
|
+
<IconButton
|
|
262
|
+
onClick={handleOpenShowHideColumnsMenu}
|
|
263
|
+
onMouseEnter={handleOpenShowHideColumnsMenu}
|
|
264
|
+
size="small"
|
|
265
|
+
sx={{ p: 0 }}
|
|
266
|
+
>
|
|
267
|
+
<ArrowRightIcon />
|
|
268
|
+
</IconButton>
|
|
269
|
+
)}
|
|
223
270
|
</MenuItem>,
|
|
271
|
+
<MRT_ShowHideColumnsMenu
|
|
272
|
+
anchorEl={showHideColumnsMenuAnchorEl}
|
|
273
|
+
isSubMenu
|
|
274
|
+
key={2}
|
|
275
|
+
setAnchorEl={setShowHideColumnsMenuAnchorEl}
|
|
276
|
+
/>,
|
|
224
277
|
]}
|
|
225
278
|
</Menu>
|
|
226
279
|
);
|
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
import React, { FC, useMemo } from 'react';
|
|
2
2
|
import { Menu, MenuItem } from '@mui/material';
|
|
3
3
|
import { useMRT } from '../useMRT';
|
|
4
|
-
import { MRT_FilterType, MRT_HeaderGroup } from '..';
|
|
5
|
-
import {
|
|
4
|
+
import type { MRT_FilterType, MRT_HeaderGroup } from '..';
|
|
5
|
+
import { MRT_FILTER_TYPE } from '../enums';
|
|
6
|
+
import {
|
|
7
|
+
containsFilterFN,
|
|
8
|
+
emptyFilterFN,
|
|
9
|
+
endsWithFilterFN,
|
|
10
|
+
equalsFilterFN,
|
|
11
|
+
fuzzyFilterFN,
|
|
12
|
+
greaterThanFilterFN,
|
|
13
|
+
lessThanFilterFN,
|
|
14
|
+
notEmptyFilterFN,
|
|
15
|
+
notEqualsFilterFN,
|
|
16
|
+
startsWithFilterFN,
|
|
17
|
+
} from '../filtersFNs';
|
|
6
18
|
|
|
19
|
+
const commonMenuItemStyles = {
|
|
20
|
+
py: '6px',
|
|
21
|
+
my: 0,
|
|
22
|
+
alignItems: 'center',
|
|
23
|
+
};
|
|
7
24
|
|
|
8
25
|
interface Props {
|
|
9
26
|
anchorEl: HTMLElement | null;
|
|
@@ -21,62 +38,83 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
|
|
|
21
38
|
const { localization, setCurrentFilterTypes, tableInstance } = useMRT();
|
|
22
39
|
|
|
23
40
|
const filterTypes: {
|
|
24
|
-
type:
|
|
41
|
+
type: MRT_FILTER_TYPE;
|
|
25
42
|
label: string;
|
|
26
43
|
divider: boolean;
|
|
44
|
+
fn: Function;
|
|
27
45
|
}[] = useMemo(
|
|
28
46
|
() => [
|
|
29
47
|
{
|
|
30
|
-
type:
|
|
31
|
-
label: localization.
|
|
48
|
+
type: MRT_FILTER_TYPE.FUZZY,
|
|
49
|
+
label: localization.filterFuzzy,
|
|
32
50
|
divider: false,
|
|
51
|
+
fn: fuzzyFilterFN,
|
|
33
52
|
},
|
|
34
53
|
{
|
|
35
|
-
type:
|
|
36
|
-
label: localization.
|
|
54
|
+
type: MRT_FILTER_TYPE.CONTAINS,
|
|
55
|
+
label: localization.filterContains,
|
|
37
56
|
divider: true,
|
|
57
|
+
fn: containsFilterFN,
|
|
38
58
|
},
|
|
39
59
|
{
|
|
40
|
-
type:
|
|
41
|
-
label: localization.
|
|
60
|
+
type: MRT_FILTER_TYPE.STARTS_WITH,
|
|
61
|
+
label: localization.filterStartsWith,
|
|
42
62
|
divider: false,
|
|
63
|
+
fn: startsWithFilterFN,
|
|
43
64
|
},
|
|
44
65
|
{
|
|
45
|
-
type:
|
|
46
|
-
label: localization.
|
|
66
|
+
type: MRT_FILTER_TYPE.ENDS_WITH,
|
|
67
|
+
label: localization.filterEndsWith,
|
|
47
68
|
divider: true,
|
|
69
|
+
fn: endsWithFilterFN,
|
|
48
70
|
},
|
|
49
71
|
{
|
|
50
|
-
type:
|
|
51
|
-
label: localization.
|
|
72
|
+
type: MRT_FILTER_TYPE.EQUALS,
|
|
73
|
+
label: localization.filterEquals,
|
|
52
74
|
divider: false,
|
|
75
|
+
fn: equalsFilterFN,
|
|
53
76
|
},
|
|
54
77
|
{
|
|
55
|
-
type:
|
|
56
|
-
label: localization.
|
|
78
|
+
type: MRT_FILTER_TYPE.NOT_EQUALS,
|
|
79
|
+
label: localization.filterNotEquals,
|
|
57
80
|
divider: true,
|
|
81
|
+
fn: notEqualsFilterFN,
|
|
58
82
|
},
|
|
59
83
|
{
|
|
60
|
-
type:
|
|
61
|
-
label: localization.
|
|
84
|
+
type: MRT_FILTER_TYPE.GREATER_THAN,
|
|
85
|
+
label: localization.filterGreaterThan,
|
|
62
86
|
divider: false,
|
|
87
|
+
fn: greaterThanFilterFN,
|
|
63
88
|
},
|
|
64
89
|
{
|
|
65
|
-
type:
|
|
66
|
-
label: localization.
|
|
90
|
+
type: MRT_FILTER_TYPE.LESS_THAN,
|
|
91
|
+
label: localization.filterLessThan,
|
|
92
|
+
divider: true,
|
|
93
|
+
fn: lessThanFilterFN,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
type: MRT_FILTER_TYPE.EMPTY,
|
|
97
|
+
label: localization.filterEmpty,
|
|
67
98
|
divider: false,
|
|
99
|
+
fn: emptyFilterFN,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
type: MRT_FILTER_TYPE.NOT_EMPTY,
|
|
103
|
+
label: localization.filterNotEmpty,
|
|
104
|
+
divider: false,
|
|
105
|
+
fn: notEmptyFilterFN,
|
|
68
106
|
},
|
|
69
107
|
],
|
|
70
108
|
[],
|
|
71
109
|
);
|
|
72
110
|
|
|
73
|
-
const handleSelectFilterType = (value:
|
|
111
|
+
const handleSelectFilterType = (value: MRT_FILTER_TYPE) => {
|
|
74
112
|
setAnchorEl(null);
|
|
75
113
|
setCurrentFilterTypes((prev: { [key: string]: MRT_FilterType }) => ({
|
|
76
114
|
...prev,
|
|
77
115
|
[column.id]: value,
|
|
78
116
|
}));
|
|
79
|
-
if ([
|
|
117
|
+
if ([MRT_FILTER_TYPE.EMPTY, MRT_FILTER_TYPE.NOT_EMPTY].includes(value)) {
|
|
80
118
|
column.setFilter(' ');
|
|
81
119
|
}
|
|
82
120
|
onSelect?.();
|
|
@@ -92,17 +130,16 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
|
|
|
92
130
|
open={!!anchorEl}
|
|
93
131
|
MenuListProps={{
|
|
94
132
|
dense: tableInstance.state.densePadding,
|
|
95
|
-
disablePadding: true,
|
|
96
133
|
}}
|
|
97
134
|
>
|
|
98
|
-
{filterTypes.map(({ type, label, divider }) => (
|
|
135
|
+
{filterTypes.map(({ type, label, divider, fn }, index) => (
|
|
99
136
|
<MenuItem
|
|
100
137
|
divider={divider}
|
|
101
|
-
key={
|
|
138
|
+
key={index}
|
|
102
139
|
onClick={() => handleSelectFilterType(type)}
|
|
103
|
-
selected={type === filterType}
|
|
104
|
-
value={type}
|
|
140
|
+
selected={type === filterType || fn === filterType}
|
|
105
141
|
sx={commonMenuItemStyles}
|
|
142
|
+
value={type}
|
|
106
143
|
>
|
|
107
144
|
{label}
|
|
108
145
|
</MenuItem>
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Menu, MenuItem } from '@mui/material';
|
|
3
3
|
import { useMRT } from '../useMRT';
|
|
4
|
-
import { MRT_Row } from '..';
|
|
4
|
+
import type { MRT_Row } from '..';
|
|
5
5
|
import { commonMenuItemStyles } from './MRT_ColumnActionMenu';
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
interface Props {
|
|
9
8
|
anchorEl: HTMLElement | null;
|
|
10
9
|
row: MRT_Row;
|
|
@@ -33,17 +32,12 @@ export const MRT_RowActionMenu: FC<Props> = ({
|
|
|
33
32
|
onClose={() => setAnchorEl(null)}
|
|
34
33
|
MenuListProps={{
|
|
35
34
|
dense: tableInstance.state.densePadding,
|
|
36
|
-
disablePadding: true,
|
|
37
35
|
}}
|
|
38
36
|
>
|
|
39
37
|
{enableRowEditing && (
|
|
40
38
|
<MenuItem onClick={handleEdit} sx={commonMenuItemStyles}>
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
</ListItemIcon>
|
|
44
|
-
<ListItemText sx={commonMenuItemStyles}>
|
|
45
|
-
{localization.rowActionMenuItemEdit}
|
|
46
|
-
</ListItemText>
|
|
39
|
+
<EditIcon />
|
|
40
|
+
{localization.edit}
|
|
47
41
|
</MenuItem>
|
|
48
42
|
)}
|
|
49
43
|
{renderRowActionMenuItems?.(row, tableInstance, () =>
|
|
@@ -1,44 +1,65 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { Button, Menu, Divider, Box } from '@mui/material';
|
|
3
|
+
import type { MRT_ColumnInstance } from '..';
|
|
4
|
+
import { useMRT } from '../useMRT';
|
|
5
|
+
import { MRT_ShowHideColumnsMenuItems } from './MRT_ShowHideColumnsMenuItems';
|
|
5
6
|
|
|
6
7
|
interface Props {
|
|
7
|
-
|
|
8
|
+
anchorEl: HTMLElement | null;
|
|
9
|
+
isSubMenu?: boolean;
|
|
10
|
+
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
8
11
|
}
|
|
9
12
|
|
|
10
|
-
export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const switchChecked = column.isVisible ?? allChildColumnsVisible;
|
|
18
|
-
|
|
19
|
-
const handleToggleColumnHidden = (column: ColumnInstance) => {
|
|
20
|
-
if (isParentHeader) {
|
|
21
|
-
column?.columns?.forEach?.((childColumn) => {
|
|
22
|
-
childColumn.toggleHidden(switchChecked);
|
|
23
|
-
});
|
|
24
|
-
} else {
|
|
25
|
-
column.toggleHidden();
|
|
26
|
-
}
|
|
27
|
-
};
|
|
13
|
+
export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
14
|
+
anchorEl,
|
|
15
|
+
isSubMenu,
|
|
16
|
+
setAnchorEl,
|
|
17
|
+
}) => {
|
|
18
|
+
const { localization, tableInstance } = useMRT();
|
|
28
19
|
|
|
29
20
|
return (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
21
|
+
<Menu
|
|
22
|
+
anchorEl={anchorEl}
|
|
23
|
+
open={!!anchorEl}
|
|
24
|
+
onClose={() => setAnchorEl(null)}
|
|
25
|
+
MenuListProps={{
|
|
26
|
+
dense: tableInstance.state.densePadding,
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
<Box
|
|
30
|
+
sx={{
|
|
31
|
+
display: 'flex',
|
|
32
|
+
justifyContent: isSubMenu ? 'center' : 'space-between',
|
|
33
|
+
p: '0.5rem',
|
|
34
|
+
pt: 0,
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
{!isSubMenu && (
|
|
38
|
+
<Button
|
|
39
|
+
disabled={
|
|
40
|
+
!tableInstance.getToggleHideAllColumnsProps().checked &&
|
|
41
|
+
!tableInstance.getToggleHideAllColumnsProps().indeterminate
|
|
42
|
+
}
|
|
43
|
+
onClick={() => tableInstance.toggleHideAllColumns(true)}
|
|
44
|
+
>
|
|
45
|
+
{localization.hideAll}
|
|
46
|
+
</Button>
|
|
47
|
+
)}
|
|
48
|
+
<Button
|
|
49
|
+
disabled={tableInstance.getToggleHideAllColumnsProps().checked}
|
|
50
|
+
onClick={() => tableInstance.toggleHideAllColumns(false)}
|
|
51
|
+
>
|
|
52
|
+
{localization.showAll}
|
|
53
|
+
</Button>
|
|
54
|
+
</Box>
|
|
55
|
+
<Divider />
|
|
56
|
+
{tableInstance.columns.map((column: MRT_ColumnInstance, index) => (
|
|
57
|
+
<MRT_ShowHideColumnsMenuItems
|
|
58
|
+
column={column}
|
|
59
|
+
isSubMenu={isSubMenu}
|
|
60
|
+
key={`${index}-${column.id}`}
|
|
37
61
|
/>
|
|
38
|
-
</MenuItem>
|
|
39
|
-
{column.columns?.map((c: MRT_ColumnInstance, i) => (
|
|
40
|
-
<MRT_ShowHideColumnsMenu key={`${i}-${c.id}`} column={c} />
|
|
41
62
|
))}
|
|
42
|
-
|
|
63
|
+
</Menu>
|
|
43
64
|
);
|
|
44
65
|
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { FormControlLabel, MenuItem, Switch } from '@mui/material';
|
|
3
|
+
import { ColumnInstance } from 'react-table';
|
|
4
|
+
import type { MRT_ColumnInstance } from '..';
|
|
5
|
+
import { commonMenuItemStyles } from './MRT_ColumnActionMenu';
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
column: MRT_ColumnInstance;
|
|
9
|
+
isSubMenu?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
13
|
+
column,
|
|
14
|
+
isSubMenu,
|
|
15
|
+
}) => {
|
|
16
|
+
const isParentHeader = !!column?.columns?.length;
|
|
17
|
+
|
|
18
|
+
const allChildColumnsVisible =
|
|
19
|
+
isParentHeader &&
|
|
20
|
+
!!column.columns?.every((childColumn) => childColumn.isVisible);
|
|
21
|
+
|
|
22
|
+
const switchChecked = column.isVisible ?? allChildColumnsVisible;
|
|
23
|
+
|
|
24
|
+
const handleToggleColumnHidden = (column: ColumnInstance) => {
|
|
25
|
+
if (isParentHeader) {
|
|
26
|
+
column?.columns?.forEach?.((childColumn) => {
|
|
27
|
+
childColumn.toggleHidden(switchChecked);
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
column.toggleHidden();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<>
|
|
36
|
+
<MenuItem
|
|
37
|
+
sx={{ ...commonMenuItemStyles, pl: `${(column.depth + 0.5) * 2}rem` }}
|
|
38
|
+
>
|
|
39
|
+
<FormControlLabel
|
|
40
|
+
componentsProps={{ typography: { sx: { marginBottom: 0 } } }}
|
|
41
|
+
checked={switchChecked}
|
|
42
|
+
control={<Switch />}
|
|
43
|
+
disabled={isSubMenu && switchChecked}
|
|
44
|
+
label={column.Header as string}
|
|
45
|
+
onChange={() => handleToggleColumnHidden(column)}
|
|
46
|
+
/>
|
|
47
|
+
</MenuItem>
|
|
48
|
+
{column.columns?.map((c: MRT_ColumnInstance, i) => (
|
|
49
|
+
<MRT_ShowHideColumnsMenuItems
|
|
50
|
+
key={`${i}-${c.id}`}
|
|
51
|
+
column={c}
|
|
52
|
+
isSubMenu={isSubMenu}
|
|
53
|
+
/>
|
|
54
|
+
))}
|
|
55
|
+
</>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
@@ -23,7 +23,7 @@ export const MRT_ToolbarAlertBanner: FC<Props> = () => {
|
|
|
23
23
|
|
|
24
24
|
const selectMessage =
|
|
25
25
|
tableInstance.selectedFlatRows.length > 0
|
|
26
|
-
? localization.
|
|
26
|
+
? localization.selectedCountOfRowCountRowsSelected
|
|
27
27
|
?.replace(
|
|
28
28
|
'{selectedCount}',
|
|
29
29
|
tableInstance.selectedFlatRows.length.toString(),
|
|
@@ -34,10 +34,10 @@ export const MRT_ToolbarAlertBanner: FC<Props> = () => {
|
|
|
34
34
|
const groupedByMessage =
|
|
35
35
|
tableInstance.state.groupBy.length > 0 ? (
|
|
36
36
|
<span>
|
|
37
|
-
{localization.
|
|
37
|
+
{localization.groupedBy}{' '}
|
|
38
38
|
{tableInstance.state.groupBy.map((columnId, index) => (
|
|
39
39
|
<Fragment key={`${index}-${columnId}`}>
|
|
40
|
-
{index > 0 ? localization.
|
|
40
|
+
{index > 0 ? localization.thenBy : ''}
|
|
41
41
|
<Chip
|
|
42
42
|
color="secondary"
|
|
43
43
|
label={
|