material-react-table 0.7.4 → 0.8.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 (57) hide show
  1. package/dist/MaterialReactTable.d.ts +25 -31
  2. package/dist/body/MRT_TableBody.d.ts +0 -1
  3. package/dist/body/MRT_TableBodyCell.d.ts +1 -0
  4. package/dist/body/MRT_TableBodyRow.d.ts +0 -1
  5. package/dist/buttons/MRT_ColumnPinningButtons.d.ts +8 -0
  6. package/dist/buttons/MRT_CopyButton.d.ts +2 -1
  7. package/dist/enums.d.ts +3 -3
  8. package/dist/filtersFNs.d.ts +31 -30
  9. package/dist/footer/MRT_TableFooter.d.ts +0 -1
  10. package/dist/head/MRT_TableHead.d.ts +0 -1
  11. package/dist/inputs/MRT_FilterRangeFields.d.ts +8 -0
  12. package/dist/inputs/MRT_FilterTextField.d.ts +1 -0
  13. package/dist/localization.d.ts +7 -2
  14. package/dist/material-react-table.cjs.development.js +489 -448
  15. package/dist/material-react-table.cjs.development.js.map +1 -1
  16. package/dist/material-react-table.cjs.production.min.js +1 -1
  17. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  18. package/dist/material-react-table.esm.js +492 -451
  19. package/dist/material-react-table.esm.js.map +1 -1
  20. package/dist/menus/{MRT_FilterTypeMenu.d.ts → MRT_FilterOptionMenu.d.ts} +1 -1
  21. package/dist/table/MRT_Table.d.ts +0 -1
  22. package/dist/toolbar/MRT_ToolbarTop.d.ts +1 -0
  23. package/dist/utils.d.ts +6 -6
  24. package/package.json +24 -24
  25. package/src/MaterialReactTable.tsx +39 -41
  26. package/src/body/MRT_TableBody.tsx +3 -11
  27. package/src/body/MRT_TableBodyCell.tsx +102 -51
  28. package/src/body/MRT_TableBodyRow.tsx +21 -30
  29. package/src/buttons/MRT_ColumnPinningButtons.tsx +57 -0
  30. package/src/buttons/MRT_CopyButton.tsx +3 -2
  31. package/src/buttons/MRT_EditActionButtons.tsx +1 -2
  32. package/src/buttons/MRT_ExpandAllButton.tsx +1 -2
  33. package/src/enums.ts +3 -3
  34. package/src/filtersFNs.ts +71 -81
  35. package/src/footer/MRT_TableFooter.tsx +6 -16
  36. package/src/footer/MRT_TableFooterCell.tsx +5 -7
  37. package/src/footer/MRT_TableFooterRow.tsx +5 -8
  38. package/src/head/MRT_TableHead.tsx +5 -16
  39. package/src/head/MRT_TableHeadCell.tsx +101 -44
  40. package/src/head/MRT_TableHeadRow.tsx +8 -15
  41. package/src/inputs/MRT_EditCellTextField.tsx +2 -2
  42. package/src/inputs/MRT_FilterRangeFields.tsx +41 -0
  43. package/src/inputs/MRT_FilterTextField.tsx +84 -52
  44. package/src/inputs/MRT_SearchTextField.tsx +2 -2
  45. package/src/inputs/MRT_SelectCheckbox.tsx +16 -17
  46. package/src/localization.ts +15 -5
  47. package/src/menus/MRT_ColumnActionMenu.tsx +9 -8
  48. package/src/menus/{MRT_FilterTypeMenu.tsx → MRT_FilterOptionMenu.tsx} +54 -49
  49. package/src/menus/MRT_ShowHideColumnsMenu.tsx +25 -11
  50. package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +15 -5
  51. package/src/table/MRT_Table.tsx +8 -19
  52. package/src/table/MRT_TableContainer.tsx +8 -69
  53. package/src/table/MRT_TableRoot.tsx +70 -70
  54. package/src/toolbar/MRT_LinearProgressBar.tsx +5 -2
  55. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +3 -2
  56. package/src/toolbar/MRT_ToolbarTop.tsx +4 -6
  57. package/src/utils.ts +10 -10
