material-react-table 0.40.4 → 0.40.7

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/index.d.ts CHANGED
@@ -408,12 +408,17 @@ declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<Column
408
408
  table: MRT_TableInstance<TData>;
409
409
  column: MRT_Column<TData>;
410
410
  }) => TableCellProps);
411
+ renderColumnActionsMenuItems?: ({ closeMenu, column, table, }: {
412
+ closeMenu: () => void;
413
+ column: MRT_Column<TData>;
414
+ table: MRT_TableInstance<TData>;
415
+ }) => ReactNode[];
411
416
  renderColumnFilterModeMenuItems?: ({ column, internalFilterOptions, onSelectFilterMode, table, }: {
412
417
  column: MRT_Column<TData>;
413
418
  internalFilterOptions: MRT_InternalFilterOption[];
414
419
  onSelectFilterMode: (filterMode: MRT_FilterOption) => void;
415
420
  table: MRT_TableInstance<TData>;
416
- }) => ReactNode;
421
+ }) => ReactNode[];
417
422
  sortingFn?: MRT_SortingFn;
418
423
  };
419
424
  declare type MRT_DefinedColumnDef<TData extends Record<string, any> = {}> = Omit<MRT_ColumnDef<TData>, 'id'> & {
@@ -498,7 +503,7 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
498
503
  enableTableHead?: boolean;
499
504
  enableToolbarInternalActions?: boolean;
500
505
  enableTopToolbar?: boolean;
501
- enabledGlobalFilterOptions?: (MRT_FilterOption | string)[] | null;
506
+ globalFilterModeOptions?: (MRT_FilterOption | string)[] | null;
502
507
  expandRowsFn?: (dataRow: TData) => TData[];
503
508
  icons?: Partial<MRT_Icons>;
504
509
  initialState?: Partial<MRT_TableState<TData>>;
@@ -664,12 +669,17 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
664
669
  renderBottomToolbarCustomActions?: ({ table, }: {
665
670
  table: MRT_TableInstance<TData>;
666
671
  }) => ReactNode;
672
+ renderColumnActionsMenuItems?: ({ column, closeMenu, table, }: {
673
+ column: MRT_Column<TData>;
674
+ closeMenu: () => void;
675
+ table: MRT_TableInstance<TData>;
676
+ }) => ReactNode[];
667
677
  renderColumnFilterModeMenuItems?: ({ column, internalFilterOptions, onSelectFilterMode, table, }: {
668
678
  column: MRT_Column<TData>;
669
679
  internalFilterOptions: MRT_InternalFilterOption[];
670
680
  onSelectFilterMode: (filterMode: MRT_FilterOption) => void;
671
681
  table: MRT_TableInstance<TData>;
672
- }) => ReactNode;
682
+ }) => ReactNode[];
673
683
  renderDetailPanel?: ({ row, table, }: {
674
684
  row: MRT_Row<TData>;
675
685
  table: MRT_TableInstance<TData>;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.40.4",
2
+ "version": "0.40.7",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
5
  "description": "A fully featured Material UI V5 implementation of TanStack React Table V8, written from the ground up in TypeScript.",
@@ -58,7 +58,7 @@
58
58
  "@mui/material": "^5.10.2",
59
59
  "@rollup/plugin-babel": "^5.3.1",
60
60
  "@rollup/plugin-node-resolve": "^13.3.0",
61
- "@rollup/plugin-typescript": "^8.3.4",
61
+ "@rollup/plugin-typescript": "^8.4.0",
62
62
  "@size-limit/preset-small-lib": "^8.0.1",
63
63
  "@storybook/addon-a11y": "^6.5.10",
64
64
  "@storybook/addon-actions": "^6.5.10",
@@ -71,7 +71,7 @@
71
71
  "@types/react": "^18.0.17",
72
72
  "@types/react-dom": "^18.0.6",
73
73
  "babel-loader": "^8.2.5",
74
- "eslint": "^8.22.0",
74
+ "eslint": "^8.23.0",
75
75
  "eslint-plugin-react-hooks": "^4.6.0",
76
76
  "husky": "^8.0.1",
77
77
  "prettier": "^2.7.1",
@@ -84,7 +84,7 @@
84
84
  "size-limit": "^8.0.1",
85
85
  "storybook-dark-mode": "^1.1.0",
86
86
  "tslib": "^2.4.0",
87
- "typescript": "^4.7.4"
87
+ "typescript": "^4.8.2"
88
88
  },
89
89
  "peerDependencies": {
90
90
  "@emotion/react": ">=11",
@@ -362,6 +362,15 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
362
362
  table: MRT_TableInstance<TData>;
363
363
  column: MRT_Column<TData>;
364
364
  }) => TableCellProps);
