material-react-table 1.4.0-beta.0 → 1.4.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +2 -0
  2. package/dist/cjs/index.js +654 -85
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/types/MaterialReactTable.d.ts +6 -13
  5. package/dist/cjs/types/body/MRT_TableBodyCell.d.ts +1 -1
  6. package/dist/cjs/types/body/MRT_TableBodyRow.d.ts +3 -1
  7. package/dist/cjs/types/body/MRT_TableBodyRowGrabHandle.d.ts +1 -1
  8. package/dist/cjs/types/table/MRT_TableRoot.d.ts +4 -4
  9. package/dist/esm/material-react-table.esm.js +927 -376
  10. package/dist/esm/material-react-table.esm.js.map +1 -1
  11. package/dist/esm/types/MaterialReactTable.d.ts +6 -13
  12. package/dist/esm/types/body/MRT_TableBodyCell.d.ts +1 -1
  13. package/dist/esm/types/body/MRT_TableBodyRow.d.ts +3 -1
  14. package/dist/esm/types/body/MRT_TableBodyRowGrabHandle.d.ts +1 -1
  15. package/dist/esm/types/table/MRT_TableRoot.d.ts +4 -4
  16. package/dist/index.d.ts +7 -14
  17. package/package.json +4 -3
  18. package/src/MaterialReactTable.tsx +15 -22
  19. package/src/body/MRT_TableBody.tsx +53 -77
  20. package/src/body/MRT_TableBodyCell.tsx +1 -3
  21. package/src/body/MRT_TableBodyRow.tsx +16 -9
  22. package/src/body/MRT_TableBodyRowGrabHandle.tsx +1 -1
  23. package/src/body/MRT_TableDetailPanel.tsx +7 -1
  24. package/src/column.utils.ts +0 -1
  25. package/src/footer/MRT_TableFooter.tsx +2 -1
  26. package/src/footer/MRT_TableFooterCell.tsx +3 -1
  27. package/src/footer/MRT_TableFooterRow.tsx +10 -2
  28. package/src/head/MRT_TableHead.tsx +3 -3
  29. package/src/head/MRT_TableHeadCell.tsx +0 -2
  30. package/src/head/MRT_TableHeadCellFilterLabel.tsx +7 -0
  31. package/src/head/MRT_TableHeadRow.tsx +2 -3
  32. package/src/table/MRT_Table.tsx +1 -2
  33. package/src/table/MRT_TableContainer.tsx +7 -5
@@ -19,7 +19,7 @@ import type { TableRowProps } from '@mui/material/TableRow';
19
19
  import type { TextFieldProps } from '@mui/material/TextField';
20
20
  import type { ToolbarProps } from '@mui/material/Toolbar';
21
21
  import type { AggregationFn, Cell, Column, ColumnDef, DeepKeys, FilterFn, Header, HeaderGroup, OnChangeFn, Row, SortingFn, Table, TableOptions, TableState } from '@tanstack/react-table';
22
- import type { Options as VirtualizerOptions, VirtualItem } from 'react-virtual';
22
+ import type { VirtualizerOptions, Virtualizer } from '@tanstack/react-virtual';
23
23
  import { MRT_AggregationFns } from './aggregationFns';
24
24
  import { MRT_FilterFns } from './filterFns';
25
25
  import { MRT_Icons } from './icons';
@@ -266,7 +266,7 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<ColumnD
266
266
  * @example columnDefType: 'display'
267
267
  */
268
268
  columnDefType?: 'data' | 'display' | 'group';
269
- columnFilterModeOptions?: MRT_FilterOption[] | null;
269
+ columnFilterModeOptions?: Array<LiteralUnion<string & MRT_FilterOption>> | null;
270
270
  columns?: MRT_ColumnDef<TData>[];
271
271
  enableClickToCopy?: boolean;
272
272
  enableColumnActions?: boolean;
@@ -405,7 +405,7 @@ export type MRT_DisplayColumnIds = 'mrt-row-actions' | 'mrt-row-drag' | 'mrt-row
405
405
  * @link https://www.material-react-table.com/docs/api/props
406
406
  */
