material-react-table 2.3.1 → 2.4.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.
@@ -21,6 +21,14 @@ import {
21
21
  DatePicker,
22
22
  type DatePickerProps,
23
23
  } from '@mui/x-date-pickers/DatePicker';
24
+ import {
25
+ DateTimePicker,
26
+ type DateTimePickerProps,
27
+ } from '@mui/x-date-pickers/DateTimePicker';
28
+ import {
29
+ TimePicker,
30
+ type TimePickerProps,
31
+ } from '@mui/x-date-pickers/TimePicker';
24
32
  import { getValueAndLabel, parseFromValuesOrFunc } from '../column.utils';
25
33
  import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
26
34
  import {
@@ -50,7 +58,9 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
50
58
  manualFiltering,
51
59
  muiFilterAutocompleteProps,
52
60
  muiFilterDatePickerProps,
61
+ muiFilterDateTimePickerProps,
53
62
  muiFilterTextFieldProps,
63
+ muiFilterTimePickerProps,
54
64
  },
55
65
  refs: { filterInputRefs },
56
66
  setColumnFilterFns,
@@ -84,7 +94,24 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
84
94
  }),
85
95
  };
86
96
 
87
- const isDateFilter = filterVariant?.startsWith('date');
97
+ const dateTimePickerProps: DateTimePickerProps<any> = {
98
+ ...parseFromValuesOrFunc(muiFilterDateTimePickerProps, { column, table }),
99
+ ...parseFromValuesOrFunc(columnDef.muiFilterDateTimePickerProps, {
100
+ column,
101
+ table,
102
+ }),
103
+ };
104
+
105
+ const timePickerProps: TimePickerProps<any> = {
106
+ ...parseFromValuesOrFunc(muiFilterTimePickerProps, { column, table }),
107
+ ...parseFromValuesOrFunc(columnDef.muiFilterTimePickerProps, {
108
+ column,
109
+ table,
110
+ }),
111
+ };
112
+
113
+ const isDateFilter =
114
+ filterVariant?.startsWith('date') || filterVariant?.startsWith('time');
88
115
  const isAutocompleteFilter = filterVariant === 'autocomplete';
89
116
  const isRangeFilter =
90
117
  filterVariant?.includes('range') || rangeFilterIndex !== undefined;
@@ -350,14 +377,50 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
350
377
  }),
351
378
  };
352
379
 
