material-react-table 2.6.0 → 2.7.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.
Files changed (47) hide show
  1. package/dist/index.d.ts +224 -240
  2. package/dist/index.esm.js +2248 -2211
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.js +2353 -2315
  5. package/dist/index.js.map +1 -1
  6. package/package.json +2 -2
  7. package/src/body/MRT_TableBody.tsx +3 -25
  8. package/src/body/MRT_TableBodyRow.tsx +4 -2
  9. package/src/body/MRT_TableDetailPanel.tsx +3 -3
  10. package/src/buttons/MRT_CopyButton.tsx +2 -3
  11. package/src/buttons/MRT_ExpandAllButton.tsx +2 -2
  12. package/src/buttons/MRT_ExpandButton.tsx +5 -2
  13. package/src/buttons/MRT_GrabHandleButton.tsx +2 -3
  14. package/src/buttons/MRT_RowPinButton.tsx +2 -2
  15. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +6 -6
  16. package/src/column.utils.ts +22 -29
  17. package/src/head/MRT_TableHead.tsx +1 -1
  18. package/src/head/MRT_TableHeadCellColumnActionsButton.tsx +2 -3
  19. package/src/hooks/useMRT_DisplayColumns.tsx +43 -52
  20. package/src/hooks/useMRT_Effects.ts +6 -5
  21. package/src/hooks/useMRT_Rows.ts +30 -4
  22. package/src/hooks/useMRT_TableInstance.ts +44 -55
  23. package/src/hooks/useMRT_TableOptions.ts +2 -0
  24. package/src/icons.ts +4 -38
  25. package/src/index.ts +84 -10
  26. package/src/inputs/MRT_FilterCheckbox.tsx +2 -2
  27. package/src/inputs/MRT_SelectCheckbox.tsx +2 -2
  28. package/src/menus/MRT_ColumnActionMenu.tsx +11 -3
  29. package/src/menus/MRT_FilterOptionMenu.tsx +8 -0
  30. package/src/menus/MRT_RowActionMenu.tsx +14 -3
  31. package/src/menus/MRT_ShowHideColumnsMenu.tsx +8 -0
  32. package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +2 -3
  33. package/src/style.utils.ts +29 -13
  34. package/src/table/MRT_TableContainer.tsx +1 -1
  35. package/src/toolbar/MRT_TablePagination.tsx +7 -5
  36. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +1 -1
  37. package/src/types.ts +5 -0
  38. package/src/body/index.ts +0 -7
  39. package/src/buttons/index.ts +0 -13
  40. package/src/footer/index.ts +0 -3
  41. package/src/head/index.ts +0 -9
  42. package/src/hooks/index.ts +0 -7
  43. package/src/inputs/index.ts +0 -7
  44. package/src/menus/index.ts +0 -5
  45. package/src/modals/index.ts +0 -1
  46. package/src/table/index.ts +0 -5
  47. package/src/toolbar/index.ts +0 -7
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.6.0",
2
+ "version": "2.7.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.",
@@ -114,7 +114,7 @@
114
114
  },
115
115
  "dependencies": {
116
116
  "@tanstack/match-sorter-utils": "8.11.3",
117
- "@tanstack/react-table": "8.11.4",
117
+ "@tanstack/react-table": "8.11.6",
118
118
  "@tanstack/react-virtual": "3.0.1",
119
119
  "highlight-words": "1.2.2"
120
120
  }
@@ -4,7 +4,7 @@ import TableBody, { type TableBodyProps } from '@mui/material/TableBody';
4
4
  import Typography from '@mui/material/Typography';
5
5
  import { MRT_TableBodyRow, Memo_MRT_TableBodyRow } from './MRT_TableBodyRow';
6
6
  import { parseFromValuesOrFunc } from '../column.utils';
7
- import { useMRT_RowVirtualizer } from '../hooks';
7
+ import { useMRT_RowVirtualizer } from '../hooks/useMRT_RowVirtualizer';
8
8
  import { useMRT_Rows } from '../hooks/useMRT_Rows';
9
9
  import {
10
10
  type MRT_ColumnVirtualizer,
@@ -30,7 +30,6 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
30
30
  getState,
31
31
  getTopRows,
32
32
  options: {
33
- createDisplayMode,
34
33
  enableStickyFooter,
35
34
  enableStickyHeader,
36
35
  layoutMode,
@@ -43,8 +42,7 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
43
42
  },
44
43
  refs: { tableFooterRef, tableHeadRef, tablePaperRef },
45
44
  } = table;
