material-react-table 0.5.9 → 0.6.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.
Files changed (38) hide show
  1. package/dist/MaterialReactTable.d.ts +13 -5
  2. package/dist/filtersFNs.d.ts +6 -10
  3. package/dist/localization.d.ts +43 -46
  4. package/dist/material-react-table.cjs.development.js +404 -331
  5. package/dist/material-react-table.cjs.development.js.map +1 -1
  6. package/dist/material-react-table.cjs.production.min.js +1 -1
  7. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  8. package/dist/material-react-table.esm.js +405 -332
  9. package/dist/material-react-table.esm.js.map +1 -1
  10. package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +3 -2
  11. package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +8 -0
  12. package/dist/useMRT.d.ts +4 -0
  13. package/package.json +3 -3
  14. package/src/MaterialReactTable.tsx +59 -47
  15. package/src/buttons/MRT_EditActionButtons.tsx +4 -7
  16. package/src/buttons/MRT_ExpandAllButton.tsx +2 -2
  17. package/src/buttons/MRT_ExpandButton.tsx +2 -2
  18. package/src/buttons/MRT_FullScreenToggleButton.tsx +2 -2
  19. package/src/buttons/MRT_ShowHideColumnsButton.tsx +4 -52
  20. package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +2 -2
  21. package/src/buttons/MRT_ToggleDensePaddingButton.tsx +2 -2
  22. package/src/buttons/MRT_ToggleFiltersButton.tsx +2 -2
  23. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +3 -7
  24. package/src/buttons/MRT_ToggleSearchButton.tsx +1 -1
  25. package/src/filtersFNs.ts +6 -16
  26. package/src/head/MRT_TableHeadCell.tsx +19 -6
  27. package/src/head/MRT_TableHeadCellActions.tsx +1 -1
  28. package/src/inputs/MRT_FilterTextField.tsx +34 -9
  29. package/src/inputs/MRT_SearchTextField.tsx +3 -3
  30. package/src/inputs/MRT_SelectCheckbox.tsx +4 -4
  31. package/src/localization.ts +87 -92
  32. package/src/menus/MRT_ColumnActionMenu.tsx +59 -14
  33. package/src/menus/MRT_FilterTypeMenu.tsx +10 -10
  34. package/src/menus/MRT_RowActionMenu.tsx +1 -1
  35. package/src/menus/MRT_ShowHideColumnsMenu.tsx +52 -35
  36. package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +57 -0
  37. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +3 -3
  38. package/src/useMRT.tsx +38 -34
