material-react-table 0.37.2 → 0.38.2

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
@@ -1,5 +1,5 @@
1
1
  import { MutableRefObject, Dispatch, SetStateAction, ReactNode, DragEvent } from 'react';
2
- import { ButtonProps, TextFieldProps, TableCellProps, IconButtonProps, LinearProgressProps, CheckboxProps, SkeletonProps, TableBodyProps, TableRowProps, ToolbarProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, PaperProps, TableProps, AlertProps } from '@mui/material';
2
+ import { ButtonProps, TextFieldProps, TableCellProps, IconButtonProps, ToolbarProps, LinearProgressProps, CheckboxProps, SkeletonProps, TableBodyProps, TableRowProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, PaperProps, TableProps, ChipProps, AlertProps } from '@mui/material';
3
3
  import { Row, Table, TableState, ColumnDef, DeepKeys, Column, Header, HeaderGroup, Cell, SortingFn, FilterFn, TableOptions, OnChangeFn } from '@tanstack/react-table';
4
4
  import { Options } from 'react-virtual';
5
5
  import * as _tanstack_table_core from '@tanstack/table-core';
@@ -239,8 +239,8 @@ declare type MRT_TableInstance<TData extends Record<string, any> = {}> = Omit<Ta
239
239
  setDensity: Dispatch<SetStateAction<'comfortable' | 'compact' | 'spacious'>>;
240
240
  setDraggingColumn: Dispatch<SetStateAction<MRT_Column<TData> | null>>;
241
241
  setDraggingRow: Dispatch<SetStateAction<MRT_Row<TData> | null>>;
242
- setEditingCell: Dispatch<SetStateAction<MRT_Cell | null>>;
243
- setEditingRow: Dispatch<SetStateAction<MRT_Row | null>>;
242
+ setEditingCell: Dispatch<SetStateAction<MRT_Cell<TData> | null>>;
243
+ setEditingRow: Dispatch<SetStateAction<MRT_Row<TData> | null>>;
244
244
  setGlobalFilterFn: Dispatch<SetStateAction<MRT_FilterOption>>;
245
245
  setHoveredColumn: Dispatch<SetStateAction<MRT_Column<TData> | {
246
246
  id: string;
@@ -304,6 +304,12 @@ declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<Column
304
304
  footer: MRT_Header<TData>;
305
305
  table: MRT_TableInstance<TData>;
306
306
  }) => ReactNode);
307
+ GroupedCell?: ({ cell, column, row, table, }: {
308
+ cell: MRT_Cell<TData>;
309
+ column: MRT_Column<TData>;
310
+ row: MRT_Row<TData>;
311
+ table: MRT_TableInstance<TData>;
312
+ }) => ReactNode;
307
313
  Header?: ReactNode | (({ column, header, table, }: {
308
314
  column: MRT_Column<TData>;
309
315
  header: MRT_Header<TData>;
@@ -483,6 +489,9 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
483
489
  icons?: Partial<MRT_Icons>;
484
490
  initialState?: Partial<MRT_TableState<TData>>;
485
491
  localization?: Partial<MRT_Localization>;
492
+ muiBottomToolbarProps?: ToolbarProps | (({ table }: {
493
+ table: MRT_TableInstance<TData>;
494
+ }) => ToolbarProps);
486
495
  muiExpandAllButtonProps?: IconButtonProps | (({ table }: {
487
496
  table: MRT_TableInstance<TData>;
488
497
  }) => IconButtonProps);
@@ -537,9 +546,6 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
537
546
  table: MRT_TableInstance<TData>;
538
547
  row: MRT_Row<TData>;
539
548
  }) => TableRowProps);
540
- muiTableBottomToolbarProps?: ToolbarProps | (({ table }: {
541
- table: MRT_TableInstance<TData>;
542
- }) => ToolbarProps);
543
549
  muiTableContainerProps?: TableContainerProps | (({ table, }: {
544
550
  table: MRT_TableInstance<TData>;
545
551
  }) => TableContainerProps);
