material-react-table 0.19.0 → 0.20.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": "0.19.0",
2
+ "version": "0.20.0",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
5
  "description": "A fully featured Material UI implementation of TanStack React Table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
@@ -61,7 +61,7 @@
61
61
  "@emotion/styled": "^11.9.3",
62
62
  "@faker-js/faker": "^7.3.0",
63
63
  "@mui/icons-material": "^5.8.4",
64
- "@mui/material": "^5.8.6",
64
+ "@mui/material": "^5.8.7",
65
65
  "@size-limit/preset-small-lib": "^7.0.8",
66
66
  "@storybook/addon-a11y": "^6.5.9",
67
67
  "@storybook/addon-actions": "^6.5.9",
@@ -99,8 +99,8 @@
99
99
  "dependencies": {
100
100
  "@tanstack/match-sorter-utils": "8.1.1",
101
101
  "@tanstack/react-table": "8.1.3",
102
+ "@tanstack/react-virtual": "^3.0.0-beta.2",
102
103
  "react-dnd": "^16.0.1",
103
- "react-dnd-html5-backend": "^16.0.1",
104
- "react-virtual": "^2.10.4"
104
+ "react-dnd-html5-backend": "^16.0.1"
105
105
  }
106
106
  }
@@ -39,7 +39,7 @@ import {
39
39
  TableOptions,
40
40
  TableState,
41
41
  } from '@tanstack/react-table';
42
- import { Options as VirtualizerOptions } from 'react-virtual';
42
+ // import type { VirtualizerOptions } from '@tanstack/react-virtual';
43
43
  import { MRT_Localization, MRT_DefaultLocalization_EN } from './localization';
44
44
  import { MRT_Default_Icons, MRT_Icons } from './icons';
45
45
  import { MRT_TableRoot } from './table/MRT_TableRoot';
@@ -685,7 +685,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
685
685
  rowNumberMode?: 'original' | 'static';
686
686
  selectAllMode?: 'all' | 'page';
687
687
  tableId?: string;
688
- virtualizerProps?: Partial<VirtualizerOptions<HTMLDivElement>>;
688
+ virtualizerProps?: any;
689
689
  };
690
690
 
691
691
  export default <D extends Record<string, any> = {}>({
@@ -1,5 +1,5 @@
1
1
  import React, { FC, RefObject, useMemo } from 'react';
2
- import { useVirtual } from 'react-virtual';
2
+ import { useVirtualizer } from '@tanstack/react-virtual';
3
3
  import { TableBody } from '@mui/material';
4
4
  import { MRT_TableBodyRow } from './MRT_TableBodyRow';
5
5
  import type { MRT_Row, MRT_TableInstance } from '..';
@@ -61,20 +61,29 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
61
61
  ]);
62
62
 
63
63
  const rowVirtualizer = enableRowVirtualization
64
- ? useVirtual({
65
- overscan: density === 'compact' ? 20 : 10,
66
- size: rows.length,
67
- parentRef: tableContainerRef,
64
+ ? useVirtualizer({
65
+ count: rows.length,
66
+ estimateSize: () => (density === 'compact' ? 25 : 50),
67
+ getScrollElement: () => tableContainerRef.current,
68
+ overscan: density === 'compact' ? 30 : 10,
68
69
  ...virtualizerProps,
69
70
  })
70
- : ({} as any);
71
+ : {};
71
72
 
72
- const { virtualItems: virtualRows } = rowVirtualizer;
73
- const paddingTop = virtualRows?.length > 0 ? virtualRows[0].start : 0;
74
- const paddingBottom =
75
- virtualRows?.length > 0
76
- ? rowVirtualizer.totalSize - virtualRows[virtualRows.length - 1].end
77
- : 0;
73
+ const virtualRows = enableRowVirtualization
74
+ ? rowVirtualizer.getVirtualItems()
75
+ : [];
76
+
77
+ let paddingTop = 0;
78
+ let paddingBottom = 0;
79
+ if (enableRowVirtualization) {
80
+ paddingTop = virtualRows.length > 0 ? virtualRows[0].start : 0;
81
+ paddingBottom =
82
+ virtualRows.length > 0
83
+ ? rowVirtualizer.getTotalSize() -
84
+ virtualRows[virtualRows.length - 1].end
85
+ : 0;
86
+ }
78
87
 
79
88
  return (
80
89
  <TableBody {...tableBodyProps}>
@@ -83,7 +92,6 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
83
92
  <td style={{ height: `${paddingTop}px` }} />
84
93
  </tr>
85
94
  )}
86
- {/* @ts-ignore */}
87
95
  {(enableRowVirtualization ? virtualRows : rows).map(
88
96
  (rowOrVirtualRow: any, rowIndex: number) => {
89
97
  const row = enableRowVirtualization