material-react-table 0.36.2 → 0.37.0

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,4 +1,4 @@
1
- import { Dispatch, SetStateAction, ReactNode, DragEvent } from 'react';
1
+ import { MutableRefObject, Dispatch, SetStateAction, ReactNode, DragEvent } from 'react';
2
2
  import { ButtonProps, TextFieldProps, TableCellProps, IconButtonProps, LinearProgressProps, CheckboxProps, SkeletonProps, TableBodyProps, TableRowProps, ToolbarProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, PaperProps, TableProps, 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';
@@ -223,9 +223,16 @@ declare type MRT_TableInstance<TData extends Record<string, any> = {}> = Omit<Ta
223
223
  getState: () => MRT_TableState<TData>;
224
224
  options: MaterialReactTableProps<TData> & {
225
225
  icons: MRT_Icons;
226
- tableId: string;
227
226
  localization: MRT_Localization;
228
227
  };
228
+ refs: {
229
+ bottomToolbarRef: MutableRefObject<HTMLDivElement>;
230
+ editInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
231
+ filterInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
232
+ searchInputRef: MutableRefObject<HTMLInputElement>;
233
+ tableContainerRef: MutableRefObject<HTMLDivElement>;
234
+ topToolbarRef: MutableRefObject<HTMLDivElement>;
235
+ };
229
236
  setColumnFilterFns: Dispatch<SetStateAction<{
230
237
  [key: string]: MRT_FilterOption;
231
238
  }>>;
@@ -269,19 +276,22 @@ declare type MRT_TableState<TData extends Record<string, any> = {}> = TableState
269
276
  showSkeletons: boolean;
270
277
  };