@@ -37,15 +37,15 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll }) => {
37
37
  enterNextDelay={1000}
38
38
  title={
39
39
  selectAll
40
- ? localization.selectAllCheckboxTitle
41
- : localization.selectCheckboxTitle
40
+ ? localization.toggleSelectAll
41
+ : localization.toggleSelectRow
42
42
  }
43
43
  >
44
44
  <Checkbox
45
45
  inputProps={{
46
46
  'aria-label': selectAll
47
- ? localization.selectAllCheckboxTitle
48
- : localization.selectCheckboxTitle,
47
+ ? localization.toggleSelectAll
48
+ : localization.toggleSelectRow,
49
49
  }}
50
50
  onChange={onSelectChange}
51
51
  {...checkboxProps}
@@ -1,99 +1,94 @@
1
1
  export interface MRT_Localization {
2
- actionsHeadColumnTitle: string;
2
+ actions: string;
3
+ cancel: string;
3
4
  changeFilterMode: string;
4
- columnActionMenuButtonTitle: string;
5
- columnActionMenuItemClearSort: string;
6
- columnActionMenuItemGroupBy: string;
7
- columnActionMenuItemHideColumn: string;
8
- columnActionMenuItemSortAsc: string;
9
- columnActionMenuItemSortDesc: string;
10
- columnActionMenuItemUnGroupBy: string;
11
- columnShowHideMenuHideAll: string;
12
- columnShowHideMenuShowAll: string;
13
- expandAllButtonTitle: string;
14
- expandButtonTitle: string;
15
- filterApplied: string;
16
- filterMenuItemContains: string;
17
- filterMenuItemEmpty: string;
18
- filterMenuItemEndsWith: string;
19
- filterMenuItemEquals: string;
20
- filterMenuItemFuzzy: string;
21
- filterMenuItemGreaterThan: string;
22
- filterMenuItemLessThan: string;
23
- filterMenuItemNotEmpty: string;
24
- filterMenuItemNotEquals: string;
25
- filterMenuItemStartsWith: string;
26
- filterMenuTitle: string;
27
- filterTextFieldChangeFilterButtonTitle: string;
28
- filterTextFieldChipLabelEmpty: string;
29
- filterTextFieldChipLabelNotEmpty: string;
30
- filterTextFieldClearButtonTitle: string;
31
- filterTextFieldPlaceholder: string;
32
- rowActionButtonCancel: string;
33
- rowActionButtonSave: string;
34
- rowActionMenuButtonTitle: string;
35
- rowActionMenuItemEdit: string;
36
- rowActionsColumnTitle: string;
37
- searchTextFieldClearButtonTitle: string;
38
- searchTextFieldPlaceholder: string;
39
- selectAllCheckboxTitle: string;
40
- selectCheckboxTitle: string;
41
- showHideColumnsButtonTitle: string;
42
- toggleDensePaddingSwitchTitle: string;
43
- toggleFilterButtonTitle: string;
44
- toggleFullScreenButtonTitle: string;
45
- toggleSearchButtonTitle: string;
46
- toolbarAlertGroupedByMessage: string;
47
- toolbarAlertGroupedThenByMessage: string;
48
- toolbarAlertSelectionMessage: string;
5
+ clearFilter: string;
6
+ clearSearch: string;
7
+ clearSort: string;
8
+ columnActions: string;
9
+ edit: string;
10
+ expand: string;
11
+ expandAll: string;
12
+ filterByColumn: string;
13
+ filterContains: string;
14
+ filterEmpty: string;
15
+ filterEndsWith: string;
16
+ filterEquals: string;
17
+ filterFuzzy: string;
18
+ filterGreaterThan: string;
19
+ filterLessThan: string;
20
+ filterMode: string;
21
+ filterNotEmpty: string;
22
+ filterNotEquals: string;
23
+ filterStartsWith: string;
24
+ filteringByColumn: string;
25
+ groupByColumn: string;
26
+ groupedBy: string;
27
+ hideAll: string;
28
+ hideColumn: string;
29
+ rowActions: string;
30
+ save: string;
31
+ search: string;
32
+ selectedCountOfRowCountRowsSelected: string;
33
+ showAll: string;
34
+ showHideColumns: string;
35
+ showAllColumns: string;
36
+ showHideFilters: string;
37
+ showHideSearch: string;
38
+ sortByColumnAsc: string;
39
+ sortByColumnDesc: string;
40
+ thenBy: string;
41
+ toggleDensePadding: string;
42
+ toggleFullScreen: string;
43
+ toggleSelectAll: string;
44
+ toggleSelectRow: string;
45
+ ungroupByColumn: string;
49
46
  }
50
47
 
51
48
  export const MRT_DefaultLocalization_EN: MRT_Localization = {
52
- actionsHeadColumnTitle: 'Actions',
49
+ actions: 'Actions',
50
+ cancel: 'Cancel',
53
51
  changeFilterMode: 'Change filter mode',
54
- columnActionMenuButtonTitle: 'Column Actions',
55
- columnActionMenuItemClearSort: 'Clear sort',
56
- columnActionMenuItemGroupBy: 'Group by {column}',
57
- columnActionMenuItemHideColumn: 'Hide {column} column',
58
- columnActionMenuItemSortAsc: 'Sort by {column} ascending',
59
- columnActionMenuItemSortDesc: 'Sort by {column} descending',
60
- columnActionMenuItemUnGroupBy: 'Ungroup by {column}',
61
- columnShowHideMenuHideAll: 'Hide all',
62
- columnShowHideMenuShowAll: 'Show all',
63
- expandAllButtonTitle: 'Expand all',
64
- expandButtonTitle: 'Expand',
65
- filterApplied: 'Filtering by {column} - ({filterType})',
66
- filterMenuItemContains: 'Contains Exact',
67
- filterMenuItemEmpty: 'Empty',
68
- filterMenuItemEndsWith: 'Ends With',
69
- filterMenuItemEquals: 'Equals',
70
- filterMenuItemFuzzy: 'Fuzzy Match (Default)',
71
- filterMenuItemGreaterThan: 'Greater Than',
72
- filterMenuItemLessThan: 'Less Than',
73
- filterMenuItemNotEmpty: 'Not Empty',
74
- filterMenuItemNotEquals: 'Not Equals',
75
- filterMenuItemStartsWith: 'Starts With',
76
- filterMenuTitle: 'Filter Mode',
77
- filterTextFieldChangeFilterButtonTitle: 'Change Filter Mode',
78
- filterTextFieldChipLabelEmpty: 'Empty',
79
- filterTextFieldChipLabelNotEmpty: 'Not Empty',
80
- filterTextFieldClearButtonTitle: 'Clear filter',
81
- filterTextFieldPlaceholder: 'Filter by {column}',
82
- rowActionButtonCancel: 'Cancel',
83
- rowActionButtonSave: 'Save',
84
- rowActionMenuButtonTitle: 'Row Actions',
85
- rowActionMenuItemEdit: 'Edit',
86
- rowActionsColumnTitle: 'Actions',
87
- searchTextFieldClearButtonTitle: 'Clear search',
88
- searchTextFieldPlaceholder: 'Search',
89
- selectAllCheckboxTitle: 'Toggle select all',
90
- selectCheckboxTitle: 'Toggle select row',
91
- showHideColumnsButtonTitle: 'Show/Hide columns',
92
- toggleDensePaddingSwitchTitle: 'Toggle dense padding',
93
- toggleFilterButtonTitle: 'Show/Hide filters',
94
- toggleFullScreenButtonTitle: 'Toggle full screen',
95
- toggleSearchButtonTitle: 'Show/Hide search',
96
- toolbarAlertGroupedByMessage: 'Grouped by ',
97
- toolbarAlertGroupedThenByMessage: ', then by ',
98
- toolbarAlertSelectionMessage: '{selectedCount} of {rowCount} row(s) selected',
52
+ clearFilter: 'Clear filter',
53
+ clearSearch: 'Clear search',
54
+ clearSort: 'Clear sort',
55
+ columnActions: 'Column Actions',
56
+ edit: 'Edit',
57
+ expand: 'Expand',
58
+ expandAll: 'Expand all',
59
+ filterByColumn: 'Filter by {column}',
60
+ filterContains: 'Contains Exact',
61
+ filterEmpty: 'Empty',
62
+ filterEndsWith: 'Ends With',
63
+ filterEquals: 'Equals',
64
+ filterFuzzy: 'Fuzzy Match',
65
+ filterGreaterThan: 'Greater Than',
66
+ filterLessThan: 'Less Than',
67
+ filterMode: 'Filter Mode: {filterType}',
68
+ filterNotEmpty: 'Not Empty',
69
+ filterNotEquals: 'Not Equals',
70
+ filterStartsWith: 'Starts With',
71
+ filteringByColumn: 'Filtering by {column} - {filterType} "{filterValue}"',
72
+ groupByColumn: 'Group by {column}',
73
+ groupedBy: 'Grouped by ',
74
+ hideAll: 'Hide all',
75
+ hideColumn: 'Hide {column} column',
76
+ rowActions: 'Row Actions',
77
+ save: 'Save',
78
+ search: 'Search',
79
+ selectedCountOfRowCountRowsSelected:
80
+ '{selectedCount} of {rowCount} row(s) selected',
81
+ showAll: 'Show all',
82
+ showAllColumns: 'Show all columns',
83
+ showHideColumns: 'Show/Hide columns',
84
+ showHideFilters: 'Show/Hide filters',
85
+ showHideSearch: 'Show/Hide search',
86
+ sortByColumnAsc: 'Sort by {column} ascending',
87
+ sortByColumnDesc: 'Sort by {column} descending',
88
+ thenBy: ', then by ',
89
+ toggleDensePadding: 'Toggle dense padding',
90
+ toggleFullScreen: 'Toggle full screen',
91
+ toggleSelectAll: 'Toggle select all',
92
+ toggleSelectRow: 'Toggle select row',
93
+ ungroupByColumn: 'Ungroup by {column}',
99
94
  };
@@ -3,6 +3,7 @@ import { Box, IconButton, Menu, MenuItem } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
4
  import type { MRT_HeaderGroup } from '..';
5
5
  import { MRT_FilterTypeMenu } from './MRT_FilterTypeMenu';
6
+ import { MRT_ShowHideColumnsMenu } from './MRT_ShowHideColumnsMenu';
6
7
 
7
8
  export const commonMenuItemStyles = {
8
9
  py: '6px',
@@ -36,6 +37,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
36
37
  icons: {
37
38
  ArrowRightIcon,
38
39
  ClearAllIcon,
40
+ ViewColumnIcon,
39
41
  DynamicFeedIcon,
40
42
  FilterListIcon,
41
43
  FilterListOffIcon,
@@ -51,6 +53,9 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
51
53
  const [filterMenuAnchorEl, setFilterMenuAnchorEl] =
52
54
  useState<null | HTMLElement>(null);
53
55
 
56
+ const [showHideColumnsMenuAnchorEl, setShowHideColumnsMenuAnchorEl] =
57
+ useState<null | HTMLElement>(null);
58
+
54
59
  const handleClearSort = () => {
55
60
  column.clearSortBy();
56
61
  setAnchorEl(null);
@@ -102,6 +107,17 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
102
107
  setFilterMenuAnchorEl(event.currentTarget);
103
108
  };
104
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
+
105
121
  return (
106
122
  <Menu
107
123
  anchorEl={anchorEl}
@@ -115,24 +131,24 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
115
131
  column.canSort && [
116
132
  <MenuItem
117
133
  disabled={!column.isSorted}
118
- key={1}
134
+ key={0}
119
135
  onClick={handleClearSort}
120
136
  sx={commonMenuItemStyles}
121
137
  >
122
138
  <Box sx={commonListItemStyles}>
123
139
  <ClearAllIcon />
124
- {localization.columnActionMenuItemClearSort}
140
+ {localization.clearSort}
125
141
  </Box>
126
142
  </MenuItem>,
127
143
  <MenuItem
128
144
  disabled={column.isSorted && !column.isSortedDesc}
129
- key={2}
145
+ key={1}
130
146
  onClick={handleSortAsc}
131
147
  sx={commonMenuItemStyles}
132
148
  >
133
149
  <Box sx={commonListItemStyles}>
134
150
  <SortIcon />
135
- {localization.columnActionMenuItemSortAsc?.replace(
151
+ {localization.sortByColumnAsc?.replace(
136
152
  '{column}',
137
153
  String(column.Header),
138
154
  )}
@@ -142,14 +158,14 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
142
158
  divider={
143
159
  !disableFilters || enableColumnGrouping || !disableColumnHiding
144
160
  }
145
- key={3}
161
+ key={2}
146
162
  disabled={column.isSorted && column.isSortedDesc}
147
163
  onClick={handleSortDesc}
148
164
  sx={commonMenuItemStyles}
149
165
  >
150
166
  <Box sx={commonListItemStyles}>
151
167
  <SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />
152
- {localization.columnActionMenuItemSortDesc?.replace(
168
+ {localization.sortByColumnDesc?.replace(
153
169
  '{column}',
154
170
  String(column.Header),
155
171
  )}
@@ -166,7 +182,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
166
182
  >
167
183
  <Box sx={commonListItemStyles}>
168
184
  <FilterListOffIcon />
169
- {localization.filterTextFieldClearButtonTitle}
185
+ {localization.clearFilter}
170
186
  </Box>
171
187
  </MenuItem>,
172
188
  <MenuItem
@@ -177,7 +193,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
177
193
  >
178
194
  <Box sx={commonListItemStyles}>
179
195
  <FilterListIcon />
180
- {localization.filterTextFieldPlaceholder?.replace(
196
+ {localization.filterByColumn?.replace(
181
197
  '{column}',
182
198
  String(column.Header),
183
199
  )}
@@ -205,30 +221,59 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
205
221
  column.canGroupBy && [
206
222
  <MenuItem
207
223
  divider={!disableColumnHiding}
208
- key={2}
224
+ key={0}
209
225
  onClick={handleGroupByColumn}
210
226
  sx={commonMenuItemStyles}
211
227
  >
212
228
  <Box sx={commonListItemStyles}>
213
229
  <DynamicFeedIcon />
214
230
  {localization[
215
- column.isGrouped
216
- ? 'columnActionMenuItemUnGroupBy'
217
- : 'columnActionMenuItemGroupBy'
231
+ column.isGrouped ? 'ungroupByColumn' : 'groupByColumn'
218
232
  ]?.replace('{column}', String(column.Header))}
219
233
  </Box>
220
234
  </MenuItem>,
221
235
  ]}
222
236
  {!disableColumnHiding && [
223
- <MenuItem key={1} onClick={handleHideColumn} sx={commonMenuItemStyles}>
237
+ <MenuItem key={0} onClick={handleHideColumn} sx={commonMenuItemStyles}>
224
238
  <Box sx={commonListItemStyles}>
225
239
  <VisibilityOffIcon />
226
- {localization.columnActionMenuItemHideColumn?.replace(
240
+ {localization.hideColumn?.replace(
241
+ '{column}',
242
+ String(column.Header),
243
+ )}
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(
227
256
  '{column}',
228
257
  String(column.Header),
229
258
  )}
230
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
+ )}
231
270
  </MenuItem>,
271
+ <MRT_ShowHideColumnsMenu
272
+ anchorEl={showHideColumnsMenuAnchorEl}
273
+ isSubMenu
274
+ key={2}
275
+ setAnchorEl={setShowHideColumnsMenuAnchorEl}
276
+ />,
232
277
  ]}
233
278
  </Menu>
234
279
  );
@@ -46,61 +46,61 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
46
46
  () => [
47
47
  {
48
48
  type: MRT_FILTER_TYPE.FUZZY,
49
- label: localization.filterMenuItemFuzzy,
49
+ label: localization.filterFuzzy,
50
50
  divider: false,
51
51
  fn: fuzzyFilterFN,
52
52
  },
53
53
  {
54
54
  type: MRT_FILTER_TYPE.CONTAINS,
55
- label: localization.filterMenuItemContains,
55
+ label: localization.filterContains,
56
56
  divider: true,
57
57
  fn: containsFilterFN,
58
58
  },
59
59
  {
60
60
  type: MRT_FILTER_TYPE.STARTS_WITH,
61
- label: localization.filterMenuItemStartsWith,
61
+ label: localization.filterStartsWith,
62
62
  divider: false,
63
63
  fn: startsWithFilterFN,
64
64
  },
65
65
  {
66
66
  type: MRT_FILTER_TYPE.ENDS_WITH,
67
- label: localization.filterMenuItemEndsWith,
67
+ label: localization.filterEndsWith,
68
68
  divider: true,
69
69
  fn: endsWithFilterFN,
70
70
  },
71
71
  {
72
72
  type: MRT_FILTER_TYPE.EQUALS,
73
- label: localization.filterMenuItemEquals,
73
+ label: localization.filterEquals,
74
74
  divider: false,
75
75
  fn: equalsFilterFN,
76
76
  },
77
77
  {
78
78
  type: MRT_FILTER_TYPE.NOT_EQUALS,
79
- label: localization.filterMenuItemNotEquals,
79
+ label: localization.filterNotEquals,
80
80
  divider: true,
81
81
  fn: notEqualsFilterFN,
82
82
  },
83
83
  {
84
84
  type: MRT_FILTER_TYPE.GREATER_THAN,
85
- label: localization.filterMenuItemGreaterThan,
85
+ label: localization.filterGreaterThan,
86
86
  divider: false,
87
87
  fn: greaterThanFilterFN,
88
88
  },
89
89
  {
90
90
  type: MRT_FILTER_TYPE.LESS_THAN,
91
- label: localization.filterMenuItemLessThan,
91
+ label: localization.filterLessThan,
92
92
  divider: true,
93
93
  fn: lessThanFilterFN,
94
94
  },
95
95
  {
96
96
  type: MRT_FILTER_TYPE.EMPTY,
97
- label: localization.filterMenuItemEmpty,
97
+ label: localization.filterEmpty,
98
98
  divider: false,
99
99
  fn: emptyFilterFN,
100
100
  },
101
101
  {
102
102
  type: MRT_FILTER_TYPE.NOT_EMPTY,
103
- label: localization.filterMenuItemNotEmpty,
103
+ label: localization.filterNotEmpty,
104
104
  divider: false,
105
105
  fn: notEmptyFilterFN,
106
106
  },
@@ -37,7 +37,7 @@ export const MRT_RowActionMenu: FC<Props> = ({
37
37
  {enableRowEditing && (
38
38
  <MenuItem onClick={handleEdit} sx={commonMenuItemStyles}>
39
39
  <EditIcon />
40
- {localization.rowActionMenuItemEdit}
40
+ {localization.edit}
41
41
  </MenuItem>
42
42
  )}
43
43
  {renderRowActionMenuItems?.(row, tableInstance, () =>
@@ -1,48 +1,65 @@
1
1
  import React, { FC } from 'react';
2
- import { FormControlLabel, MenuItem, Switch } from '@mui/material';
3
- import { ColumnInstance } from 'react-table';
2
+ import { Button, Menu, Divider, Box } from '@mui/material';
4
3
  import type { MRT_ColumnInstance } from '..';
5
- import { commonMenuItemStyles } from './MRT_ColumnActionMenu';
4
+ import { useMRT } from '../useMRT';
5
+ import { MRT_ShowHideColumnsMenuItems } from './MRT_ShowHideColumnsMenuItems';
6
6
 
7
7
  interface Props {
8
- column: MRT_ColumnInstance;
8
+ anchorEl: HTMLElement | null;
9
+ isSubMenu?: boolean;
10
+ setAnchorEl: (anchorEl: HTMLElement | null) => void;
9
11
  }
10
12
 
11
- export const MRT_ShowHideColumnsMenu: FC<Props> = ({ column }) => {
12
- const isParentHeader = !!column?.columns?.length;
13
-
14
- const allChildColumnsVisible =
15
- isParentHeader &&
16
- !!column.columns?.every((childColumn) => childColumn.isVisible);
17
-
18
- const switchChecked = column.isVisible ?? allChildColumnsVisible;
19
-
20
- const handleToggleColumnHidden = (column: ColumnInstance) => {
21
- if (isParentHeader) {
22
- column?.columns?.forEach?.((childColumn) => {
23
- childColumn.toggleHidden(switchChecked);
24
- });
25
- } else {
26
- column.toggleHidden();
27
- }
28
- };
13
+ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
14
+ anchorEl,
15
+ isSubMenu,
16
+ setAnchorEl,
17
+ }) => {
18
+ const { localization, tableInstance } = useMRT();
29
19
 
30
20
  return (
31
- <>
32
- <MenuItem
33
- sx={{ ...commonMenuItemStyles, pl: `${(column.depth + 0.5) * 2}rem` }}
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
+ }}
34
36
  >
35
- <FormControlLabel
36
- componentsProps={{ typography: { sx: { marginBottom: 0 } } }}
37
- checked={switchChecked}
38
- control={<Switch />}
39
- label={column.Header as string}
40
- onChange={() => handleToggleColumnHidden(column)}
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}`}
41
61
  />
42
- </MenuItem>
43
- {column.columns?.map((c: MRT_ColumnInstance, i) => (
44
- <MRT_ShowHideColumnsMenu key={`${i}-${c.id}`} column={c} />
45
62
  ))}
46
- </>
63
+ </Menu>
47
64
  );
48
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.toolbarAlertSelectionMessage
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.toolbarAlertGroupedByMessage}{' '}
37
+ {localization.groupedBy}{' '}
38
38
  {tableInstance.state.groupBy.map((columnId, index) => (
39
39
  <Fragment key={`${index}-${columnId}`}>
40
- {index > 0 ? localization.toolbarAlertGroupedThenByMessage : ''}
40
+ {index > 0 ? localization.thenBy : ''}
41
41
  <Chip
42
42
  color="secondary"
43
43
  label={