407
407
  export type MaterialReactTableProps<TData extends Record<string, any> = {}> = Omit<Partial<TableOptions<TData>>, 'columns' | 'data' | 'defaultColumn' | 'enableRowSelection' | 'expandRowsFn' | 'getRowId' | 'globalFilterFn' | 'initialState' | 'onStateChange' | 'state'> & {
408
- columnFilterModeOptions?: (MRT_FilterOption | string)[] | null;
408
+ columnFilterModeOptions?: Array<LiteralUnion<string & MRT_FilterOption>> | null;
409
409
  /**
410
410
  * The columns to display in the table. `accessorKey`s or `accessorFn`s must match keys in the `data` prop.
411
411
  *
@@ -687,17 +687,10 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> = Om
687
687
  selectAllMode?: 'all' | 'page';
688
688
  state?: Partial<MRT_TableState<TData>>;
689
689
  tableInstanceRef?: MutableRefObject<MRT_TableInstance<TData> | null>;
690
- virtualizerProps?: Partial<VirtualizerOptions<HTMLDivElement>> | (({ table, }: {
690
+ virtualizerProps?: Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>> | (({ table, }: {
691
691
  table: MRT_TableInstance<TData>;
692
- }) => Partial<VirtualizerOptions<HTMLDivElement>>);
693
- virtualizerInstanceRef?: MutableRefObject<Virtualizer | null>;
694
- };
695
- export type Virtualizer = {
696
- virtualItems: VirtualItem[];
697
- totalSize: number;
698
- scrollToOffset: (index: number, options?: any | undefined) => void;
699
- scrollToIndex: (index: number, options?: any | undefined) => void;
700
- measure: () => void;
692
+ }) => Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>);
693
+ virtualizerInstanceRef?: MutableRefObject<Virtualizer<HTMLDivElement, HTMLTableRowElement> | null>;
701
694
  };
702
695
  declare const MaterialReactTable: <TData extends Record<string, any> = {}>({ aggregationFns, autoResetExpanded, columnResizeMode, defaultColumn, defaultDisplayColumn, editingMode, enableBottomToolbar, enableColumnActions, enableColumnFilters, enableColumnOrdering, enableColumnResizing, enableDensityToggle, enableExpandAll, enableFilters, enableFullScreenToggle, enableGlobalFilter, enableGlobalFilterRankedResults, enableGrouping, enableHiding, enableMultiRowSelection, enableMultiSort, enablePagination, enablePinning, enableRowSelection, enableSelectAll, enableSorting, enableStickyHeader, enableTableFooter, enableTableHead, enableToolbarInternalActions, enableTopToolbar, filterFns, icons, layoutMode, localization, positionActionsColumn, positionExpandColumn, positionGlobalFilter, positionPagination, positionToolbarAlertBanner, positionToolbarDropZone, rowNumberMode, selectAllMode, sortingFns, ...rest }: MaterialReactTableProps<TData>) => JSX.Element;
703
696
  export default MaterialReactTable;
@@ -5,7 +5,7 @@ interface Props {
5
5
  enableHover?: boolean;
6
6
  numRows: number;
7
7
  rowIndex: number;
8
- rowRef: RefObject<HTMLDivElement | HTMLTableRowElement>;
8
+ rowRef: RefObject<HTMLTableRowElement>;
9
9
  table: MRT_TableInstance;
10
10
  }
11
11
  export declare const MRT_TableBodyCell: FC<Props>;
@@ -1,11 +1,13 @@
1
1
  import React, { FC } from 'react';
2
+ import type { VirtualItem } from '@tanstack/react-virtual';
2
3
  import type { MRT_Row, MRT_TableInstance } from '..';
3
4
  interface Props {
5
+ measureElement?: (element: HTMLTableRowElement) => void;
4
6
  numRows: number;
5
7
  row: MRT_Row;
6
8
  rowIndex: number;
7
9
  table: MRT_TableInstance;
8
- virtualRow?: any;
10
+ virtualRow?: VirtualItem;
9
11
  }
10
12
  export declare const MRT_TableBodyRow: FC<Props>;
11
13
  export declare const Memo_MRT_TableBodyRow: React.NamedExoticComponent<Props>;
@@ -2,7 +2,7 @@ import { FC, RefObject } from 'react';
2
2
  import { MRT_Cell, MRT_TableInstance } from '..';
3
3
  interface Props {
4
4
  cell: MRT_Cell;
5
- rowRef: RefObject<HTMLDivElement | HTMLTableRowElement>;
5
+ rowRef: RefObject<HTMLTableRowElement>;
6
6
  table: MRT_TableInstance;
7
7
  }
8
8
  export declare const MRT_TableBodyRowGrabHandle: FC<Props>;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import type { MRT_Cell, MRT_Column, MRT_ColumnDef, MRT_FilterOption, MRT_Row, MRT_TableInstance, MRT_TableState, MaterialReactTableProps, MRT_Localization } from '..';
3
3
  export declare const MRT_TableRoot: <TData extends Record<string, any> = {}>(props: Omit<Partial<import("@tanstack/react-table").TableOptions<TData>>, "state" | "data" | "onStateChange" | "initialState" | "getRowId" | "columns" | "defaultColumn" | "globalFilterFn" | "enableRowSelection" | "expandRowsFn"> & {
4
- columnFilterModeOptions?: (string | (string & Record<never, never>))[] | null | undefined;
4
+ columnFilterModeOptions?: (string & MRT_FilterOption)[] | null | undefined;
5
5
  columns: MRT_ColumnDef<TData>[];
6
6
  data: TData[];
7
7
  defaultColumn?: Partial<MRT_ColumnDef<TData>> | undefined;
@@ -253,10 +253,10 @@ export declare const MRT_TableRoot: <TData extends Record<string, any> = {}>(pro
253
253
  selectAllMode?: "all" | "page" | undefined;
254
254
  state?: Partial<MRT_TableState<TData>> | undefined;
255
255
  tableInstanceRef?: React.MutableRefObject<MRT_TableInstance<TData> | null> | undefined;
256
- virtualizerProps?: Partial<import("react-virtual").Options<HTMLDivElement>> | (({ table, }: {
256
+ virtualizerProps?: Partial<import("@tanstack/react-virtual").VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>> | (({ table, }: {
257
257
  table: MRT_TableInstance<TData>;
258
- }) => Partial<import("react-virtual").Options<HTMLDivElement>>) | undefined;
259
- virtualizerInstanceRef?: React.MutableRefObject<import("..").Virtualizer | null> | undefined;
258
+ }) => Partial<import("@tanstack/react-virtual").VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>) | undefined;
259
+ virtualizerInstanceRef?: React.MutableRefObject<import("@tanstack/react-virtual").Virtualizer<HTMLDivElement, HTMLTableRowElement> | null> | undefined;
260
260
  } & {
261
261
  localization: MRT_Localization;
262
262
  }) => JSX.Element;
package/dist/index.d.ts CHANGED
@@ -21,7 +21,7 @@ import { TextFieldProps } from '@mui/material/TextField';
21
21
  import { ToolbarProps } from '@mui/material/Toolbar';
22
22
  import * as _tanstack_react_table from '@tanstack/react-table';
23
23
  import { Row, Table, TableState, ColumnDef, DeepKeys, Column, Header, HeaderGroup, Cell, AggregationFn, SortingFn, FilterFn, TableOptions, OnChangeFn } from '@tanstack/react-table';
24
- import { Options, VirtualItem } from 'react-virtual';
24
+ import { VirtualizerOptions, Virtualizer } from '@tanstack/react-virtual';
25
25
  import { RankingInfo } from '@tanstack/match-sorter-utils';
26
26
 
27
27
  declare const MRT_AggregationFns: {
@@ -389,7 +389,7 @@ type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<ColumnDef<TDat
389
389
  * @example columnDefType: 'display'
390
390
  */
391
391
  columnDefType?: 'data' | 'display' | 'group';
392
- columnFilterModeOptions?: MRT_FilterOption[] | null;
392
+ columnFilterModeOptions?: Array<LiteralUnion<string & MRT_FilterOption>> | null;
393
393
  columns?: MRT_ColumnDef<TData>[];
394
394
  enableClickToCopy?: boolean;
395
395
  enableColumnActions?: boolean;
@@ -528,7 +528,7 @@ type MRT_DisplayColumnIds = 'mrt-row-actions' | 'mrt-row-drag' | 'mrt-row-expand
528
528
  * @link https://www.material-react-table.com/docs/api/props
529
529
  */
530
530
  type MaterialReactTableProps<TData extends Record<string, any> = {}> = Omit<Partial<TableOptions<TData>>, 'columns' | 'data' | 'defaultColumn' | 'enableRowSelection' | 'expandRowsFn' | 'getRowId' | 'globalFilterFn' | 'initialState' | 'onStateChange' | 'state'> & {
531
- columnFilterModeOptions?: (MRT_FilterOption | string)[] | null;
531
+ columnFilterModeOptions?: Array<LiteralUnion<string & MRT_FilterOption>> | null;
532
532
  /**
533
533
  * The columns to display in the table. `accessorKey`s or `accessorFn`s must match keys in the `data` prop.
534
534
  *
@@ -810,17 +810,10 @@ type MaterialReactTableProps<TData extends Record<string, any> = {}> = Omit<Part
810
810
  selectAllMode?: 'all' | 'page';
811
811
  state?: Partial<MRT_TableState<TData>>;
812
812
  tableInstanceRef?: MutableRefObject<MRT_TableInstance<TData> | null>;
813
- virtualizerProps?: Partial<Options<HTMLDivElement>> | (({ table, }: {
813
+ virtualizerProps?: Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>> | (({ table, }: {
814
814
  table: MRT_TableInstance<TData>;
815
- }) => Partial<Options<HTMLDivElement>>);
816
- virtualizerInstanceRef?: MutableRefObject<Virtualizer | null>;
817
- };
818
- type Virtualizer = {
819
- virtualItems: VirtualItem[];
820
- totalSize: number;
821
- scrollToOffset: (index: number, options?: any | undefined) => void;
822
- scrollToIndex: (index: number, options?: any | undefined) => void;
823
- measure: () => void;
815
+ }) => Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>);
816
+ virtualizerInstanceRef?: MutableRefObject<Virtualizer<HTMLDivElement, HTMLTableRowElement> | null>;
824
817
  };
825
818
  declare const MaterialReactTable: <TData extends Record<string, any> = {}>({ aggregationFns, autoResetExpanded, columnResizeMode, defaultColumn, defaultDisplayColumn, editingMode, enableBottomToolbar, enableColumnActions, enableColumnFilters, enableColumnOrdering, enableColumnResizing, enableDensityToggle, enableExpandAll, enableFilters, enableFullScreenToggle, enableGlobalFilter, enableGlobalFilterRankedResults, enableGrouping, enableHiding, enableMultiRowSelection, enableMultiSort, enablePagination, enablePinning, enableRowSelection, enableSelectAll, enableSorting, enableStickyHeader, enableTableFooter, enableTableHead, enableToolbarInternalActions, enableTopToolbar, filterFns, icons, layoutMode, localization, positionActionsColumn, positionExpandColumn, positionGlobalFilter, positionPagination, positionToolbarAlertBanner, positionToolbarDropZone, rowNumberMode, selectAllMode, sortingFns, ...rest }: MaterialReactTableProps<TData>) => JSX.Element;
826
819
 
@@ -882,4 +875,4 @@ interface Props<TData extends Record<string, any> = {}> {
882
875
  }
883
876
  declare const MRT_ToolbarInternalButtons: <TData extends Record<string, any> = {}>({ table, }: Props<TData>) => JSX.Element;
884
877
 
885
- export { DensityState, MRT_AggregationFn, MRT_AggregationOption, MRT_Cell, MRT_Column, MRT_ColumnDef, MRT_CopyButton, MRT_DefinedColumnDef, MRT_DisplayColumnIds, MRT_FilterFn, MRT_FilterOption, MRT_FilterOptionMenu, MRT_FullScreenToggleButton, MRT_GlobalFilterTextField, MRT_Header, MRT_HeaderGroup, MRT_Icons, MRT_InternalFilterOption, MRT_Localization, MRT_Row, MRT_RowModel, MRT_ShowHideColumnsButton, MRT_SortingFn, MRT_SortingOption, MRT_TableInstance, MRT_TablePagination, MRT_TableState, MRT_ToggleDensePaddingButton, MRT_ToggleFiltersButton, MRT_ToggleGlobalFilterButton, MRT_ToolbarInternalButtons, MaterialReactTableProps, Virtualizer, MaterialReactTable as default };
878
+ export { DensityState, MRT_AggregationFn, MRT_AggregationOption, MRT_Cell, MRT_Column, MRT_ColumnDef, MRT_CopyButton, MRT_DefinedColumnDef, MRT_DisplayColumnIds, MRT_FilterFn, MRT_FilterOption, MRT_FilterOptionMenu, MRT_FullScreenToggleButton, MRT_GlobalFilterTextField, MRT_Header, MRT_HeaderGroup, MRT_Icons, MRT_InternalFilterOption, MRT_Localization, MRT_Row, MRT_RowModel, MRT_ShowHideColumnsButton, MRT_SortingFn, MRT_SortingOption, MRT_TableInstance, MRT_TablePagination, MRT_TableState, MRT_ToggleDensePaddingButton, MRT_ToggleFiltersButton, MRT_ToggleGlobalFilterButton, MRT_ToolbarInternalButtons, MaterialReactTableProps, MaterialReactTable as default };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.4.0-beta.0",
2
+ "version": "1.4.0-beta.2",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
5
  "description": "A fully featured Material UI V5 implementation of TanStack React Table V8, written from the ground up in TypeScript.",
@@ -46,7 +46,9 @@
46
46
  },
47
47
  "scripts": {
48
48
  "build": "rm -rf dist locales && rollup -c && size-limit",
49
+ "dev": "rm -rf dist locales && rollup -c -w",
49
50
  "lib:build": "rm -rf dist locales && rollup -c && size-limit",
51
+ "lib:dev": "rm -rf dist locales && rollup -c -w",
50
52
  "lint": "eslint .",
51
53
  "size": "size-limit"
52
54
  },
@@ -55,7 +57,6 @@
55
57
  "@babel/preset-react": "^7.18.6",
56
58
  "@emotion/react": "^11.10.5",
57
59
  "@emotion/styled": "^11.10.5",
58
- "@faker-js/faker": "^7.6.0",
59
60
  "@mui/icons-material": "^5.10.16",
60
61
  "@mui/material": "^5.10.16",
61
62
  "@rollup/plugin-babel": "^6.0.3",
@@ -91,6 +92,6 @@
91
92
  "dependencies": {
92
93
  "@tanstack/match-sorter-utils": "8.7.0",
93
94
  "@tanstack/react-table": "8.7.0",
94
- "react-virtual": "^2.10.4"
95
+ "@tanstack/react-virtual": "^3.0.0-beta.29"
95
96
  }
96
97
  }
@@ -40,8 +40,7 @@ import type {
40
40
  TableOptions,
41
41
  TableState,
42
42
  } from '@tanstack/react-table';
43
- import type { Options as VirtualizerOptions, VirtualItem } from 'react-virtual';
44
- // import type { VirtualizerOptions } from '@tanstack/react-virtual';
43
+ import type { VirtualizerOptions, Virtualizer } from '@tanstack/react-virtual';
45
44
  import { MRT_AggregationFns } from './aggregationFns';
46
45
  import { MRT_DefaultColumn, MRT_DefaultDisplayColumn } from './column.utils';
47
46
  import { MRT_FilterFns } from './filterFns';
@@ -361,7 +360,9 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
361
360
  * @example columnDefType: 'display'
362
361
  */
363
362
  columnDefType?: 'data' | 'display' | 'group';
364
- columnFilterModeOptions?: MRT_FilterOption[] | null;
363
+ columnFilterModeOptions?: Array<
364
+ LiteralUnion<string & MRT_FilterOption>
365
+ > | null;
365
366
  columns?: MRT_ColumnDef<TData>[];
366
367
  enableClickToCopy?: boolean;
367
368
  enableColumnActions?: boolean;
@@ -619,7 +620,9 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
619
620
  | 'onStateChange'
620
621
  | 'state'
621
622
  > & {
622
- columnFilterModeOptions?: (MRT_FilterOption | string)[] | null;
623
+ columnFilterModeOptions?: Array<
624
+ LiteralUnion<string & MRT_FilterOption>
625
+ > | null;
623
626
  /**
624
627
  * The columns to display in the table. `accessorKey`s or `accessorFn`s must match keys in the `data` prop.
625
628
  *
@@ -1049,30 +1052,18 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
1049
1052
  state?: Partial<MRT_TableState<TData>>;
1050
1053
  tableInstanceRef?: MutableRefObject<MRT_TableInstance<TData> | null>;
1051
1054
  virtualizerProps?:
1052
- | Partial<VirtualizerOptions<HTMLDivElement>>
1055
+ | Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>
1053
1056
  | (({
1054
1057
  table,
1055
1058
  }: {
1056
1059
  table: MRT_TableInstance<TData>;
1057
- }) => Partial<VirtualizerOptions<HTMLDivElement>>);
1058
- // virtualizerProps?:
1059
- // | Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>
1060
- // | (({
1061
- // table,
1062
- // }: {
1063
- // table: MRT_TableInstance<TData>;
1064
- // }) => Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>);
1065
- virtualizerInstanceRef?: MutableRefObject<Virtualizer | null>;
1060
+ }) => Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>);
1061
+ virtualizerInstanceRef?: MutableRefObject<Virtualizer<
1062
+ HTMLDivElement,
1063
+ HTMLTableRowElement
1064
+ > | null>;
1066
1065
  };
1067
1066
 
1068
- export type Virtualizer = {
1069
- virtualItems: VirtualItem[];
1070
- totalSize: number;
1071
- scrollToOffset: (index: number, options?: any | undefined) => void;
1072
- scrollToIndex: (index: number, options?: any | undefined) => void;
1073
- measure: () => void;
1074
- };
1075
-
1076
1067
  const MaterialReactTable = <TData extends Record<string, any> = {}>({
1077
1068
  aggregationFns,
1078
1069
  autoResetExpanded = false,
@@ -1146,6 +1137,8 @@ const MaterialReactTable = <TData extends Record<string, any> = {}>({
1146
1137
  [],
1147
1138
  );
1148
1139
 
1140
+ if (rest.enableRowVirtualization) layoutMode = 'grid';
1141
+
1149
1142
  return (
1150
1143
  <MRT_TableRoot
1151
1144
  aggregationFns={_aggregationFns}
@@ -1,6 +1,9 @@
1
1
  import React, { FC, memo, useMemo } from 'react';
2
- import { useVirtual } from 'react-virtual'; //stuck on v2 for now
3
- // import { useVirtualizer, Virtualizer } from '@tanstack/react-virtual';
2
+ import {
3
+ useVirtualizer,
4
+ Virtualizer,
5
+ VirtualItem,
6
+ } from '@tanstack/react-virtual';
4
7
  import TableBody from '@mui/material/TableBody';
5
8
  import Typography from '@mui/material/Typography';
6
9
  import { Memo_MRT_TableBodyRow, MRT_TableBodyRow } from './MRT_TableBodyRow';
@@ -31,7 +34,8 @@ export const MRT_TableBody: FC<Props> = ({ table }) => {
31
34
  },
32
35
  refs: { tableContainerRef, tablePaperRef },
33
36
  } = table;
34
- const { columnFilters, globalFilter, pagination, sorting } = getState();
37
+ const { columnFilters, density, globalFilter, pagination, sorting } =
38
+ getState();
35
39
 
36
40
  const tableBodyProps =
37
41
  muiTableBodyProps instanceof Function
@@ -74,70 +78,51 @@ export const MRT_TableBody: FC<Props> = ({ table }) => {
74
78
  pagination.pageSize,
75
79
  ]);
76
80
 
77
- const virtualizer = enableRowVirtualization
78
- ? useVirtual({
79
- size: rows.length,
80
- parentRef: tableContainerRef,
81
- overscan: 15,
81
+ const virtualizer:
82
+ | Virtualizer<HTMLDivElement, HTMLTableRowElement>
83
+ | undefined = enableRowVirtualization
84
+ ? useVirtualizer({
85
+ count: rows.length,
86
+ estimateSize: () =>
87
+ density === 'compact' ? 37 : density === 'comfortable' ? 58 : 73,
88
+ getScrollElement: () => tableContainerRef.current,
89
+ measureElement: (element) => element?.getBoundingClientRect().height,
90
+ overscan: 10,
82
91
  ...vProps,
83
92
  })
84
- : ({} as any);
93
+ : undefined;
85
94
 
86
- if (virtualizerInstanceRef) {
95
+ if (virtualizerInstanceRef && virtualizer) {
87
96
  virtualizerInstanceRef.current = virtualizer;
88
97
  }
89
98
 
90
- // const virtualizer: Virtualizer = enableRowVirtualization
91
- // ? useVirtualizer({
92
- // count: rows.length,
93
- // estimateSize: () => (density === 'compact' ? 25 : 50),
94
- // getScrollElement: () => tableContainerRef.current as HTMLDivElement,
95
- // overscan: 15,
96
- // ...vProps,
97
- // })
98
- // : ({} as any);
99
-
100
- const virtualRows = enableRowVirtualization ? virtualizer.virtualItems : [];
101
-
102
- // const virtualRows = enableRowVirtualization
103
- // ? virtualizer.getVirtualItems()
104
- // : [];
105
-
106
- let paddingTop = 0;
107
- let paddingBottom = 0;
108
- if (enableRowVirtualization) {
109
- paddingTop = virtualRows.length ? virtualRows[0].start : 0;
110
- paddingBottom = virtualRows.length
111
- ? virtualizer.totalSize - virtualRows[virtualRows.length - 1].end
112
- : 0;
113
- }
114
- // if (enableRowVirtualization) {
115
- // paddingTop = !!virtualRows.length ? virtualRows[0].start : 0;
116
- // paddingBottom = !!virtualRows.length
117
- // ? virtualizer.getTotalSize() - virtualRows[virtualRows.length - 1].end
118
- // : 0;
119
- // }
99
+ const virtualRows = virtualizer ? virtualizer.getVirtualItems() : undefined;
120
100
 
121
101
  return (
122
102
  <TableBody
123
- component={layoutMode === 'grid' ? 'div' : 'tbody'}
124
- role="rowgroup"
125
103
  {...tableBodyProps}
126
104
  sx={(theme) => ({
127
105
  display: layoutMode === 'grid' ? 'grid' : 'table-row-group',
106
+ height: virtualizer ? `${virtualizer.getTotalSize()}px` : 'inherit',
107
+ position: 'relative',
128
108
  ...(tableBodyProps?.sx instanceof Function
129
109
  ? tableBodyProps?.sx(theme)
130
110
  : (tableBodyProps?.sx as any)),
131
111
  })}
132
112
  >
133
113
  {tableBodyProps?.children ?? !rows.length ? (
134
- <tr>
135
- <td colSpan={table.getVisibleLeafColumns().length}>
114
+ <tr style={{ display: layoutMode === 'grid' ? 'grid' : 'table-row' }}>
115
+ <td
116
+ colSpan={table.getVisibleLeafColumns().length}
117
+ style={{ display: layoutMode === 'grid' ? 'grid' : 'table-cell' }}
118
+ >
136
119
  <Typography
137
120
  sx={{
138
121
  color: 'text.secondary',
139
122
  fontStyle: 'italic',
140
- maxWidth: `min(100vw, ${tablePaperRef.current?.clientWidth}px)`,
123
+ maxWidth: `min(100vw, ${
124
+ tablePaperRef.current?.clientWidth ?? 360
125
+ }px)`,
141
126
  py: '2rem',
142
127
  textAlign: 'center',
143
128
  width: '100%',
@@ -151,38 +136,29 @@ export const MRT_TableBody: FC<Props> = ({ table }) => {
151
136
  </tr>
152
137
  ) : (
153
138
  <>
154
- {enableRowVirtualization && paddingTop > 0 && (
155
- <tr>
156
- <td style={{ height: `${paddingTop}px` }} />
157
- </tr>
158
- )}
159
- {(enableRowVirtualization ? virtualRows : rows).map(
160
- (rowOrVirtualRow: any, rowIndex: number) => {
161
- const row = enableRowVirtualization
162
- ? (rows[rowOrVirtualRow.index] as MRT_Row)
163
- : (rowOrVirtualRow as MRT_Row);
164
- const props = {
165
- key: row.id,
166
- numRows: rows.length,
167
- row,
168
- rowIndex: enableRowVirtualization
169
- ? rowOrVirtualRow.index
170
- : rowIndex,
171
- table,
172
- virtualRow: enableRowVirtualization ? rowOrVirtualRow : null,
173
- };
174
- return memoMode === 'rows' ? (
175
- <Memo_MRT_TableBodyRow {...props} />
176
- ) : (
177
- <MRT_TableBodyRow {...props} />
178
- );
179
- },
180
- )}
181
- {enableRowVirtualization && paddingBottom > 0 && (
182
- <tr>
183
- <td style={{ height: `${paddingBottom}px` }} />
184
- </tr>
185
- )}
139
+ {(virtualRows ?? rows).map((rowOrVirtualRow, rowIndex) => {
140
+ const row = virtualizer
141
+ ? rows[rowOrVirtualRow.index]
142
+ : (rowOrVirtualRow as MRT_Row);
143
+ const props = {
144
+ key: row.id,
145
+ measureElement: virtualizer
146
+ ? virtualizer.measureElement
147
+ : undefined,
148
+ numRows: rows.length,
149
+ row,
150
+ rowIndex: virtualizer ? rowOrVirtualRow.index : rowIndex,
151
+ table,
152
+ virtualRow: virtualizer
153
+ ? (rowOrVirtualRow as VirtualItem)
154
+ : undefined,
155
+ };
156
+ return memoMode === 'rows' ? (
157
+ <Memo_MRT_TableBodyRow {...props} />
158
+ ) : (
159
+ <MRT_TableBodyRow {...props} />
160
+ );
161
+ })}
186
162
  </>
187
163
  )}
188
164
  </TableBody>
@@ -23,7 +23,7 @@ interface Props {
23
23
  enableHover?: boolean;
24
24
  numRows: number;
25
25
  rowIndex: number;
26
- rowRef: RefObject<HTMLDivElement | HTMLTableRowElement>;
26
+ rowRef: RefObject<HTMLTableRowElement>;
27
27
  table: MRT_TableInstance;
28
28
  }
29
29
 
@@ -169,8 +169,6 @@ export const MRT_TableBodyCell: FC<Props> = ({
169
169
 
170
170
  return (
171
171
  <TableCell
172
- component={layoutMode === 'grid' ? 'div' : 'td'}
173
- role="gridcell"
174
172
  {...tableCellProps}
175
173
  onDragEnter={handleDragEnter}
176
174
  onDoubleClick={handleDoubleClick}
@@ -3,17 +3,20 @@ import TableRow from '@mui/material/TableRow';
3
3
  import { darken, lighten, useTheme } from '@mui/material/styles';
4
4
  import { Memo_MRT_TableBodyCell, MRT_TableBodyCell } from './MRT_TableBodyCell';
5
5
  import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
6
+ import type { VirtualItem } from '@tanstack/react-virtual';
6
7
  import type { MRT_Row, MRT_TableInstance } from '..';
7
8
 
8
9
  interface Props {
10
+ measureElement?: (element: HTMLTableRowElement) => void;
9
11
  numRows: number;
10
12
  row: MRT_Row;
11
13
  rowIndex: number;
12
14
  table: MRT_TableInstance;
13
- virtualRow?: any;
15
+ virtualRow?: VirtualItem;
14
16
  }
15
17
 
16
18
  export const MRT_TableBodyRow: FC<Props> = ({
19
+ measureElement,
17
20
  numRows,
18
21
  row,
19
22
  rowIndex,
@@ -47,7 +50,7 @@ export const MRT_TableBodyRow: FC<Props> = ({
47
50
  }
48
51
  };
49
52
 
50
- const rowRef = useRef<HTMLDivElement | HTMLTableRowElement | null>(null);
53
+ const rowRef = useRef<HTMLTableRowElement | null>(null);
51
54
 
52
55
  const draggingBorder = useMemo(
53
56
  () =>
@@ -68,24 +71,28 @@ export const MRT_TableBodyRow: FC<Props> = ({
68
71
  return (
69
72
  <>
70
73
  <TableRow
71
- component={layoutMode === 'grid' ? 'div' : 'tr'}
74
+ data-index={virtualRow?.index}
72
75
  hover
73
76
  onDragEnter={handleDragEnter}
74
77
  selected={row.getIsSelected()}
75
- ref={(node: HTMLTableRowElement | HTMLDivElement) => {
76
- rowRef.current = node;
77
- if (virtualRow?.measureRef) {
78
- virtualRow.measureRef = node;
78
+ ref={(node: HTMLTableRowElement) => {
79
+ if (node) {
80
+ rowRef.current = node;
81
+ measureElement?.(node);
79
82
  }
80
83
  }}
81
- role="row"
82
84
  {...tableRowProps}
83
85
  sx={(theme) => ({
84
86
  backgroundColor: lighten(theme.palette.background.default, 0.06),
85
87
  display: layoutMode === 'grid' ? 'flex' : 'table-row',
86
88
  opacity:
87
89
  draggingRow?.id === row.id || hoveredRow?.id === row.id ? 0.5 : 1,
88
- transition: 'all 150ms ease-in-out',
90
+ position: virtualRow ? 'absolute' : undefined,
91
+ top: virtualRow ? 0 : undefined,
92
+ transform: virtualRow
93
+ ? `translateY(${virtualRow?.start}px)`
94
+ : undefined,
95
+ transition: virtualRow ? 'none' : 'all 150ms ease-in-out',
89
96
  '&:hover td': {
90
97
  backgroundColor:
91
98
  tableRowProps?.hover !== false && getIsSomeColumnsPinned()
@@ -4,7 +4,7 @@ import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
4
4
 
5
5
  interface Props {
6
6
  cell: MRT_Cell;
7
- rowRef: RefObject<HTMLDivElement | HTMLTableRowElement>;
7
+ rowRef: RefObject<HTMLTableRowElement>;
8
8
  table: MRT_TableInstance;
9
9
  }
10
10
 
@@ -14,6 +14,7 @@ export const MRT_TableDetailPanel: FC<Props> = ({ row, table }) => {
14
14
  getVisibleLeafColumns,
15
15
  getState,
16
16
  options: {
17
+ layoutMode,
17
18
  muiTableBodyRowProps,
18
19
  muiTableDetailPanelProps,
19
20
  renderDetailPanel,
@@ -32,7 +33,12 @@ export const MRT_TableDetailPanel: FC<Props> = ({ row, table }) => {
32
33
  : muiTableDetailPanelProps;
33
34
 
34
35
  return (
35
- <TableRow {...tableRowProps}>
36
+ <TableRow
37
+ sx={{
38
+ display: layoutMode === 'grid' ? 'flex' : 'table-row',
39
+ }}
40
+ {...tableRowProps}
41
+ >
36
42
  <TableCell
37
43
  colSpan={getVisibleLeafColumns().length}
38
44
  {...tableCellProps}
@@ -274,7 +274,6 @@ export const getCommonCellStyles = ({
274
274
  table.options.layoutMode === 'grid'
275
275
  ? `${column.getSize()} 0 auto`
276
276
  : undefined,
277
- maxWidth: `min(${column.getSize()}px, fit-content)`,
278
277
  minWidth: `max(${column.getSize()}px, ${column.columnDef.minSize ?? 30}px)`,
279
278
  width: header?.getSize() ?? column.getSize(),
280
279
  });
@@ -12,7 +12,7 @@ export const MRT_TableFooter: FC<Props> = ({ table }) => {
12
12
  const {
13
13
  getFooterGroups,
14
14
  getState,
15
- options: { enableStickyFooter, muiTableFooterProps },
15
+ options: { enableStickyFooter, layoutMode, muiTableFooterProps },
16
16
  } = table;
17
17
  const { isFullScreen } = getState();
18
18
 
@@ -30,6 +30,7 @@ export const MRT_TableFooter: FC<Props> = ({ table }) => {
30
30
  sx={(theme) => ({
31
31
  backgroundColor: lighten(theme.palette.background.default, 0.06),
32
32
  bottom: stickFooter ? 0 : undefined,
33
+ display: layoutMode === 'grid' ? 'grid' : 'table-row-group',
33
34
  opacity: stickFooter ? 0.97 : undefined,
34
35
  outline: stickFooter
35
36
  ? theme.palette.mode === 'light'
@@ -11,7 +11,7 @@ interface Props {
11
11
  export const MRT_TableFooterCell: FC<Props> = ({ footer, table }) => {
12
12
  const {
13
13
  getState,
14
- options: { muiTableFooterCellProps },
14
+ options: { layoutMode, muiTableFooterCellProps },
15
15
  } = table;
16
16
  const { density } = getState();
17
17
  const { column } = footer;
@@ -40,7 +40,9 @@ export const MRT_TableFooterCell: FC<Props> = ({ footer, table }) => {
40
40
  variant="head"
41
41
  {...tableCellProps}
42
42
  sx={(theme) => ({
43
+ display: layoutMode === 'grid' ? 'grid' : 'table-cell',
43
44
  fontWeight: 'bold',
45
+ justifyContent: columnDefType === 'group' ? 'center' : undefined,
44
46
  p:
45
47
  density === 'compact'
46
48
  ? '0.5rem'
@@ -10,7 +10,7 @@ interface Props {
10
10
 
11
11
  export const MRT_TableFooterRow: FC<Props> = ({ footerGroup, table }) => {
12
12
  const {
13
- options: { muiTableFooterRowProps },
13
+ options: { layoutMode, muiTableFooterRowProps },
14
14
  } = table;
15
15
 
16
16
  // if no content in row, skip row
@@ -30,7 +30,15 @@ export const MRT_TableFooterRow: FC<Props> = ({ footerGroup, table }) => {
30
30
  : muiTableFooterRowProps;
31
31
 
32
32
  return (
33
- <TableRow {...tableRowProps}>
33
+ <TableRow
34
+ {...tableRowProps}
35
+ sx={(theme) => ({
36
+ display: layoutMode === 'grid' ? 'flex' : 'table-row',
37
+ ...(tableRowProps?.sx instanceof Function
38
+ ? tableRowProps?.sx(theme)
39
+ : (tableRowProps?.sx as any)),
40
+ })}
41
+ >
34
42
  {footerGroup.headers.map((footer: MRT_Header) => (
35
43
  <MRT_TableFooterCell footer={footer} key={footer.id} table={table} />
36
44
  ))}