46
- const { columnFilters, creatingRow, globalFilter, isFullScreen, rowPinning } =
47
- getState();
45
+ const { columnFilters, globalFilter, isFullScreen, rowPinning } = getState();
48
46
 
49
47
  const tableBodyProps = {
50
48
  ...parseFromValuesOrFunc(muiTableBodyProps, { table }),
@@ -77,14 +75,6 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
77
75
  table,
78
76
  };
79
77
 
80
- const CreatingRow = creatingRow && createDisplayMode === 'row' && (
81
- <MRT_TableBodyRow
82
- {...commonRowProps}
83
- row={creatingRow}
84
- staticRowIndex={-1}
85
- />
86
- );
87
-
88
78
  return (
89
79
  <>
90
80
  {!rowPinningDisplayMode?.includes('sticky') &&
@@ -113,17 +103,6 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
113
103
  })}
114
104
  </TableBody>
115
105
  )}
116
- {rowVirtualizer && CreatingRow && (
117
- <TableBody
118
- {...tableBodyProps}
119
- sx={(theme) => ({
120
- display: layoutMode?.startsWith('grid') ? 'grid' : undefined,
121
- ...(parseFromValuesOrFunc(tableBodyProps?.sx, theme) as any),
122
- })}
123
- >
124
- {CreatingRow}
125
- </TableBody>
126
- )}
127
106
  <TableBody
128
107
  {...tableBodyProps}
129
108
  sx={(theme) => ({
@@ -136,9 +115,8 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
136
115
  ...(parseFromValuesOrFunc(tableBodyProps?.sx, theme) as any),
137
116
  })}
138
117
  >
