material-react-table 1.4.0-beta.1 → 1.4.0-beta.3
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/_locales/nl.d.ts +2 -0
- 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/_locales/nl.d.ts +2 -0
- 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/locales/nl.d.ts +2 -0
- package/locales/nl.esm.d.ts +2 -0
- package/locales/nl.esm.js +94 -0
- package/locales/nl.esm.js.map +1 -0
- package/locales/nl.js +98 -0
- package/locales/nl.js.map +1 -0
- package/package.json +4 -3
- package/src/MaterialReactTable.tsx +9 -20
- package/src/_locales/nl.ts +94 -0
- package/src/body/MRT_TableBody.tsx +45 -72
- package/src/body/MRT_TableBodyRow.tsx +14 -5
- package/src/table/MRT_TableContainer.tsx +7 -5
@@ -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) => ({
|