380
+ const commonDatePickerProps = {
381
+ onChange: (newDate: any) => {
382
+ handleChange(newDate);
383
+ },
384
+ value: filterValue || null,
385
+ };
386
+
353
387
  return (
354
388
  <>
355
- {isDateFilter ? (
356
- <DatePicker
357
- onChange={(newDate) => {
358
- handleChange(newDate);
389
+ {filterVariant?.startsWith('time') ? (
390
+ <TimePicker
391
+ {...commonDatePickerProps}
392
+ {...timePickerProps}
393
+ slotProps={{
394
+ field: {
395
+ clearable: true,
396
+ onClear: () => handleClear(),
397
+ ...timePickerProps?.slotProps?.field,
398
+ },
399
+ textField: {
400
+ ...commonTextFieldProps,
401
+ ...timePickerProps?.slotProps?.textField,
402
+ },
403
+ }}
404
+ />
405
+ ) : filterVariant?.startsWith('datetime') ? (
406
+ <DateTimePicker
407
+ {...commonDatePickerProps}
408
+ {...dateTimePickerProps}
409
+ slotProps={{
410
+ field: {
411
+ clearable: true,
412
+ onClear: () => handleClear(),
413
+ ...dateTimePickerProps?.slotProps?.field,
414
+ },
415
+ textField: {
416
+ ...commonTextFieldProps,
417
+ ...dateTimePickerProps?.slotProps?.textField,
418
+ },
359
419
  }}
360
- value={filterValue || null}
420
+ />
421
+ ) : filterVariant?.startsWith('date') ? (
422
+ <DatePicker
423
+ {...commonDatePickerProps}
361
424
  {...datePickerProps}
362
425
  slotProps={{
363
426
  field: {
@@ -67,6 +67,7 @@ export const MRT_ColumnActionMenu = <TData extends MRT_RowData>({
67
67
  renderColumnActionsMenuItems,
68
68
  },
69
69
  refs: { filterInputRefs },
70
+ setColumnFilterFns,
70
71
  setColumnOrder,
71
72
  setColumnSizingInfo,
72
73
  setShowColumnFilters,
@@ -119,8 +120,14 @@ export const MRT_ColumnActionMenu = <TData extends MRT_RowData>({
119
120
  };
120
121
 
121
122
  const handleClearFilter = () => {
122
- column.setFilterValue('');
123
+ column.setFilterValue(undefined);
123
124
  setAnchorEl(null);
125
+ if (['empty', 'notEmpty'].includes(columnDef._filterFn)) {
126
+ setColumnFilterFns((prev) => ({
127
+ ...prev,
128
+ [header.id]: allowedColumnFilterOptions?.[0] ?? 'fuzzy',
129
+ }));
130
+ }
124
131
  };
125
132
 
126
133
  const handleFilterByColumn = () => {
@@ -103,7 +103,7 @@ export const mrtFilterOptions = (
103
103
  const rangeModes = ['between', 'betweenInclusive', 'inNumberRange'];
104
104
  const emptyModes = ['empty', 'notEmpty'];
105
105
  const arrModes = ['arrIncludesSome', 'arrIncludesAll', 'arrIncludes'];
106
- const rangeVariants = ['range-slider', 'date-range', 'range'];
106
+ const rangeVariants = ['range-slider', 'date-range', 'datetime-range', 'range'];
107
107
 
108
108
  interface Props<TData extends MRT_RowData> extends Partial<MenuProps> {
109
109
  anchorEl: HTMLElement | null;
@@ -90,25 +90,6 @@ export const getCommonMRTCellStyles = <TData extends MRT_RowData>({
90
90
  column.getIsPinned() === 'left'
91
91
  ? `${column.getStart('left')}px`
92
92
  : undefined,
93
- ml:
94
- table.options.enableColumnVirtualization &&
95
- column.getIsPinned() === 'left' &&
96
- column.getPinnedIndex() === 0
97
- ? `-${
98
- column.getSize() *
99
- (table.getState().columnPinning.left?.length ?? 1)
100
- }px`
101
- : undefined,
102
- mr:
103
- table.options.enableColumnVirtualization &&
104
- column.getIsPinned() === 'right' &&
105
- column.getPinnedIndex() === table.getVisibleLeafColumns().length - 1
106
- ? `-${
107
- column.getSize() *
108
- (table.getState().columnPinning.right?.length ?? 1) *
109
- 1.2
110
- }px`
111
- : undefined,
112
93
  opacity:
113
94
  table.getState().draggingColumn?.id === column.id ||
114
95
  table.getState().hoveredColumn?.id === column.id
@@ -53,22 +53,9 @@ export const MRT_Table = <TData extends MRT_RowData>({
53
53
 
54
54
  const columnVirtualizer = useMRT_ColumnVirtualizer(table);
55
55
 
56
- const { virtualPaddingLeft, virtualPaddingRight } = columnVirtualizer ?? {};
57
-
58
- const virtualColumns = columnVirtualizer
59
- ? columnVirtualizer.getVirtualItems()
60
- : undefined;
61
-
62
56
  const commonTableGroupProps = {
63
- table,
64
- virtualColumns,
65
- virtualPaddingLeft,
66
- virtualPaddingRight,
67
- };
68
-
69
- const commonTableBodyProps = {
70
- ...commonTableGroupProps,
71
57
  columnVirtualizer,
58
+ table,
72
59
  };
73
60
 
74
61
  return (
@@ -84,9 +71,9 @@ export const MRT_Table = <TData extends MRT_RowData>({
84
71
  >
85
72
  {enableTableHead && <MRT_TableHead {...commonTableGroupProps} />}
86
73
  {memoMode === 'table-body' || columnSizingInfo.isResizingColumn ? (
87
- <Memo_MRT_TableBody {...commonTableBodyProps} />
74
+ <Memo_MRT_TableBody {...commonTableGroupProps} />
88
75
  ) : (
89
- <MRT_TableBody {...commonTableBodyProps} />
76
+ <MRT_TableBody {...commonTableGroupProps} />
90
77
  )}
91
78
  {enableTableFooter && <MRT_TableFooter {...commonTableGroupProps} />}
92
79
  </Table>
@@ -4,7 +4,8 @@ import InputLabel from '@mui/material/InputLabel';
4
4
  import MenuItem from '@mui/material/MenuItem';
5
5
  import Pagination, { type PaginationProps } from '@mui/material/Pagination';
6
6
  import PaginationItem from '@mui/material/PaginationItem';
7
- import Select from '@mui/material/Select';
7
+ import Select, { type SelectProps } from '@mui/material/Select';
8
+ import Tooltip from '@mui/material/Tooltip';
8
9
  import Typography from '@mui/material/Typography';
9
10
  import { parseFromValuesOrFunc } from '../column.utils';
10
11
  import { type MRT_RowData, type MRT_TableInstance } from '../types';
@@ -14,6 +15,7 @@ const defaultRowsPerPage = [5, 10, 15, 20, 25, 30, 50, 100];
14
15
  interface Props<TData extends MRT_RowData>
15
16
  extends Partial<
16
17
  PaginationProps & {
18
+ SelectProps?: Partial<SelectProps>;
17
19
  disabled?: boolean;
18
20
  rowsPerPageOptions?: { label: string; value: number }[] | number[];
19
21
  showRowsPerPage?: boolean;
@@ -70,6 +72,9 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
70
72
  ..._rest
71
73
  } = paginationProps ?? {};
72
74
 
75
+ const disableBack = pageIndex <= 0 || disabled;
76
+ const disableNext = lastRowIndex >= totalRowCount || disabled;
77
+
73
78
  return (
74
79
  <Box
75
80
  className="MuiTablePagination-root"
@@ -164,40 +169,56 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
164
169
  } ${totalRowCount.toLocaleString()}`}</Typography>
165
170
  <Box gap="xs">
166
171
  {showFirstButton && (
167
- <IconButton
168
- aria-label={localization.goToFirstPage}
169
- disabled={pageIndex <= 0 || disabled}
170
- onClick={() => setPageIndex(0)}
171
- size="small"
172
- >
173
- <FirstPageIcon />
174
- </IconButton>
172
+ <Tooltip enterDelay={1000} title={localization.goToFirstPage}>
173
+ <span>
174
+ <IconButton
175
+ aria-label={localization.goToFirstPage}
176
+ disabled={disableBack}
177
+ onClick={() => setPageIndex(0)}
178
+ size="small"
179
+ >
180
+ <FirstPageIcon />
181
+ </IconButton>
182
+ </span>
183
+ </Tooltip>
175
184
  )}
176
- <IconButton
177
- aria-label={localization.goToPreviousPage}
178
- disabled={pageIndex <= 0 || disabled}
179
- onClick={() => setPageIndex(pageIndex - 1)}
180
- size="small"
181
- >
182
- <ChevronLeftIcon />
183
- </IconButton>
184
- <IconButton
185
- aria-label={localization.goToNextPage}
186
- disabled={lastRowIndex >= totalRowCount || disabled}
187
- onClick={() => setPageIndex(pageIndex + 1)}
188
- size="small"
189
- >
190
- <ChevronRightIcon />
191
- </IconButton>
185
+ <Tooltip enterDelay={1000} title={localization.goToPreviousPage}>
186
+ <span>
187
+ <IconButton
188
+ aria-label={localization.goToPreviousPage}
189
+ disabled={disableBack}
190
+ onClick={() => setPageIndex(pageIndex - 1)}
191
+ size="small"
192
+ >
193
+ <ChevronLeftIcon />
194
+ </IconButton>
195
+ </span>
196
+ </Tooltip>
197
+ <Tooltip enterDelay={1000} title={localization.goToNextPage}>
198
+ <span>
199
+ <IconButton
200
+ aria-label={localization.goToNextPage}
201
+ disabled={disableNext}
202
+ onClick={() => setPageIndex(pageIndex + 1)}
203
+ size="small"
204
+ >
205
+ <ChevronRightIcon />
206
+ </IconButton>
207
+ </span>
208
+ </Tooltip>
192
209
  {showLastButton && (
193
- <IconButton
194
- aria-label={localization.goToLastPage}
195
- disabled={lastRowIndex >= totalRowCount || disabled}
196
- onClick={() => setPageIndex(numberOfPages - 1)}
197
- size="small"
198
- >
199
- <LastPageIcon />
200
- </IconButton>
210
+ <Tooltip enterDelay={1000} title={localization.goToLastPage}>
211
+ <span>
212
+ <IconButton
213
+ aria-label={localization.goToLastPage}
214
+ disabled={disableNext}
215
+ onClick={() => setPageIndex(numberOfPages - 1)}
216
+ size="small"
217
+ >
218
+ <LastPageIcon />
219
+ </IconButton>
220
+ </span>
221
+ </Tooltip>
201
222
  )}
202
223
  </Box>
203
224
  </>
package/src/types.ts CHANGED
@@ -66,7 +66,11 @@ import { type TableHeadProps } from '@mui/material/TableHead';
66
66
  import { type TableRowProps } from '@mui/material/TableRow';
67
67
  import { type TextFieldProps } from '@mui/material/TextField';
68
68
  import { type Theme } from '@mui/material/styles';
69
- import { type DatePickerProps } from '@mui/x-date-pickers';
69
+ import {
70
+ type DatePickerProps,
71
+ type DateTimePickerProps,
72
+ type TimePickerProps,
73
+ } from '@mui/x-date-pickers';
70
74
  import { type MRT_AggregationFns } from './aggregationFns';
71
75
  import { type MRT_FilterFns } from './filterFns';
72
76
  import { type MRT_Icons } from './icons';
@@ -89,24 +93,48 @@ export type MRT_ColumnFilterFnsState = Record<string, MRT_FilterOption>;
89
93
 
90
94
  export type MRT_RowData = Record<string, any>;
91
95
 
92
- export type {
93
- ColumnFiltersState as MRT_ColumnFiltersState,
94
- ColumnOrderState as MRT_ColumnOrderState,
95
- ColumnPinningState as MRT_ColumnPinningState,
96
- ColumnSizingInfoState as MRT_ColumnSizingInfoState,
97
- ColumnSizingState as MRT_ColumnSizingState,
98
- ExpandedState as MRT_ExpandedState,
99
- GroupingState as MRT_GroupingState,
100
- PaginationState as MRT_PaginationState,
101
- RowSelectionState as MRT_RowSelectionState,
102
- SortingState as MRT_SortingState,
103
- Updater as MRT_Updater,
104
- VirtualItem as MRT_VirtualItem,
105
- Virtualizer as MRT_Virtualizer,
106
- VirtualizerOptions as MRT_VirtualizerOptions,
107
- VisibilityState as MRT_VisibilityState,
96
+ export type MRT_ColumnFiltersState = ColumnFiltersState;
97
+ export type MRT_ColumnOrderState = ColumnOrderState;
98
+ export type MRT_ColumnPinningState = ColumnPinningState;
99
+ export type MRT_ColumnSizingInfoState = ColumnSizingInfoState;
100
+ export type MRT_ColumnSizingState = ColumnSizingState;
101
+ export type MRT_ExpandedState = ExpandedState;
102
+ export type MRT_GroupingState = GroupingState;
103
+ export type MRT_PaginationState = PaginationState;
104
+ export type MRT_RowSelectionState = RowSelectionState;
105
+ export type MRT_SortingState = SortingState;
106
+ export type MRT_Updater<T> = Updater<T>;
107
+ export type MRT_VirtualItem = VirtualItem;
108
+ export type MRT_VisibilityState = VisibilityState;
109
+
110
+ export type MRT_VirtualizerOptions<
111
+ TScrollElement extends Element | Window = Element | Window,
112
+ TItemElement extends Element = Element,
113
+ > = VirtualizerOptions<TScrollElement, TItemElement>;
114
+
115
+ export type MRT_ColumnVirtualizer<
116
+ TScrollElement extends Element | Window = HTMLDivElement,
117
+ TItemElement extends Element = HTMLTableCellElement,
118
+ > = Virtualizer<TScrollElement, TItemElement> & {
119
+ virtualColumns: MRT_VirtualItem[];
120
+ virtualPaddingLeft?: number;
121
+ virtualPaddingRight?: number;
108
122
  };
109
123
 
124
+ export type MRT_RowVirtualizer<
125
+ TScrollElement extends Element | Window = HTMLDivElement,
126
+ TItemElement extends Element = HTMLTableRowElement,
127
+ > = Virtualizer<TScrollElement, TItemElement> & {
128
+ virtualRows: MRT_VirtualItem[];
129
+ };
130
+
131
+ /**
132
+ * @deprecated use `MRT_ColumnVirtualizer` or `MRT_RowVirtualizer` instead
133
+ */
134
+ export type MRT_Virtualizer<_TScrollElement = any, _TItemElement = any> =
135
+ | MRT_ColumnVirtualizer
136
+ | MRT_RowVirtualizer;
137
+
110
138
  export type MRT_ColumnHelper<TData extends MRT_RowData> = {
111
139
  accessor: <
112
140
  TAccessor extends AccessorFn<TData> | DeepKeys<TData>,
@@ -463,11 +491,15 @@ export type MRT_ColumnDef<TData extends MRT_RowData, TValue = unknown> = Omit<
463
491
  | 'checkbox'
464
492
  | 'date'
465
493
  | 'date-range'
494
+ | 'datetime'
495
+ | 'datetime-range'
466
496
  | 'multi-select'
467
497
  | 'range'
468
498
  | 'range-slider'
469
499
  | 'select'
470
- | 'text';
500
+ | 'text'
501
+ | 'time'
502
+ | 'time-range';
471
503
  /**
472
504
  * footer must be a string. If you want custom JSX to render the footer, you can also specify a `Footer` option. (Capital F)
473
505
  */
@@ -533,6 +565,13 @@ export type MRT_ColumnDef<TData extends MRT_RowData, TValue = unknown> = Omit<
533
565
  table: MRT_TableInstance<TData>;
534
566
  }) => DatePickerProps<any>)
535
567
  | DatePickerProps<any>;
568
+ muiFilterDateTimePickerProps?:
569
+ | ((props: {
570
+ column: MRT_Column<TData>;
571
+ rangeFilterIndex?: number;
572
+ table: MRT_TableInstance<TData>;
573
+ }) => DateTimePickerProps<any>)
574
+ | DateTimePickerProps<any>;
536
575
  muiFilterSliderProps?:
537
576
  | ((props: {
538
577
  column: MRT_Column<TData>;
@@ -546,6 +585,13 @@ export type MRT_ColumnDef<TData extends MRT_RowData, TValue = unknown> = Omit<
546
585
  table: MRT_TableInstance<TData>;
547
586
  }) => TextFieldProps)
548
587
  | TextFieldProps;
588
+ muiFilterTimePickerProps?:
589
+ | ((props: {
590
+ column: MRT_Column<TData>;
591
+ rangeFilterIndex?: number;
592
+ table: MRT_TableInstance<TData>;
593
+ }) => TimePickerProps<any>)
594
+ | TimePickerProps<any>;
549
595
  muiTableBodyCellProps?:
550
596
  | ((props: {
551
597
  cell: MRT_Cell<TData, TValue>;
@@ -708,10 +754,9 @@ export type MRT_TableOptions<TData extends MRT_RowData> = Omit<
708
754
  columnFilterModeOptions?: Array<
709
755
  LiteralUnion<string & MRT_FilterOption>
710
756
  > | null;
711
- columnVirtualizerInstanceRef?: MutableRefObject<Virtualizer<
712
- HTMLDivElement,
713
- HTMLTableCellElement
714
- > | null>;
757
+ columnVirtualizerInstanceRef?: MutableRefObject<
758
+ MRT_ColumnVirtualizer | MRT_Virtualizer | null
759
+ >;
715
760
  columnVirtualizerOptions?:
716
761
  | ((props: {
717
762
  table: MRT_TableInstance<TData>;
@@ -886,6 +931,13 @@ export type MRT_TableOptions<TData extends MRT_RowData> = Omit<
886
931
  table: MRT_TableInstance<TData>;
887
932
  }) => DatePickerProps<any>)
888
933
  | DatePickerProps<any>;
934
+ muiFilterDateTimePickerProps?:
935
+ | ((props: {
936
+ column: MRT_Column<TData>;
937
+ rangeFilterIndex?: number;
938
+ table: MRT_TableInstance<TData>;
939
+ }) => DateTimePickerProps<any>)
940
+ | DateTimePickerProps<any>;
889
941
  muiFilterSliderProps?:
890
942
  | ((props: {
891
943
  column: MRT_Column<TData>;
@@ -899,6 +951,13 @@ export type MRT_TableOptions<TData extends MRT_RowData> = Omit<
899
951
  table: MRT_TableInstance<TData>;
900
952
  }) => TextFieldProps)
901
953
  | TextFieldProps;
954
+ muiFilterTimePickerProps?:
955
+ | ((props: {
956
+ column: MRT_Column<TData>;
957
+ rangeFilterIndex?: number;
958
+ table: MRT_TableInstance<TData>;
959
+ }) => TimePickerProps<any>)
960
+ | TimePickerProps<any>;
902
961
  muiLinearProgressProps?:
903
962
  | ((props: {
904
963
  isTopToolbar: boolean;
@@ -909,6 +968,7 @@ export type MRT_TableOptions<TData extends MRT_RowData> = Omit<
909
968
  | ((props: { table: MRT_TableInstance<TData> }) => Partial<
910
969
  PaginationProps & {
911
970
  SelectProps?: Partial<SelectProps>;
971
+ disabled?: boolean;
912
972
  rowsPerPageOptions?: { label: string; value: number }[] | number[];
913
973
  showRowsPerPage?: boolean;
914
974
  }
@@ -916,6 +976,7 @@ export type MRT_TableOptions<TData extends MRT_RowData> = Omit<
916
976
  | Partial<
917
977
  PaginationProps & {
918
978
  SelectProps?: Partial<SelectProps>;
979
+ disabled?: boolean;
919
980
  rowsPerPageOptions?: { label: string; value: number }[] | number[];
920
981
  showRowsPerPage?: boolean;
921
982
  }
@@ -1129,10 +1190,9 @@ export type MRT_TableOptions<TData extends MRT_RowData> = Omit<
1129
1190
  | 'sticky'
1130
1191
  | 'top'
1131
1192
  | 'top-and-bottom';
1132
- rowVirtualizerInstanceRef?: MutableRefObject<Virtualizer<
1133
- HTMLDivElement,
1134
- HTMLTableRowElement
1135
- > | null>;
1193
+ rowVirtualizerInstanceRef?: MutableRefObject<
1194
+ MRT_RowVirtualizer | MRT_Virtualizer | null
1195
+ >;
1136
1196
  rowVirtualizerOptions?:
1137
1197
  | ((props: {
1138
1198
  table: MRT_TableInstance<TData>;