139
- {!rowVirtualizer && CreatingRow}
140
118
  {tableBodyProps?.children ??
141
- (!rows.length && !CreatingRow ? (
119
+ (!rows.length ? (
142
120
  <tr
143
121
  style={{
144
122
  display: layoutMode?.startsWith('grid') ? 'grid' : undefined,
@@ -136,13 +136,15 @@ export const MRT_TableBodyRow = <TData extends MRT_RowData>({
136
136
  data-index={renderDetailPanel ? staticRowIndex * 2 : staticRowIndex}
137
137
  data-pinned={!!isPinned || undefined}
138
138
  data-selected={
139
- row.getIsSelected() || row.getIsAllSubRowsSelected() || undefined
139
+ row?.getIsSelected() ||
140
+ (row?.getIsAllSubRowsSelected() && row.getCanSelectSubRows()) ||
141
+ undefined
140
142
  }
141
143
  onDragEnter={handleDragEnter}
142
144
  ref={(node: HTMLTableRowElement) => {
143
145
  if (node) {
144
146
  rowRef.current = node;
145
- rowVirtualizer?.measureElement?.(node);
147
+ rowVirtualizer?.measureElement(node);
146
148
  }
147
149
  }}
148
150
  selected={row.getIsSelected()}
@@ -1,5 +1,4 @@
1
1
  import { type RefObject } from 'react';
2
- import { type VirtualItem } from '@tanstack/react-virtual';
3
2
  import Collapse from '@mui/material/Collapse';
4
3
  import TableCell, { type TableCellProps } from '@mui/material/TableCell';
5
4
  import TableRow from '@mui/material/TableRow';
@@ -10,6 +9,7 @@ import {
10
9
  type MRT_RowData,
11
10
  type MRT_RowVirtualizer,
12
11
  type MRT_TableInstance,
12
+ type MRT_VirtualItem,
13
13
  } from '../types';
14
14
 
15
15
  interface Props<TData extends MRT_RowData> extends TableCellProps {
@@ -18,7 +18,7 @@ interface Props<TData extends MRT_RowData> extends TableCellProps {
18
18
  rowVirtualizer?: MRT_RowVirtualizer;
19
19
  staticRowIndex: number;
20
20
  table: MRT_TableInstance<TData>;
21
- virtualRow?: VirtualItem;
21
+ virtualRow?: MRT_VirtualItem;
22
22
  }
23
23
 
24
24
  export const MRT_TableDetailPanel = <TData extends MRT_RowData>({
@@ -104,7 +104,7 @@ export const MRT_TableDetailPanel = <TData extends MRT_RowData>({
104
104
  {enableRowVirtualization ? (
105
105
  row.getIsExpanded() && DetailPanel
106
106
  ) : (
107
- <Collapse in={!!row.getIsExpanded()} mountOnEnter unmountOnExit>
107
+ <Collapse in={row.getIsExpanded()} mountOnEnter unmountOnExit>
108
108
  {DetailPanel}
109
109
  </Collapse>
110
110
  )}
@@ -2,6 +2,7 @@ import { type MouseEvent, useState } from 'react';
2
2
  import Button, { type ButtonProps } from '@mui/material/Button';
3
3
  import Tooltip from '@mui/material/Tooltip';
4
4
  import { parseFromValuesOrFunc } from '../column.utils';
5
+ import { getCommonTooltipProps } from '../style.utils';
5
6
  import {
6
7
  type MRT_Cell,
7
8
  type MRT_RowData,
@@ -51,9 +52,7 @@ export const MRT_CopyButton = <TData extends MRT_RowData>({
51
52
 
52
53
  return (
53
54
  <Tooltip
54
- enterDelay={1000}
55
- enterNextDelay={1000}
56
- placement="top"
55
+ {...getCommonTooltipProps('top')}
57
56
  title={
58
57
  buttonProps?.title ??
59
58
  (copied ? localization.copiedToClipboard : localization.clickToCopy)
@@ -1,6 +1,7 @@
1
1
  import IconButton, { type IconButtonProps } from '@mui/material/IconButton';
2
2
  import Tooltip from '@mui/material/Tooltip';
3
3
  import { parseFromValuesOrFunc } from '../column.utils';
4
+ import { getCommonTooltipProps } from '../style.utils';
4
5
  import { type MRT_RowData, type MRT_TableInstance } from '../types';
5
6
 
6
7
  interface Props<TData extends MRT_RowData> extends IconButtonProps {
@@ -37,8 +38,7 @@ export const MRT_ExpandAllButton = <TData extends MRT_RowData>({
37
38
 
38
39
  return (
39
40
  <Tooltip
40
- enterDelay={1000}
41
- enterNextDelay={1000}
41
+ {...getCommonTooltipProps()}
42
42
  title={
43
43
  iconButtonProps?.title ??
44
44
  (isAllRowsExpanded ? localization.collapseAll : localization.expandAll)
@@ -3,6 +3,7 @@ import IconButton, { type IconButtonProps } from '@mui/material/IconButton';
3
3
  import Tooltip from '@mui/material/Tooltip';
4
4
  import { useTheme } from '@mui/material/styles';
5
5
  import { parseFromValuesOrFunc } from '../column.utils';
6
+ import { getCommonTooltipProps } from '../style.utils';
6
7
  import {
7
8
  type MRT_Row,
8
9
  type MRT_RowData,
@@ -11,11 +12,13 @@ import {
11
12
 
12
13
  interface Props<TData extends MRT_RowData> extends IconButtonProps {
13
14
  row: MRT_Row<TData>;
15
+ staticRowIndex?: number;
14
16
  table: MRT_TableInstance<TData>;
15
17
  }
16
18
 
17
19
  export const MRT_ExpandButton = <TData extends MRT_RowData>({
18
20
  row,
21
+ staticRowIndex,
19
22
  table,
20
23
  }: Props<TData>) => {
21
24
  const theme = useTheme();
@@ -33,6 +36,7 @@ export const MRT_ExpandButton = <TData extends MRT_RowData>({
33
36
 
34
37
  const iconButtonProps = parseFromValuesOrFunc(muiExpandButtonProps, {
35
38
  row,
39
+ staticRowIndex,
36
40
  table,
37
41
  });
38
42
 
@@ -50,8 +54,7 @@ export const MRT_ExpandButton = <TData extends MRT_RowData>({
50
54
  return (
51
55
  <Tooltip
52
56
  disableHoverListener={!canExpand && !detailPanel}
53
- enterDelay={1000}
54
- enterNextDelay={1000}
57
+ {...getCommonTooltipProps()}
55
58
  title={
56
59
  iconButtonProps?.title ??
57
60
  (isExpanded ? localization.collapse : localization.expand)
@@ -2,6 +2,7 @@ import { type DragEventHandler } from 'react';
2
2
  import IconButton, { type IconButtonProps } from '@mui/material/IconButton';
3
3
  import Tooltip from '@mui/material/Tooltip';
4
4
  import { parseFromValuesOrFunc } from '../column.utils';
5
+ import { getCommonTooltipProps } from '../style.utils';
5
6
  import { type MRT_RowData, type MRT_TableInstance } from '../types';
6
7
 
7
8
  interface Props<TData extends MRT_RowData> extends IconButtonProps {
@@ -31,9 +32,7 @@ export const MRT_GrabHandleButton = <TData extends MRT_RowData>({
31
32
 
32
33
  return (
33
34
  <Tooltip
34
- enterDelay={1000}
35
- enterNextDelay={1000}
36
- placement="top"
35
+ {...getCommonTooltipProps('top')}
37
36
  title={_iconButtonProps?.title ?? localization.move}
38
37
  >
39
38
  <IconButton
@@ -3,6 +3,7 @@ import { type RowPinningPosition } from '@tanstack/react-table';
3
3
  import IconButton, { type IconButtonProps } from '@mui/material/IconButton';
4
4
  import Tooltip from '@mui/material/Tooltip';
5
5
  import { parseFromValuesOrFunc } from '../column.utils';
6
+ import { getCommonTooltipProps } from '../style.utils';
6
7
  import {
7
8
  type MRT_Row,
8
9
  type MRT_RowData,
@@ -41,8 +42,7 @@ export const MRT_RowPinButton = <TData extends MRT_RowData>({
41
42
 
42
43
  return (
43
44
  <Tooltip
44
- enterDelay={1000}
45
- enterNextDelay={1000}
45
+ {...getCommonTooltipProps()}
46
46
  open={tooltipOpened}
47
47
  title={isPinned ? localization.unpin : localization.pin}
48
48
  >
@@ -4,6 +4,7 @@ import Tooltip from '@mui/material/Tooltip';
4
4
  import { MRT_EditActionButtons } from './MRT_EditActionButtons';
5
5
  import { parseFromValuesOrFunc } from '../column.utils';
6
6
  import { MRT_RowActionMenu } from '../menus/MRT_RowActionMenu';
7
+ import { getCommonTooltipProps } from '../style.utils';
7
8
  import {
8
9
  type MRT_Cell,
9
10
  type MRT_Row,
@@ -25,12 +26,14 @@ const commonIconButtonStyles = {
25
26
  interface Props<TData extends MRT_RowData> extends IconButtonProps {
26
27
  cell: MRT_Cell<TData>;
27
28
  row: MRT_Row<TData>;
29
+ staticRowIndex?: number;
28
30
  table: MRT_TableInstance<TData>;
29
31
  }
30
32
 
31
33
  export const MRT_ToggleRowActionMenuButton = <TData extends MRT_RowData>({
32
34
  cell,
33
35
  row,
36
+ staticRowIndex,
34
37
  table,
35
38
  ...rest
36
39
  }: Props<TData>) => {
@@ -74,7 +77,7 @@ export const MRT_ToggleRowActionMenuButton = <TData extends MRT_RowData>({
74
77
  return (
75
78
  <>
76
79
  {renderRowActions && !showEditActionButtons ? (
77
- renderRowActions({ cell, row, table })
80
+ renderRowActions({ cell, row, staticRowIndex, table })
78
81
  ) : showEditActionButtons ? (
79
82
  <MRT_EditActionButtons row={row} table={table} />
80
83
  ) : !renderRowActionMenuItems &&
@@ -92,11 +95,7 @@ export const MRT_ToggleRowActionMenuButton = <TData extends MRT_RowData>({
92
95
  </Tooltip>
93
96
  ) : renderRowActionMenuItems ? (
94
97
  <>
95
- <Tooltip
96
- enterDelay={1000}
97
- enterNextDelay={1000}
98
- title={localization.rowActions}
99
- >
98
+ <Tooltip {...getCommonTooltipProps()} title={localization.rowActions}>
100
99
  <IconButton
101
100
  aria-label={localization.rowActions}
102
101
  onClick={handleOpenRowActionMenu}
@@ -112,6 +111,7 @@ export const MRT_ToggleRowActionMenuButton = <TData extends MRT_RowData>({
112
111
  handleEdit={handleStartEditMode}
113
112
  row={row}
114
113
  setAnchorEl={setAnchorEl}
114
+ staticRowIndex={staticRowIndex}
115
115
  table={table}
116
116
  />
117
117
  </>
@@ -6,15 +6,13 @@ import {
6
6
  type Row,
7
7
  } from '@tanstack/react-table';
8
8
  import { type Range, defaultRangeExtractor } from '@tanstack/react-virtual';
9
- import { type MRT_AggregationFns } from './aggregationFns';
10
- import { type MRT_FilterFns } from './filterFns';
11
- import { type MRT_SortingFns } from './sortingFns';
12
9
  import {
13
10
  type MRT_Column,
14
11
  type MRT_ColumnDef,
15
12
  type MRT_ColumnHelper,
16
13
  type MRT_ColumnOrderState,
17
14
  type MRT_DefinedColumnDef,
15
+ type MRT_DefinedTableOptions,
18
16
  type MRT_DisplayColumnDef,
19
17
  type MRT_DisplayColumnIds,
20
18
  type MRT_FilterOption,
@@ -49,42 +47,30 @@ export const getAllLeafColumnDefs = <TData extends MRT_RowData>(
49
47
  };
50
48
 
51
49
  export const prepareColumns = <TData extends MRT_RowData>({
52
- aggregationFns,
53
50
  columnDefs,
54
- columnFilterFns,
55
- defaultDisplayColumn,
56
- filterFns,
57
- sortingFns,
51
+ tableOptions,
58
52
  }: {
59
- aggregationFns: typeof MRT_AggregationFns &
60
- MRT_TableOptions<TData>['aggregationFns'];
61
53
  columnDefs: MRT_ColumnDef<TData>[];
62
- columnFilterFns: { [key: string]: MRT_FilterOption };
63
- defaultDisplayColumn: Partial<MRT_ColumnDef<TData>>;
64
- filterFns: typeof MRT_FilterFns & MRT_TableOptions<TData>['filterFns'];
65
- sortingFns: typeof MRT_SortingFns & MRT_TableOptions<TData>['sortingFns'];
66
- }): MRT_DefinedColumnDef<TData>[] =>
67
- columnDefs.map((columnDef) => {
54
+ tableOptions: MRT_DefinedTableOptions<TData>;
55
+ }): MRT_DefinedColumnDef<TData>[] => {
56
+ const {
57
+ aggregationFns = {},
58
+ defaultDisplayColumn,
59
+ filterFns = {},
60
+ sortingFns = {},
61
+ state: { columnFilterFns = {} } = {},
62
+ } = tableOptions;
63
+ return columnDefs.map((columnDef) => {
68
64
  //assign columnId
69
65
  if (!columnDef.id) columnDef.id = getColumnId(columnDef);
70
- if (process.env.NODE_ENV !== 'production' && !columnDef.id) {
71
- console.error(
72
- 'Column definitions must have a valid `accessorKey` or `id` property',
73
- );
74
- }
75
-
76
66
  //assign columnDefType
77
67
  if (!columnDef.columnDefType) columnDef.columnDefType = 'data';
78
68
  if (columnDef.columns?.length) {
79
69
  columnDef.columnDefType = 'group';
80
70
  //recursively prepare columns if this is a group column
81
71
  columnDef.columns = prepareColumns({
82
- aggregationFns,
83
72
  columnDefs: columnDef.columns,
84
- columnFilterFns,
85
- defaultDisplayColumn,
86
- filterFns,
87
- sortingFns,
73
+ tableOptions,
88
74
  });
89
75
  } else if (columnDef.columnDefType === 'data') {
90
76
  //assign aggregationFns if multiple aggregationFns are provided
@@ -121,6 +107,7 @@ export const prepareColumns = <TData extends MRT_RowData>({
121
107
  }
122
108
  return columnDef;
123
109
  }) as MRT_DefinedColumnDef<TData>[];
110
+ };
124
111
 
125
112
  export const reorderColumn = <TData extends MRT_RowData>(
126
113
  draggedColumn: MRT_Column<TData>,
@@ -297,6 +284,10 @@ export const flexRender = _flexRender as (
297
284
  export const createRow = <TData extends MRT_RowData>(
298
285
  table: MRT_TableInstance<TData>,
299
286
  originalRow?: TData,
287
+ rowIndex = -1,
288
+ depth = 0,
289
+ subRows?: MRT_Row<TData>[],
290
+ parentId?: string,
300
291
  ): MRT_Row<TData> =>
301
292
  _createRow(
302
293
  table as any,
@@ -308,8 +299,10 @@ export const createRow = <TData extends MRT_RowData>(
308
299
  [getColumnId(col)]: '',
309
300
  })),
310
301
  ),
311
- -1,
312
- 0,
302
+ rowIndex,
303
+ depth,
304
+ subRows as any,
305
+ parentId,
313
306
  ) as MRT_Row<TData>;
314
307
 
315
308
  export const extraIndexRangeExtractor = (
@@ -1,7 +1,7 @@
1
1
  import TableHead, { type TableHeadProps } from '@mui/material/TableHead';
2
2
  import { MRT_TableHeadRow } from './MRT_TableHeadRow';
3
3
  import { parseFromValuesOrFunc } from '../column.utils';
4
- import { MRT_ToolbarAlertBanner } from '../toolbar';
4
+ import { MRT_ToolbarAlertBanner } from '../toolbar/MRT_ToolbarAlertBanner';
5
5
  import {
6
6
  type MRT_ColumnVirtualizer,
7
7
  type MRT_RowData,
@@ -3,6 +3,7 @@ import IconButton, { type IconButtonProps } from '@mui/material/IconButton';
3
3
  import Tooltip from '@mui/material/Tooltip';
4
4
  import { parseFromValuesOrFunc } from '../column.utils';
5
5
  import { MRT_ColumnActionMenu } from '../menus/MRT_ColumnActionMenu';
6
+ import { getCommonTooltipProps } from '../style.utils';
6
7
  import {
7
8
  type MRT_Header,
8
9
  type MRT_RowData,
@@ -54,9 +55,7 @@ export const MRT_TableHeadCellColumnActionsButton = <
54
55
  return (
55
56
  <>
56
57
  <Tooltip
57
- enterDelay={1000}
58
- enterNextDelay={1000}
59
- placement="top"
58
+ {...getCommonTooltipProps('top')}
60
59
  title={iconButtonProps?.title ?? localization.columnActions}
61
60
  >
62
61
  <IconButton
@@ -1,37 +1,28 @@
1
1
  import { type ReactNode, type RefObject, useMemo } from 'react';
2
2
  import Stack from '@mui/material/Stack';
3
3
  import Tooltip from '@mui/material/Tooltip';
4
- import { MRT_TableBodyRowGrabHandle } from '../body';
4
+ import { MRT_TableBodyRowGrabHandle } from '../body/MRT_TableBodyRowGrabHandle';
5
5
  import { MRT_TableBodyRowPinButton } from '../body/MRT_TableBodyRowPinButton';
6
6
  import { MRT_ExpandAllButton } from '../buttons/MRT_ExpandAllButton';
7
7
  import { MRT_ExpandButton } from '../buttons/MRT_ExpandButton';
8
8
  import { MRT_ToggleRowActionMenuButton } from '../buttons/MRT_ToggleRowActionMenuButton';
9
9
  import { showExpandColumn } from '../column.utils';
10
10
  import { MRT_SelectCheckbox } from '../inputs/MRT_SelectCheckbox';
11
+ import { getCommonTooltipProps } from '../style.utils';
11
12
  import {
12
13
  type MRT_ColumnDef,
13
- type MRT_ColumnOrderState,
14
14
  type MRT_DefinedTableOptions,
15
15
  type MRT_DisplayColumnIds,
16
- type MRT_GroupingState,
17
16
  type MRT_Localization,
18
- type MRT_Row,
19
17
  type MRT_RowData,
20
18
  } from '../types';
21
- import { MRT_DefaultDisplayColumn } from '.';
22
-
23
- interface Params<TData extends MRT_RowData> {
24
- columnOrder: MRT_ColumnOrderState;
25
- creatingRow: MRT_Row<TData> | null;
26
- grouping: MRT_GroupingState;
27
- tableOptions: MRT_DefinedTableOptions<TData>;
28
- }
19
+ import { MRT_DefaultDisplayColumn } from './useMRT_TableOptions';
29
20
 
30
21
  export const useMRT_DisplayColumns = <TData extends MRT_RowData>(
31
- params: Params<TData>,
22
+ tableOptions: MRT_DefinedTableOptions<TData>,
32
23
  ): MRT_ColumnDef<TData>[] => {
33
- const { columnOrder, creatingRow, grouping, tableOptions } = params;
34
- const order = tableOptions.state?.columnOrder ?? columnOrder;
24
+ const { columnOrder, creatingRow, grouping, pagination } =
25
+ tableOptions.state!;
35
26
 
36
27
  return useMemo(
37
28
  () =>
@@ -44,12 +35,13 @@ export const useMRT_DisplayColumns = <TData extends MRT_RowData>(
44
35
  makeRowNumbersColumn,
45
36
  makeSpacerColumn,
46
37
  ]
47
- .map((makeCol) => makeCol(params, order))
38
+ .map((makeCol) => makeCol(tableOptions))
48
39
  .filter(Boolean) as MRT_ColumnDef<TData>[],
49
40
  [
50
41
  columnOrder,
51
42
  creatingRow,
52
43
  grouping,
44
+ pagination,
53
45
  tableOptions.displayColumnDefOptions,
54
46
  tableOptions.editDisplayMode,
55
47
  tableOptions.enableColumnDragging,
@@ -72,8 +64,6 @@ export const useMRT_DisplayColumns = <TData extends MRT_RowData>(
72
64
  tableOptions.renderDetailPanel,
73
65
  tableOptions.renderRowActionMenuItems,
74
66
  tableOptions.renderRowActions,
75
- tableOptions.state?.columnOrder,
76
- tableOptions.state?.grouping,
77
67
  ],
78
68
  );
79
69
  };
@@ -98,11 +88,11 @@ function defaultDisplayColumnProps<TData extends MRT_RowData>(
98
88
  }
99
89
 
100
90
  function makeRowPinColumn<TData extends MRT_RowData>(
101
- { tableOptions }: Params<TData>,
102
- order: MRT_ColumnOrderState,
91
+ tableOptions: MRT_DefinedTableOptions<TData>,
103
92
  ): MRT_ColumnDef<TData> | null {
104
93
  const id: MRT_DisplayColumnIds = 'mrt-row-pin';
105
- if (order.includes(id)) {
94
+ const { columnOrder } = tableOptions.state!;
95
+ if (columnOrder?.includes(id)) {
106
96
  return {
107
97
  Cell: ({ row, table }) => (
108
98
  <MRT_TableBodyRowPinButton row={row} table={table} />
@@ -114,11 +104,11 @@ function makeRowPinColumn<TData extends MRT_RowData>(
114
104
  }
115
105
 
116
106
  function makeRowDragColumn<TData extends MRT_RowData>(
117
- { tableOptions }: Params<TData>,
118
- order: MRT_ColumnOrderState,
107
+ tableOptions: MRT_DefinedTableOptions<TData>,
119
108
  ): MRT_ColumnDef<TData> | null {
120
109
  const id: MRT_DisplayColumnIds = 'mrt-row-drag';
121
- if (order.includes(id)) {
110
+ const { columnOrder } = tableOptions.state!;
111
+ if (columnOrder?.includes(id)) {
122
112
  return {
123
113
  Cell: ({ row, rowRef, table }) => (
124
114
  <MRT_TableBodyRowGrabHandle
@@ -134,17 +124,22 @@ function makeRowDragColumn<TData extends MRT_RowData>(
134
124
  }
135
125
 
136
126
  function makeRowActionsColumn<TData extends MRT_RowData>(
137
- { creatingRow, tableOptions }: Params<TData>,
138
- order: MRT_ColumnOrderState,
127
+ tableOptions: MRT_DefinedTableOptions<TData>,
139
128
  ): MRT_ColumnDef<TData> | null {
140
129
  const id: MRT_DisplayColumnIds = 'mrt-row-actions';
130
+ const { columnOrder, creatingRow } = tableOptions.state!;
141
131
  if (
142
- order.includes(id) ||
132
+ columnOrder?.includes(id) ||
143
133
  (creatingRow && tableOptions.createDisplayMode === 'row')
144
134
  ) {
145
135
  return {
146
- Cell: ({ cell, row, table }) => (
147
- <MRT_ToggleRowActionMenuButton cell={cell} row={row} table={table} />
136
+ Cell: ({ cell, row, staticRowIndex, table }) => (
137
+ <MRT_ToggleRowActionMenuButton
138
+ cell={cell}
139
+ row={row}
140
+ staticRowIndex={staticRowIndex}
141
+ table={table}
142
+ />
148
143
  ),
149
144
  ...defaultDisplayColumnProps(tableOptions, id, 'actions'),
150
145
  };
@@ -153,14 +148,11 @@ function makeRowActionsColumn<TData extends MRT_RowData>(
153
148
  }
154
149
 
155
150
  function makeRowExpandColumn<TData extends MRT_RowData>(
156
- { grouping, tableOptions }: Params<TData>,
157
- order: MRT_ColumnOrderState,
151
+ tableOptions: MRT_DefinedTableOptions<TData>,
158
152
  ): MRT_ColumnDef<TData> | null {
159
153
  const id: MRT_DisplayColumnIds = 'mrt-row-expand';
160
- if (
161
- order.includes(id) &&
162
- showExpandColumn(tableOptions, tableOptions.state?.grouping ?? grouping)
163
- ) {
154
+ const { columnOrder, grouping } = tableOptions.state!;
155
+ if (columnOrder?.includes(id) && showExpandColumn(tableOptions, grouping)) {
164
156
  const alignProps =
165
157
  tableOptions.positionExpandColumn === 'last'
166
158
  ? ({
@@ -169,8 +161,8 @@ function makeRowExpandColumn<TData extends MRT_RowData>(
169
161
  : undefined;
170
162
 
171
163
  return {
172
- Cell: ({ cell, column, row, table }) => {
173
- const expandButtonProps = { row, table };
164
+ Cell: ({ cell, column, row, staticRowIndex, table }) => {
165
+ const expandButtonProps = { row, staticRowIndex, table };
174
166
  const subRowsLength = row.subRows?.length;
175
167
  if (
176
168
  tableOptions.groupedColumnMode === 'remove' &&
@@ -180,9 +172,7 @@ function makeRowExpandColumn<TData extends MRT_RowData>(
180
172
  <Stack alignItems="center" flexDirection="row" gap="0.25rem">
181
173
  <MRT_ExpandButton {...expandButtonProps} />
182
174
  <Tooltip
183
- enterDelay={1000}
184
- enterNextDelay={1000}
185
- placement="right"
175
+ {...getCommonTooltipProps('right')}
186
176
  title={table.getColumn(row.groupingColumnId).columnDef.header}
187
177
  >
188
178
  <span>{row.groupingValue as ReactNode}</span>
@@ -206,11 +196,11 @@ function makeRowExpandColumn<TData extends MRT_RowData>(
206
196
  <MRT_ExpandAllButton table={table} />
207
197
  {tableOptions.groupedColumnMode === 'remove' &&
208
198
  grouping
209
- .map(
199
+ ?.map(
210
200
  (groupedColumnId) =>
211
201
  table.getColumn(groupedColumnId).columnDef.header,
212
202
  )
213
- .join(', ')}
203
+ ?.join(', ')}
214
204
  </>
215
205
  );
216
206
  }
@@ -231,11 +221,11 @@ function makeRowExpandColumn<TData extends MRT_RowData>(
231
221
  }
232
222
 
233
223
  function makeRowSelectColumn<TData extends MRT_RowData>(
234
- { tableOptions }: Params<TData>,
235
- order: MRT_ColumnOrderState,
224
+ tableOptions: MRT_DefinedTableOptions<TData>,
236
225
  ): MRT_ColumnDef<TData> | null {
237
226
  const id: MRT_DisplayColumnIds = 'mrt-row-select';
238
- if (order.includes(id)) {
227
+ const { columnOrder } = tableOptions.state!;
228
+ if (columnOrder?.includes(id)) {
239
229
  return {
240
230
  Cell: ({ row, staticRowIndex, table }) => (
241
231
  <MRT_SelectCheckbox
@@ -255,15 +245,16 @@ function makeRowSelectColumn<TData extends MRT_RowData>(
255
245
  }
256
246
 
257
247
  function makeRowNumbersColumn<TData extends MRT_RowData>(
258
- { tableOptions }: Params<TData>,
259
- order: MRT_ColumnOrderState,
248
+ tableOptions: MRT_DefinedTableOptions<TData>,
260
249
  ): MRT_ColumnDef<TData> | null {
261
250
  const id: MRT_DisplayColumnIds = 'mrt-row-numbers';
262
- if (order.includes(id) || tableOptions.enableRowNumbers)
251
+ const { columnOrder, pagination } = tableOptions.state!;
252
+ if (columnOrder?.includes(id) || tableOptions.enableRowNumbers)
263
253
  return {
264
254
  Cell: ({ row, staticRowIndex }) =>
265
255
  ((tableOptions.rowNumberDisplayMode === 'static'
266
- ? staticRowIndex
256
+ ? (staticRowIndex || 0) +
257
+ (pagination?.pageSize || 0) * (pagination?.pageIndex || 0)
267
258
  : row.index) ?? 0) + 1,
268
259
  Header: () => tableOptions.localization.rowNumber,
269
260
  ...defaultDisplayColumnProps(tableOptions, id, 'rowNumbers'),
@@ -282,11 +273,11 @@ const blankColProps = {
282
273
  };
283
274
 
284
275
  function makeSpacerColumn<TData extends MRT_RowData>(
285
- { tableOptions }: Params<TData>,
286
- order: MRT_ColumnOrderState,
276
+ tableOptions: MRT_DefinedTableOptions<TData>,
287
277
  ): MRT_ColumnDef<TData> | null {
288
278
  const id: MRT_DisplayColumnIds = 'mrt-row-spacer';
289
- if (order.includes(id)) {
279
+ const { columnOrder } = tableOptions.state!;
280
+ if (columnOrder?.includes(id)) {
290
281
  return {
291
282
  ...defaultDisplayColumnProps(tableOptions, id, undefined, 0),
292
283
  ...MRT_DefaultDisplayColumn,