@@ -17,9 +17,7 @@ export const MRT_SelectCheckbox: FC<Props> = ({
17
17
  getRowModel,
18
18
  getSelectedRowModel,
19
19
  getState,
20
- getToggleAllRowsSelectedProps,
21
20
  options: {
22
- isLoading,
23
21
  localization,
24
22
  muiSelectCheckboxProps,
25
23
  onSelectChange,
@@ -27,18 +25,18 @@ export const MRT_SelectCheckbox: FC<Props> = ({
27
25
  },
28
26
  } = tableInstance;
29
27
 
30
- const { isDensePadding } = getState();
28
+ const { isDensePadding, isLoading } = getState();
31
29
 
32
30
  const handleSelectChange = (event: ChangeEvent<HTMLInputElement>) => {
33
31
  if (selectAll) {
34
- getToggleAllRowsSelectedProps?.()?.onChange?.(event as any);
32
+ tableInstance.getToggleAllRowsSelectedHandler()(event as any);
35
33
  onSelectAllChange?.({
36
34
  event,
37
35
  selectedRows: event.target.checked ? getRowModel().flatRows : [],
38
36
  tableInstance,
39
37
  });
40
38
  } else if (row) {
41
- row?.getToggleSelectedProps()?.onChange?.(event as any);
39
+ row?.getToggleSelectedHandler()(event as any);
42
40
  onSelectChange?.({
43
41
  event,
44
42
  row,
@@ -52,20 +50,11 @@ export const MRT_SelectCheckbox: FC<Props> = ({
52
50
  }
53
51
  };
54
52
 
55
- const mTableBodyRowSelectCheckboxProps =
53
+ const checkboxProps =
56
54
  muiSelectCheckboxProps instanceof Function
57
55
  ? muiSelectCheckboxProps({ isSelectAll: !!selectAll, row, tableInstance })
58
56
  : muiSelectCheckboxProps;
59
57
 
60
- const rtSelectCheckboxProps = selectAll
61
- ? getToggleAllRowsSelectedProps()
62
- : row?.getToggleSelectedProps();
63
-
64
- const checkboxProps = {
65
- ...rtSelectCheckboxProps,
66
- ...mTableBodyRowSelectCheckboxProps,
67
- };
68
-
69
58
  return (
70
59
  <Tooltip
71
60
  arrow
@@ -76,20 +65,30 @@ export const MRT_SelectCheckbox: FC<Props> = ({
76
65
  }
77
66
  >
78
67
  <Checkbox
68
+ checked={
69
+ selectAll
70
+ ? tableInstance.getIsAllRowsSelected()
71
+ : row?.getIsSelected()
72
+ }
79
73
  disabled={isLoading}
74
+ indeterminate={
75
+ selectAll
76
+ ? tableInstance.getIsSomeRowsSelected()
77
+ : row?.getIsSomeSelected()
78
+ }
80
79
  inputProps={{
81
80
  'aria-label': selectAll
82
81
  ? localization.toggleSelectAll
83
82
  : localization.toggleSelectRow,
84
83
  }}
84
+ onChange={handleSelectChange}
85
85
  size={isDensePadding ? 'small' : 'medium'}
86
86
  {...checkboxProps}
87
87
  sx={{
88
88
  height: isDensePadding ? '1.75rem' : '2.25rem',
89
89
  width: isDensePadding ? '1.75rem' : '2.25rem',
90
+ ...checkboxProps?.sx,
90
91
  }}
91
- onChange={handleSelectChange}
92
- title={undefined}
93
92
  />
94
93
  </Tooltip>
95
94
  );
@@ -1,5 +1,6 @@
1
1
  export interface MRT_Localization {
2
2
  actions: string;
3
+ and: string;
3
4
  cancel: string;
4
5
  changeFilterMode: string;
5
6
  changeSearchMode: string;
@@ -12,13 +13,13 @@ export interface MRT_Localization {
12
13
  edit: string;
13
14
  expand: string;
14
15
  expandAll: string;
15
- filterBestMatch: string;
16
- filterBestMatchFirst: string;
16
+ filterBetween: string;
17
17
  filterByColumn: string;
18
18
  filterContains: string;
19
19
  filterEmpty: string;
20
20
  filterEndsWith: string;
21
21
  filterEquals: string;
22
+ filterFuzzy: string;
22
23
  filterGreaterThan: string;
23
24
  filterLessThan: string;
24
25
  filterMode: string;
@@ -30,6 +31,8 @@ export interface MRT_Localization {
30
31
  groupedBy: string;
31
32
  hideAll: string;
32
33
  hideColumn: string;
34
+ max: string;
35
+ min: string;
33
36
  pinToLeft: string;
34
37
  pinToRight: string;
35
38
  resetColumnSize: string;
@@ -50,17 +53,20 @@ export interface MRT_Localization {
50
53
  sortedByColumnAsc: string;
51
54
  sortedByColumnDesc: string;
52
55
  thenBy: string;
56
+ to: string;
53
57
  toggleDensePadding: string;
54
58
  toggleFullScreen: string;
55
59
  toggleSelectAll: string;
56
60
  toggleSelectRow: string;
57
61
  ungroupByColumn: string;
58
62
  unpin: string;
63
+ unpinAll: string;
59
64
  unsorted: string;
60
65
  }
61
66
 
62
67
  export const MRT_DefaultLocalization_EN: MRT_Localization = {
63
68
  actions: 'Actions',
69
+ and: 'and',
64
70
  cancel: 'Cancel',
65
71
  changeFilterMode: 'Change filter mode',
66
72
  changeSearchMode: 'Change search mode',
@@ -73,24 +79,26 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
73
79
  edit: 'Edit',
74
80
  expand: 'Expand',
75
81
  expandAll: 'Expand all',
76
- filterBestMatch: 'Best Match',
77
- filterBestMatchFirst: 'Best Match First',
82
+ filterBetween: 'Between',
78
83
  filterByColumn: 'Filter by {column}',
79
84
  filterContains: 'Contains',
80
85
  filterEmpty: 'Empty',
81
86
  filterEndsWith: 'Ends With',
82
87
  filterEquals: 'Equals',
88
+ filterFuzzy: 'Fuzzy',
83
89
  filterGreaterThan: 'Greater Than',
84
90
  filterLessThan: 'Less Than',
85
91
  filterMode: 'Filter Mode: {filterType}',
86
92
  filterNotEmpty: 'Not Empty',
87
93
  filterNotEquals: 'Not Equals',
88
94
  filterStartsWith: 'Starts With',
89
- filteringByColumn: 'Filtering by {column} - {filterType} "{filterValue}"',
95
+ filteringByColumn: 'Filtering by {column} - {filterType} {filterValue}',
90
96
  groupByColumn: 'Group by {column}',
91
97
  groupedBy: 'Grouped by ',
92
98
  hideAll: 'Hide all',
93
99
  hideColumn: 'Hide {column} column',
100
+ max: 'Max',
101
+ min: 'Min',
94
102
  pinToLeft: 'Pin to left',
95
103
  pinToRight: 'Pin to right',
96
104
  resetColumnSize: 'Reset column size',
@@ -112,11 +120,13 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
112
120
  sortedByColumnAsc: 'Sorted by {column} ascending',
113
121
  sortedByColumnDesc: 'Sorted by {column} descending',
114
122
  thenBy: ', then by ',
123
+ to: 'to',
115
124
  toggleDensePadding: 'Toggle dense padding',
116
125
  toggleFullScreen: 'Toggle full screen',
117
126
  toggleSelectAll: 'Toggle select all',
118
127
  toggleSelectRow: 'Toggle select row',
119
128
  ungroupByColumn: 'Ungroup by {column}',
120
129
  unpin: 'Unpin',
130
+ unpinAll: 'Unpin all',
121
131
  unsorted: 'Unsorted',
122
132
  };
@@ -1,7 +1,7 @@
1
1
  import React, { FC, useState } from 'react';
2
2
  import { Box, IconButton, ListItemIcon, Menu, MenuItem } from '@mui/material';
3
3
  import type { MRT_Header, MRT_TableInstance } from '..';
4
- import { MRT_FilterTypeMenu } from './MRT_FilterTypeMenu';
4
+ import { MRT_FilterOptionMenu } from './MRT_FilterOptionMenu';
5
5
  import { MRT_ShowHideColumnsMenu } from './MRT_ShowHideColumnsMenu';
6
6
 
7
7
  export const commonMenuItemStyles = {
@@ -69,7 +69,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
69
69
  useState<null | HTMLElement>(null);
70
70
 
71
71
  const handleClearSort = () => {
72
- column.resetSorting();
72
+ column.clearSorting();
73
73
  setAnchorEl(null);
74
74
  };
75
75
 
@@ -95,6 +95,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
95
95
 
96
96
  const handlePinColumn = (pinDirection: 'left' | 'right' | false) => {
97
97
  column.pin(pinDirection);
98
+ setAnchorEl(null);
98
99
  };
99
100
 
100
101
  const handleGroupByColumn = () => {
@@ -104,7 +105,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
104
105
  };
105
106
 
106
107
  const handleClearFilter = () => {
107
- column.setColumnFilterValue('');
108
+ column.setFilterValue('');
108
109
  setAnchorEl(null);
109
110
  };
110
111
 
@@ -200,9 +201,9 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
200
201
  </MenuItem>,
201
202
  ]}
202
203
  {enableColumnFilters &&
203
- column.getCanColumnFilter() && [
204
+ column.getCanFilter() && [
204
205
  <MenuItem
205
- disabled={!column.getColumnFilterValue()}
206
+ disabled={!column.getFilterValue()}
206
207
  key={0}
207
208
  onClick={handleClearFilter}
208
209
  sx={commonMenuItemStyles}
@@ -240,7 +241,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
240
241
  </IconButton>
241
242
  )}
242
243
  </MenuItem>,
243
- <MRT_FilterTypeMenu
244
+ <MRT_FilterOptionMenu
244
245
  anchorEl={filterMenuAnchorEl}
245
246
  header={header}
246
247
  key={2}
@@ -284,7 +285,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
284
285
  </MenuItem>,
285
286
  <MenuItem
286
287
  disabled={column.getIsPinned() === 'right' || !column.getCanPin()}
287
- key={0}
288
+ key={1}
288
289
  onClick={() => handlePinColumn('right')}
289
290
  sx={commonMenuItemStyles}
290
291
  >
@@ -298,7 +299,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
298
299
  <MenuItem
299
300
  disabled={!column.getIsPinned()}
300
301
  divider={enableHiding}
301
- key={0}
302
+ key={2}
302
303
  onClick={() => handlePinColumn(false)}
303
304
  sx={commonMenuItemStyles}
304
305
  >
@@ -1,14 +1,14 @@
1
1
  import React, { FC, useMemo } from 'react';
2
2
  import { Menu, MenuItem } from '@mui/material';
3
- import type { MRT_FilterType, MRT_Header, MRT_TableInstance } from '..';
4
- import { MRT_FILTER_TYPE } from '../enums';
3
+ import type { MRT_FilterFn, MRT_Header, MRT_TableInstance } from '..';
4
+ import { MRT_FILTER_OPTION } from '../enums';
5
5
  import {
6
- bestMatch,
7
- bestMatchFirst,
6
+ between,
8
7
  contains,
9
8
  empty,
10
9
  endsWith,
11
10
  equals,
11
+ fuzzy,
12
12
  greaterThan,
13
13
  lessThan,
14
14
  notEmpty,
@@ -30,7 +30,7 @@ interface Props {
30
30
  tableInstance: MRT_TableInstance;
31
31
  }
32
32
 
33
- export const MRT_FilterTypeMenu: FC<Props> = ({
33
+ export const MRT_FilterOptionMenu: FC<Props> = ({
34
34
  anchorEl,
35
35
  header,
36
36
  onSelect,
@@ -39,16 +39,16 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
39
39
  }) => {
40
40
  const {
41
41
  getState,
42
- options: { enabledGlobalFilterTypes, localization },
43
- setCurrentFilterTypes,
44
- setCurrentGlobalFilterType,
42
+ options: { enabledGlobalFilterOptions, localization },
43
+ setCurrentFilterFns,
44
+ setCurrentGlobalFilterFn,
45
45
  } = tableInstance;
46
46
 
47
- const { isDensePadding, currentFilterTypes, currentGlobalFilterType } =
47
+ const { isDensePadding, currentFilterFns, currentGlobalFilterFn } =
48
48
  getState();
49
49
 
50
- const filterTypes: {
51
- type: MRT_FILTER_TYPE;
50
+ const filterOptions: {
51
+ option: MRT_FILTER_OPTION;
52
52
  label: string;
53
53
  divider: boolean;
54
54
  fn: Function;
@@ -56,104 +56,109 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
56
56
  () =>
57
57
  [
58
58
  {
59
- type: MRT_FILTER_TYPE.BEST_MATCH_FIRST,
60
- label: localization.filterBestMatchFirst,
59
+ option: MRT_FILTER_OPTION.FUZZY,
60
+ label: localization.filterFuzzy,
61
61
  divider: false,
62
- fn: bestMatchFirst,
62
+ fn: fuzzy,
63
63
  },
64
64
  {
65
- type: MRT_FILTER_TYPE.BEST_MATCH,
66
- label: localization.filterBestMatch,
67
- divider: !!header,
68
- fn: bestMatch,
69
- },
70
- {
71
- type: MRT_FILTER_TYPE.CONTAINS,
65
+ option: MRT_FILTER_OPTION.CONTAINS,
72
66
  label: localization.filterContains,
73
67
  divider: false,
74
68
  fn: contains,
75
69
  },
76
70
  {
77
- type: MRT_FILTER_TYPE.STARTS_WITH,
71
+ option: MRT_FILTER_OPTION.STARTS_WITH,
78
72
  label: localization.filterStartsWith,
79
73
  divider: false,
80
74
  fn: startsWith,
81
75
  },
82
76
  {
83
- type: MRT_FILTER_TYPE.ENDS_WITH,
77
+ option: MRT_FILTER_OPTION.ENDS_WITH,
84
78
  label: localization.filterEndsWith,
85
79
  divider: true,
86
80
  fn: endsWith,
87
81
  },
88
82
  {
89
- type: MRT_FILTER_TYPE.EQUALS,
83
+ option: MRT_FILTER_OPTION.EQUALS,
90
84
  label: localization.filterEquals,
91
85
  divider: false,
92
86
  fn: equals,
93
87
  },
94
88
  {
95
- type: MRT_FILTER_TYPE.NOT_EQUALS,
89
+ option: MRT_FILTER_OPTION.NOT_EQUALS,
96
90
  label: localization.filterNotEquals,
97
91
  divider: true,
98
92
  fn: notEquals,
99
93
  },
100
94
  {
101
- type: MRT_FILTER_TYPE.GREATER_THAN,
95
+ option: MRT_FILTER_OPTION.BETWEEN,
96
+ label: localization.filterBetween,
97
+ divider: false,
98
+ fn: between,
99
+ },
100
+ {
101
+ option: MRT_FILTER_OPTION.GREATER_THAN,
102
102
  label: localization.filterGreaterThan,
103
103
  divider: false,
104
104
  fn: greaterThan,
105
105
  },
106
106
  {
107
- type: MRT_FILTER_TYPE.LESS_THAN,
107
+ option: MRT_FILTER_OPTION.LESS_THAN,
108
108
  label: localization.filterLessThan,
109
109
  divider: true,
110
110
  fn: lessThan,
111
111
  },
112
112
  {
113
- type: MRT_FILTER_TYPE.EMPTY,
113
+ option: MRT_FILTER_OPTION.EMPTY,
114
114
  label: localization.filterEmpty,
115
115
  divider: false,
116
116
  fn: empty,
117
117
  },
118
118
  {
119
- type: MRT_FILTER_TYPE.NOT_EMPTY,
119
+ option: MRT_FILTER_OPTION.NOT_EMPTY,
120
120
  label: localization.filterNotEmpty,
121
121
  divider: false,
122
122
  fn: notEmpty,
123
123
  },
124
124
  ].filter((filterType) =>
125
125
  header
126
- ? !header.column.enabledColumnFilterTypes ||
127
- header.column.enabledColumnFilterTypes.includes(filterType.type)
128
- : (!enabledGlobalFilterTypes ||
129
- enabledGlobalFilterTypes.includes(filterType.type)) &&
130
- [
131
- MRT_FILTER_TYPE.BEST_MATCH_FIRST,
132
- MRT_FILTER_TYPE.BEST_MATCH,
133
- ].includes(filterType.type),
126
+ ? !header.column.enabledColumnFilterOptions ||
127
+ header.column.enabledColumnFilterOptions.includes(filterType.option)
128
+ : (!enabledGlobalFilterOptions ||
129
+ enabledGlobalFilterOptions.includes(filterType.option)) &&
130
+ [MRT_FILTER_OPTION.FUZZY, MRT_FILTER_OPTION.CONTAINS].includes(
131
+ filterType.option,
132
+ ),
134
133
  ),
135
134
  [],
136
135
  );
137
136
 
138
- const handleSelectFilterType = (value: MRT_FILTER_TYPE) => {
137
+ const handleSelectFilterType = (value: MRT_FILTER_OPTION) => {
139
138
  if (header) {
140
- setCurrentFilterTypes((prev: { [key: string]: MRT_FilterType }) => ({
139
+ setCurrentFilterFns((prev: { [key: string]: MRT_FilterFn }) => ({
141
140
  ...prev,
142
141
  [header.id]: value,
143
142
  }));
144
- if ([MRT_FILTER_TYPE.EMPTY, MRT_FILTER_TYPE.NOT_EMPTY].includes(value)) {
145
- header.column.setColumnFilterValue(' ');
143
+ if (
144
+ [MRT_FILTER_OPTION.EMPTY, MRT_FILTER_OPTION.NOT_EMPTY].includes(value)
145
+ ) {
146
+ header.column.setFilterValue(' ');
147
+ } else if (value === MRT_FILTER_OPTION.BETWEEN) {
148
+ header.column.setFilterValue(['', '']);
149
+ } else {
150
+ header.column.setFilterValue('');
146
151
  }
147
152
  } else {
148
- setCurrentGlobalFilterType(value);
153
+ setCurrentGlobalFilterFn(value);
149
154
  }
150
155
  setAnchorEl(null);
151
156
  onSelect?.();
152
157
  };
153
158
 
154
- const filterType = !!header
155
- ? currentFilterTypes[header.id]
156
- : currentGlobalFilterType;
159
+ const filterOption = !!header
160
+ ? currentFilterFns[header.id]
161
+ : currentGlobalFilterFn;
157
162
 
158
163
  return (
159
164
  <Menu
@@ -165,14 +170,14 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
165
170
  dense: isDensePadding,
166
171
  }}
167
172
  >
168
- {filterTypes.map(({ type, label, divider, fn }, index) => (
173
+ {filterOptions.map(({ option, label, divider, fn }, index) => (
169
174
  <MenuItem
170
175
  divider={divider}
171
176
  key={index}
172
- onClick={() => handleSelectFilterType(type)}
173
- selected={type === filterType || fn === filterType}
177
+ onClick={() => handleSelectFilterType(option)}
178
+ selected={option === filterOption || fn === filterOption}
174
179
  sx={commonMenuItemStyles}
175
- value={type}
180
+ value={option}
176
181
  >
177
182
  {label}
178
183
  </MenuItem>
@@ -1,7 +1,7 @@
1
1
  import React, { FC, useMemo } from 'react';
2
2
  import { Button, Menu, Divider, Box } from '@mui/material';
3
3
  import { MRT_ShowHideColumnsMenuItems } from './MRT_ShowHideColumnsMenuItems';
4
- import { MRT_TableInstance } from '..';
4
+ import { MRT_Column, MRT_TableInstance } from '..';
5
5
 
6
6
  interface Props {
7
7
  anchorEl: HTMLElement | null;
@@ -24,7 +24,7 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
24
24
  getState,
25
25
  toggleAllColumnsVisible,
26
26
  getAllLeafColumns,
27
- options: { localization },
27
+ options: { localization, enablePinning },
28
28
  } = tableInstance;
29
29
 
30
30
  const { isDensePadding } = getState();
@@ -40,14 +40,16 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
40
40
  [getAllColumns()],
41
41
  );
42
42
 
43
- const allDataColumns = useMemo(() => {
43
+ const allDataColumns: (MRT_Column | null)[] = useMemo(() => {
44
44
  const dataColumns = getAllColumns().filter(
45
45
  (col) => col.columnDefType !== 'display',
46
46
  );
47
47
  return getIsSomeColumnsPinned()
48
48
  ? [
49
49
  ...dataColumns.filter((c) => c.getIsPinned() === 'left'),
50
+ null,
50
51
  ...dataColumns.filter((c) => c.getIsPinned() === false),
52
+ null,
51
53
  ...dataColumns.filter((c) => c.getIsPinned() === 'right'),
52
54
  ]
53
55
  : dataColumns;
@@ -78,6 +80,14 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
78
80
  {localization.hideAll}
79
81
  </Button>
80
82
  )}
83
+ {!isSubMenu && enablePinning && (
84
+ <Button
85
+ disabled={!getIsSomeColumnsPinned()}
86
+ onClick={() => tableInstance.resetColumnPinning(true)}
87
+ >
88
+ {localization.unpinAll}
89
+ </Button>
90
+ )}
81
91
  <Button
82
92
  disabled={getIsAllColumnsVisible()}
83
93
  onClick={() => toggleAllColumnsVisible(true)}
@@ -95,14 +105,18 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
95
105
  />
96
106
  ))}
97
107
  <Divider />
98
- {allDataColumns.map((column, index) => (
99
- <MRT_ShowHideColumnsMenuItems
100
- column={column}
101
- isSubMenu={isSubMenu}
102
- key={`${index}-${column.id}`}
103
- tableInstance={tableInstance}
104
- />
105
- ))}
108
+ {allDataColumns.map((column, index) =>
109
+ column ? (
110
+ <MRT_ShowHideColumnsMenuItems
111
+ column={column}
112
+ isSubMenu={isSubMenu}
113
+ key={`${index}-${column.id}`}
114
+ tableInstance={tableInstance}
115
+ />
116
+ ) : (
117
+ <Divider key={`${index}-divider`} />
118
+ ),
119
+ )}
106
120
  </Menu>
107
121
  );
108
122
  };
@@ -1,7 +1,7 @@
1
1
  import React, { FC } from 'react';
2
2
  import { FormControlLabel, MenuItem, Switch } from '@mui/material';
3
3
  import type { MRT_Column, MRT_TableInstance } from '..';
4
- import { commonMenuItemStyles } from './MRT_ColumnActionMenu';
4
+ import { MRT_ColumnPinningButtons } from '../buttons/MRT_ColumnPinningButtons';
5
5
 
6
6
  interface Props {
7
7
  column: MRT_Column;
@@ -44,15 +44,25 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
44
44
  return (
45
45
  <>
46
46
  <MenuItem
47
- sx={{ ...commonMenuItemStyles, pl: `${(column.depth + 0.5) * 2}rem` }}
47
+ sx={{
48
+ alignItems: 'center',
49
+ justifyContent: 'flex-start',
50
+ my: 0,
51
+ pl: `${(column.depth + 0.5) * 2}rem`,
52
+ py: '6px',
53
+ }}
48
54
  >
55
+ {!isSubMenu && column.getCanPin() && (
56
+ <MRT_ColumnPinningButtons
57
+ column={column}
58
+ tableInstance={tableInstance}
59
+ />
60
+ )}
49
61
  <FormControlLabel
50
62
  componentsProps={{ typography: { sx: { marginBottom: 0 } } }}
51
63
  checked={switchChecked}
52
64
  control={<Switch />}
53
- disabled={
54
- (isSubMenu && switchChecked) || column.enableHiding === false
55
- }
65
+ disabled={(isSubMenu && switchChecked) || !column.getCanHide()}
56
66
  label={column.header}
57
67
  onChange={() => handleToggleColumnHidden(column)}
58
68
  />
@@ -6,40 +6,29 @@ import { MRT_TableFooter } from '../footer/MRT_TableFooter';
6
6
  import { MRT_TableInstance } from '..';
7
7
 
8
8
  interface Props {
9
- pinned: 'left' | 'center' | 'right' | 'none';
10
9
  tableInstance: MRT_TableInstance;
11
10
  }
12
11
 
13
- export const MRT_Table: FC<Props> = ({ pinned, tableInstance }) => {
12
+ export const MRT_Table: FC<Props> = ({ tableInstance }) => {
14
13
  const {
15
- getTableProps,
16
14
  options: {
17
- muiTableProps,
18
- enableTableHead,
19
- enableTableFooter,
20
15
  enableStickyHeader,
16
+ enableTableFooter,
17
+ enableTableHead,
18
+ muiTableProps,
21
19
  },
22
20
  } = tableInstance;
23
21
 
24
- const mTableProps =
22
+ const tableProps =
25
23
  muiTableProps instanceof Function
26
24
  ? muiTableProps({ tableInstance })
27
25
  : muiTableProps;
28
26
 
29
- const tableProps = {
30
- ...getTableProps(),
31
- ...mTableProps,
32
- };
33
-
34
27
  return (
35
28
  <Table stickyHeader={enableStickyHeader} {...tableProps}>
36
- {enableTableHead && (
37
- <MRT_TableHead pinned={pinned} tableInstance={tableInstance} />
38
- )}
39
- <MRT_TableBody pinned={pinned} tableInstance={tableInstance} />
40
- {enableTableFooter && (
41
- <MRT_TableFooter pinned={pinned} tableInstance={tableInstance} />
42
- )}
29
+ {enableTableHead && <MRT_TableHead tableInstance={tableInstance} />}
30
+ <MRT_TableBody tableInstance={tableInstance} />
31
+ {enableTableFooter && <MRT_TableFooter tableInstance={tableInstance} />}
43
32
  </Table>
44
33
  );
45
34
  };