material-react-table 0.6.8 → 0.7.0-alpha.1

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 (107) hide show
  1. package/dist/MaterialReactTable.d.ts +147 -82
  2. package/dist/body/MRT_TableBody.d.ts +3 -0
  3. package/dist/body/MRT_TableBodyCell.d.ts +2 -11
  4. package/dist/body/MRT_TableBodyRow.d.ts +3 -1
  5. package/dist/body/MRT_TableDetailPanel.d.ts +2 -1
  6. package/dist/buttons/MRT_CopyButton.d.ts +4 -2
  7. package/dist/buttons/MRT_EditActionButtons.d.ts +2 -1
  8. package/dist/buttons/MRT_ExpandAllButton.d.ts +2 -0
  9. package/dist/buttons/MRT_ExpandButton.d.ts +2 -1
  10. package/dist/buttons/MRT_FullScreenToggleButton.d.ts +2 -0
  11. package/dist/buttons/MRT_ShowHideColumnsButton.d.ts +2 -0
  12. package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +3 -2
  13. package/dist/buttons/MRT_ToggleDensePaddingButton.d.ts +2 -0
  14. package/dist/buttons/MRT_ToggleFiltersButton.d.ts +2 -0
  15. package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +2 -1
  16. package/dist/buttons/MRT_ToggleSearchButton.d.ts +2 -0
  17. package/dist/enums.d.ts +2 -1
  18. package/dist/filtersFNs.d.ts +13 -5
  19. package/dist/footer/MRT_TableFooter.d.ts +3 -0
  20. package/dist/footer/MRT_TableFooterCell.d.ts +3 -2
  21. package/dist/footer/MRT_TableFooterRow.d.ts +2 -1
  22. package/dist/head/MRT_TableHead.d.ts +3 -0
  23. package/dist/head/MRT_TableHeadCell.d.ts +4 -18
  24. package/dist/head/MRT_TableHeadRow.d.ts +2 -1
  25. package/dist/icons.d.ts +1 -1
  26. package/dist/inputs/MRT_EditCellTextField.d.ts +2 -1
  27. package/dist/inputs/MRT_FilterTextField.d.ts +3 -2
  28. package/dist/inputs/MRT_SearchTextField.d.ts +2 -0
  29. package/dist/inputs/MRT_SelectCheckbox.d.ts +2 -1
  30. package/dist/localization.d.ts +9 -2
  31. package/dist/material-react-table.cjs.development.js +2183 -1686
  32. package/dist/material-react-table.cjs.development.js.map +1 -1
  33. package/dist/material-react-table.cjs.production.min.js +1 -1
  34. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  35. package/dist/material-react-table.esm.js +2191 -1694
  36. package/dist/material-react-table.esm.js.map +1 -1
  37. package/dist/menus/MRT_ColumnActionMenu.d.ts +3 -2
  38. package/dist/menus/MRT_FilterTypeMenu.d.ts +4 -3
  39. package/dist/menus/MRT_RowActionMenu.d.ts +3 -2
  40. package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +2 -0
  41. package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +2 -1
  42. package/dist/table/MRT_Table.d.ts +3 -0
  43. package/dist/table/MRT_TableContainer.d.ts +2 -0
  44. package/dist/table/MRT_TablePaper.d.ts +7 -0
  45. package/dist/table/MRT_TableRoot.d.ts +3 -0
  46. package/dist/toolbar/MRT_LinearProgressBar.d.ts +2 -0
  47. package/dist/toolbar/MRT_TablePagination.d.ts +2 -0
  48. package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +2 -0
  49. package/dist/toolbar/MRT_ToolbarBottom.d.ts +2 -0
  50. package/dist/toolbar/MRT_ToolbarInternalButtons.d.ts +2 -0
  51. package/dist/toolbar/MRT_ToolbarTop.d.ts +4 -2
  52. package/dist/utils.d.ts +12 -2
  53. package/package.json +27 -28
  54. package/src/MaterialReactTable.tsx +314 -241
  55. package/src/body/MRT_TableBody.tsx +25 -21
  56. package/src/body/MRT_TableBodyCell.tsx +74 -53
  57. package/src/body/MRT_TableBodyRow.tsx +35 -51
  58. package/src/body/MRT_TableDetailPanel.tsx +16 -14
  59. package/src/buttons/MRT_CopyButton.tsx +36 -11
  60. package/src/buttons/MRT_EditActionButtons.tsx +13 -12
  61. package/src/buttons/MRT_ExpandAllButton.tsx +36 -28
  62. package/src/buttons/MRT_ExpandButton.tsx +34 -40
  63. package/src/buttons/MRT_FullScreenToggleButton.tsx +18 -11
  64. package/src/buttons/MRT_ShowHideColumnsButton.tsx +18 -7
  65. package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +17 -9
  66. package/src/buttons/MRT_ToggleDensePaddingButton.tsx +18 -11
  67. package/src/buttons/MRT_ToggleFiltersButton.tsx +16 -9
  68. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +26 -21
  69. package/src/buttons/MRT_ToggleSearchButton.tsx +18 -11
  70. package/src/enums.ts +2 -1
  71. package/src/filtersFNs.ts +17 -3
  72. package/src/footer/MRT_TableFooter.tsx +23 -7
  73. package/src/footer/MRT_TableFooterCell.tsx +32 -24
  74. package/src/footer/MRT_TableFooterRow.tsx +20 -38
  75. package/src/head/MRT_TableHead.tsx +23 -7
  76. package/src/head/MRT_TableHeadCell.tsx +201 -151
  77. package/src/head/MRT_TableHeadRow.tsx +15 -81
  78. package/src/icons.ts +3 -3
  79. package/src/inputs/MRT_EditCellTextField.tsx +23 -24
  80. package/src/inputs/MRT_FilterTextField.tsx +51 -37
  81. package/src/inputs/MRT_SearchTextField.tsx +63 -22
  82. package/src/inputs/MRT_SelectCheckbox.tsx +75 -42
  83. package/src/localization.ts +19 -4
  84. package/src/menus/MRT_ColumnActionMenu.tsx +129 -69
  85. package/src/menus/MRT_FilterTypeMenu.tsx +55 -23
  86. package/src/menus/MRT_RowActionMenu.tsx +16 -11
  87. package/src/menus/MRT_ShowHideColumnsMenu.tsx +52 -20
  88. package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +28 -17
  89. package/src/table/MRT_Table.tsx +24 -14
  90. package/src/table/MRT_TableContainer.tsx +109 -44
  91. package/src/table/MRT_TablePaper.tsx +61 -0
  92. package/src/table/MRT_TableRoot.tsx +236 -0
  93. package/src/toolbar/MRT_LinearProgressBar.tsx +9 -6
  94. package/src/toolbar/MRT_TablePagination.tsx +28 -18
  95. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +31 -19
  96. package/src/toolbar/MRT_ToolbarBottom.tsx +31 -20
  97. package/src/toolbar/MRT_ToolbarInternalButtons.tsx +29 -16
  98. package/src/toolbar/MRT_ToolbarTop.tsx +34 -27
  99. package/src/utils.ts +37 -8
  100. package/dist/head/MRT_TableHeadCellActions.d.ts +0 -5
  101. package/dist/table/MRT_TableSpacerCell.d.ts +0 -6
  102. package/dist/useMRT.d.ts +0 -27
  103. package/src/@types/faker.d.ts +0 -4
  104. package/src/@types/react-table-config.d.ts +0 -53
  105. package/src/head/MRT_TableHeadCellActions.tsx +0 -29
  106. package/src/table/MRT_TableSpacerCell.tsx +0 -20
  107. 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 { useMRT } from '../useMRT';
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
- column: MRT_HeaderGroup;
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
- column,
28
+ header,
29
29
  setAnchorEl,
