material-react-table 0.6.6 → 0.6.9

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/utils.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { MRT_ColumnInterface } from '.';
2
- export declare const findLowestLevelCols: (columns: MRT_ColumnInterface[]) => MRT_ColumnInterface<{}>[];
1
+ import { MRT_ColumnInstance, MRT_ColumnInterface } from '.';
2
+ export declare const findLowestLevelCols: (columns: MRT_ColumnInterface[] | MRT_ColumnInstance[]) => MRT_ColumnInterface<{}>[];
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.6.6",
2
+ "version": "0.6.9",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
5
  "description": "A fully featured Material-UI implementation of react-table, inspired by material-table and the mui DataGrid, written from the ground up in TypeScript.",
@@ -59,7 +59,7 @@
59
59
  "@emotion/react": "^11.8.2",
60
60
  "@emotion/styled": "^11.8.1",
61
61
  "@etchteam/storybook-addon-status": "^4.2.0",
62
- "@faker-js/faker": "^6.0.0-beta.0",
62
+ "@faker-js/faker": "^6.0.0",
63
63
  "@mui/icons-material": "^5.5.1",
64
64
  "@mui/material": "^5.5.1",
65
65
  "@size-limit/preset-small-lib": "^7.0.8",
@@ -75,10 +75,10 @@
75
75
  "@types/faker": "^6.6.8",
76
76
  "@types/react": "^17.0.40",
77
77
  "@types/react-dom": "^17.0.13",
78
- "@types/react-table": "^7.7.9",
78
+ "@types/react-table": "^7.7.10",
79
79
  "babel-loader": "^8.2.3",
80
80
  "husky": "^7.0.4",
81
- "prettier": "^2.5.1",
81
+ "prettier": "^2.6.0",
82
82
  "react": "^17.0.2",
83
83
  "react-dom": "^17.0.2",
84
84
  "react-is": "^17.0.2",
@@ -1,6 +1,7 @@
1
1
  import React, { ChangeEvent, FC, MouseEvent, ReactNode } from 'react';
2
2
  import {
3
3
  AlertProps,
4
+ CheckboxProps,
4
5
  IconButtonProps,
5
6
  LinearProgressProps,
6
7
  SkeletonProps,
@@ -134,9 +135,11 @@ export type MRT_ColumnInterface<D extends {} = {}> = ColumnInterface<D> &
134
135
  Header?: string;
135
136
  accessor?: string;
136
137
  columns?: MRT_ColumnInterface<D>[];
138
+ disableClickToCopy?: boolean;
139
+ disableColumnActions?: boolean;
140
+ disableColumnHiding?: boolean;
137
141
  disableEditing?: boolean;
138
142
  disableFilters?: boolean;
139
- disableCellCopyButton?: boolean;
140
143
  filter?: MRT_FilterType | string | FilterType<D>;
141
144
  filterSelectOptions?: (string | { text: string; value: string })[];
142
145
  filterTypes?: (MRT_FILTER_TYPE | string)[];
@@ -152,6 +155,9 @@ export type MRT_ColumnInterface<D extends {} = {}> = ColumnInterface<D> &
152
155
  muiTableHeadCellFilterTextFieldProps?:
153
156
  | TextFieldProps
154
157
  | ((column: Column<D>) => TextFieldProps);
158
+ muiTableHeadCellColumnActionsButtonProps?:
159
+ | IconButtonProps
160
+ | ((column: Column<D>) => IconButtonProps);
155
161
  muiTableHeadCellProps?:
156
162
  | TableCellProps
157
163
  | ((column: Column<D>) => TableCellProps);
@@ -233,7 +239,7 @@ export type MaterialReactTableProps<D extends {} = {}> = UseTableOptions<D> &
233
239
  disableFullScreenToggle?: boolean;
234
240
  disableSelectAll?: boolean;
235
241
  disableSubRowTree?: boolean;
236
- enableCellCopyButtons?: boolean;
242
+ enableClickToCopy?: boolean;
237
243
  enableColumnGrouping?: boolean;
238
244
  enableColumnResizing?: boolean;
239
245
  enableRowActions?: boolean;
@@ -255,6 +261,13 @@ export type MaterialReactTableProps<D extends {} = {}> = UseTableOptions<D> &
255
261
  | LinearProgressProps
256
262
  | ((tableInstance: MRT_TableInstance) => LinearProgressProps);
257
263
  muiSearchTextFieldProps?: TextFieldProps;
264
+ muiSelectCheckboxProps?:
265
+ | CheckboxProps
266
+ | ((
267
+ isSelectAll?: boolean,
268
+ row?: MRT_Row<D>,
269
+ tableInstance?: MRT_TableInstance<D>,
270
+ ) => CheckboxProps);
258
271
  muiTableBodyCellEditTextFieldProps?:
259
272
  | TextFieldProps
260
273
  | ((cell?: MRT_Cell<D>) => TextFieldProps);
@@ -283,6 +296,9 @@ export type MaterialReactTableProps<D extends {} = {}> = UseTableOptions<D> &
283
296
  muiTableFooterRowProps?:
284
297
  | TableRowProps
285
298
  | ((footerGroup: MRT_HeaderGroup<D>) => TableRowProps);
299
+ muiTableHeadCellColumnActionsButtonProps?:
300
+ | IconButtonProps
301
+ | ((column: Column<D>) => IconButtonProps);
286
302
  muiTableHeadCellFilterTextFieldProps?:
287
303
  | TextFieldProps
288
304
  | ((column: Column<D>) => TextFieldProps);
@@ -328,7 +344,7 @@ export type MaterialReactTableProps<D extends {} = {}> = UseTableOptions<D> &
328
344
  event: MouseEvent<HTMLButtonElement>,
329
345
  row: Row<D>,
330
346
  ) => void;