@@ -591,10 +597,13 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
591
597
  muiTableProps?: TableProps | (({ table }: {
592
598
  table: MRT_TableInstance<TData>;
593
599
  }) => TableProps);
594
- muiTableToolbarAlertBannerProps?: AlertProps | (({ table }: {
600
+ muiToolbarAlertBannerChipProps?: ChipProps | (({ table }: {
601
+ table: MRT_TableInstance<TData>;
602
+ }) => ChipProps);
603
+ muiToolbarAlertBannerProps?: AlertProps | (({ table }: {
595
604
  table: MRT_TableInstance<TData>;
596
605
  }) => AlertProps);
597
- muiTableTopToolbarProps?: ToolbarProps | (({ table }: {
606
+ muiTopToolbarProps?: ToolbarProps | (({ table }: {
598
607
  table: MRT_TableInstance<TData>;
599
608
  }) => ToolbarProps);
600
609
  onColumnDrop?: ({ event, draggedColumn, targetColumn, }: {
@@ -607,13 +616,13 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
607
616
  onDensityChange?: OnChangeFn<boolean>;
608
617
  onDraggingColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
609
618
  onDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
619
+ onEditingCellChange?: OnChangeFn<MRT_Cell<TData> | null>;
610
620
  onEditingRowSave?: ({ exitEditingMode, row, table, values, }: {
611
621
  exitEditingMode: () => void;
612
622
  row: MRT_Row<TData>;
613
623
  table: MRT_TableInstance<TData>;
614
624
  values: Record<LiteralUnion<string & DeepKeys<TData>>, any>;
615
625
  }) => Promise<void> | void;
616
- onEditingCellChange?: OnChangeFn<MRT_Cell<TData> | null>;
617
626
  onEditingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
618
627
  onFilterFnsChange?: OnChangeFn<{
619
628
  [key: string]: MRT_FilterOption;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.37.2",
2
+ "version": "0.38.2",
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.",
@@ -9,6 +9,7 @@ import type {
9
9
  AlertProps,
10
10
  ButtonProps,
11
11
  CheckboxProps,
12
+ ChipProps,
12
13
  IconButtonProps,
13
14
  LinearProgressProps,
14
15
  PaperProps,
@@ -108,8 +109,8 @@ export type MRT_TableInstance<TData extends Record<string, any> = {}> = Omit<
108
109
  setDensity: Dispatch<SetStateAction<'comfortable' | 'compact' | 'spacious'>>;
109
110
  setDraggingColumn: Dispatch<SetStateAction<MRT_Column<TData> | null>>;
110
111
  setDraggingRow: Dispatch<SetStateAction<MRT_Row<TData> | null>>;
111
- setEditingCell: Dispatch<SetStateAction<MRT_Cell | null>>;
112
- setEditingRow: Dispatch<SetStateAction<MRT_Row | null>>;
112
+ setEditingCell: Dispatch<SetStateAction<MRT_Cell<TData> | null>>;
113
+ setEditingRow: Dispatch<SetStateAction<MRT_Row<TData> | null>>;
113
114
  setGlobalFilterFn: Dispatch<SetStateAction<MRT_FilterOption>>;
114
115
  setHoveredColumn: Dispatch<
115
116
  SetStateAction<MRT_Column<TData> | { id: string } | null>
@@ -207,6 +208,17 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
207
208
  footer: MRT_Header<TData>;
208
209
  table: MRT_TableInstance<TData>;
209
210
  }) => ReactNode);
211
+ GroupedCell?: ({
212
+ cell,
213
+ column,
214
+ row,
215
+ table,
216
+ }: {
217
+ cell: MRT_Cell<TData>;
218
+ column: MRT_Column<TData>;
219
+ row: MRT_Row<TData>;
220
+ table: MRT_TableInstance<TData>;
221
+ }) => ReactNode;
210
222
  Header?:
211
223
  | ReactNode
212
224
  | (({
@@ -486,6 +498,9 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
486
498
  icons?: Partial<MRT_Icons>;
487
499
  initialState?: Partial<MRT_TableState<TData>>;
488
500
  localization?: Partial<MRT_Localization>;
501
+ muiBottomToolbarProps?:
502
+ | ToolbarProps
503
+ | (({ table }: { table: MRT_TableInstance<TData> }) => ToolbarProps);
489
504
  muiExpandAllButtonProps?:
490
505
  | IconButtonProps
491
506
  | (({ table }: { table: MRT_TableInstance<TData> }) => IconButtonProps);
@@ -590,9 +605,6 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
590
605
  table: MRT_TableInstance<TData>;
591
606
  row: MRT_Row<TData>;
592
607
  }) => TableRowProps);
593
- muiTableBottomToolbarProps?:
594
- | ToolbarProps
595
- | (({ table }: { table: MRT_TableInstance<TData> }) => ToolbarProps);
596
608
  muiTableContainerProps?:
597
609
  | TableContainerProps
598
610
  | (({
@@ -693,10 +705,13 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
693
705
  muiTableProps?:
694
706
  | TableProps
695
707
  | (({ table }: { table: MRT_TableInstance<TData> }) => TableProps);
696
- muiTableToolbarAlertBannerProps?:
708
+ muiToolbarAlertBannerChipProps?:
709
+ | ChipProps
710
+ | (({ table }: { table: MRT_TableInstance<TData> }) => ChipProps);
711
+ muiToolbarAlertBannerProps?:
697
712
  | AlertProps
698
713
  | (({ table }: { table: MRT_TableInstance<TData> }) => AlertProps);
699
- muiTableTopToolbarProps?:
714
+ muiTopToolbarProps?:
700
715
  | ToolbarProps
701
716
  | (({ table }: { table: MRT_TableInstance<TData> }) => ToolbarProps);
702
717
  onColumnDrop?: ({
@@ -711,6 +726,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
711
726
  onDensityChange?: OnChangeFn<boolean>;
712
727
  onDraggingColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
713
728
  onDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
729
+ onEditingCellChange?: OnChangeFn<MRT_Cell<TData> | null>;
714
730
  onEditingRowSave?: ({
715
731
  exitEditingMode,
716
732
  row,
@@ -722,7 +738,6 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
722
738
  table: MRT_TableInstance<TData>;
723
739
  values: Record<LiteralUnion<string & DeepKeys<TData>>, any>;
724
740
  }) => Promise<void> | void;
725
- onEditingCellChange?: OnChangeFn<MRT_Cell<TData> | null>;
726
741
  onEditingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
727
742
  onFilterFnsChange?: OnChangeFn<{ [key: string]: MRT_FilterOption }>;
728
743
  onGlobalFilterFnChange?: OnChangeFn<MRT_FilterOption>;
@@ -290,7 +290,9 @@ export const MRT_TableBodyCell: FC<Props> = ({
290
290
  <MRT_TableBodyCellValue cell={cell} table={table} />
291
291
  )}
292
292
  </>
293
- {cell.getIsGrouped() && <> ({row.subRows?.length})</>}
293
+ {cell.getIsGrouped() && !columnDef.GroupedCell && (
294
+ <> ({row.subRows?.length})</>
295
+ )}
294
296
  </TableCell>
295
297
  );
296
298
  };
@@ -21,7 +21,15 @@ export const MRT_TableBodyCellValue: FC<Props> = ({ cell, table }) => {
21
21
  })
22
22
  : row.getIsGrouped() && !cell.getIsGrouped()
23
23
  ? null
24
- : columnDef?.Cell?.({ cell, column, row, table }) ?? cell.renderValue()}
24
+ : (cell.getIsGrouped() &&
25
+ columnDef.GroupedCell?.({
26
+ cell,
27
+ column,
28
+ row,
29
+ table,
30
+ })) ||
31
+ (columnDef?.Cell?.({ cell, column, row, table }) ??
32
+ cell.renderValue())}
25
33
  </>
26
34
  );
27
35
  };
@@ -1,4 +1,10 @@
1
- import React, { ChangeEvent, FocusEvent, MouseEvent, useState } from 'react';
1
+ import React, {
2
+ ChangeEvent,
3
+ FocusEvent,
4
+ KeyboardEvent,
5
+ MouseEvent,
6
+ useState,
7
+ } from 'react';
2
8
  import { TextField, TextFieldProps } from '@mui/material';
3
9
  import type { MRT_Cell, MRT_TableInstance } from '..';
4
10
 
@@ -46,22 +52,36 @@ export const MRT_EditCellTextField = <TData extends Record<string, any> = {}>({
46
52
  ...mcTableBodyCellEditTextFieldProps,
47
53
  };
48
54
 
55
+ const saveRow = (newValue: string) => {
56
+ if (editingRow) {
57
+ setEditingRow({
58
+ ...editingRow,
59
+ _valuesCache: { ...editingRow._valuesCache, [column.id]: newValue },
60
+ });
61
+ }
62
+ };
63
+
49
64
  const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
50
65
  textFieldProps.onChange?.(event);
51
66
  setValue(event.target.value);
67
+ if (textFieldProps?.select) {
68
+ saveRow(event.target.value);
69
+ }
52
70
  };
53
71
 
54
72
  const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
55
73
  textFieldProps.onBlur?.(event);
56
- if (editingRow) {
57
- setEditingRow({
58
- ...editingRow,
59
- _valuesCache: { ...editingRow._valuesCache, [column.id]: value },
60
- } as any);
61
- }
74
+ saveRow(value);
62
75
  setEditingCell(null);
63
76
  };
64
77
 
78
+ const handleEnterKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
79
+ textFieldProps.onKeyDown?.(event);
80
+ if (event.key === 'Enter') {
81
+ editInputRefs.current[column.id]?.blur();
82
+ }
83
+ };
84
+
65
85
  if (columnDef.Edit) {
66
86
  return <>{columnDef.Edit?.({ cell, column, row, table })}</>;
67
87
  }
@@ -70,14 +90,6 @@ export const MRT_EditCellTextField = <TData extends Record<string, any> = {}>({
70
90
  <TextField
71
91
  disabled={columnDef.enableEditing === false}
72
92
  fullWidth
73
- label={showLabel ? column.columnDef.header : undefined}
74
- margin="none"
75
- name={cell.id}
76
- onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
77
- placeholder={columnDef.header}
78
- value={value}
79
- variant="standard"
80
- {...textFieldProps}
81
93
  inputRef={(inputRef) => {
82
94
  if (inputRef) {
83
95
  editInputRefs.current[column.id] = inputRef;
@@ -86,8 +98,17 @@ export const MRT_EditCellTextField = <TData extends Record<string, any> = {}>({
86
98
  }
87
99
  }
88
100
  }}
101
+ label={showLabel ? column.columnDef.header : undefined}
102
+ margin="none"
103
+ name={column.id}
104
+ onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
105
+ placeholder={columnDef.header}
106
+ value={value}
107
+ variant="standard"
108
+ {...textFieldProps}
89
109
  onBlur={handleBlur}
90
110
  onChange={handleChange}
111
+ onKeyDown={handleEnterKeyDown}
91
112
  />
92
113
  );
93
114
  };
@@ -299,7 +299,7 @@ export const MRT_FilterTextField: FC<Props> = ({
299
299
  }}
300
300
  sx={(theme) => ({
301
301
  p: 0,
302
- minWidth: !filterChipLabel ? '6rem' : 'auto',
302
+ minWidth: !filterChipLabel ? '150px' : 'auto',
303
303
  width: '100%',
304
304
  '& .MuiSelect-icon': {
305
305
  mr: '1.5rem',
@@ -16,7 +16,7 @@ export const MRT_BottomToolbar: FC<Props> = ({ table }) => {
16
16
  getState,
17
17
  options: {
18
18
  enablePagination,
19
- muiTableBottomToolbarProps,
19
+ muiBottomToolbarProps,
20
20
  positionPagination,
21
21
  positionToolbarAlertBanner,
22
22
  positionToolbarDropZone,
@@ -29,9 +29,9 @@ export const MRT_BottomToolbar: FC<Props> = ({ table }) => {
29
29
  const isMobile = useMediaQuery('(max-width:720px)');
30
30
 
31
31
  const toolbarProps =
32
- muiTableBottomToolbarProps instanceof Function
33
- ? muiTableBottomToolbarProps({ table })
34
- : muiTableBottomToolbarProps;
32
+ muiBottomToolbarProps instanceof Function
33
+ ? muiBottomToolbarProps({ table })
34
+ : muiBottomToolbarProps;
35
35
 
36
36
  const stackAlertBanner = isMobile || !!renderBottomToolbarCustomActions;
37
37
 
@@ -15,14 +15,23 @@ export const MRT_ToolbarAlertBanner: FC<Props> = ({
15
15
  getPrePaginationRowModel,
16
16
  getSelectedRowModel,
17
17
  getState,
18
- options: { localization, muiTableToolbarAlertBannerProps },
18
+ options: {
19
+ localization,
20
+ muiToolbarAlertBannerProps,
21
+ muiToolbarAlertBannerChipProps,
22
+ },
19
23
  } = table;
20
24
  const { grouping, showAlertBanner } = getState();
21
25
 
22
26
  const alertProps =
23
- muiTableToolbarAlertBannerProps instanceof Function
24
- ? muiTableToolbarAlertBannerProps({ table })
25
- : muiTableToolbarAlertBannerProps;
27
+ muiToolbarAlertBannerProps instanceof Function
28
+ ? muiToolbarAlertBannerProps({ table })
29
+ : muiToolbarAlertBannerProps;
30
+
31
+ const chipProps =
32
+ muiToolbarAlertBannerChipProps instanceof Function
33
+ ? muiToolbarAlertBannerChipProps({ table })
34
+ : muiToolbarAlertBannerChipProps;
26
35
 
27
36
  const selectMessage =
28
37
  getSelectedRowModel().rows.length > 0
@@ -45,9 +54,9 @@ export const MRT_ToolbarAlertBanner: FC<Props> = ({
45
54
  <Fragment key={`${index}-${columnId}`}>
46
55
  {index > 0 ? localization.thenBy : ''}
47
56
  <Chip
48
- color="secondary"
49
57
  label={table.getColumn(columnId).columnDef.header}
50
58
  onDelete={() => table.getColumn(columnId).toggleGrouping()}
59
+ {...chipProps}
51
60
  />
52
61
  </Fragment>
53
62
  ))}
@@ -31,7 +31,7 @@ export const MRT_TopToolbar: FC<Props> = ({ table }) => {
31
31
  enableGlobalFilter,
32
32
  enablePagination,
33
33
  enableToolbarInternalActions,
34
- muiTableTopToolbarProps,
34
+ muiTopToolbarProps,
35
35
  positionGlobalFilter,
36
36
  positionPagination,
37
37
  positionToolbarAlertBanner,
@@ -46,9 +46,9 @@ export const MRT_TopToolbar: FC<Props> = ({ table }) => {
46
46
  const isMobile = useMediaQuery('(max-width:720px)');
47
47
 
48
48
  const toolbarProps =
49
- muiTableTopToolbarProps instanceof Function
50
- ? muiTableTopToolbarProps({ table })
51
- : muiTableTopToolbarProps;
49
+ muiTopToolbarProps instanceof Function
50
+ ? muiTopToolbarProps({ table })
51
+ : muiTopToolbarProps;
52
52
 
53
53
  const stackAlertBanner =
54
54
  isMobile || !!renderTopToolbarCustomActions || showGlobalFilter;