material-react-table 1.4.0-beta.1 → 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.
- package/dist/cjs/index.js +624 -65
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/MaterialReactTable.d.ts +4 -11
- package/dist/cjs/types/body/MRT_TableBodyRow.d.ts +3 -1
- package/dist/cjs/types/table/MRT_TableRoot.d.ts +3 -3
- package/dist/esm/material-react-table.esm.js +909 -368
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/MaterialReactTable.d.ts +4 -11
- package/dist/esm/types/body/MRT_TableBodyRow.d.ts +3 -1
- package/dist/esm/types/table/MRT_TableRoot.d.ts +3 -3
- package/dist/index.d.ts +5 -12
- package/package.json +4 -3
- package/src/MaterialReactTable.tsx +9 -20
- package/src/body/MRT_TableBody.tsx +45 -72
- package/src/body/MRT_TableBodyRow.tsx +14 -5
- 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 {
|
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';
|
@@ -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;
|
@@ -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?:
|
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>;
|
@@ -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").
|
256
|
+
virtualizerProps?: Partial<import("@tanstack/react-virtual").VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>> | (({ table, }: {
|
257
257
|
table: MRT_TableInstance<TData>;
|
258
|
-
}) => Partial<import("react-virtual").
|
259
|
-
virtualizerInstanceRef?: React.MutableRefObject<import("
|
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 {
|
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: {
|
@@ -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<
|
813
|
+
virtualizerProps?: Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>> | (({ table, }: {
|
814
814
|
table: MRT_TableInstance<TData>;
|
815
|
-
}) => Partial<
|
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,
|
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.
|
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": "^
|
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 {
|
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';
|
@@ -1053,30 +1052,18 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
1053
1052
|
state?: Partial<MRT_TableState<TData>>;
|
1054
1053
|
tableInstanceRef?: MutableRefObject<MRT_TableInstance<TData> | null>;
|
1055
1054
|
virtualizerProps?:
|
1056
|
-
| Partial<VirtualizerOptions<HTMLDivElement>>
|
1055
|
+
| Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>
|
1057
1056
|
| (({
|
1058
1057
|
table,
|
1059
1058
|
}: {
|
1060
1059
|
table: MRT_TableInstance<TData>;
|
1061
|
-
}) => Partial<VirtualizerOptions<HTMLDivElement>>);
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
// }: {
|
1067
|
-
// table: MRT_TableInstance<TData>;
|
1068
|
-
// }) => Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>);
|
1069
|
-
virtualizerInstanceRef?: MutableRefObject<Virtualizer | null>;
|
1060
|
+
}) => Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>);
|
1061
|
+
virtualizerInstanceRef?: MutableRefObject<Virtualizer<
|
1062
|
+
HTMLDivElement,
|
1063
|
+
HTMLTableRowElement
|
1064
|
+
> | null>;
|
1070
1065
|
};
|
1071
1066
|
|
1072
|
-
export type Virtualizer = {
|
1073
|
-
virtualItems: VirtualItem[];
|
1074
|
-
totalSize: number;
|
1075
|
-
scrollToOffset: (index: number, options?: any | undefined) => void;
|
1076
|
-
scrollToIndex: (index: number, options?: any | undefined) => void;
|
1077
|
-
measure: () => void;
|
1078
|
-
};
|
1079
|
-
|
1080
1067
|
const MaterialReactTable = <TData extends Record<string, any> = {}>({
|
1081
1068
|
aggregationFns,
|
1082
1069
|
autoResetExpanded = false,
|
@@ -1150,6 +1137,8 @@ const MaterialReactTable = <TData extends Record<string, any> = {}>({
|
|
1150
1137
|
[],
|
1151
1138
|
);
|
1152
1139
|
|
1140
|
+
if (rest.enableRowVirtualization) layoutMode = 'grid';
|
1141
|
+
|
1153
1142
|
return (
|
1154
1143
|
<MRT_TableRoot
|
1155
1144
|
aggregationFns={_aggregationFns}
|
@@ -1,6 +1,9 @@
|
|
1
1
|
import React, { FC, memo, useMemo } from 'react';
|
2
|
-
import {
|
3
|
-
|
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 } =
|
37
|
+
const { columnFilters, density, globalFilter, pagination, sorting } =
|
38
|
+
getState();
|
35
39
|
|
36
40
|
const tableBodyProps =
|
37
41
|
muiTableBodyProps instanceof Function
|
@@ -74,55 +78,33 @@ export const MRT_TableBody: FC<Props> = ({ table }) => {
|
|
74
78
|
pagination.pageSize,
|
75
79
|
]);
|
76
80
|
|
77
|
-
const virtualizer
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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
|
-
:
|
93
|
+
: undefined;
|
85
94
|
|
86
|
-
if (virtualizerInstanceRef) {
|
95
|
+
if (virtualizerInstanceRef && virtualizer) {
|
87
96
|
virtualizerInstanceRef.current = virtualizer;
|
88
97
|
}
|
89
98
|
|
90
|
-
|
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
103
|
{...tableBodyProps}
|
124
104
|
sx={(theme) => ({
|
125
105
|
display: layoutMode === 'grid' ? 'grid' : 'table-row-group',
|
106
|
+
height: virtualizer ? `${virtualizer.getTotalSize()}px` : 'inherit',
|
107
|
+
position: 'relative',
|
126
108
|
...(tableBodyProps?.sx instanceof Function
|
127
109
|
? tableBodyProps?.sx(theme)
|
128
110
|
: (tableBodyProps?.sx as any)),
|
@@ -154,38 +136,29 @@ export const MRT_TableBody: FC<Props> = ({ table }) => {
|
|
154
136
|
</tr>
|
155
137
|
) : (
|
156
138
|
<>
|
157
|
-
{
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
<MRT_TableBodyRow {...props} />
|
181
|
-
);
|
182
|
-
},
|
183
|
-
)}
|
184
|
-
{enableRowVirtualization && paddingBottom > 0 && (
|
185
|
-
<tr>
|
186
|
-
<td style={{ height: `${paddingBottom}px` }} />
|
187
|
-
</tr>
|
188
|
-
)}
|
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
|
+
})}
|
189
162
|
</>
|
190
163
|
)}
|
191
164
|
</TableBody>
|
@@ -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?:
|
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,
|
@@ -68,13 +71,14 @@ export const MRT_TableBodyRow: FC<Props> = ({
|
|
68
71
|
return (
|
69
72
|
<>
|
70
73
|
<TableRow
|
74
|
+
data-index={virtualRow?.index}
|
71
75
|
hover
|
72
76
|
onDragEnter={handleDragEnter}
|
73
77
|
selected={row.getIsSelected()}
|
74
78
|
ref={(node: HTMLTableRowElement) => {
|
75
|
-
|
76
|
-
|
77
|
-
|
79
|
+
if (node) {
|
80
|
+
rowRef.current = node;
|
81
|
+
measureElement?.(node);
|
78
82
|
}
|
79
83
|
}}
|
80
84
|
{...tableRowProps}
|
@@ -83,7 +87,12 @@ export const MRT_TableBodyRow: FC<Props> = ({
|
|
83
87
|
display: layoutMode === 'grid' ? 'flex' : 'table-row',
|
84
88
|
opacity:
|
85
89
|
draggingRow?.id === row.id || hoveredRow?.id === row.id ? 0.5 : 1,
|
86
|
-
|
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',
|
87
96
|
'&:hover td': {
|
88
97
|
backgroundColor:
|
89
98
|
tableRowProps?.hover !== false && getIsSomeColumnsPinned()
|
@@ -46,11 +46,13 @@ export const MRT_TableContainer: FC<Props> = ({ table }) => {
|
|
46
46
|
return (
|
47
47
|
<TableContainer
|
48
48
|
{...tableContainerProps}
|
49
|
-
ref={(
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
ref={(node: HTMLDivElement) => {
|
50
|
+
if (node) {
|
51
|
+
tableContainerRef.current = node;
|
52
|
+
if (tableContainerProps?.ref) {
|
53
|
+
//@ts-ignore
|
54
|
+
tableContainerProps.ref.current = node;
|
55
|
+
}
|
54
56
|
}
|
55
57
|
}}
|
56
58
|
sx={(theme) => ({
|