331
- onRowSelectChange?: (
347
+ onSelectChange?: (
332
348
  event: ChangeEvent,
333
349
  row: Row<D>,
334
350
  selectedRows: Row<D>[],
@@ -1,5 +1,5 @@
1
1
  import React, { FC, MouseEvent } from 'react';
2
- import { Box, Skeleton, TableCell, TableCellProps } from '@mui/material';
2
+ import { Skeleton, TableCell, TableCellProps } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
4
  import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
5
5
  import type { MRT_Cell } from '..';
@@ -23,7 +23,7 @@ interface Props {
23
23
 
24
24
  export const MRT_TableBodyCell: FC<Props> = ({ cell }) => {
25
25
  const {
26
- enableCellCopyButtons,
26
+ enableClickToCopy,
27
27
  isLoading,
28
28
  muiTableBodyCellProps,
29
29
  muiTableBodyCellSkeletonProps,
@@ -83,11 +83,8 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell }) => {
83
83
  <span>
84
84
  {cell.render('Cell')} ({cell.row.subRows.length})
85
85
  </span>
86
- ) : enableCellCopyButtons && !cell.column.disableCellCopyButton ? (
87
- <Box sx={{ whiteSpace: 'nowrap' }}>
88
- {cell.render('Cell')}
89
- {<MRT_CopyButton cell={cell} />}
90
- </Box>
86
+ ) : enableClickToCopy && !cell.column.disableClickToCopy ? (
87
+ <MRT_CopyButton cell={cell} />
91
88
  ) : (
92
89
  cell.render('Cell')
93
90
  )}
@@ -1,6 +1,7 @@
1
1
  import React, { FC, MouseEvent } from 'react';
2
2
  import { TableCell, TableRow } from '@mui/material';
3
3
  import {
4
+ commonTableBodyButtonCellStyles,
4
5
  commonTableBodyCellStyles,
5
6
  MRT_TableBodyCell,
6
7
  } from './MRT_TableBodyCell';
@@ -26,6 +27,7 @@ export const MRT_TableBodyRow: FC<Props> = ({ row }) => {
26
27
  onRowClick,
27
28
  positionActionsColumn,
28
29
  renderDetailPanel,
30
+ tableInstance,
29
31
  tableInstance: {
30
32
  state: { densePadding },
31
33
  },
@@ -67,7 +69,19 @@ export const MRT_TableBodyRow: FC<Props> = ({ row }) => {
67
69
  {(anyRowsCanExpand || renderDetailPanel) && (
68
70
  <MRT_ExpandButton row={row} />
69
71
  )}
70
- {enableSelection && <MRT_SelectCheckbox row={row} />}
72
+ {enableSelection && (
73
+ <TableCell
74
+ sx={{
75
+ ...commonTableBodyButtonCellStyles(
76
+ tableInstance.state.densePadding,
77
+ ),
78
+ maxWidth: '3rem',
79
+ width: '3rem',
80
+ }}
81
+ >
82
+ <MRT_SelectCheckbox row={row} />
83
+ </TableCell>
84
+ )}
71
85
  {row.cells.map((cell: MRT_Cell) => (
72
86
  <MRT_TableBodyCell key={cell.getCellProps().key} cell={cell} />
73
87
  ))}
@@ -1,5 +1,5 @@
1
1
  import React, { FC, useState } from 'react';
2
- import { IconButton, Tooltip } from '@mui/material';
2
+ import { Button, Tooltip } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
4
  import { MRT_Cell } from '..';
5
5
 
@@ -8,43 +8,43 @@ interface Props {
8
8
  }
9
9
 
10
10
  export const MRT_CopyButton: FC<Props> = ({ cell }) => {
11
- const {
12
- icons: { CheckBoxIcon, ContentCopyIcon },
13
- localization,
14
- } = useMRT();
11
+ const { localization } = useMRT();
15
12
 
16
13
  const [copied, setCopied] = useState(false);
17
14
 
18
15
  const handleCopy = (text: string) => {
19
16
  navigator.clipboard.writeText(text);
20
17
  setCopied(true);
21
- setTimeout(() => setCopied(false), 2000);
18
+ setTimeout(() => setCopied(false), 4000);
22
19
  };
23
20
 
24
21
  return (
25
22
  <Tooltip
26
23
  arrow
24
+ enterDelay={1000}
25
+ enterNextDelay={1000}
26
+ placement="top"
27
27
  title={copied ? localization.copiedToClipboard : localization.clickToCopy}
28
28
  >
29
- <IconButton
29
+ <Button
30
30
  aria-label={localization.clickToCopy}
31
31
  onClick={() => handleCopy(cell.value)}
32
32
  size="small"
33
33
  sx={{
34
- opacity: 0.05,
35
- m: '0 0.5rem',
36
- transition: 'all 0.2s ease-in-out',
37
- '&:hover': {
38
- opacity: 1,
39
- },
34
+ backgroundColor: 'transparent',
35
+ color: 'inherit',
36
+ letterSpacing: 'inherit',
37
+ fontFamily: 'inherit',
38
+ fontSize: 'inherit',
39
+ m: '-0.25rem',
40
+ textTransform: 'inherit',
41
+ textAlign: 'inherit',
42
+ minWidth: 'unset',
40
43
  }}
44
+ variant="text"
41
45
  >
42
- {copied ? (
43
- <CheckBoxIcon color="success" fontSize="small" />
44
- ) : (
45
- <ContentCopyIcon fontSize="small" />
46
- )}
47
- </IconButton>
46
+ {cell.render('Cell')}
47
+ </Button>
48
48
  </Tooltip>
49
49
  );
50
50
  };
@@ -10,8 +10,9 @@ interface Props {
10
10
 
11
11
  export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({ column }) => {
12
12
  const {
13
- localization,
14
13
  icons: { MoreVertIcon },
14
+ localization,
15
+ muiTableHeadCellColumnActionsButtonProps,
15
16
  } = useMRT();
16
17
 
17
18
  const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
@@ -22,6 +23,21 @@ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({ column }) => {
22
23
  setAnchorEl(event.currentTarget);
23
24
  };
24
25
 
26
+ const mTableHeadCellColumnActionsButtonProps =
27
+ muiTableHeadCellColumnActionsButtonProps instanceof Function
28
+ ? muiTableHeadCellColumnActionsButtonProps(column)
29
+ : muiTableHeadCellColumnActionsButtonProps;
30
+
31
+ const mcTableHeadCellColumnActionsButtonProps =
32
+ column.muiTableHeadCellColumnActionsButtonProps instanceof Function
33
+ ? column.muiTableHeadCellColumnActionsButtonProps(column)
34
+ : column.muiTableHeadCellColumnActionsButtonProps;
35
+
36
+ const iconButtonProps = {
37
+ ...mTableHeadCellColumnActionsButtonProps,
38
+ ...mcTableHeadCellColumnActionsButtonProps,
39
+ };
40
+
25
41
  return (
26
42
  <>
27
43
  <Tooltip
@@ -35,6 +51,7 @@ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({ column }) => {
35
51
  aria-label={localization.columnActions}
36
52
  onClick={handleClick}
37
53
  size="small"
54
+ {...iconButtonProps}
38
55
  sx={{
39
56
  height: '2rem',
40
57
  mr: '2px',
@@ -45,6 +62,7 @@ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({ column }) => {
45
62
  '&:hover': {
46
63
  opacity: 1,
47
64
  },
65
+ ...iconButtonProps.sx,
48
66
  }}
49
67
  >
50
68
  <MoreVertIcon />
@@ -1,4 +1,4 @@
1
- import React, { FC } from 'react';
1
+ import React, { CSSProperties, FC } from 'react';
2
2
  import {
3
3
  TableCell,
4
4
  TableSortLabel,
@@ -16,6 +16,11 @@ import type { MRT_HeaderGroup } from '..';
16
16
  export const commonTableHeadCellStyles = (
17
17
  densePadding: boolean,
18
18
  enableColumnResizing?: boolean,
19
+ widths?: {
20
+ maxWidth?: CSSProperties['maxWidth'];
21
+ minWidth?: CSSProperties['minWidth'];
22
+ width?: CSSProperties['width'];
23
+ },
19
24
  ) => ({
20
25
  fontWeight: 'bold',
21
26
  height: '100%',
@@ -23,6 +28,7 @@ export const commonTableHeadCellStyles = (
23
28
  pt: densePadding ? '0.75rem' : '1.25rem',
24
29
  transition: `all ${enableColumnResizing ? '10ms' : '0.2s'} ease-in-out`,
25
30
  verticalAlign: 'text-top',
31
+ ...widths,
26
32
  });
27
33
 
28
34
  interface Props {
@@ -105,6 +111,11 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
105
111
  ...commonTableHeadCellStyles(
106
112
  tableInstance.state.densePadding,
107
113
  enableColumnResizing,
114
+ {
115
+ maxWidth: column.maxWidth,
116
+ minWidth: column.minWidth,
117
+ width: column.width,
118
+ },
108
119
  ),
109
120
  ...tableCellProps?.sx,
110
121
  }}
@@ -167,9 +178,11 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
167
178
  )}
168
179
  </Box>
169
180
  <Box sx={{ alignItems: 'center', display: 'flex', flexWrap: 'nowrap' }}>
170
- {!disableColumnActions && !isParentHeader && (
171
- <MRT_ToggleColumnActionMenuButton column={column} />
172
- )}
181
+ {!disableColumnActions &&
182
+ !column.disableColumnActions &&
183
+ !isParentHeader && (
184
+ <MRT_ToggleColumnActionMenuButton column={column} />
185
+ )}
173
186
  {enableColumnResizing && !isParentHeader && (
174
187
  <Divider
175
188
  flexItem
@@ -16,7 +16,12 @@ export const MRT_TableHeadCellActions: FC<Props> = () => {
16
16
  return (
17
17
  <TableCell
18
18
  style={{ textAlign: 'center' }}
19
- sx={{ ...commonTableHeadCellStyles(densePadding), textAlign: 'center' }}
19
+ sx={{
20
+ ...commonTableHeadCellStyles(densePadding),
21
+ textAlign: 'center',
22
+ maxWidth: '4rem',
23
+ width: '4rem',
24
+ }}
20
25
  >
21
26
  {localization.actions}
22
27
  </TableCell>
@@ -4,6 +4,7 @@ import {
4
4
  commonTableHeadCellStyles,
5
5
  MRT_TableHeadCell,
6
6
  } from './MRT_TableHeadCell';
7
+ import { commonTableBodyButtonCellStyles } from '../body/MRT_TableBodyCell';
7
8
  import { useMRT } from '../useMRT';
8
9
  import { MRT_SelectCheckbox } from '../inputs/MRT_SelectCheckbox';
9
10
  import { MRT_ExpandAllButton } from '../buttons/MRT_ExpandAllButton';
@@ -19,6 +20,7 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
19
20
  const {
20
21
  anyRowsCanExpand,
21
22
  disableExpandAll,
23
+ disableSelectAll,
22
24
  enableRowActions,
23
25
  enableRowEditing,
24
26
  enableRowNumbers,
@@ -81,8 +83,18 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
81
83
  )
82
84
  ) : null}
83
85
  {enableSelection ? (
84
- !isParentHeader ? (
85
- <MRT_SelectCheckbox selectAll />
86
+ !isParentHeader && !disableSelectAll ? (
87
+ <TableCell
88
+ sx={{
89
+ ...commonTableBodyButtonCellStyles(
90
+ tableInstance.state.densePadding,
91
+ ),
92
+ maxWidth: '3rem',
93
+ width: '3rem',
94
+ }}
95
+ >
96
+ <MRT_SelectCheckbox selectAll />
97
+ </TableCell>
86
98
  ) : (
87
99
  <MRT_TableSpacerCell width="1rem" />
88
100
  )
@@ -39,12 +39,6 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell }) => {
39
39
  const textFieldProps = {
40
40
  ...mTableBodyCellEditTextFieldProps,
41
41
  ...mcTableBodyCellEditTextFieldProps,
42
- style: {
43
- //@ts-ignore
44
- ...muiTableBodyCellEditTextFieldProps?.style,
45
- //@ts-ignore
46
- ...cell.column.muiTableBodyCellEditTextFieldProps?.style,
47
- },
48
42
  };
49
43
 
50
44
  if (!cell.column.disableEditing && cell.column.Edit) {
@@ -43,10 +43,6 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
43
43
  const textFieldProps = {
44
44
  ...mTableHeadCellFilterTextFieldProps,
45
45
  ...mcTableHeadCellFilterTextFieldProps,
46
- style: {
47
- ...mTableHeadCellFilterTextFieldProps?.style,
48
- ...mcTableHeadCellFilterTextFieldProps?.style,
49
- },
50
46
  } as TextFieldProps;
51
47
 
52
48
  const [filterValue, setFilterValue] = useState('');
@@ -1,8 +1,7 @@
1
1
  import React, { ChangeEvent, FC } from 'react';
2
- import { Checkbox, TableCell, Tooltip } from '@mui/material';
2
+ import { Checkbox, Tooltip } from '@mui/material';
3
3
  import { useMRT } from '../useMRT';
4
4
  import type { MRT_Row } from '..';
5
- import { commonTableBodyButtonCellStyles } from '../body/MRT_TableBodyCell';
6
5
 
7
6
  interface Props {
8
7
  row?: MRT_Row;
@@ -10,48 +9,76 @@ interface Props {
10
9
  }
11
10
 
12
11
  export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll }) => {
13
- const { localization, onRowSelectChange, onSelectAllChange, tableInstance } =
14
- useMRT();
12
+ const {
13
+ localization,
14
+ muiSelectCheckboxProps,
15
+ onSelectChange,
16
+ onSelectAllChange,
17
+ tableInstance,
18
+ tableInstance: {
19
+ state: { densePadding },
20
+ },
21
+ } = useMRT();
15
22
 
16
- const onSelectChange = (event: ChangeEvent<HTMLInputElement>) => {
23
+ const handleSelectChange = (event: ChangeEvent<HTMLInputElement>) => {
17
24
  if (selectAll) {
18
25
  tableInstance?.getToggleAllRowsSelectedProps?.()?.onChange?.(event);
19
- onSelectAllChange?.(event, tableInstance.selectedFlatRows);
26
+ onSelectAllChange?.(
27
+ event,
28
+ event.target.checked ? tableInstance.rows : [],
29
+ );
20
30
  } else if (row) {
21
31
  row?.getToggleRowSelectedProps()?.onChange?.(event);
22
- onRowSelectChange?.(event, row, tableInstance.selectedFlatRows);
32
+ onSelectChange?.(
33
+ event,
34
+ row,
35
+ event.target.checked
36
+ ? [...tableInstance.selectedFlatRows, row]
37
+ : tableInstance.selectedFlatRows.filter(
38
+ (selectedRow) => selectedRow.id !== row.id,
39
+ ),
40
+ );
23
41
  }
24
42
  };
25
43
 
26
- const checkboxProps = selectAll
44
+ const mTableBodyRowSelectCheckboxProps =
45
+ muiSelectCheckboxProps instanceof Function
46
+ ? muiSelectCheckboxProps(selectAll, row, tableInstance)
47
+ : muiSelectCheckboxProps;
48
+
49
+ const rtSelectCheckboxProps = selectAll
27
50
  ? tableInstance.getToggleAllRowsSelectedProps()
28
51
  : row?.getToggleRowSelectedProps();
29
52
 
53
+ const checkboxProps = {
54
+ ...mTableBodyRowSelectCheckboxProps,
55
+ ...rtSelectCheckboxProps,
56
+ style: {
57
+ ...rtSelectCheckboxProps?.style,
58
+ ...mTableBodyRowSelectCheckboxProps?.style,
59
+ },
60
+ };
61
+
30
62
  return (
31
- <TableCell
32
- sx={commonTableBodyButtonCellStyles(tableInstance.state.densePadding)}
63
+ <Tooltip
64
+ arrow
65
+ enterDelay={1000}
66
+ enterNextDelay={1000}
67
+ title={
68
+ selectAll ? localization.toggleSelectAll : localization.toggleSelectRow
69
+ }
33
70
  >
34
- <Tooltip
35
- arrow
36
- enterDelay={1000}
37
- enterNextDelay={1000}
38
- title={
39
- selectAll
71
+ <Checkbox
72
+ inputProps={{
73
+ 'aria-label': selectAll
40
74
  ? localization.toggleSelectAll
41
- : localization.toggleSelectRow
42
- }
43
- >
44
- <Checkbox
45
- inputProps={{
46
- 'aria-label': selectAll
47
- ? localization.toggleSelectAll
48
- : localization.toggleSelectRow,
49
- }}
50
- onChange={onSelectChange}
51
- {...checkboxProps}
52
- title={undefined}
53
- />
54
- </Tooltip>
55
- </TableCell>
75
+ : localization.toggleSelectRow,
76
+ }}
77
+ size={densePadding ? 'small' : 'medium'}
78
+ {...checkboxProps}
79
+ onChange={handleSelectChange}
80
+ title={undefined}
81
+ />
82
+ </Tooltip>
56
83
  );
57
84
  };
@@ -246,7 +246,12 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
246
246
  </MenuItem>,
247
247
  ]}
248
248
  {!disableColumnHiding && [
249
- <MenuItem key={0} onClick={handleHideColumn} sx={commonMenuItemStyles}>
249
+ <MenuItem
250
+ disabled={column.disableColumnHiding}
251
+ key={0}
252
+ onClick={handleHideColumn}
253
+ sx={commonMenuItemStyles}
254
+ >
250
255
  <Box sx={commonListItemStyles}>
251
256
  <ListItemIcon>
252
257
  <VisibilityOffIcon />
@@ -3,6 +3,7 @@ import { Button, Menu, Divider, Box } from '@mui/material';
3
3
  import type { MRT_ColumnInstance } from '..';
4
4
  import { useMRT } from '../useMRT';
5
5
  import { MRT_ShowHideColumnsMenuItems } from './MRT_ShowHideColumnsMenuItems';
6
+ import { findLowestLevelCols } from '../utils';
6
7
 
7
8
  interface Props {
8
9
  anchorEl: HTMLElement | null;
@@ -17,6 +18,16 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
17
18
  }) => {
18
19
  const { localization, tableInstance } = useMRT();
19
20
 
21
+ 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));
29
+ };
30
+
20
31
  return (
21
32
  <Menu
22
33
  anchorEl={anchorEl}
@@ -40,7 +51,7 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
40
51
  !tableInstance.getToggleHideAllColumnsProps().checked &&
41
52
  !tableInstance.getToggleHideAllColumnsProps().indeterminate
42
53
  }
43
- onClick={() => tableInstance.toggleHideAllColumns(true)}
54
+ onClick={hideAllColumns}
44
55
  >
45
56
  {localization.hideAll}
46
57
  </Button>
@@ -43,7 +43,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
43
43
  componentsProps={{ typography: { sx: { marginBottom: 0 } } }}
44
44
  checked={switchChecked}
45
45
  control={<Switch />}
46
- disabled={isSubMenu && switchChecked}
46
+ disabled={(isSubMenu && switchChecked) || column.disableColumnHiding}
47
47
  label={column.Header as string}
48
48
  onChange={() => handleToggleColumnHidden(column)}
49
49
  />
@@ -9,18 +9,11 @@ interface Props {
9
9
  export const MRT_TableSpacerCell: FC<Props> = ({ width }) => {
10
10
  const { muiTableBodyCellProps } = useMRT();
11
11
 
12
- const mTableBodyCellrops =
12
+ const tableCellProps =
13
13
  muiTableBodyCellProps instanceof Function
14
14
  ? muiTableBodyCellProps()
15
15
  : muiTableBodyCellProps;
16
16
 
17
- const tableCellProps = {
18
- ...mTableBodyCellrops,
19
- style: {
20
- ...mTableBodyCellrops?.style,
21
- },
22
- };
23
-
24
17
  return (
25
18
  <TableCell {...tableCellProps} sx={{ width, ...tableCellProps?.sx }} />
26
19
  );
package/src/utils.ts CHANGED
@@ -1,8 +1,12 @@
1
- import { MRT_ColumnInterface } from '.';
1
+ import { MRT_ColumnInstance, MRT_ColumnInterface } from '.';
2
2
 
3
- export const findLowestLevelCols = (columns: MRT_ColumnInterface[]) => {
4
- let lowestLevelColumns: MRT_ColumnInterface[] = columns;
5
- let currentCols: MRT_ColumnInterface[] | undefined = columns;
3
+ export const findLowestLevelCols = (
4
+ columns: MRT_ColumnInterface[] | MRT_ColumnInstance[],
5
+ ) => {
6
+ let lowestLevelColumns: MRT_ColumnInterface[] | MRT_ColumnInstance[] =
7
+ columns;
8
+ let currentCols: MRT_ColumnInterface[] | MRT_ColumnInstance[] | undefined =
9
+ columns;
6
10
  while (!!currentCols?.length && currentCols.some((col) => col.columns)) {
7
11
  const nextCols: MRT_ColumnInterface[] = currentCols
8
12
  .filter((col) => !!col.columns)