material-react-table 2.6.1 → 2.8.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 (104) hide show
  1. package/dist/index.d.ts +390 -260
  2. package/dist/index.esm.js +1977 -1921
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.js +2372 -2318
  5. package/dist/index.js.map +1 -1
  6. package/package.json +20 -20
  7. package/src/{MaterialReactTable.tsx → components/MaterialReactTable.tsx} +3 -3
  8. package/src/{body → components/body}/MRT_TableBody.tsx +6 -28
  9. package/src/{body → components/body}/MRT_TableBodyCell.tsx +6 -23
  10. package/src/{body → components/body}/MRT_TableBodyCellValue.tsx +2 -2
  11. package/src/{body → components/body}/MRT_TableBodyRow.tsx +7 -5
  12. package/src/{body → components/body}/MRT_TableBodyRowGrabHandle.tsx +3 -3
  13. package/src/{body → components/body}/MRT_TableBodyRowPinButton.tsx +3 -3
  14. package/src/{body → components/body}/MRT_TableDetailPanel.tsx +6 -6
  15. package/src/{buttons → components/buttons}/MRT_ColumnPinningButtons.tsx +2 -2
  16. package/src/{buttons → components/buttons}/MRT_CopyButton.tsx +4 -5
  17. package/src/{buttons → components/buttons}/MRT_EditActionButtons.tsx +2 -2
  18. package/src/{buttons → components/buttons}/MRT_ExpandAllButton.tsx +4 -4
  19. package/src/{buttons → components/buttons}/MRT_ExpandButton.tsx +10 -4
  20. package/src/{buttons → components/buttons}/MRT_GrabHandleButton.tsx +4 -5
  21. package/src/{buttons → components/buttons}/MRT_RowPinButton.tsx +4 -4
  22. package/src/{buttons → components/buttons}/MRT_ShowHideColumnsButton.tsx +1 -1
  23. package/src/{buttons → components/buttons}/MRT_ToggleDensePaddingButton.tsx +1 -1
  24. package/src/{buttons → components/buttons}/MRT_ToggleFiltersButton.tsx +1 -1
  25. package/src/{buttons → components/buttons}/MRT_ToggleFullScreenButton.tsx +1 -1
  26. package/src/{buttons → components/buttons}/MRT_ToggleGlobalFilterButton.tsx +1 -1
  27. package/src/{buttons → components/buttons}/MRT_ToggleRowActionMenuButton.tsx +9 -9
  28. package/src/{footer → components/footer}/MRT_TableFooter.tsx +2 -2
  29. package/src/{footer → components/footer}/MRT_TableFooterCell.tsx +3 -3
  30. package/src/{footer → components/footer}/MRT_TableFooterRow.tsx +3 -3
  31. package/src/{head → components/head}/MRT_TableHead.tsx +3 -3
  32. package/src/{head → components/head}/MRT_TableHeadCell.tsx +3 -3
  33. package/src/{head → components/head}/MRT_TableHeadCellColumnActionsButton.tsx +5 -6
  34. package/src/{head → components/head}/MRT_TableHeadCellFilterContainer.tsx +5 -5
  35. package/src/{head → components/head}/MRT_TableHeadCellFilterLabel.tsx +2 -2
  36. package/src/{head → components/head}/MRT_TableHeadCellGrabHandle.tsx +4 -3
  37. package/src/{head → components/head}/MRT_TableHeadCellResizeHandle.tsx +2 -2
  38. package/src/{head → components/head}/MRT_TableHeadCellSortLabel.tsx +2 -2
  39. package/src/{head → components/head}/MRT_TableHeadRow.tsx +3 -3
  40. package/src/{inputs → components/inputs}/MRT_EditCellTextField.tsx +12 -4
  41. package/src/{inputs → components/inputs}/MRT_FilterCheckbox.tsx +4 -4
  42. package/src/{inputs → components/inputs}/MRT_FilterRangeFields.tsx +2 -2
  43. package/src/{inputs → components/inputs}/MRT_FilterRangeSlider.tsx +2 -2
  44. package/src/{inputs → components/inputs}/MRT_FilterTextField.tsx +3 -3
  45. package/src/{inputs → components/inputs}/MRT_GlobalFilterTextField.tsx +2 -2
  46. package/src/{inputs → components/inputs}/MRT_SelectCheckbox.tsx +4 -4
  47. package/src/{menus → components/menus}/MRT_ColumnActionMenu.tsx +9 -1
  48. package/src/{menus → components/menus}/MRT_FilterOptionMenu.tsx +9 -1
  49. package/src/{menus → components/menus}/MRT_RowActionMenu.tsx +13 -2
  50. package/src/{menus → components/menus}/MRT_ShowHideColumnsMenu.tsx +11 -5
  51. package/src/{menus → components/menus}/MRT_ShowHideColumnsMenuItems.tsx +7 -7
  52. package/src/{modals → components/modals}/MRT_EditRowModal.tsx +4 -4
  53. package/src/{table → components/table}/MRT_Table.tsx +4 -4
  54. package/src/{table → components/table}/MRT_TableContainer.tsx +3 -3
  55. package/src/{table → components/table}/MRT_TableLoadingOverlay.tsx +3 -3
  56. package/src/{table → components/table}/MRT_TablePaper.tsx +3 -3
  57. package/src/{toolbar → components/toolbar}/MRT_BottomToolbar.tsx +3 -3
  58. package/src/{toolbar → components/toolbar}/MRT_LinearProgressBar.tsx +2 -2
  59. package/src/{toolbar → components/toolbar}/MRT_TablePagination.tsx +9 -7
  60. package/src/{toolbar → components/toolbar}/MRT_ToolbarAlertBanner.tsx +3 -3
  61. package/src/{toolbar → components/toolbar}/MRT_ToolbarDropZone.tsx +2 -2
  62. package/src/{toolbar → components/toolbar}/MRT_ToolbarInternalButtons.tsx +2 -2
  63. package/src/{toolbar → components/toolbar}/MRT_TopToolbar.tsx +3 -3
  64. package/src/{filterFns.ts → fns/filterFns.ts} +1 -1
  65. package/src/{sortingFns.ts → fns/sortingFns.ts} +1 -1
  66. package/src/hooks/display-columns/getMRT_DisplayColumns.tsx +26 -0
  67. package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +34 -0
  68. package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +35 -0
  69. package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +96 -0
  70. package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +36 -0
  71. package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +30 -0
  72. package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +40 -0
  73. package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +40 -0
  74. package/src/hooks/useMRT_ColumnVirtualizer.ts +2 -4
  75. package/src/hooks/useMRT_Effects.ts +7 -6
  76. package/src/hooks/useMRT_RowVirtualizer.ts +2 -4
  77. package/src/hooks/useMRT_Rows.ts +32 -6
  78. package/src/hooks/useMRT_TableInstance.ts +91 -87
  79. package/src/hooks/useMRT_TableOptions.ts +5 -3
  80. package/src/{useMaterialReactTable.ts → hooks/useMaterialReactTable.ts} +3 -3
  81. package/src/icons.ts +4 -38
  82. package/src/index.ts +88 -17
  83. package/src/types.ts +59 -26
  84. package/src/utils/column.utils.ts +173 -0
  85. package/src/utils/displayColumn.utils.ts +134 -0
  86. package/src/utils/row.utils.ts +26 -0
  87. package/src/{style.utils.ts → utils/style.utils.ts} +50 -28
  88. package/src/utils/tanstack.helpers.ts +64 -0
  89. package/src/utils/utils.ts +23 -0
  90. package/src/utils/virtualization.utils.ts +19 -0
  91. package/src/utils.ts +0 -0
  92. package/src/body/index.ts +0 -7
  93. package/src/buttons/index.ts +0 -13
  94. package/src/column.utils.ts +0 -368
  95. package/src/footer/index.ts +0 -3
  96. package/src/head/index.ts +0 -9
  97. package/src/hooks/index.ts +0 -7
  98. package/src/hooks/useMRT_DisplayColumns.tsx +0 -299
  99. package/src/inputs/index.ts +0 -7
  100. package/src/menus/index.ts +0 -5
  101. package/src/modals/index.ts +0 -1
  102. package/src/table/index.ts +0 -5
  103. package/src/toolbar/index.ts +0 -7
  104. /package/src/{aggregationFns.ts → fns/aggregationFns.ts} +0 -0