30
+ tableInstance,
30
31
  }) => {
31
32
  const {
32
- disableColumnHiding,
33
- disableFilters,
34
- disableSortBy,
35
- enableColumnGrouping,
36
- icons: {
37
- ArrowRightIcon,
38
- ClearAllIcon,
39
- ViewColumnIcon,
40
- DynamicFeedIcon,
41
- FilterListIcon,
42
- FilterListOffIcon,
43
- SortIcon,
44
- VisibilityOffIcon,
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
- idPrefix,
47
- localization,
48
- setShowFilters,
49
- tableInstance,
50
- } = useMRT();
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.clearSortBy();
70
+ column.resetSorting();
60
71
  setAnchorEl(null);
61
72
  };
62
73
 
63
74
  const handleSortAsc = () => {
64
- column.toggleSortBy(false);
75
+ column.toggleSorting(false);
65
76
  setAnchorEl(null);
66
77
  };
67
78
 
68
79
  const handleSortDesc = () => {
69
- column.toggleSortBy(true);
80
+ column.toggleSorting(true);
70
81
  setAnchorEl(null);
71
82
  };
72
83
 
73
84
  const handleHideColumn = () => {
74
- column.toggleHidden();
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.toggleGroupBy();
94
+ column.toggleGrouping();
95
+ setColumnOrder((old) => ['mrt-expand', ...old]);
80
96
  setAnchorEl(null);
81
97
  };
82
98
 
83
99
  const handleClearFilter = () => {
84
- column.setFilter('');
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
- column.muiTableHeadCellFilterTextFieldProps?.id ??
96
- `mrt-${idPrefix}-${column.id}-filter-text-field`,
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
- tableInstance.toggleHideAllColumns(false);
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: tableInstance.state.densePadding,
143
+ dense: isDensePadding,
128
144
  }}