271
278
  declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<ColumnDef<TData, unknown>, 'aggregatedCell' | 'cell' | 'columns' | 'filterFn' | 'footer' | 'header' | 'id' | 'sortingFn'> & {
272
- AggregatedCell?: ({ cell, column, table, }: {
279
+ AggregatedCell?: ({ cell, column, row, table, }: {
273
280
  cell: MRT_Cell<TData>;
274
281
  column: MRT_Column<TData>;
282
+ row: MRT_Row<TData>;
275
283
  table: MRT_TableInstance<TData>;
276
284
  }) => ReactNode;
277
- Cell?: ({ cell, column, table, }: {
285
+ Cell?: ({ cell, column, row, table, }: {
278
286
  cell: MRT_Cell<TData>;
279
287
  column: MRT_Column<TData>;
288
+ row: MRT_Row<TData>;
280
289
  table: MRT_TableInstance<TData>;
281
290
  }) => ReactNode;
282
- Edit?: ({ cell, column, table, }: {
291
+ Edit?: ({ cell, column, row, table, }: {
283
292
  cell: MRT_Cell<TData>;
284
293
  column: MRT_Column<TData>;
294
+ row: MRT_Row<TData>;
285
295
  table: MRT_TableInstance<TData>;
286
296
  }) => ReactNode;
287
297
  Filter?: ({ column, header, table, }: {
@@ -360,8 +370,10 @@ declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<Column
360
370
  table: MRT_TableInstance<TData>;
361
371
  cell: MRT_Cell<TData>;
362
372
  }) => ButtonProps);
363
- muiTableBodyCellEditTextFieldProps?: TextFieldProps | (({ cell, table, }: {
373
+ muiTableBodyCellEditTextFieldProps?: TextFieldProps | (({ cell, column, row, table, }: {
364
374
  cell: MRT_Cell<TData>;
375
+ column: MRT_Column<TData>;
376
+ row: MRT_Row<TData>;
365
377
  table: MRT_TableInstance<TData>;
366
378
  }) => TextFieldProps);
367
379
  muiTableBodyCellProps?: TableCellProps | (({ cell, table, }: {
@@ -422,7 +434,7 @@ declare type MRT_SortingOption = LiteralUnion<string & keyof typeof MRT_SortingF
422
434
  declare type MRT_SortingFn<TData extends Record<string, any> = {}> = SortingFn<TData> | MRT_SortingOption;
423
435
  declare type MRT_FilterOption = LiteralUnion<string & keyof typeof MRT_FilterFns>;
424
436
  declare type MRT_FilterFn<TData extends Record<string, any> = {}> = FilterFn<TData> | MRT_FilterOption;
425
- declare type MRT_DisplayColumnIds = 'mrt-row-drag' | 'mrt-row-actions' | 'mrt-row-expand' | 'mrt-row-select' | 'mrt-row-numbers';
437
+ declare type MRT_DisplayColumnIds = 'mrt-row-actions' | 'mrt-row-drag' | 'mrt-row-expand' | 'mrt-row-numbers' | 'mrt-row-select';
426
438
  /**
427
439
  * `columns` and `data` props are the only required props, but there are over 150 other optional props.
428
440
  *
@@ -492,17 +504,23 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
492
504
  table: MRT_TableInstance<TData>;
493
505
  row: MRT_Row<TData>;
494
506
  }) => CheckboxProps);
495
- muiTableBodyCellCopyButtonProps?: ButtonProps | (({ table, cell, }: {
496
- table: MRT_TableInstance<TData>;
507
+ muiTableBodyCellCopyButtonProps?: ButtonProps | (({ cell, column, row, table, }: {
497
508
  cell: MRT_Cell<TData>;
509
+ column: MRT_Column<TData>;
510
+ row: MRT_Row<TData>;
511
+ table: MRT_TableInstance<TData>;
498
512
  }) => ButtonProps);
499
- muiTableBodyCellEditTextFieldProps?: TextFieldProps | (({ cell, table, }: {
513
+ muiTableBodyCellEditTextFieldProps?: TextFieldProps | (({ cell, column, row, table, }: {
500
514
  cell: MRT_Cell<TData>;
515
+ column: MRT_Column<TData>;
516
+ row: MRT_Row<TData>;
501
517
  table: MRT_TableInstance<TData>;
502
518
  }) => TextFieldProps);
503
- muiTableBodyCellProps?: TableCellProps | (({ table, cell, }: {
504
- table: MRT_TableInstance<TData>;
519
+ muiTableBodyCellProps?: TableCellProps | (({ cell, column, row, table, }: {
505
520
  cell: MRT_Cell<TData>;
521
+ column: MRT_Column<TData>;
522
+ row: MRT_Row<TData>;
523
+ table: MRT_TableInstance<TData>;
506
524
  }) => TableCellProps);
507
525
  muiTableBodyCellSkeletonProps?: SkeletonProps | (({ table, cell, }: {
508
526
  table: MRT_TableInstance<TData>;
@@ -589,7 +607,8 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
589
607
  onDensityChange?: OnChangeFn<boolean>;
590
608
  onDraggingColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
591
609
  onDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
592
- onEditingRowSave?: ({ row, table, values, }: {
610
+ onEditingRowSave?: ({ exitEditingMode, row, table, values, }: {
611
+ exitEditingMode: () => void;
593
612
  row: MRT_Row<TData>;
594
613
  table: MRT_TableInstance<TData>;
595
614
  values: Record<LiteralUnion<string & DeepKeys<TData>>, any>;
@@ -645,7 +664,6 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
645
664
  rowNumberMode?: 'original' | 'static';
646
665
  selectAllMode?: 'all' | 'page';
647
666
  state?: Partial<MRT_TableState<TData>>;
648
- tableId?: string;
649
667
  virtualizerProps?: Partial<Options<HTMLDivElement>> | (({ table, }: {
650
668
  table: MRT_TableInstance<TData>;
651
669
  }) => Partial<Options<HTMLDivElement>>);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.36.2",
2
+ "version": "0.37.0",
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.",
@@ -1,4 +1,10 @@
1
- import React, { Dispatch, DragEvent, ReactNode, SetStateAction } from 'react';
1
+ import React, {
2
+ Dispatch,
3
+ DragEvent,
4
+ MutableRefObject,
5
+ ReactNode,
6
+ SetStateAction,
7
+ } from 'react';
2
8
  import type {
3
9
  AlertProps,
4
10
  ButtonProps,
@@ -86,9 +92,16 @@ export type MRT_TableInstance<TData extends Record<string, any> = {}> = Omit<
86
92
  getState: () => MRT_TableState<TData>;
87
93
  options: MaterialReactTableProps<TData> & {
88
94
  icons: MRT_Icons;
89
- tableId: string;
90
95
  localization: MRT_Localization;
91
96
  };
97
+ refs: {
98
+ bottomToolbarRef: MutableRefObject<HTMLDivElement>;
99
+ editInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
100
+ filterInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
101
+ searchInputRef: MutableRefObject<HTMLInputElement>;
102
+ tableContainerRef: MutableRefObject<HTMLDivElement>;
103
+ topToolbarRef: MutableRefObject<HTMLDivElement>;
104
+ };
92
105
  setColumnFilterFns: Dispatch<
93
106
  SetStateAction<{ [key: string]: MRT_FilterOption }>
94
107
  >;
@@ -144,28 +157,34 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
144
157
  AggregatedCell?: ({
145
158
  cell,
146
159
  column,
160
+ row,
147
161
  table,
148
162
  }: {
149
163
  cell: MRT_Cell<TData>;
150
164
  column: MRT_Column<TData>;
165
+ row: MRT_Row<TData>;
151
166
  table: MRT_TableInstance<TData>;
152
167
  }) => ReactNode;
153
168
  Cell?: ({
154
169
  cell,
155
170
  column,
171
+ row,
156
172
  table,
157
173
  }: {
158
174
  cell: MRT_Cell<TData>;
159
175
  column: MRT_Column<TData>;
176
+ row: MRT_Row<TData>;
160
177
  table: MRT_TableInstance<TData>;
161
178
  }) => ReactNode;
162
179
  Edit?: ({
163
180
  cell,
164
181
  column,
182
+ row,
165
183
  table,
166
184
  }: {
167
185
  cell: MRT_Cell<TData>;
168
186
  column: MRT_Column<TData>;
187
+ row: MRT_Row<TData>;
169
188
  table: MRT_TableInstance<TData>;
170
189
  }) => ReactNode;
171
190
  Filter?: ({
@@ -266,9 +285,13 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
266
285
  | TextFieldProps
267
286
  | (({
268
287
  cell,
288
+ column,
289
+ row,
269
290
  table,
270
291
  }: {
271
292
  cell: MRT_Cell<TData>;
293
+ column: MRT_Column<TData>;
294
+ row: MRT_Row<TData>;
272
295
  table: MRT_TableInstance<TData>;
273
296
  }) => TextFieldProps);
274
297
  muiTableBodyCellProps?:
@@ -398,11 +421,11 @@ export type MRT_FilterFn<TData extends Record<string, any> = {}> =
398
421
  | MRT_FilterOption;
399
422
 
400
423
  export type MRT_DisplayColumnIds =
401
- | 'mrt-row-drag'
402
424
  | 'mrt-row-actions'
425
+ | 'mrt-row-drag'
403
426
  | 'mrt-row-expand'
404
- | 'mrt-row-select'
405
- | 'mrt-row-numbers';
427
+ | 'mrt-row-numbers'
428
+ | 'mrt-row-select';
406
429
 
407
430
  /**
408
431
  * `columns` and `data` props are the only required props, but there are over 150 other optional props.
@@ -501,29 +524,41 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
501
524
  muiTableBodyCellCopyButtonProps?:
502
525
  | ButtonProps
503
526
  | (({
504
- table,
505
527
  cell,
528
+ column,
529
+ row,
530
+ table,
506
531
  }: {
507
- table: MRT_TableInstance<TData>;
508
532
  cell: MRT_Cell<TData>;
533
+ column: MRT_Column<TData>;
534
+ row: MRT_Row<TData>;
535
+ table: MRT_TableInstance<TData>;
509
536
  }) => ButtonProps);
510
537
  muiTableBodyCellEditTextFieldProps?:
511
538
  | TextFieldProps
512
539
  | (({
513
540
  cell,
541
+ column,
542
+ row,
514
543
  table,
515
544
  }: {
516
545
  cell: MRT_Cell<TData>;
546
+ column: MRT_Column<TData>;
547
+ row: MRT_Row<TData>;
517
548
  table: MRT_TableInstance<TData>;
518
549
  }) => TextFieldProps);
519
550
  muiTableBodyCellProps?:
520
551
  | TableCellProps
521
552
  | (({
522
- table,
523
553
  cell,
554
+ column,
555
+ row,
556
+ table,
524
557
  }: {
525
- table: MRT_TableInstance<TData>;
526
558
  cell: MRT_Cell<TData>;
559
+ column: MRT_Column<TData>;
560
+ row: MRT_Row<TData>;
561
+ table: MRT_TableInstance<TData>;
527
562
  }) => TableCellProps);
528
563
  muiTableBodyCellSkeletonProps?:
529
564
  | SkeletonProps
@@ -677,10 +712,12 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
677
712
  onDraggingColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
678
713
  onDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
679
714
  onEditingRowSave?: ({
715
+ exitEditingMode,
680
716
  row,
681
717
  table,
682
718
  values,
683
719
  }: {
720
+ exitEditingMode: () => void;
684
721
  row: MRT_Row<TData>;
685
722
  table: MRT_TableInstance<TData>;
686
723
  values: Record<LiteralUnion<string & DeepKeys<TData>>, any>;
@@ -752,7 +789,6 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
752
789
  rowNumberMode?: 'original' | 'static';
753
790
  selectAllMode?: 'all' | 'page';
754
791
  state?: Partial<MRT_TableState<TData>>;
755
- tableId?: string;
756
792
  virtualizerProps?:
757
793
  | Partial<VirtualizerOptions<HTMLDivElement>>
758
794
  | (({
@@ -774,7 +810,7 @@ export default <TData extends Record<string, any> = {}>({
774
810
  autoResetExpanded = false,
775
811
  columnResizeMode = 'onEnd',
776
812
  defaultColumn = { minSize: 40, maxSize: 1000, size: 180 },
777
- editingMode = 'row',
813
+ editingMode = 'modal',
778
814
  enableBottomToolbar = true,
779
815
  enableColumnActions = true,
780
816
  enableColumnFilterChangeMode = false,
@@ -29,25 +29,27 @@ export const MRT_EditRowModal = <TData extends Record<string, any> = {}>({
29
29
  <Dialog open={open}>
30
30
  <DialogTitle textAlign="center">{localization.edit}</DialogTitle>
31
31
  <DialogContent>
32
- <Stack
33
- sx={{
34
- width: '100%',
35
- minWidth: { xs: '300px', sm: '360px', md: '400px' },
36
- gap: '1.5rem',
37
- }}
38
- >
39
- {row
40
- .getVisibleCells()
41
- .filter((cell) => cell.column.columnDef.columnDefType === 'data')
42
- .map((cell) => (
43
- <MRT_EditCellTextField
44
- cell={cell}
45
- key={cell.id}
46
- showLabel
47
- table={table}
48
- />
49
- ))}
50
- </Stack>
32
+ <form onSubmit={(e) => e.preventDefault()}>
33
+ <Stack
34
+ sx={{
35
+ width: '100%',
36
+ minWidth: { xs: '300px', sm: '360px', md: '400px' },
37
+ gap: '1.5rem',
38
+ }}
39
+ >
40
+ {row
41
+ .getAllCells()
42
+ .filter((cell) => cell.column.columnDef.columnDefType === 'data')
43
+ .map((cell) => (
44
+ <MRT_EditCellTextField
45
+ cell={cell as any}
46
+ key={cell.id}
47
+ showLabel
48
+ table={table as any}
49
+ />
50
+ ))}
51
+ </Stack>
52
+ </form>
51
53
  </DialogContent>
52
54
  <DialogActions sx={{ p: '1.25rem' }}>
53
55
  <MRT_EditActionButtons row={row} table={table} variant="text" />
@@ -48,8 +48,8 @@ export const MRT_TableBodyCell: FC<Props> = ({
48
48
  muiTableBodyCellProps,
49
49
  muiTableBodyCellSkeletonProps,
50
50
  rowNumberMode,
51
- tableId,
52
51
  },
52
+ refs: { editInputRefs },
53
53
  setEditingCell,
54
54
  setHoveredColumn,
55
55
  } = table;
@@ -68,7 +68,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
68
68
 
69
69
  const mTableCellBodyProps =
70
70
  muiTableBodyCellProps instanceof Function
71
- ? muiTableBodyCellProps({ cell, table })
71
+ ? muiTableBodyCellProps({ cell, column, row, table })
72
72
  : muiTableBodyCellProps;
73
73
 
74
74
  const mcTableCellBodyProps =
@@ -115,15 +115,13 @@ export const MRT_TableBodyCell: FC<Props> = ({
115
115
  editingMode === 'cell'
116
116
  ) {
117
117
  setEditingCell(cell);
118
- setTimeout(() => {
119
- const textField = document.getElementById(
120
- `mrt-${tableId}-edit-cell-text-field-${cell.id}`,
121
- ) as HTMLInputElement;
118
+ queueMicrotask(() => {
119
+ const textField = editInputRefs.current[column.id];
122
120
  if (textField) {
123
121
  textField.focus();
124
122
  textField.select();
125
123
  }
126
- }, 200);
124
+ });
127
125
  }
128
126
  };
129
127
 
@@ -279,7 +277,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
279
277
  (column.id === 'mrt-row-select' ||
280
278
  column.id === 'mrt-row-expand' ||
281
279
  !row.getIsGrouped()) ? (
282
- columnDef.Cell?.({ cell, column, table })
280
+ columnDef.Cell?.({ cell, column, row, table })
283
281
  ) : isEditing ? (
284
282
  <MRT_EditCellTextField cell={cell} table={table} />
285
283
  ) : (enableClickToCopy || columnDef.enableClickToCopy) &&
@@ -289,7 +287,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
289
287
  <>
290
288
  {row.getIsGrouped() && !cell.getIsGrouped()
291
289
  ? null
292
- : columnDef?.Cell?.({ cell, column, table }) ??
290
+ : columnDef?.Cell?.({ cell, column, row, table }) ??
293
291
  cell.renderValue()}
294
292
  </>
295
293
  </MRT_CopyButton>
@@ -299,7 +297,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
299
297
  <>
300
298
  {row.getIsGrouped() && !cell.getIsGrouped()
301
299
  ? null
302
- : columnDef?.Cell?.({ cell, column, table }) ??
300
+ : columnDef?.Cell?.({ cell, column, row, table }) ??
303
301
  cell.renderValue()}
304
302
  {cell.getIsGrouped() && <> ({row.subRows?.length ?? ''})</>}
305
303
  </>
@@ -76,8 +76,8 @@ export const MRT_TableBodyRow: FC<Props> = ({ row, rowIndex, table }) => {
76
76
  {row?.getVisibleCells()?.map?.((cell) => (
77
77
  <MRT_TableBodyCell
78
78
  cell={cell}
79
- key={cell.id}
80
79
  enableHover={tableRowProps?.hover !== false}
80
+ key={cell.id}
81
81
  rowIndex={rowIndex}
82
82
  rowRef={rowRef}
83
83
  table={table}
@@ -16,15 +16,16 @@ export const MRT_TableBodyRowGrabHandle: FC<Props> = ({
16
16
  const {
17
17
  options: { muiTableBodyRowDragHandleProps, onRowDrop },
18
18
  } = table;
19
+ const { row } = cell;
19
20
 
20
21
  const iconButtonProps =
21
22
  muiTableBodyRowDragHandleProps instanceof Function
22
- ? muiTableBodyRowDragHandleProps({ row: cell.row, table })
23
+ ? muiTableBodyRowDragHandleProps({ row, table })
23
24
  : muiTableBodyRowDragHandleProps;
24
25
 
25
26
  const handleDragStart = (e: DragEvent<HTMLButtonElement>) => {
26
27
  e.dataTransfer.setDragImage(rowRef.current as HTMLElement, 0, 0);
27
- table.setDraggingRow(cell.row as any);
28
+ table.setDraggingRow(row as any);
28
29
  };
29
30
 
30
31
  const handleDragEnd = (event: DragEvent<HTMLButtonElement>) => {
@@ -12,7 +12,7 @@ export const MRT_CopyButton: FC<Props> = ({ cell, children, table }) => {
12
12
  const {
13
13
  options: { localization, muiTableBodyCellCopyButtonProps },
14
14
  } = table;
15
- const { column } = cell;
15
+ const { column, row } = cell;
16
16
  const { columnDef } = column;
17
17
 
18
18
  const [copied, setCopied] = useState(false);
@@ -25,7 +25,7 @@ export const MRT_CopyButton: FC<Props> = ({ cell, children, table }) => {
25
25
 
26
26
  const mTableBodyCellCopyButtonProps =
27
27
  muiTableBodyCellCopyButtonProps instanceof Function
28
- ? muiTableBodyCellCopyButtonProps({ cell, table })
28
+ ? muiTableBodyCellCopyButtonProps({ cell, column, row, table })
29
29
  : muiTableBodyCellCopyButtonProps;
30
30
 
31
31
  const mcTableBodyCellCopyButtonProps =
@@ -20,21 +20,30 @@ export const MRT_EditActionButtons = <TData extends Record<string, any> = {}>({
20
20
  localization,
21
21
  onEditingRowSave,
22
22
  },
23
+ refs: { editInputRefs },
23
24
  setEditingRow,
24
25
  } = table;
25
26
  const { editingRow } = getState();
26
27
 
27
- const handleCancel = () => {
28
- setEditingRow(null);
29
- };
28
+ const handleCancel = () => setEditingRow(null);
30
29
 
31
30
  const handleSave = () => {
31
+ //look for auto-filled input values
32
+ Object.values(editInputRefs?.current)?.forEach((input) => {
33
+ if (
34
+ input.value !== undefined &&
35
+ Object.hasOwn(editingRow?._valuesCache as object, input.name)
36
+ ) {
37
+ // @ts-ignore
38
+ editingRow._valuesCache[input.name] = input.value;
39
+ }
40
+ });
32
41
  onEditingRowSave?.({
42
+ exitEditingMode: () => setEditingRow(null),
33
43
  row: editingRow ?? row,
34
44
  table,
35
45
  values: editingRow?._valuesCache ?? { ...row.original },
36
46
  });
37
- setEditingRow(null);
38
47
  };
39
48
 
40
49
  return (
@@ -17,30 +17,17 @@ export const MRT_ToggleGlobalFilterButton = <
17
17
  getState,
18
18
  options: {
19
19
  icons: { SearchIcon, SearchOffIcon },
20
- tableId,
20
+
21
21
  localization,
22
- muiSearchTextFieldProps,
23
22
  },
23
+ refs: { searchInputRef },
24
24
  setShowGlobalFilter,
25
25
  } = table;
26
26
  const { showGlobalFilter } = getState();
27
27
 
28
- const textFieldProps =
29
- muiSearchTextFieldProps instanceof Function
30
- ? muiSearchTextFieldProps({ table })
31
- : muiSearchTextFieldProps;
32
-
33
28
  const handleToggleSearch = () => {
34
29
  setShowGlobalFilter(!showGlobalFilter);
35
- setTimeout(
36
- () =>
37
- document
38
- .getElementById(
39
- textFieldProps?.id ?? `mrt-${tableId}-search-text-field`,
40
- )
41
- ?.focus(),
42
- 200,
43
- );
30
+ queueMicrotask(() => searchInputRef.current?.focus());
44
31
  };
45
32
 
46
33
  return (
@@ -74,10 +74,9 @@ export const prepareColumns = <TData extends Record<string, any> = {}>(
74
74
  } else if (columnDef.columnDefType === 'data') {
75
75
  if (Object.keys(filterFns).includes(columnFilterFns[columnDef.id])) {
76
76
  columnDef.filterFn =
77
- // @ts-ignore
78
77
  filterFns[columnFilterFns[columnDef.id]] ?? filterFns.fuzzy;
79
- //@ts-ignore
80
- columnDef._filterFn = columnFilterFns[columnDef.id];
78
+ (columnDef as MRT_DefinedColumnDef)._filterFn =
79
+ columnFilterFns[columnDef.id];
81
80
  }
82
81
  if (Object.keys(sortingFns).includes(columnDef.sortingFn as string)) {
83
82
  // @ts-ignore
@@ -15,11 +15,12 @@ export const MRT_EditCellTextField = <TData extends Record<string, any> = {}>({
15
15
  }: Props<TData>) => {
16
16
  const {
17
17
  getState,
18
- options: { tableId, muiTableBodyCellEditTextFieldProps },
18
+ options: { muiTableBodyCellEditTextFieldProps },
19
+ refs: { editInputRefs },
19
20
  setEditingCell,
20
21
  setEditingRow,
21
22
  } = table;
22
- const { column } = cell;
23
+ const { column, row } = cell;
23
24
  const { columnDef } = column;
24
25
  const { editingRow } = getState();
25
26
 
@@ -27,13 +28,15 @@ export const MRT_EditCellTextField = <TData extends Record<string, any> = {}>({
27
28
 
28
29
  const mTableBodyCellEditTextFieldProps =
29
30
  muiTableBodyCellEditTextFieldProps instanceof Function
30
- ? muiTableBodyCellEditTextFieldProps({ cell, table })
31
+ ? muiTableBodyCellEditTextFieldProps({ cell, column, row, table })
31
32
  : muiTableBodyCellEditTextFieldProps;
32
33
 
33
34
  const mcTableBodyCellEditTextFieldProps =
34
35
  columnDef.muiTableBodyCellEditTextFieldProps instanceof Function
35
36
  ? columnDef.muiTableBodyCellEditTextFieldProps({
36
37
  cell,
38
+ column,
39
+ row,
37
40
  table,
38
41
  })
39
42
  : columnDef.muiTableBodyCellEditTextFieldProps;
@@ -60,21 +63,29 @@ export const MRT_EditCellTextField = <TData extends Record<string, any> = {}>({
60
63
  };
61
64
 
62
65
  if (columnDef.Edit) {
63
- return <>{columnDef.Edit?.({ cell, column, table })}</>;
66
+ return <>{columnDef.Edit?.({ cell, column, row, table })}</>;
64
67
  }
65
68
 
66
69
  return (
67
70
  <TextField
68
71
  disabled={columnDef.enableEditing === false}
69
72
  fullWidth
70
- id={`mrt-${tableId}-edit-cell-text-field-${cell.id}`}
71
73
  label={showLabel ? column.columnDef.header : undefined}
72
74
  margin="none"
75
+ name={cell.id}
73
76
  onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
74
77
  placeholder={columnDef.header}
75
78
  value={value}
76
79
  variant="standard"
77
80
  {...textFieldProps}
81
+ inputRef={(inputRef) => {
82
+ if (inputRef) {
83
+ editInputRefs.current[column.id] = inputRef;
84
+ if (textFieldProps.inputRef) {
85
+ textFieldProps.inputRef = inputRef;
86
+ }
87
+ }
88
+ }}
78
89
  onBlur={handleBlur}
79
90
  onChange={handleChange}
80
91
  />
@@ -40,8 +40,8 @@ export const MRT_FilterTextField: FC<Props> = ({
40
40
  icons: { FilterListIcon, CloseIcon },
41
41
  localization,
42
42
  muiTableHeadCellFilterTextFieldProps,
43
- tableId,
44
43
  },
44
+ refs: { filterInputRefs },
45
45
  setColumnFilterFns,
46
46
  } = table;
47
47
  const { column } = header;
@@ -80,9 +80,6 @@ export const MRT_FilterTextField: FC<Props> = ({
80
80
  (!isSelectFilter && !isMultiSelectFilter);
81
81
 
82
82
  const currentFilterOption = columnFilterFns?.[header.id];
83
- const filterId = `mrt-${tableId}-${header.id}-filter-text-field${
84
- rangeFilterIndex ?? ''
85
- }`;
86
83
  const filterChipLabel = ['empty', 'notEmpty'].includes(currentFilterOption)
87
84
  ? //@ts-ignore
88
85
  localization[
@@ -184,7 +181,6 @@ export const MRT_FilterTextField: FC<Props> = ({
184
181
  <>
185
182
  <TextField
186
183
  fullWidth
187
- id={filterId}
188
184
  inputProps={{
189
185
  disabled: !!filterChipLabel,
190
186
  sx: {
@@ -195,7 +191,7 @@ export const MRT_FilterTextField: FC<Props> = ({
195
191
  }}
196
192
  helperText={
197
193
  showChangeModeButton ? (
198
- <label htmlFor={filterId}>
194
+ <label>
199
195
  {localization.filterMode.replace(
200
196
  '{filterType}',
201
197
  // @ts-ignore
@@ -294,6 +290,13 @@ export const MRT_FilterTextField: FC<Props> = ({
294
290
  : undefined,
295
291
  }}
296
292
  {...textFieldProps}
293
+ inputRef={(inputRef) => {
294
+ filterInputRefs.current[`${column.id}-${rangeFilterIndex ?? 0}`] =
295
+ inputRef;
296
+ if (textFieldProps.inputRef) {
297
+ textFieldProps.inputRef = inputRef;
298
+ }
299
+ }}
297
300
  sx={(theme) => ({
298
301
  p: 0,
299
302
  minWidth: !filterChipLabel ? '6rem' : 'auto',