material-react-table 2.4.0 → 2.5.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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.4.0",
2
+ "version": "2.5.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.",
@@ -118,4 +118,4 @@
118
118
  "@tanstack/react-virtual": "3.0.1",
119
119
  "highlight-words": "1.2.2"
120
120
  }
121
- }
121
+ }
@@ -16,13 +16,11 @@ import {
16
16
  interface Props<TData extends MRT_RowData> extends TableBodyProps {
17
17
  columnVirtualizer?: MRT_ColumnVirtualizer;
18
18
  table: MRT_TableInstance<TData>;
19
- virtualColumns?: VirtualItem[];
20
19
  }
21
20
 
22
21
  export const MRT_TableBody = <TData extends MRT_RowData>({
23
22
  columnVirtualizer,
24
23
  table,
25
- virtualColumns,
26
24
  ...rest
27
25
  }: Props<TData>) => {
28
26
  const {
@@ -70,15 +68,12 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
70
68
 
71
69
  const rowVirtualizer = useMRT_RowVirtualizer(table, rows);
72
70
 
73
- const virtualRows = rowVirtualizer
74
- ? rowVirtualizer.getVirtualItems()
75
- : undefined;
71
+ const { virtualRows } = rowVirtualizer ?? {};
76
72
 
77
73
  const commonRowProps = {
78
74
  columnVirtualizer,
79
75
  numRows: rows.length,
80
76
  table,
81
- virtualColumns,
82
77
  };
83
78
 
84
79
  const CreatingRow = creatingRow && createDisplayMode === 'row' && (
@@ -186,13 +181,11 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
186
181
  ? (rowOrVirtualRow as VirtualItem)
187
182
  : undefined,
188
183
  };
184
+ const key = `${row.id}-${row.index}`;
189
185
  return memoMode === 'rows' ? (
190
- <Memo_MRT_TableBodyRow
191
- key={`${row.id}-${row.index}`}
192
- {...props}
193
- />
186
+ <Memo_MRT_TableBodyRow key={key} {...props} />
194
187
  ) : (
195
- <MRT_TableBodyRow key={`${row.id}-${row.index}`} {...props} />
188
+ <MRT_TableBodyRow key={key} {...props} />
196
189
  );
197
190
  })}
198
191
  </>
@@ -217,7 +210,7 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
217
210
  rowIndex,
218
211
  };
219
212
  return memoMode === 'rows' ? (
220
- <Memo_MRT_TableBodyRow key={`${row.id}`} {...props} />
213
+ <Memo_MRT_TableBodyRow key={row.id} {...props} />
221
214
  ) : (
222
215
  <MRT_TableBodyRow key={row.id} {...props} />
223
216
  );
@@ -11,7 +11,6 @@ import Skeleton from '@mui/material/Skeleton';
11
11
  import TableCell, { type TableCellProps } from '@mui/material/TableCell';
12
12
  import { useTheme } from '@mui/material/styles';
13
13
  import { MRT_TableBodyCellValue } from './MRT_TableBodyCellValue';
14
- import { MRT_TableBodyRowGrabHandle } from './MRT_TableBodyRowGrabHandle';
15
14
  import { MRT_CopyButton } from '../buttons/MRT_CopyButton';
16
15
  import {
17
16
  getIsFirstColumn,
@@ -58,11 +57,9 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
58
57
  enableColumnOrdering,
59
58
  enableEditing,
60
59
  enableGrouping,
61
- enableRowNumbers,
62
60
  layoutMode,
63
61
  muiSkeletonProps,
64
62
  muiTableBodyCellProps,
65
- rowNumberDisplayMode,
66
63
  },
67
64
  refs: { editInputRefs },
68
65
  setEditingCell,
@@ -210,6 +207,11 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
210
207
  }
211
208
  };
212
209
 
210
+ const cellValueProps = {
211
+ cell,
212
+ table,
213
+ };
214
+
213
215
  return (
214
216
  <TableCell
215
217
  data-index={virtualColumnIndex}
@@ -286,25 +288,18 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
286
288
  width={skeletonWidth}
287
289
  {...skeletonProps}
288
290
  />
289
- ) : enableRowNumbers &&
290
- rowNumberDisplayMode === 'static' &&
291
- column.id === 'mrt-row-numbers' ? (
292
- rowIndex + 1
293
- ) : column.id === 'mrt-row-drag' ? (
294
- <MRT_TableBodyRowGrabHandle
295
- row={row}
296
- rowRef={rowRef}
297
- table={table}
298
- />
299
291
  ) : columnDefType === 'display' &&