365
+ renderColumnActionsMenuItems?: ({
366
+ closeMenu,
367
+ column,
368
+ table,
369
+ }: {
370
+ closeMenu: () => void;
371
+ column: MRT_Column<TData>;
372
+ table: MRT_TableInstance<TData>;
373
+ }) => ReactNode[];
365
374
  renderColumnFilterModeMenuItems?: ({
366
375
  column,
367
376
  internalFilterOptions,
@@ -372,7 +381,7 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
372
381
  internalFilterOptions: MRT_InternalFilterOption[];
373
382
  onSelectFilterMode: (filterMode: MRT_FilterOption) => void;
374
383
  table: MRT_TableInstance<TData>;
375
- }) => ReactNode;
384
+ }) => ReactNode[];
376
385
  sortingFn?: MRT_SortingFn;
377
386
  };
378
387
 
@@ -512,7 +521,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
512
521
  enableTableHead?: boolean;
513
522
  enableToolbarInternalActions?: boolean;
514
523
  enableTopToolbar?: boolean;
515
- enabledGlobalFilterOptions?: (MRT_FilterOption | string)[] | null;
524
+ globalFilterModeOptions?: (MRT_FilterOption | string)[] | null;
516
525
  expandRowsFn?: (dataRow: TData) => TData[];
517
526
  icons?: Partial<MRT_Icons>;
518
527
  initialState?: Partial<MRT_TableState<TData>>;
@@ -786,6 +795,15 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
786
795
  }: {
787
796
  table: MRT_TableInstance<TData>;
788
797
  }) => ReactNode;
798
+ renderColumnActionsMenuItems?: ({
799
+ column,
800
+ closeMenu,
801
+ table,
802
+ }: {
803
+ column: MRT_Column<TData>;
804
+ closeMenu: () => void;
805
+ table: MRT_TableInstance<TData>;
806
+ }) => ReactNode[];
789
807
  renderColumnFilterModeMenuItems?: ({
790
808
  column,
791
809
  internalFilterOptions,
@@ -796,7 +814,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
796
814
  internalFilterOptions: MRT_InternalFilterOption[];
797
815
  onSelectFilterMode: (filterMode: MRT_FilterOption) => void;
798
816
  table: MRT_TableInstance<TData>;
799
- }) => ReactNode;
817
+ }) => ReactNode[];
800
818
  renderDetailPanel?: ({
801
819
  row,
802
820
  table,
@@ -1,4 +1,4 @@
1
- import React, { FC, RefObject, useEffect, useMemo } from 'react';
1
+ import React, { FC, RefObject, useMemo } from 'react';
2
2
  import { useVirtual } from 'react-virtual'; //stuck on v2 for now
3
3
  // import { useVirtualizer, Virtualizer } from '@tanstack/react-virtual';
4
4
  import { TableBody } from '@mui/material';
@@ -20,9 +20,11 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
20
20
  enableGlobalFilterRankedResults,
21
21
  enablePagination,
22
22
  enableRowVirtualization,
23
+ manualFiltering,
24
+ manualSorting,
23
25
  muiTableBodyProps,
24
- virtualizerProps,
25
26
  virtualizerInstanceRef,
27
+ virtualizerProps,
26
28
  },
27
29
  } = table;
28
30
  const { globalFilter, pagination, sorting } = getState();
@@ -41,6 +43,8 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
41
43
  if (
42
44
  enableGlobalFilterRankedResults &&
43
45
  globalFilter &&
46
+ !manualFiltering &&
47
+ !manualSorting &&
44
48
  !Object.values(sorting).some(Boolean)
45
49
  ) {
46
50
  const rankedRows = getPrePaginationRowModel().rows.sort((a, b) =>
@@ -72,11 +76,9 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
72
76
  })
73
77
  : ({} as any);
74
78
 
75
- useEffect(() => {
76
- if (virtualizerInstanceRef) {
77
- virtualizerInstanceRef.current = virtualizer;
78
- }
79
- }, [virtualizer]);
79
+ if (virtualizerInstanceRef) {
80
+ virtualizerInstanceRef.current = virtualizer;
81
+ }
80
82
 
81
83
  // const virtualizer: Virtualizer = enableRowVirtualization
82
84
  // ? useVirtualizer({
