material-react-table 0.6.9 → 0.7.0-alpha.2
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 +308 -107
- 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 +4 -2
- 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 +9 -2
- package/dist/material-react-table.cjs.development.js +2258 -2470
- 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 +2260 -2472
- 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 +27 -28
- package/src/MaterialReactTable.tsx +598 -295
- package/src/body/MRT_TableBody.tsx +26 -22
- package/src/body/MRT_TableBodyCell.tsx +76 -55
- package/src/body/MRT_TableBodyRow.tsx +37 -67
- package/src/body/MRT_TableDetailPanel.tsx +21 -17
- package/src/buttons/MRT_CopyButton.tsx +36 -11
- 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 +27 -22
- 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 +23 -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 +19 -4
- package/src/menus/MRT_ColumnActionMenu.tsx +129 -69
- package/src/menus/MRT_FilterTypeMenu.tsx +55 -23
- package/src/menus/MRT_RowActionMenu.tsx +21 -14
- 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 +236 -0
- package/src/toolbar/MRT_LinearProgressBar.tsx +10 -7
- package/src/toolbar/MRT_TablePagination.tsx +30 -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,7 +1,6 @@
|
|
|
1
1
|
import React, { FC, useState } from 'react';
|
|
2
2
|
import { Box, IconButton, ListItemIcon, Menu, MenuItem } from '@mui/material';
|
|
3
|
-
import {
|
|
4
|
-
import type { MRT_HeaderGroup } from '..';
|
|
3
|
+
import type { MRT_Header, MRT_TableInstance } from '..';
|
|
5
4
|
import { MRT_FilterTypeMenu } from './MRT_FilterTypeMenu';
|
|
6
5
|
import { MRT_ShowHideColumnsMenu } from './MRT_ShowHideColumnsMenu';
|
|
7
6
|
|
|
@@ -19,35 +18,47 @@ export const commonListItemStyles = {
|
|
|
19
18
|
|
|
20
19
|
interface Props {
|
|
21
20
|
anchorEl: HTMLElement | null;
|
|
22
|
-
|
|
21
|
+
header: MRT_Header;
|
|
23
22
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
23
|
+
tableInstance: MRT_TableInstance;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
27
27
|
anchorEl,
|
|
28
|
-
|
|
28
|
+
header,
|
|
29
29
|
setAnchorEl,
|
|
30
|
+
tableInstance,
|
|
30
31
|
}) => {
|
|
31
32
|
const {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
getState,
|
|
34
|
+
toggleAllColumnsVisible,
|
|
35
|
+
setColumnOrder,
|
|
36
|
+
options: {
|
|
37
|
+
enableColumnFilters,
|
|
38
|
+
enableColumnPinning,
|
|
39
|
+
enableGrouping,
|
|
40
|
+
enableHiding,
|
|
41
|
+
enableSorting,
|
|
42
|
+
icons: {
|
|
43
|
+
ArrowRightIcon,
|
|
44
|
+
ClearAllIcon,
|
|
45
|
+
ViewColumnIcon,
|
|
46
|
+
DynamicFeedIcon,
|
|
47
|
+
FilterListIcon,
|
|
48
|
+
FilterListOffIcon,
|
|
49
|
+
PushPinIcon,
|
|
50
|
+
SortIcon,
|
|
51
|
+
VisibilityOffIcon,
|
|
52
|
+
},
|
|
53
|
+
idPrefix,
|
|
54
|
+
localization,
|
|
55
|
+
setShowFilters,
|
|
45
56
|
},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
} =
|
|
57
|
+
} = tableInstance;
|
|
58
|
+
|
|
59
|
+
const { column } = header;
|
|
60
|
+
|
|
61
|
+
const { isDensePadding, columnVisibility } = getState();
|
|
51
62
|
|
|
52
63
|
const [filterMenuAnchorEl, setFilterMenuAnchorEl] =
|
|
53
64
|
useState<null | HTMLElement>(null);
|
|
@@ -56,32 +67,37 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
56
67
|
useState<null | HTMLElement>(null);
|
|
57
68
|
|
|
58
69
|
const handleClearSort = () => {
|
|
59
|
-
column.
|
|
70
|
+
column.resetSorting();
|
|
60
71
|
setAnchorEl(null);
|
|
61
72
|
};
|
|
62
73
|
|
|
63
74
|
const handleSortAsc = () => {
|
|
64
|
-
column.
|
|
75
|
+
column.toggleSorting(false);
|
|
65
76
|
setAnchorEl(null);
|
|
66
77
|
};
|
|
67
78
|
|
|
68
79
|
const handleSortDesc = () => {
|
|
69
|
-
column.
|
|
80
|
+
column.toggleSorting(true);
|
|
70
81
|
setAnchorEl(null);
|
|
71
82
|
};
|
|
72
83
|
|
|
73
84
|
const handleHideColumn = () => {
|
|
74
|
-
column.
|
|
85
|
+
column.toggleVisibility(false);
|
|
75
86
|
setAnchorEl(null);
|
|
76
87
|
};
|
|
77
88
|
|
|
89
|
+
const handlePinColumn = (pinDirection: 'left' | 'right' | false) => {
|
|
90
|
+
column.pin(pinDirection);
|
|
91
|
+
};
|
|
92
|
+
|
|
78
93
|
const handleGroupByColumn = () => {
|
|
79
|
-
column.
|
|
94
|
+
column.toggleGrouping();
|
|
95
|
+
setColumnOrder((old) => ['mrt-expand', ...old]);
|
|
80
96
|
setAnchorEl(null);
|
|
81
97
|
};
|
|
82
98
|
|
|
83
99
|
const handleClearFilter = () => {
|
|
84
|
-
column.
|
|
100
|
+
column.setColumnFilterValue('');
|
|
85
101
|
setAnchorEl(null);
|
|
86
102
|
};
|
|
87
103
|
|
|
@@ -92,8 +108,8 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
92
108
|
document
|
|
93
109
|
.getElementById(
|
|
94
110
|
// @ts-ignore
|
|
95
|
-
|
|
96
|
-
`mrt-${idPrefix}-${
|
|
111
|
+
header.muiTableHeadCellFilterTextFieldProps?.id ??
|
|
112
|
+
`mrt-${idPrefix}-${header.id}-filter-text-field`,
|
|
97
113
|
)
|
|
98
114
|
?.focus(),
|
|
99
115
|
200,
|
|
@@ -102,7 +118,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
102
118
|
};
|
|
103
119
|
|
|
104
120
|
const handleShowAllColumns = () => {
|
|
105
|
-
|
|
121
|
+
toggleAllColumnsVisible(true);
|
|
106
122
|
setAnchorEl(null);
|
|
107
123
|
};
|
|
108
124
|
|
|
@@ -124,13 +140,13 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
124
140
|
open={!!anchorEl}
|
|
125
141
|
onClose={() => setAnchorEl(null)}
|
|
126
142
|
MenuListProps={{
|
|
127
|
-
dense:
|
|
143
|
+
dense: isDensePadding,
|
|
128
144
|
}}
|
|
129
145
|
>
|
|
130
|
-
{
|
|
131
|
-
column.
|
|
146
|
+
{enableSorting &&
|
|
147
|
+
column.getCanSort() && [
|
|
132
148
|
<MenuItem
|
|
133
|
-
disabled={!column.
|
|
149
|
+
disabled={!column.getIsSorted()}
|
|
134
150
|
key={0}
|
|
135
151
|
onClick={handleClearSort}
|
|
136
152
|
sx={commonMenuItemStyles}
|
|
@@ -143,7 +159,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
143
159
|
</Box>
|
|
144
160
|
</MenuItem>,
|
|
145
161
|
<MenuItem
|
|
146
|
-
disabled={column.
|
|
162
|
+
disabled={column.getIsSorted() === 'asc'}
|
|
147
163
|
key={1}
|
|
148
164
|
onClick={handleSortAsc}
|
|
149
165
|
sx={commonMenuItemStyles}
|
|
@@ -154,16 +170,14 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
154
170
|
</ListItemIcon>
|
|
155
171
|
{localization.sortByColumnAsc?.replace(
|
|
156
172
|
'{column}',
|
|
157
|
-
String(column.
|
|
173
|
+
String(column.header),
|
|
158
174
|
)}
|
|
159
175
|
</Box>
|
|
160
176
|
</MenuItem>,
|
|
161
177
|
<MenuItem
|
|
162
|
-
divider={
|
|
163
|
-
!disableFilters || enableColumnGrouping || !disableColumnHiding
|
|
164
|
-
}
|
|
178
|
+
divider={enableColumnFilters || enableGrouping || enableHiding}
|
|
165
179
|
key={2}
|
|
166
|
-
disabled={column.
|
|
180
|
+
disabled={column.getIsSorted() === 'desc'}
|
|
167
181
|
onClick={handleSortDesc}
|
|
168
182
|
sx={commonMenuItemStyles}
|
|
169
183
|
>
|
|
@@ -173,15 +187,15 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
173
187
|
</ListItemIcon>
|
|
174
188
|
{localization.sortByColumnDesc?.replace(
|
|
175
189
|
'{column}',
|
|
176
|
-
String(column.
|
|
190
|
+
String(column.header),
|
|
177
191
|
)}
|
|
178
192
|
</Box>
|
|
179
193
|
</MenuItem>,
|
|
180
194
|
]}
|
|
181
|
-
{
|
|
182
|
-
column.
|
|
195
|
+
{enableColumnFilters &&
|
|
196
|
+
column.getCanColumnFilter() && [
|
|
183
197
|
<MenuItem
|
|
184
|
-
disabled={!column.
|
|
198
|
+
disabled={!column.getColumnFilterValue()}
|
|
185
199
|
key={0}
|
|
186
200
|
onClick={handleClearFilter}
|
|
187
201
|
sx={commonMenuItemStyles}
|
|
@@ -194,7 +208,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
194
208
|
</Box>
|
|
195
209
|
</MenuItem>,
|
|
196
210
|
<MenuItem
|
|
197
|
-
divider={
|
|
211
|
+
divider={enableGrouping || enableHiding}
|
|
198
212
|
key={1}
|
|
199
213
|
onClick={handleFilterByColumn}
|
|
200
214
|
sx={commonMenuItemStyles}
|
|
@@ -205,7 +219,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
205
219
|
</ListItemIcon>
|
|
206
220
|
{localization.filterByColumn?.replace(
|
|
207
221
|
'{column}',
|
|
208
|
-
String(column.
|
|
222
|
+
String(column.header),
|
|
209
223
|
)}
|
|
210
224
|
</Box>
|
|
211
225
|
{!column.filterSelectOptions && (
|
|
@@ -221,16 +235,17 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
221
235
|
</MenuItem>,
|
|
222
236
|
<MRT_FilterTypeMenu
|
|
223
237
|
anchorEl={filterMenuAnchorEl}
|
|
224
|
-
|
|
238
|
+
header={header}
|
|
225
239
|
key={2}
|
|
226
|
-
setAnchorEl={setFilterMenuAnchorEl}
|
|
227
240
|
onSelect={handleFilterByColumn}
|
|
241
|
+
setAnchorEl={setFilterMenuAnchorEl}
|
|
242
|
+
tableInstance={tableInstance}
|
|
228
243
|
/>,
|
|
229
244
|
]}
|
|
230
|
-
{
|
|
231
|
-
column.
|
|
245
|
+
{enableGrouping &&
|
|
246
|
+
column.getCanGroup() && [
|
|
232
247
|
<MenuItem
|
|
233
|
-
divider={
|
|
248
|
+
divider={enableColumnPinning}
|
|
234
249
|
key={0}
|
|
235
250
|
onClick={handleGroupByColumn}
|
|
236
251
|
sx={commonMenuItemStyles}
|
|
@@ -240,14 +255,57 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
240
255
|
<DynamicFeedIcon />
|
|
241
256
|
</ListItemIcon>
|
|
242
257
|
{localization[
|
|
243
|
-
column.
|
|
244
|
-
]?.replace('{column}', String(column.
|
|
258
|
+
column.getIsGrouped() ? 'ungroupByColumn' : 'groupByColumn'
|
|
259
|
+
]?.replace('{column}', String(column.header))}
|
|
245
260
|
</Box>
|
|
246
261
|
</MenuItem>,
|
|
247
262
|
]}
|
|
248
|
-
{
|
|
263
|
+
{enableColumnPinning &&
|
|
264
|
+
column.getCanPin() && [
|
|
265
|
+
<MenuItem
|
|
266
|
+
disabled={column.getIsPinned() === 'left'}
|
|
267
|
+
key={0}
|
|
268
|
+
onClick={() => handlePinColumn('left')}
|
|
269
|
+
sx={commonMenuItemStyles}
|
|
270
|
+
>
|
|
271
|
+
<Box sx={commonListItemStyles}>
|
|
272
|
+
<ListItemIcon>
|
|
273
|
+
<PushPinIcon style={{ transform: 'rotate(90deg)' }} />
|
|
274
|
+
</ListItemIcon>
|
|
275
|
+
{localization.pinToLeft}
|
|
276
|
+
</Box>
|
|
277
|
+
</MenuItem>,
|
|
278
|
+
<MenuItem
|
|
279
|
+
disabled={column.getIsPinned() === 'right'}
|
|
280
|
+
key={0}
|
|
281
|
+
onClick={() => handlePinColumn('right')}
|
|
282
|
+
sx={commonMenuItemStyles}
|
|
283
|
+
>
|
|
284
|
+
<Box sx={commonListItemStyles}>
|
|
285
|
+
<ListItemIcon>
|
|
286
|
+
<PushPinIcon style={{ transform: 'rotate(-90deg)' }} />
|
|
287
|
+
</ListItemIcon>
|
|
288
|
+
{localization.pinToRight}
|
|
289
|
+
</Box>
|
|
290
|
+
</MenuItem>,
|
|
291
|
+
<MenuItem
|
|
292
|
+
disabled={!column.getIsPinned()}
|
|
293
|
+
divider={enableHiding}
|
|
294
|
+
key={0}
|
|
295
|
+
onClick={() => handlePinColumn(false)}
|
|
296
|
+
sx={commonMenuItemStyles}
|
|
297
|
+
>
|
|
298
|
+
<Box sx={commonListItemStyles}>
|
|
299
|
+
<ListItemIcon>
|
|
300
|
+
<PushPinIcon />
|
|
301
|
+
</ListItemIcon>
|
|
302
|
+
{localization.unpin}
|
|
303
|
+
</Box>
|
|
304
|
+
</MenuItem>,
|
|
305
|
+
]}
|
|
306
|
+
{enableHiding && [
|
|
249
307
|
<MenuItem
|
|
250
|
-
disabled={column.
|
|
308
|
+
disabled={column.enableHiding === false}
|
|
251
309
|
key={0}
|
|
252
310
|
onClick={handleHideColumn}
|
|
253
311
|
sx={commonMenuItemStyles}
|
|
@@ -258,12 +316,15 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
258
316
|
</ListItemIcon>
|
|
259
317
|
{localization.hideColumn?.replace(
|
|
260
318
|
'{column}',
|
|
261
|
-
String(column.
|
|
319
|
+
String(column.header),
|
|
262
320
|
)}
|
|
263
321
|
</Box>
|
|
264
322
|
</MenuItem>,
|
|
265
323
|
<MenuItem
|
|
266
|
-
disabled={
|
|
324
|
+
disabled={
|
|
325
|
+
!Object.values(columnVisibility).filter((visible) => !visible)
|
|
326
|
+
.length
|
|
327
|
+
}
|
|
267
328
|
key={1}
|
|
268
329
|
onClick={handleShowAllColumns}
|
|
269
330
|
sx={commonMenuItemStyles}
|
|
@@ -274,25 +335,24 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
274
335
|
</ListItemIcon>
|
|
275
336
|
{localization.showAllColumns?.replace(
|
|
276
337
|
'{column}',
|
|
277
|
-
String(column.
|
|
338
|
+
String(column.header),
|
|
278
339
|
)}
|
|
279
340
|
</Box>
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
</IconButton>
|
|
289
|
-
)}
|
|
341
|
+
<IconButton
|
|
342
|
+
onClick={handleOpenShowHideColumnsMenu}
|
|
343
|
+
onMouseEnter={handleOpenShowHideColumnsMenu}
|
|
344
|
+
size="small"
|
|
345
|
+
sx={{ p: 0 }}
|
|
346
|
+
>
|
|
347
|
+
<ArrowRightIcon />
|
|
348
|
+
</IconButton>
|
|
290
349
|
</MenuItem>,
|
|
291
350
|
<MRT_ShowHideColumnsMenu
|
|
292
351
|
anchorEl={showHideColumnsMenuAnchorEl}
|
|
293
352
|
isSubMenu
|
|
294
353
|
key={2}
|
|
295
354
|
setAnchorEl={setShowHideColumnsMenuAnchorEl}
|
|
355
|
+
tableInstance={tableInstance}
|
|
296
356
|
/>,
|
|
297
357
|
]}
|
|
298
358
|
</Menu>
|
|
@@ -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
|
+
enableRowEditing,
|
|
29
|
+
localization,
|
|
30
|
+
renderRowActionMenuItems,
|
|
31
|
+
},
|
|
32
|
+
} = tableInstance;
|
|
33
|
+
|
|
34
|
+
const { isDensePadding } = getState();
|
|
30
35
|
|
|
31
36
|
return (
|
|
32
37
|
<Menu
|
|
@@ -34,7 +39,7 @@ 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
|
{enableRowEditing && (
|
|
@@ -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>
|