300
- (column.id === 'mrt-row-select' ||
301
- column.id === 'mrt-row-expand' ||
292
+ (['mrt-row-expand', 'mrt-row-numbers', 'mrt-row-select'].includes(
293
+ column.id,
294
+ ) ||
302
295
  !row.getIsGrouped()) ? (
303
296
  columnDef.Cell?.({
304
297
  cell,
305
298
  column,
306
299
  renderedCellValue: cell.renderValue() as any,
307
300
  row,
301
+ rowRef,
302
+ staticRowIndex: rowIndex,
308
303
  table,
309
304
  })
310
305
  ) : isCreating || isEditing ? (
@@ -312,10 +307,10 @@ export const MRT_TableBodyCell = <TData extends MRT_RowData>({
312
307
  ) : (enableClickToCopy || columnDef.enableClickToCopy) &&
313
308
  columnDef.enableClickToCopy !== false ? (
314
309
  <MRT_CopyButton cell={cell} table={table}>
315
- <MRT_TableBodyCellValue cell={cell} table={table} />
310
+ <MRT_TableBodyCellValue {...cellValueProps} />
316
311
  </MRT_CopyButton>
317
312
  ) : (
318
- <MRT_TableBodyCellValue cell={cell} table={table} />
313
+ <MRT_TableBodyCellValue {...cellValueProps} />
319
314
  )}
320
315
  {cell.getIsGrouped() && !columnDef.GroupedCell && (
321
316
  <> ({row.subRows?.length})</>
@@ -1,4 +1,4 @@
1
- import { type ReactNode } from 'react';
1
+ import { type ReactNode, type RefObject } from 'react';
2
2
  import Box from '@mui/material/Box';
3
3
  import { getMRTTheme } from '../style.utils';
4
4
  import {
@@ -12,11 +12,15 @@ const allowedTypes = ['string', 'number'];
12
12
 
13
13
  interface Props<TData extends MRT_RowData> {
14
14
  cell: MRT_Cell<TData>;
15
+ rowRef?: RefObject<HTMLTableRowElement>;
16
+ staticRowIndex?: number;
15
17
  table: MRT_TableInstance<TData>;
16
18
  }
17
19
 
18
20
  export const MRT_TableBodyCellValue = <TData extends MRT_RowData>({
19
21
  cell,
22
+ rowRef,
23
+ staticRowIndex,
20
24
  table,
21
25
  }: Props<TData>) => {
22
26
  const {
@@ -108,6 +112,8 @@ export const MRT_TableBodyCellValue = <TData extends MRT_RowData>({
108
112
  column,
109
113
  renderedCellValue,
110
114
  row,
115
+ rowRef,
116
+ staticRowIndex,
111
117
  table,
112
118
  });
113
119
  }
@@ -28,7 +28,6 @@ interface Props<TData extends MRT_RowData> {
28
28
  row: MRT_Row<TData>;
29
29
  rowIndex: number;
30
30
  table: MRT_TableInstance<TData>;
31
- virtualColumns?: VirtualItem[];
32
31
  virtualRow?: VirtualItem;
33
32
  }
34
33
 
@@ -40,7 +39,6 @@ export const MRT_TableBodyRow = <TData extends MRT_RowData>({
40
39
  row,
41
40
  rowIndex,
42
41
  table,
43
- virtualColumns,
44
42
  virtualRow,
45
43
  }: Props<TData>) => {
46
44
  const theme = useTheme();
@@ -72,7 +70,8 @@ export const MRT_TableBodyRow = <TData extends MRT_RowData>({
72
70
  rowPinning,
73
71
  } = getState();
74
72
 
75
- const { virtualPaddingLeft, virtualPaddingRight } = columnVirtualizer ?? {};
73
+ const { virtualColumns, virtualPaddingLeft, virtualPaddingRight } =
74
+ columnVirtualizer ?? {};
76
75
 
77
76
  const isPinned = enableRowPinning && row.getIsPinned();
78
77
 
@@ -314,9 +314,10 @@ export const createRow = <TData extends MRT_RowData>(
314
314
 
315
315
  export const extraIndexRangeExtractor = (
316
316
  range: Range,
317
- draggingIndex: number,
317
+ draggingIndex?: number,
318
318
  ) => {
319
319
  const newIndexes = defaultRangeExtractor(range);
320
+ if (draggingIndex === undefined) return newIndexes;
320
321
  if (
321
322
  draggingIndex >= 0 &&
322
323
  draggingIndex < Math.max(range.startIndex - range.overscan, 0)
@@ -1,4 +1,3 @@
1
- import { type VirtualItem } from '@tanstack/react-virtual';
2
1
  import TableFooter, { type TableFooterProps } from '@mui/material/TableFooter';
3
2
  import { MRT_TableFooterRow } from './MRT_TableFooterRow';
4
3
  import { parseFromValuesOrFunc } from '../column.utils';
@@ -11,13 +10,11 @@ import {
11
10
  interface Props<TData extends MRT_RowData> extends TableFooterProps {
12
11
  columnVirtualizer?: MRT_ColumnVirtualizer;
13
12
  table: MRT_TableInstance<TData>;
14
- virtualColumns?: VirtualItem[];
15
13
  }
16
14
 
17
15
  export const MRT_TableFooter = <TData extends MRT_RowData>({
18
16
  columnVirtualizer,
19
17
  table,
20
- virtualColumns,
21
18
  ...rest
22
19
  }: Props<TData>) => {
23
20
  const {
@@ -68,7 +65,6 @@ export const MRT_TableFooter = <TData extends MRT_RowData>({
68
65
  footerGroup={footerGroup as any}
69
66
  key={footerGroup.id}
70
67
  table={table}
71
- virtualColumns={virtualColumns}
72
68
  />
73
69
  ))}
74
70
  </TableFooter>
@@ -1,4 +1,3 @@
1
- import { type VirtualItem } from '@tanstack/react-virtual';
2
1
  import TableRow, { type TableRowProps } from '@mui/material/TableRow';
3
2
  import { MRT_TableFooterCell } from './MRT_TableFooterCell';
4
3
  import { parseFromValuesOrFunc } from '../column.utils';
@@ -15,21 +14,20 @@ interface Props<TData extends MRT_RowData> extends TableRowProps {
15
14
  columnVirtualizer?: MRT_ColumnVirtualizer;
16
15
  footerGroup: MRT_HeaderGroup<TData>;
17
16
  table: MRT_TableInstance<TData>;
18
- virtualColumns?: VirtualItem[];
19
17
  }
20
18
 
21
19
  export const MRT_TableFooterRow = <TData extends MRT_RowData>({
22
20
  columnVirtualizer,
23
21
  footerGroup,
24
22
  table,
25
- virtualColumns,
26
23
  ...rest
27
24
  }: Props<TData>) => {
28
25
  const {
29
26
  options: { layoutMode, muiTableFooterRowProps },
30
27
  } = table;
31
28
 
32
- const { virtualPaddingLeft, virtualPaddingRight } = columnVirtualizer ?? {};
29
+ const { virtualColumns, virtualPaddingLeft, virtualPaddingRight } =
30
+ columnVirtualizer ?? {};
33
31
 
34
32
  // if no content in row, skip row
35
33
  if (
@@ -1,4 +1,3 @@
1
- import { type VirtualItem } from '@tanstack/react-virtual';
2
1
  import TableHead, { type TableHeadProps } from '@mui/material/TableHead';
3
2
  import { MRT_TableHeadRow } from './MRT_TableHeadRow';
4
3
  import { parseFromValuesOrFunc } from '../column.utils';
@@ -12,13 +11,11 @@ import {
12
11
  interface Props<TData extends MRT_RowData> extends TableHeadProps {
13
12
  columnVirtualizer?: MRT_ColumnVirtualizer;
14
13
  table: MRT_TableInstance<TData>;
15
- virtualColumns?: VirtualItem[];
16
14
  }
17
15
 
18
16
  export const MRT_TableHead = <TData extends MRT_RowData>({
19
17
  columnVirtualizer,
20
18
  table,
21
- virtualColumns,
22
19
  ...rest
23
20
  }: Props<TData>) => {
24
21
  const {
@@ -85,7 +82,6 @@ export const MRT_TableHead = <TData extends MRT_RowData>({
85
82
  headerGroup={headerGroup as any}
86
83
  key={headerGroup.id}
87
84
  table={table}
88
- virtualColumns={virtualColumns}
89
85
  />
90
86
  ))
91
87
  )}
@@ -1,4 +1,3 @@
1
- import { type VirtualItem } from '@tanstack/react-virtual';
2
1
  import { alpha } from '@mui/material';
3
2
  import TableRow, { type TableRowProps } from '@mui/material/TableRow';
4
3
  import { MRT_TableHeadCell } from './MRT_TableHeadCell';
@@ -16,21 +15,20 @@ interface Props<TData extends MRT_RowData> extends TableRowProps {
16
15
  columnVirtualizer?: MRT_ColumnVirtualizer;
17
16
  headerGroup: MRT_HeaderGroup<TData>;
18
17
  table: MRT_TableInstance<TData>;
19
- virtualColumns?: VirtualItem[];
20
18
  }
21
19
 
22
20
  export const MRT_TableHeadRow = <TData extends MRT_RowData>({
23
21
  columnVirtualizer,
24
22
  headerGroup,
25
23
  table,
26
- virtualColumns,
27
24
  ...rest
28
25
  }: Props<TData>) => {
29
26
  const {
30
27
  options: { layoutMode, muiTableHeadRowProps },
31
28
  } = table;
32
29
 
33
- const { virtualPaddingLeft, virtualPaddingRight } = columnVirtualizer ?? {};
30
+ const { virtualColumns, virtualPaddingLeft, virtualPaddingRight } =
31
+ columnVirtualizer ?? {};
34
32
 
35
33
  const tableRowProps = {
36
34
  ...parseFromValuesOrFunc(muiTableHeadRowProps, {
@@ -1,8 +1,5 @@
1
1
  import { useCallback, useMemo } from 'react';
2
- import {
3
- type Range,
4
- useVirtualizer,
5
- } from '@tanstack/react-virtual';
2
+ import { type Range, useVirtualizer } from '@tanstack/react-virtual';
6
3
  import {
7
4
  extraIndexRangeExtractor,
8
5
  parseFromValuesOrFunc,
@@ -49,7 +46,8 @@ export const useMRT_ColumnVirtualizer = <
49
46
  .map(
50
47
  (c) =>
51
48
  table.getVisibleLeafColumns().length - c.getPinnedIndex() - 1,
52
- ),
49
+ )
50
+ .sort((a, b) => a - b),
53
51
  ]
54
52
  : [[], []],
55
53
  [columnPinning, enableColumnVirtualization, enableColumnPinning],
@@ -69,9 +67,11 @@ export const useMRT_ColumnVirtualizer = <
69
67
  return columnsWidths.reduce((a, b) => a + b, 0) / columnsWidths.length;
70
68
  }, [table.getRowModel().rows, columnPinning, columnVisibility]);
71
69
 
72
- const draggingColumnIndex = table
73
- .getVisibleLeafColumns()
74
- .findIndex((c) => c.id === draggingColumn?.id);
70
+ const draggingColumnIndex = draggingColumn?.id
71
+ ? table
72
+ .getVisibleLeafColumns()
73
+ .findIndex((c) => c.id === draggingColumn?.id)
74
+ : undefined;
75
75
 
76
76
  const columnVirtualizer = enableColumnVirtualization
77
77
  ? (useVirtualizer({
@@ -100,24 +100,27 @@ export const useMRT_ColumnVirtualizer = <
100
100
  }) as unknown as MRT_ColumnVirtualizer<TScrollElement, TItemElement>)
101
101
  : undefined;
102
102
 
103
- if (columnVirtualizerInstanceRef && columnVirtualizer) {
104
- //@ts-ignore
105
- columnVirtualizerInstanceRef.current = columnVirtualizer;
106
- }
107
-
108
- const virtualColumns = columnVirtualizer
109
- ? columnVirtualizer.getVirtualItems()
110
- : undefined;
111
-
112
- if (columnVirtualizer && virtualColumns?.length) {
113
- // @ts-ignore
114
- columnVirtualizer.virtualPaddingLeft =
115
- virtualColumns[leftPinnedIndexes!.length]?.start ?? 0;
116
- // @ts-ignore
117
- columnVirtualizer.virtualPaddingRight =
118
- columnVirtualizer.getTotalSize() -
119
- (virtualColumns[virtualColumns.length - 1 - rightPinnedIndexes!.length]
120
- ?.end ?? 0);
103
+ if (columnVirtualizer) {
104
+ const virtualColumns = columnVirtualizer.getVirtualItems();
105
+ columnVirtualizer.virtualColumns = virtualColumns;
106
+ if (virtualColumns.length) {
107
+ columnVirtualizer.virtualPaddingLeft =
108
+ (virtualColumns[leftPinnedIndexes.length]?.start ?? 0) -
109
+ (virtualColumns[leftPinnedIndexes.length - 1]?.end ?? 0);
110
+ columnVirtualizer.virtualPaddingRight =
111
+ columnVirtualizer.getTotalSize() -
112
+ (virtualColumns[virtualColumns.length - rightPinnedIndexes.length - 1]
113
+ ?.end ?? 0) -
114
+ (rightPinnedIndexes.length
115
+ ? columnVirtualizer.getTotalSize() -
116
+ (virtualColumns[virtualColumns.length - rightPinnedIndexes.length]
117
+ ?.start ?? 0)
118
+ : 0);
119
+ }
120
+ if (columnVirtualizerInstanceRef) {
121
+ //@ts-ignore
122
+ columnVirtualizerInstanceRef.current = columnVirtualizer;
123
+ }
121
124
  }
122
125
 
123
126
  return columnVirtualizer as any;
@@ -1,4 +1,6 @@
1
- import { type RefObject, useMemo } from 'react';
1
+ import { type ReactNode, type RefObject, useMemo } from 'react';
2
+ import Stack from '@mui/material/Stack';
3
+ import Tooltip from '@mui/material/Tooltip';
2
4
  import { MRT_TableBodyRowGrabHandle } from '../body';
3
5
  import { MRT_TableBodyRowPinButton } from '../body/MRT_TableBodyRowPinButton';
4
6
  import { MRT_ExpandAllButton } from '../buttons/MRT_ExpandAllButton';
@@ -63,6 +65,7 @@ export const useMRT_DisplayColumns = <TData extends MRT_RowData>(
63
65
  tableOptions.enableRowOrdering,
64
66
  tableOptions.enableRowSelection,
65
67
  tableOptions.enableSelectAll,
68
+ tableOptions.groupedColumnMode,
66
69
  tableOptions.localization,
67
70
  tableOptions.positionActionsColumn,
68
71
  tableOptions.renderDetailPanel,
@@ -158,11 +161,60 @@ function makeRowExpandColumn<TData extends MRT_RowData>(
158
161
  showExpandColumn(tableOptions, tableOptions.state?.grouping ?? grouping)
159
162
  ) {
160
163
  return {
161
- Cell: ({ row, table }) => <MRT_ExpandButton row={row} table={table} />,
164
+ Cell: ({ cell, column, row, table }) => {
165
+ const expandButtonProps = { row, table };
166
+ const subRowsLength = row.subRows?.length;
167
+ if (
168
+ tableOptions.groupedColumnMode === 'remove' &&
169
+ row.groupingColumnId
170
+ ) {
171
+ return (
172
+ <Stack alignItems="center" flexDirection="row" gap="0.25rem">
173
+ <MRT_ExpandButton {...expandButtonProps} />
174
+ <Tooltip
175
+ enterDelay={1000}
176
+ enterNextDelay={1000}
177
+ placement="right"
178
+ title={table.getColumn(row.groupingColumnId).columnDef.header}
179
+ >
180
+ <span>{row.groupingValue as ReactNode}</span>
181
+ </Tooltip>
182
+ {!!subRowsLength && <span>({subRowsLength})</span>}
183
+ </Stack>
184
+ );
185
+ } else {
186
+ return (
187
+ <>
188
+ <MRT_ExpandButton {...expandButtonProps} />
189
+ {column.columnDef.GroupedCell?.({ cell, column, row, table })}
190
+ </>
191
+ );
192
+ }
193
+ },
162
194
  Header: tableOptions.enableExpandAll
163
- ? ({ table }) => <MRT_ExpandAllButton table={table} />
195
+ ? ({ table }) => {
196
+ return (
197
+ <>
198
+ <MRT_ExpandAllButton table={table} />
199
+ {tableOptions.groupedColumnMode === 'remove' &&
200
+ grouping
201
+ .map(
202
+ (groupedColumnId) =>
203
+ table.getColumn(groupedColumnId).columnDef.header,
204
+ )
205
+ .join(', ')}
206
+ </>
207
+ );
208
+ }
164
209
  : undefined,
165
- ...defaultDisplayColumnProps(tableOptions, id, 'expand'),
210
+ ...defaultDisplayColumnProps(
211
+ tableOptions,
212
+ id,
213
+ 'expand',
214
+ tableOptions.groupedColumnMode === 'remove'
215
+ ? tableOptions?.defaultColumn?.size
216
+ : 60,
217
+ ),
166
218
  };
167
219
  }
168
220
  return null;
@@ -175,7 +227,13 @@ function makeRowSelectColumn<TData extends MRT_RowData>(
175
227
  const id: MRT_DisplayColumnIds = 'mrt-row-select';
176
228
  if (order.includes(id)) {
177
229
  return {
178
- Cell: ({ row, table }) => <MRT_SelectCheckbox row={row} table={table} />,
230
+ Cell: ({ row, staticRowIndex, table }) => (
231
+ <MRT_SelectCheckbox
232
+ row={row}
233
+ staticRowIndex={staticRowIndex}
234
+ table={table}
235
+ />
236
+ ),
179
237
  Header:
180
238
  tableOptions.enableSelectAll && tableOptions.enableMultiRowSelection
181
239
  ? ({ table }) => <MRT_SelectCheckbox selectAll table={table} />
@@ -193,7 +251,10 @@ function makeRowNumbersColumn<TData extends MRT_RowData>(
193
251
  const id: MRT_DisplayColumnIds = 'mrt-row-numbers';
194
252
  if (order.includes(id) || tableOptions.enableRowNumbers)
195
253
  return {
196
- Cell: ({ row }) => row.index + 1,
254
+ Cell: ({ row, staticRowIndex }) =>
255
+ ((tableOptions.rowNumberDisplayMode === 'static'
256
+ ? staticRowIndex
257
+ : row.index) ?? 0) + 1,
197
258
  Header: () => tableOptions.localization.rowNumber,
198
259
  ...defaultDisplayColumnProps(tableOptions, id, 'rowNumbers'),
199
260
  };
@@ -57,9 +57,13 @@ export const useMRT_RowVirtualizer = <
57
57
  }) as unknown as MRT_RowVirtualizer<TScrollElement, TItemElement>)
58
58
  : undefined;
59
59
 
60
- if (rowVirtualizerInstanceRef && rowVirtualizer) {
61
- //@ts-ignore
62
- rowVirtualizerInstanceRef.current = rowVirtualizer;
60
+ if (rowVirtualizer) {
61
+ const virtualRows = rowVirtualizer.getVirtualItems();
62
+ rowVirtualizer.virtualRows = virtualRows;
63
+ if (rowVirtualizerInstanceRef) {
64
+ //@ts-ignore
65
+ rowVirtualizerInstanceRef.current = rowVirtualizer;
66
+ }
63
67
  }
64
68
 
65
69
  return rowVirtualizer;
@@ -465,6 +465,8 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
465
465
  />
466
466
  ) : (
467
467
  <TextField
468
+ select={isSelectFilter || isMultiSelectFilter}
469
+ {...commonTextFieldProps}
468
470
  SelectProps={{
469
471
  displayEmpty: true,
470
472
  multiple: isMultiSelectFilter,
@@ -488,10 +490,9 @@ export const MRT_FilterTextField = <TData extends MRT_RowData>({
488
490
  </Box>
489
491
  )
490
492
  : undefined,
493
+ ...commonTextFieldProps.SelectProps,
491
494
  }}
492
495
  onChange={handleTextFieldChange}
493
- select={isSelectFilter || isMultiSelectFilter}
494
- {...commonTextFieldProps}
495
496
  value={filterValue ?? ''}
496
497
  >
497
498
  {(isSelectFilter || isMultiSelectFilter) && [
@@ -1,4 +1,4 @@
1
- import { type MouseEvent } from 'react';
1
+ import { type ChangeEvent, type MouseEvent } from 'react';
2
2
  import Checkbox, { type CheckboxProps } from '@mui/material/Checkbox';
3
3
  import Radio, { type RadioProps } from '@mui/material/Radio';
4
4
  import Tooltip from '@mui/material/Tooltip';
@@ -13,12 +13,14 @@ import {
13
13
  interface Props<TData extends MRT_RowData> extends CheckboxProps {
14
14
  row?: MRT_Row<TData>;
15
15
  selectAll?: boolean;
16
+ staticRowIndex?: number;
16
17
  table: MRT_TableInstance<TData>;
17
18
  }
18
19
 
19
20
  export const MRT_SelectCheckbox = <TData extends MRT_RowData>({
20
21
  row,
21
22
  selectAll,
23
+ staticRowIndex,
22
24
  table,
23
25
  ...rest
24
26
  }: Props<TData>) => {
@@ -39,18 +41,56 @@ export const MRT_SelectCheckbox = <TData extends MRT_RowData>({
39
41
  const checkboxProps = {
40
42
  ...(!row
41
43
  ? parseFromValuesOrFunc(muiSelectAllCheckboxProps, { table })
42
- : parseFromValuesOrFunc(muiSelectCheckboxProps, { row, table })),
44
+ : parseFromValuesOrFunc(muiSelectCheckboxProps, {
45
+ row,
46
+ staticRowIndex,
47
+ table,
48
+ })),
43
49
  ...rest,
44
50
  };
45
51
 
52
+ const isStickySelection =
53
+ enableRowPinning && rowPinningDisplayMode?.includes('select');
54
+
46
55
  const allRowsSelected = selectAll
47
56
  ? selectAllMode === 'page'
48
57
  ? table.getIsAllPageRowsSelected()
49
58
  : table.getIsAllRowsSelected()
50
59
  : undefined;
51
60
 
61
+ const onSelectionChange = (
62
+ event: ChangeEvent<HTMLInputElement>,
63
+ row: MRT_Row<TData>,
64
+ ) => {
65
+ if (row.getIsAllSubRowsSelected()) {
66
+ row.subRows?.forEach((r) => r.toggleSelected(false));
67
+ }
68
+ row.getToggleSelectedHandler()(event);
69
+
70
+ if (isStickySelection) {
71
+ row.pin(
72
+ !row.getIsPinned() && event.target.checked
73
+ ? rowPinningDisplayMode?.includes('bottom')
74
+ ? 'bottom'
75
+ : 'top'
76
+ : false,
77
+ );
78
+ }
79
+ };
80
+
81
+ const onSelectAllChange = (event: ChangeEvent<HTMLInputElement>) => {
82
+ selectAllMode === 'all'
83
+ ? table.getToggleAllRowsSelectedHandler()(event)
84
+ : table.getToggleAllPageRowsSelectedHandler()(event);
85
+ if (isStickySelection) {
86
+ table.setRowPinning({ bottom: [], top: [] });
87
+ }
88
+ };
89
+
52
90
  const commonProps = {
53
- checked: selectAll ? allRowsSelected : row?.getIsSelected(),
91
+ checked: selectAll
92
+ ? allRowsSelected
93
+ : row?.getIsSelected() || row?.getIsAllSubRowsSelected(),
54
94
  disabled:
55
95
  isLoading || (row && !row.getCanSelect()) || row?.id === 'mrt-row-create',
56
96
  inputProps: {
@@ -60,24 +100,7 @@ export const MRT_SelectCheckbox = <TData extends MRT_RowData>({
60
100
  },
61
101
  onChange: (event) => {
62
102
  event.stopPropagation();
63
- row
64
- ? row.getToggleSelectedHandler()(event)
65
- : selectAllMode === 'all'
66
- ? table.getToggleAllRowsSelectedHandler()(event)
67
- : table.getToggleAllPageRowsSelectedHandler()(event);
68
- if (enableRowPinning && rowPinningDisplayMode?.includes('select')) {
69
- if (row) {
70
- row.pin(
71
- !row.getIsPinned() && event.target.checked
72
- ? rowPinningDisplayMode?.includes('bottom')
73
- ? 'bottom'
74
- : 'top'
75
- : false,
76
- );
77
- } else {
78
- table.setRowPinning({ bottom: [], top: [] });
79
- }
80
- }
103
+ row ? onSelectionChange(event, row) : onSelectAllChange(event);
81
104
  },
82
105
  size: (density === 'compact' ? 'small' : 'medium') as 'medium' | 'small',
83
106
  ...checkboxProps,