@@ -9,13 +9,11 @@ interface Props {
9
9
 
10
10
  export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
11
11
  const {
12
- getState,
13
12
  options: {
14
13
  icons: { FilterAltIcon },
15
14
  localization,
16
15
  },
17
16
  } = table;
18
- const { columnFilterFns } = getState();
19
17
  const { column } = header;
20
18
  const { columnDef } = column;
21
19
 
@@ -24,7 +22,7 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
24
22
  'betweenInclusive',
25
23
  'inNumberRange',
26
24
  ].includes(columnDef._filterFn);
27
- const currentFilterOption = columnFilterFns?.[header.id];
25
+ const currentFilterOption = columnDef._filterFn;
28
26
  const filterTooltip = localization.filteringByColumn
29
27
  .replace('{column}', String(columnDef.header))
30
28
  .replace(
@@ -1,9 +1,4 @@
1
- import React, {
2
- ChangeEvent,
3
- FocusEvent,
4
- KeyboardEvent,
5
- useState,
6
- } from 'react';
1
+ import React, { ChangeEvent, FocusEvent, KeyboardEvent, useState } from 'react';
7
2
  import { TextField, TextFieldProps } from '@mui/material';
8
3
  import type { MRT_Cell, MRT_TableInstance } from '..';
9
4
 
@@ -12,7 +12,6 @@ import {
12
12
  debounce,
13
13
  IconButton,
14
14
  InputAdornment,
15
- ListItemText,
16
15
  MenuItem,
17
16
  TextField,
18
17
  TextFieldProps,
@@ -323,7 +322,16 @@ export const MRT_FilterTextField: FC<Props> = ({
323
322
  text = option.text;
324
323
  }
325
324
  return (
326
- <MenuItem key={value} value={value}>
325
+ <MenuItem
326
+ key={value}
327
+ sx={{
328
+ display: 'flex',
329
+ m: 0,
330
+ alignItems: 'center',
331
+ gap: '0.5rem',
332
+ }}
333
+ value={value}
334
+ >
327
335
  {isMultiSelectFilter && (
328
336
  <Checkbox
329
337
  checked={(
@@ -332,7 +340,7 @@ export const MRT_FilterTextField: FC<Props> = ({
332
340
  sx={{ mr: '0.5rem' }}
333
341
  />
334
342
  )}
335
- <ListItemText>{text}</ListItemText>
343
+ {text}
336
344
  </MenuItem>
337
345
  );
338
346
  },
@@ -34,6 +34,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
34
34
  toggleAllColumnsVisible,
35
35
  setColumnOrder,
36
36
  options: {
37
+ columnFilterModeOptions,
37
38
  enableColumnFilterModes,
38
39
  enableColumnFilters,
39
40
  enableColumnResizing,
@@ -41,7 +42,6 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
41
42
  enableHiding,
42
43
  enablePinning,
43
44
  enableSorting,
44
- columnFilterModeOptions,
45
45
  icons: {
46
46
  ArrowRightIcon,
47
47
  ClearAllIcon,
@@ -55,6 +55,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
55
55
  VisibilityOffIcon,
56
56
  },
57
57
  localization,
58
+ renderColumnActionsMenuItems,
58
59
  },
59
60
  refs: { filterInputRefs },
60
61
  setShowFilters,
@@ -153,55 +154,67 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
153
154
  dense: density === 'compact',
154
155
  }}
155
156
  >
156
- {enableSorting &&
157
- column.getCanSort() && [
158
- <MenuItem
159
- disabled={!column.getIsSorted()}
160
- key={0}
161
- onClick={handleClearSort}
162
- sx={commonMenuItemStyles}
163
- >
164
- <Box sx={commonListItemStyles}>
165
- <ListItemIcon>
166
- <ClearAllIcon />
167
- </ListItemIcon>
168
- {localization.clearSort}
169
- </Box>
170
- </MenuItem>,
171
- <MenuItem
172
- disabled={column.getIsSorted() === 'asc'}
173
- key={1}
174
- onClick={handleSortAsc}
175
- sx={commonMenuItemStyles}
176
- >
177
- <Box sx={commonListItemStyles}>
178
- <ListItemIcon>
179
- <SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />
180
- </ListItemIcon>
181
- {localization.sortByColumnAsc?.replace(
182
- '{column}',
183
- String(columnDef.header),
184
- )}
185
- </Box>
186
- </MenuItem>,
187
- <MenuItem
188
- divider={enableColumnFilters || enableGrouping || enableHiding}
189
- key={2}
190
- disabled={column.getIsSorted() === 'desc'}
191
- onClick={handleSortDesc}
192
- sx={commonMenuItemStyles}
193
- >
194
- <Box sx={commonListItemStyles}>
195
- <ListItemIcon>
196
- <SortIcon />
197
- </ListItemIcon>
198
- {localization.sortByColumnDesc?.replace(
199
- '{column}',
200
- String(columnDef.header),
201
- )}
202
- </Box>
203
- </MenuItem>,
204
- ]}
157
+ {columnDef.renderColumnActionsMenuItems?.({
158
+ closeMenu: () => setAnchorEl(null),
159
+ column,
160
+ table,
161
+ }) ??
162
+ renderColumnActionsMenuItems?.({
163
+ closeMenu: () => setAnchorEl(null),
164
+ column,
165
+ table,
166
+ }) ??
167
+ (enableSorting &&
168
+ column.getCanSort() && [
169
+ <MenuItem
170
+ disabled={!column.getIsSorted()}
171
+ key={0}
172
+ onClick={handleClearSort}
173
+ sx={commonMenuItemStyles}
174
+ >
175
+ <Box sx={commonListItemStyles}>
176
+ <ListItemIcon>
177
+ <ClearAllIcon />
178
+ </ListItemIcon>
179
+ {localization.clearSort}
180
+ </Box>
181
+ </MenuItem>,
182
+ <MenuItem
183
+ disabled={column.getIsSorted() === 'asc'}
184
+ key={1}
185
+ onClick={handleSortAsc}
186
+ sx={commonMenuItemStyles}
187
+ >
188
+ <Box sx={commonListItemStyles}>
189
+ <ListItemIcon>
190
+ <SortIcon
191
+ style={{ transform: 'rotate(180deg) scaleX(-1)' }}
192
+ />
193
+ </ListItemIcon>
194
+ {localization.sortByColumnAsc?.replace(
195
+ '{column}',
196
+ String(columnDef.header),
197
+ )}
198
+ </Box>
199
+ </MenuItem>,
200
+ <MenuItem
201
+ divider={enableColumnFilters || enableGrouping || enableHiding}
202
+ key={2}
203
+ disabled={column.getIsSorted() === 'desc'}
204
+ onClick={handleSortDesc}
205
+ sx={commonMenuItemStyles}
206
+ >
207
+ <Box sx={commonListItemStyles}>
208
+ <ListItemIcon>
209
+ <SortIcon />
210
+ </ListItemIcon>
211
+ {localization.sortByColumnDesc?.replace(
212
+ '{column}',
213
+ String(columnDef.header),
214
+ )}
215
+ </Box>
216
+ </MenuItem>,
217
+ ])}
205
218
  {enableColumnFilters &&
206
219
  column.getCanFilter() &&
207
220
  [
@@ -115,8 +115,8 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any> = {}>({
115
115
  const {
116
116
  getState,
117
117
  options: {
118
- enabledGlobalFilterOptions,
119
118
  columnFilterModeOptions,
119
+ globalFilterModeOptions,
120
120
  localization,
121
121
  renderColumnFilterModeMenuItems,
122
122
  renderGlobalFilterModeMenuItems,
@@ -137,8 +137,8 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any> = {}>({
137
137
  columnDef
138
138
  ? allowedColumnFilterOptions === undefined ||
139
139
  allowedColumnFilterOptions?.includes(filterOption.option)
140
- : (!enabledGlobalFilterOptions ||
141
- enabledGlobalFilterOptions.includes(filterOption.option)) &&
140
+ : (!globalFilterModeOptions ||
141
+ globalFilterModeOptions.includes(filterOption.option)) &&
142
142
  ['fuzzy', 'contains', 'startsWith'].includes(filterOption.option),
143
143
  ),
144
144
  [],
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useMemo, useRef, useState } from 'react';
1
+ import React, { useMemo, useRef, useState } from 'react';
2
2
  import {
3
3
  TableState,
4
4
  getCoreRowModel,
@@ -189,6 +189,7 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
189
189
  props.displayColumnDefOptions,
190
190
  props.editingMode,
191
191
  props.enableColumnDragging,
192
+ props.enableColumnFilterModes,
192
193
  props.enableColumnOrdering,
193
194
  props.enableEditing,
194
195
  props.enableExpandAll,
@@ -303,11 +304,9 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
303
304
  setShowGlobalFilter: props.onShowGlobalFilterChange ?? setShowGlobalFilter,
304
305
  } as MRT_TableInstance<TData>;
305
306
 
306
- useEffect(() => {
307
- if (props.tableInstanceRef) {
308
- props.tableInstanceRef.current = table;
309
- }
310
- }, [table]);
307
+ if (props.tableInstanceRef) {
308
+ props.tableInstanceRef.current = table;
309
+ }
311
310
 
312
311
  return (
313
312
  <>