@@ -3,9 +3,9 @@ import CircularProgress, {
3
3
  type CircularProgressProps,
4
4
  } from '@mui/material/CircularProgress';
5
5
  import { alpha } from '@mui/material/styles';
6
- import { parseFromValuesOrFunc } from '../column.utils';
7
- import { getMRTTheme } from '../style.utils';
8
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
6
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
7
+ import { getMRTTheme } from '../../utils/style.utils';
8
+ import { parseFromValuesOrFunc } from '../../utils/utils';
9
9
 
10
10
  interface Props<TData extends MRT_RowData> extends CircularProgressProps {
11
11
  table: MRT_TableInstance<TData>;
@@ -1,10 +1,10 @@
1
1
  import Paper, { type PaperProps } from '@mui/material/Paper';
2
2
  import { MRT_TableContainer } from './MRT_TableContainer';
3
- import { parseFromValuesOrFunc } from '../column.utils';
4
- import { getMRTTheme } from '../style.utils';
3
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
4
+ import { getMRTTheme } from '../../utils/style.utils';
5
+ import { parseFromValuesOrFunc } from '../../utils/utils';
5
6
  import { MRT_BottomToolbar } from '../toolbar/MRT_BottomToolbar';
6
7
  import { MRT_TopToolbar } from '../toolbar/MRT_TopToolbar';
7
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
8
8
 
9
9
  interface Props<TData extends MRT_RowData> extends PaperProps {
10
10
  table: MRT_TableInstance<TData>;
@@ -5,9 +5,9 @@ import { MRT_LinearProgressBar } from './MRT_LinearProgressBar';
5
5
  import { MRT_TablePagination } from './MRT_TablePagination';
6
6
  import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
7
7
  import { MRT_ToolbarDropZone } from './MRT_ToolbarDropZone';
8
- import { parseFromValuesOrFunc } from '../column.utils';
9
- import { getCommonToolbarStyles } from '../style.utils';
10
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
8
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
9
+ import { getCommonToolbarStyles } from '../../utils/style.utils';
10
+ import { parseFromValuesOrFunc } from '../../utils/utils';
11
11
 
12
12
  interface Props<TData extends MRT_RowData> extends BoxProps {
13
13
  table: MRT_TableInstance<TData>;
@@ -2,8 +2,8 @@ import Collapse from '@mui/material/Collapse';
2
2
  import LinearProgress, {
3
3
  type LinearProgressProps,
4
4
  } from '@mui/material/LinearProgress';
5
- import { parseFromValuesOrFunc } from '../column.utils';
6
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
5
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
6
+ import { parseFromValuesOrFunc } from '../../utils/utils';
7
7
 
8
8
  interface Props<TData extends MRT_RowData> extends LinearProgressProps {
9
9
  isTopToolbar: boolean;
@@ -8,9 +8,9 @@ import Select, { type SelectProps } from '@mui/material/Select';
8
8
  import Tooltip from '@mui/material/Tooltip';
9
9
  import Typography from '@mui/material/Typography';
10
10
  import { useTheme } from '@mui/material/styles';
11
- import { parseFromValuesOrFunc } from '../column.utils';
12
- import { flipIconStyles } from '../style.utils';
13
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
11
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
12
+ import { flipIconStyles, getCommonTooltipProps } from '../../utils/style.utils';
13
+ import { parseFromValuesOrFunc } from '../../utils/utils';
14
14
 
15
15
  const defaultRowsPerPage = [5, 10, 15, 20, 25, 30, 50, 100];
16
16
 
@@ -79,6 +79,8 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
79
79
  const disableBack = pageIndex <= 0 || disabled;
80
80
  const disableNext = lastRowIndex >= totalRowCount || disabled;
81
81
 
82
+ const tooltipProps = getCommonTooltipProps();
83
+
82
84
  return (
83
85
  <Box
84
86
  className="MuiTablePagination-root"
@@ -173,7 +175,7 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
173
175
  } ${totalRowCount.toLocaleString()}`}</Typography>
174
176
  <Box gap="xs">
175
177
  {showFirstButton && (
176
- <Tooltip enterDelay={1000} title={localization.goToFirstPage}>
178
+ <Tooltip {...tooltipProps} title={localization.goToFirstPage}>
177
179
  <span>
178
180
  <IconButton
179
181
  aria-label={localization.goToFirstPage}
@@ -186,7 +188,7 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
186
188
  </span>
187
189
  </Tooltip>
188
190
  )}
189
- <Tooltip enterDelay={1000} title={localization.goToPreviousPage}>
191
+ <Tooltip {...tooltipProps} title={localization.goToPreviousPage}>
190
192
  <span>
191
193
  <IconButton
192
194
  aria-label={localization.goToPreviousPage}
@@ -198,7 +200,7 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
198
200
  </IconButton>
199
201
  </span>
200
202
  </Tooltip>
201
- <Tooltip enterDelay={1000} title={localization.goToNextPage}>
203
+ <Tooltip {...tooltipProps} title={localization.goToNextPage}>
202
204
  <span>
203
205
  <IconButton
204
206
  aria-label={localization.goToNextPage}
@@ -211,7 +213,7 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
211
213
  </span>
212
214
  </Tooltip>
213
215
  {showLastButton && (
214
- <Tooltip enterDelay={1000} title={localization.goToLastPage}>
216
+ <Tooltip {...tooltipProps} title={localization.goToLastPage}>
215
217
  <span>
216
218
  <IconButton
217
219
  aria-label={localization.goToLastPage}
@@ -5,9 +5,9 @@ import Box from '@mui/material/Box';
5
5
  import Chip from '@mui/material/Chip';
6
6
  import Collapse from '@mui/material/Collapse';
7
7
  import Stack from '@mui/material/Stack';
8
- import { parseFromValuesOrFunc } from '../column.utils';
9
- import { MRT_SelectCheckbox } from '../inputs';
10
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
8
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
9
+ import { parseFromValuesOrFunc } from '../../utils/utils';
10
+ import { MRT_SelectCheckbox } from '../inputs/MRT_SelectCheckbox';
11
11
 
12
12
  interface Props<TData extends MRT_RowData> extends AlertProps {
13
13
  stackAlertBanner?: boolean;
@@ -3,8 +3,8 @@ import Box, { type BoxProps } from '@mui/material/Box';
3
3
  import Fade from '@mui/material/Fade';
4
4
  import Typography from '@mui/material/Typography';
5
5
  import { alpha } from '@mui/material/styles';
6
- import { parseFromValuesOrFunc } from '../column.utils';
7
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
6
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
7
+ import { parseFromValuesOrFunc } from '../../utils/utils';
8
8
 
9
9
  interface Props<TData extends MRT_RowData> extends BoxProps {
10
10
  table: MRT_TableInstance<TData>;
@@ -1,11 +1,11 @@
1
1
  import Box, { type BoxProps } from '@mui/material/Box';
2
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
3
+ import { parseFromValuesOrFunc } from '../../utils/utils';
2
4
  import { MRT_ShowHideColumnsButton } from '../buttons/MRT_ShowHideColumnsButton';
3
5
  import { MRT_ToggleDensePaddingButton } from '../buttons/MRT_ToggleDensePaddingButton';
4
6
  import { MRT_ToggleFiltersButton } from '../buttons/MRT_ToggleFiltersButton';
5
7
  import { MRT_ToggleFullScreenButton } from '../buttons/MRT_ToggleFullScreenButton';
6
8
  import { MRT_ToggleGlobalFilterButton } from '../buttons/MRT_ToggleGlobalFilterButton';
7
- import { parseFromValuesOrFunc } from '../column.utils';
8
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
9
9
 
10
10
  interface Props<TData extends MRT_RowData> extends BoxProps {
11
11
  table: MRT_TableInstance<TData>;
@@ -5,10 +5,10 @@ import { MRT_TablePagination } from './MRT_TablePagination';
5
5
  import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
6
6
  import { MRT_ToolbarDropZone } from './MRT_ToolbarDropZone';
7
7
  import { MRT_ToolbarInternalButtons } from './MRT_ToolbarInternalButtons';
8
- import { parseFromValuesOrFunc } from '../column.utils';
8
+ import { type MRT_RowData, type MRT_TableInstance } from '../../types';
9
+ import { getCommonToolbarStyles } from '../../utils/style.utils';
10
+ import { parseFromValuesOrFunc } from '../../utils/utils';
9
11
  import { MRT_GlobalFilterTextField } from '../inputs/MRT_GlobalFilterTextField';
10
- import { getCommonToolbarStyles } from '../style.utils';
11
- import { type MRT_RowData, type MRT_TableInstance } from '../types';
12
12
 
13
13
  interface Props<TData extends MRT_RowData> {
14
14
  table: MRT_TableInstance<TData>;
@@ -4,7 +4,7 @@ import {
4
4
  rankings,
5
5
  } from '@tanstack/match-sorter-utils';
6
6
  import { type Row, filterFns } from '@tanstack/react-table';
7
- import { type MRT_RowData } from './types';
7
+ import { type MRT_RowData } from '../types';
8
8
 
9
9
  const fuzzy = <TData extends MRT_RowData>(
10
10
  row: Row<TData>,
@@ -1,6 +1,6 @@
1
1
  import { type RankingInfo, compareItems } from '@tanstack/match-sorter-utils';
2
2
  import { type Row, sortingFns } from '@tanstack/react-table';
3
- import { type MRT_Row, type MRT_RowData } from './types';
3
+ import { type MRT_Row, type MRT_RowData } from '../types';
4
4
 
5
5
  const fuzzy = <TData extends MRT_RowData>(
6
6
  rowA: Row<TData>,
@@ -0,0 +1,26 @@
1
+ import {
2
+ type MRT_ColumnDef,
3
+ type MRT_RowData,
4
+ type MRT_StatefulTableOptions,
5
+ } from '../../types';
6
+ import { getMRT_RowActionsColumnDef } from './getMRT_RowActionsColumnDef';
7
+ import { getMRT_RowDragColumnDef } from './getMRT_RowDragColumnDef';
8
+ import { getMRT_RowExpandColumnDef } from './getMRT_RowExpandColumnDef';
9
+ import { getMRT_RowNumbersColumnDef } from './getMRT_RowNumbersColumnDef';
10
+ import { getMRT_RowPinningColumnDef } from './getMRT_RowPinningColumnDef';
11
+ import { getMRT_RowSelectColumnDef } from './getMRT_RowSelectColumnDef';
12
+ import { getMRT_RowSpacerColumnDef } from './getMRT_RowSpacerColumnDef';
13
+
14
+ export const getMRT_DisplayColumns = <TData extends MRT_RowData>(
15
+ tableOptions: MRT_StatefulTableOptions<TData>,
16
+ ): MRT_ColumnDef<TData>[] => {
17
+ return [
18
+ getMRT_RowNumbersColumnDef(tableOptions),
19
+ getMRT_RowSelectColumnDef(tableOptions),
20
+ getMRT_RowExpandColumnDef(tableOptions),
21
+ getMRT_RowActionsColumnDef(tableOptions),
22
+ getMRT_RowDragColumnDef(tableOptions),
23
+ getMRT_RowPinningColumnDef(tableOptions),
24
+ getMRT_RowSpacerColumnDef(tableOptions),
25
+ ].filter(Boolean) as MRT_ColumnDef<TData>[];
26
+ };
@@ -0,0 +1,34 @@
1
+ import { MRT_ToggleRowActionMenuButton } from '../../components/buttons/MRT_ToggleRowActionMenuButton';
2
+ import {
3
+ type MRT_ColumnDef,
4
+ type MRT_RowData,
5
+ type MRT_StatefulTableOptions,
6
+ } from '../../types';
7
+ import {
8
+ defaultDisplayColumnProps,
9
+ showRowActionsColumn,
10
+ } from '../../utils/displayColumn.utils';
11
+
12
+ export const getMRT_RowActionsColumnDef = <TData extends MRT_RowData>(
13
+ tableOptions: MRT_StatefulTableOptions<TData>,
14
+ ): MRT_ColumnDef<TData> | null => {
15
+ if (!showRowActionsColumn(tableOptions)) {
16
+ return null;
17
+ }
18
+
19
+ return {
20
+ Cell: ({ cell, row, staticRowIndex, table }) => (
21
+ <MRT_ToggleRowActionMenuButton
22
+ cell={cell}
23
+ row={row}
24
+ staticRowIndex={staticRowIndex}
25
+ table={table}
26
+ />
27
+ ),
28
+ ...defaultDisplayColumnProps({
29
+ header: 'actions',
30
+ id: 'mrt-row-actions',
31
+ tableOptions,
32
+ }),
33
+ };
34
+ };
@@ -0,0 +1,35 @@
1
+ import { type RefObject } from 'react';
2
+ import { MRT_TableBodyRowGrabHandle } from '../../components/body/MRT_TableBodyRowGrabHandle';
3
+ import {
4
+ type MRT_ColumnDef,
5
+ type MRT_RowData,
6
+ type MRT_StatefulTableOptions,
7
+ } from '../../types';
8
+ import {
9
+ defaultDisplayColumnProps,
10
+ showRowDragColumn,
11
+ } from '../../utils/displayColumn.utils';
12
+
13
+ export const getMRT_RowDragColumnDef = <TData extends MRT_RowData>(
14
+ tableOptions: MRT_StatefulTableOptions<TData>,
15
+ ): MRT_ColumnDef<TData> | null => {
16
+ if (!showRowDragColumn(tableOptions)) {
17
+ return null;
18
+ }
19
+
20
+ return {
21
+ Cell: ({ row, rowRef, table }) => (
22
+ <MRT_TableBodyRowGrabHandle
23
+ row={row}
24
+ rowRef={rowRef as RefObject<HTMLTableRowElement>}
25
+ table={table}
26
+ />
27
+ ),
28
+ grow: false,
29
+ ...defaultDisplayColumnProps({
30
+ header: 'move',
31
+ id: 'mrt-row-drag',
32
+ tableOptions,
33
+ }),
34
+ };
35
+ };
@@ -0,0 +1,96 @@
1
+ import { type ReactNode } from 'react';
2
+ import Stack from '@mui/material/Stack';
3
+ import Tooltip from '@mui/material/Tooltip';
4
+ import { MRT_ExpandAllButton } from '../../components/buttons/MRT_ExpandAllButton';
5
+ import { MRT_ExpandButton } from '../../components/buttons/MRT_ExpandButton';
6
+ import {
7
+ type MRT_ColumnDef,
8
+ type MRT_RowData,
9
+ type MRT_StatefulTableOptions,
10
+ } from '../../types';
11
+ import {
12
+ defaultDisplayColumnProps,
13
+ showRowExpandColumn,
14
+ } from '../../utils/displayColumn.utils';
15
+ import { getCommonTooltipProps } from '../../utils/style.utils';
16
+
17
+ export const getMRT_RowExpandColumnDef = <TData extends MRT_RowData>(
18
+ tableOptions: MRT_StatefulTableOptions<TData>,
19
+ ): MRT_ColumnDef<TData> | null => {
20
+ if (!showRowExpandColumn(tableOptions)) {
21
+ return null;
22
+ }
23
+
24
+ const {
25
+ defaultColumn,
26
+ enableExpandAll,
27
+ groupedColumnMode,
28
+ positionExpandColumn,
29
+ renderDetailPanel,
30
+ state: { grouping },
31
+ } = tableOptions;
32
+
33
+ const alignProps =
34
+ positionExpandColumn === 'last'
35
+ ? ({
36
+ align: 'right',
37
+ } as const)
38
+ : undefined;
39
+
40
+ return {
41
+ Cell: ({ cell, column, row, staticRowIndex, table }) => {
42
+ const expandButtonProps = { row, staticRowIndex, table };
43
+ const subRowsLength = row.subRows?.length;
44
+ if (groupedColumnMode === 'remove' && row.groupingColumnId) {
45
+ return (
46
+ <Stack alignItems="center" flexDirection="row" gap="0.25rem">
47
+ <MRT_ExpandButton {...expandButtonProps} />
48
+ <Tooltip
49
+ {...getCommonTooltipProps('right')}
50
+ title={table.getColumn(row.groupingColumnId).columnDef.header}
51
+ >
52
+ <span>{row.groupingValue as ReactNode}</span>
53
+ </Tooltip>
54
+ {!!subRowsLength && <span>({subRowsLength})</span>}
55
+ </Stack>
56
+ );
57
+ } else {
58
+ return (
59
+ <>
60
+ <MRT_ExpandButton {...expandButtonProps} />
61
+ {column.columnDef.GroupedCell?.({ cell, column, row, table })}
62
+ </>
63
+ );
64
+ }
65
+ },
66
+ Header: enableExpandAll
67
+ ? ({ table }) => {
68
+ return (
69
+ <>
70
+ <MRT_ExpandAllButton table={table} />
71
+ {groupedColumnMode === 'remove' &&
72
+ grouping
73
+ ?.map(
74
+ (groupedColumnId) =>
75
+ table.getColumn(groupedColumnId).columnDef.header,
76
+ )
77
+ ?.join(', ')}
78
+ </>
79
+ );
80
+ }
81
+ : undefined,
82
+ muiTableBodyCellProps: alignProps,
83
+ muiTableHeadCellProps: alignProps,
84
+ ...defaultDisplayColumnProps({
85
+ header: 'expand',
86
+ id: 'mrt-row-expand',
87
+ size:
88
+ groupedColumnMode === 'remove'
89
+ ? defaultColumn?.size
90
+ : renderDetailPanel
91
+ ? 60
92
+ : 100,
93
+ tableOptions,
94
+ }),
95
+ };
96
+ };
@@ -0,0 +1,36 @@
1
+ import {
2
+ type MRT_ColumnDef,
3
+ type MRT_RowData,
4
+ type MRT_StatefulTableOptions,
5
+ } from '../../types';
6
+ import {
7
+ defaultDisplayColumnProps,
8
+ showRowNumbersColumn,
9
+ } from '../../utils/displayColumn.utils';
10
+
11
+ export const getMRT_RowNumbersColumnDef = <TData extends MRT_RowData>(
12
+ tableOptions: MRT_StatefulTableOptions<TData>,
13
+ ): MRT_ColumnDef<TData> | null => {
14
+ if (!showRowNumbersColumn(tableOptions)) {
15
+ return null;
16
+ }
17
+
18
+ const { localization, rowNumberDisplayMode } = tableOptions;
19
+ const {
20
+ pagination: { pageIndex, pageSize },
21
+ } = tableOptions.state;
22
+
23
+ return {
24
+ Cell: ({ row, staticRowIndex }) =>
25
+ ((rowNumberDisplayMode === 'static'
26
+ ? (staticRowIndex || 0) + (pageSize || 0) * (pageIndex || 0)
27
+ : row.index) ?? 0) + 1,
28
+ Header: () => localization.rowNumber,
29
+ grow: false,
30
+ ...defaultDisplayColumnProps({
31
+ header: 'rowNumbers',
32
+ id: 'mrt-row-numbers',
33
+ tableOptions,
34
+ }),
35
+ };
36
+ };
@@ -0,0 +1,30 @@
1
+ import { MRT_TableBodyRowPinButton } from '../../components/body/MRT_TableBodyRowPinButton';
2
+ import {
3
+ type MRT_ColumnDef,
4
+ type MRT_RowData,
5
+ type MRT_StatefulTableOptions,
6
+ } from '../../types';
7
+ import {
8
+ defaultDisplayColumnProps,
9
+ showRowPinningColumn,
10
+ } from '../../utils/displayColumn.utils';
11
+
12
+ export const getMRT_RowPinningColumnDef = <TData extends MRT_RowData>(
13
+ tableOptions: MRT_StatefulTableOptions<TData>,
14
+ ): MRT_ColumnDef<TData> | null => {
15
+ if (!showRowPinningColumn(tableOptions)) {
16
+ return null;
17
+ }
18
+
19
+ return {
20
+ Cell: ({ row, table }) => (
21
+ <MRT_TableBodyRowPinButton row={row} table={table} />
22
+ ),
23
+ grow: false,
24
+ ...defaultDisplayColumnProps({
25
+ header: 'pin',
26
+ id: 'mrt-row-pin',
27
+ tableOptions,
28
+ }),
29
+ };
30
+ };
@@ -0,0 +1,40 @@
1
+ import { MRT_SelectCheckbox } from '../../components/inputs/MRT_SelectCheckbox';
2
+ import {
3
+ type MRT_ColumnDef,
4
+ type MRT_RowData,
5
+ type MRT_StatefulTableOptions,
6
+ } from '../../types';
7
+ import {
8
+ defaultDisplayColumnProps,
9
+ showRowSelectionColumn,
10
+ } from '../../utils/displayColumn.utils';
11
+
12
+ export const getMRT_RowSelectColumnDef = <TData extends MRT_RowData>(
13
+ tableOptions: MRT_StatefulTableOptions<TData>,
14
+ ): MRT_ColumnDef<TData> | null => {
15
+ if (!showRowSelectionColumn(tableOptions)) {
16
+ return null;
17
+ }
18
+
19
+ const { enableMultiRowSelection, enableSelectAll } = tableOptions;
20
+
21
+ return {
22
+ Cell: ({ row, staticRowIndex, table }) => (
23
+ <MRT_SelectCheckbox
24
+ row={row}
25
+ staticRowIndex={staticRowIndex}
26
+ table={table}
27
+ />
28
+ ),
29
+ Header:
30
+ enableSelectAll && enableMultiRowSelection
31
+ ? ({ table }) => <MRT_SelectCheckbox selectAll table={table} />
32
+ : undefined,
33
+ grow: false,
34
+ ...defaultDisplayColumnProps({
35
+ header: 'select',
36
+ id: 'mrt-row-select',
37
+ tableOptions,
38
+ }),
39
+ };
40
+ };
@@ -0,0 +1,40 @@
1
+ import { MRT_DefaultDisplayColumn } from '../useMRT_TableOptions';
2
+ import {
3
+ type MRT_ColumnDef,
4
+ type MRT_RowData,
5
+ type MRT_StatefulTableOptions,
6
+ } from '../../types';
7
+ import {
8
+ defaultDisplayColumnProps,
9
+ showRowSpacerColumn,
10
+ } from '../../utils/displayColumn.utils';
11
+
12
+ const blankColProps = {
13
+ children: null,
14
+ sx: {
15
+ minWidth: 0,
16
+ p: 0,
17
+ width: 0,
18
+ },
19
+ };
20
+
21
+ export const getMRT_RowSpacerColumnDef = <TData extends MRT_RowData>(
22
+ tableOptions: MRT_StatefulTableOptions<TData>,
23
+ ): MRT_ColumnDef<TData> | null => {
24
+ if (!showRowSpacerColumn(tableOptions)) {
25
+ return null;
26
+ }
27
+
28
+ return {
29
+ ...defaultDisplayColumnProps({
30
+ id: 'mrt-row-spacer',
31
+ size: 0,
32
+ tableOptions,
33
+ }),
34
+ grow: true,
35
+ ...MRT_DefaultDisplayColumn,
36
+ muiTableBodyCellProps: blankColProps,
37
+ muiTableFooterCellProps: blankColProps,
38
+ muiTableHeadCellProps: blankColProps,
39
+ };
40
+ };
@@ -1,14 +1,12 @@
1
1
  import { useCallback, useMemo } from 'react';
2
2
  import { type Range, useVirtualizer } from '@tanstack/react-virtual';
3
- import {
4
- extraIndexRangeExtractor,
5
- parseFromValuesOrFunc,
6
- } from '../column.utils';
7
3
  import {
8
4
  type MRT_ColumnVirtualizer,
9
5
  type MRT_RowData,
10
6
  type MRT_TableInstance,
11
7
  } from '../types';
8
+ import { parseFromValuesOrFunc } from '../utils/utils';
9
+ import { extraIndexRangeExtractor } from '../utils/virtualization.utils';
12
10
 
13
11
  export const useMRT_ColumnVirtualizer = <
14
12
  TData extends MRT_RowData,
@@ -1,16 +1,17 @@
1
1
  import { useEffect, useReducer, useRef } from 'react';
2
- import { getCanRankRows } from '../column.utils';
3
2
  import {
4
3
  type MRT_RowData,
5
4
  type MRT_SortingState,
6
5
  type MRT_TableInstance,
7
6
  } from '../types';
7
+ import { getCanRankRows } from '../utils/row.utils';
8
8
 
9
9
  export const useMRT_Effects = <TData extends MRT_RowData>(
10
10
  table: MRT_TableInstance<TData>,
11
11
  ) => {
12
12
  const {
13
13
  getIsSomeRowsPinned,
14
+ getPrePaginationRowModel,
14
15
  getState,
15
16
  options: { enablePagination, enableRowPinning, rowCount },
16
17
  } = table;
@@ -24,6 +25,8 @@ export const useMRT_Effects = <TData extends MRT_RowData>(
24
25
  sorting,
25
26
  } = getState();
26
27
 
28
+ const totalRowCount = rowCount ?? getPrePaginationRowModel().rows.length;
29
+
27
30
  const rerender = useReducer(() => ({}), {})[1];
28
31
  const isMounted = useRef(false);
29
32
  const initialBodyHeight = useRef<string>();
@@ -57,13 +60,11 @@ export const useMRT_Effects = <TData extends MRT_RowData>(
57
60
  useEffect(() => {
58
61
  if (!enablePagination || isLoading || showSkeletons) return;
59
62
  const { pageIndex, pageSize } = pagination;
60
- const totalRowCount =
61
- rowCount ?? table.getPrePaginationRowModel().rows.length;
62
63
  const firstVisibleRowIndex = pageIndex * pageSize;
63
- if (firstVisibleRowIndex > totalRowCount) {
64
- table.setPageIndex(Math.floor(totalRowCount / pageSize));
64
+ if (firstVisibleRowIndex >= totalRowCount) {
65
+ table.setPageIndex(Math.ceil(totalRowCount / pageSize) - 1);
65
66
  }
66
- }, [rowCount, table.getPrePaginationRowModel().rows.length]);
67
+ }, [totalRowCount]);
67
68
 
68
69
  //turn off sort when global filter is looking for ranked results
69
70
  const appliedSort = useRef<MRT_SortingState>(sorting);
@@ -1,15 +1,13 @@
1
1
  import { useCallback } from 'react';
2
2
  import { type Range, useVirtualizer } from '@tanstack/react-virtual';
3
- import {
4
- extraIndexRangeExtractor,
5
- parseFromValuesOrFunc,
6
- } from '../column.utils';
7
3
  import {
8
4
  type MRT_Row,
9
5
  type MRT_RowData,
10
6
  type MRT_RowVirtualizer,
11
7
  type MRT_TableInstance,
12
8
  } from '../types';
9
+ import { parseFromValuesOrFunc } from '../utils/utils';
10
+ import { extraIndexRangeExtractor } from '../utils/virtualization.utils';
13
11
 
14
12
  export const useMRT_RowVirtualizer = <
15
13
  TData extends MRT_RowData,