129
145
  >
130
- {!disableSortBy &&
131
- column.canSort && [
146
+ {enableSorting &&
147
+ column.getCanSort() && [
132
148
  <MenuItem
133
- disabled={!column.isSorted}
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.isSorted && !column.isSortedDesc}
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.Header),
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.isSorted && column.isSortedDesc}
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.Header),
190
+ String(column.header),
177
191
  )}
178
192
  </Box>
179
193
  </MenuItem>,
180
194
  ]}
181
- {!disableFilters &&
182
- column.canFilter && [
195
+ {enableColumnFilters &&
196
+ column.getCanColumnFilter() && [
183
197
  <MenuItem
184
- disabled={!column.filterValue}
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={enableColumnGrouping || !disableColumnHiding}
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.Header),
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
- column={column}
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
- {enableColumnGrouping &&
231
- column.canGroupBy && [
245
+ {enableGrouping &&
246
+ column.getCanGroup() && [
232
247
  <MenuItem
233
- divider={!disableColumnHiding}
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.isGrouped ? 'ungroupByColumn' : 'groupByColumn'
244
- ]?.replace('{column}', String(column.Header))}
258
+ column.getIsGrouped() ? 'ungroupByColumn' : 'groupByColumn'
259
+ ]?.replace('{column}', String(column.header))}
245
260
  </Box>
246
261
  </MenuItem>,
247
262
  ]}
248
- {!disableColumnHiding && [
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.disableColumnHiding}
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.Header),
319
+ String(column.header),
262
320
  )}
263
321
  </Box>
264
322
  </MenuItem>,
265
323
  <MenuItem
266
- disabled={!tableInstance.state.hiddenColumns?.length}
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.Header),
338
+ String(column.header),
278
339
  )}
279
340
  </Box>
280
- {!column.filterSelectOptions && (
281
- <IconButton
282
- onClick={handleOpenShowHideColumnsMenu}
283
- onMouseEnter={handleOpenShowHideColumnsMenu}
284
- size="small"
285
- sx={{ p: 0 }}
286
- >
287
- <ArrowRightIcon />
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 { useMRT } from '../useMRT';
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
- column: MRT_HeaderGroup;
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
- column,
35
+ header,
35
36
  onSelect,
36
37
  setAnchorEl,
38
+ tableInstance,
37
39
  }) => {
38
- const { localization, setCurrentFilterTypes, tableInstance } = useMRT();
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.FUZZY,
50
- label: localization.filterFuzzy,
62
+ type: MRT_FILTER_TYPE.BEST_MATCH_FIRST,
63
+ label: localization.filterBestMatchFirst,
51
64
  divider: false,
52
- fn: fuzzy,
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: true,
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
- (filterType) =>
110
- !column.filterTypes || column.filterTypes.includes(filterType.type),
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
- setAnchorEl(null);
117
- setCurrentFilterTypes((prev: { [key: string]: MRT_FilterType }) => ({
118
- ...prev,
119
- [column.id]: value,
120
- }));
121
- if ([MRT_FILTER_TYPE.EMPTY, MRT_FILTER_TYPE.NOT_EMPTY].includes(value)) {
122
- column.setFilter(' ');
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 = tableInstance.state.currentFilterTypes[column.id];
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: tableInstance.state.densePadding,
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 { useMRT } from '../useMRT';
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
- handleEdit: () => void;
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
- icons: { EditIcon },
25
- enableRowEditing,
26
- localization,
27
- renderRowActionMenuItems,
28
- tableInstance,
29
- } = useMRT();
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: tableInstance.state.densePadding,
42
+ dense: isDensePadding,
38
43
  }}
39
44
  >
40
45
  {enableRowEditing && (
@@ -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 { findLowestLevelCols } from '../utils';
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 { localization, tableInstance } = useMRT();
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
- findLowestLevelCols(
24
- tableInstance.columns as MRT_ColumnInstance[],
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: tableInstance.state.densePadding,
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={tableInstance.getToggleHideAllColumnsProps().checked}
61
- onClick={() => tableInstance.toggleHideAllColumns(false)}
82
+ disabled={getIsAllColumnsVisible()}
83
+ onClick={() => toggleAllColumnsVisible(true)}
62
84
  >
63
85
  {localization.showAll}
64
86
  </Button>
65
87
  </Box>
66
88
  <Divider />
67
- {tableInstance.columns.map((column: MRT_ColumnInstance, index) => (
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>