material-react-table 2.0.0-alpha.0 → 2.0.0-alpha.1
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 +437 -384
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/body/MRT_TableBodyRow.d.ts +3 -2
- package/dist/cjs/types/body/MRT_TableBodyRowPinButton.d.ts +7 -0
- package/dist/cjs/types/body/index.d.ts +1 -0
- package/dist/cjs/types/buttons/MRT_RowPinButton.d.ts +9 -0
- package/dist/cjs/types/buttons/index.d.ts +2 -1
- package/dist/cjs/types/column.utils.d.ts +1 -0
- package/dist/cjs/types/types.d.ts +15 -9
- package/dist/esm/material-react-table.esm.js +433 -383
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/body/MRT_TableBodyRow.d.ts +3 -2
- package/dist/esm/types/body/MRT_TableBodyRowPinButton.d.ts +7 -0
- package/dist/esm/types/body/index.d.ts +1 -0
- package/dist/esm/types/buttons/MRT_RowPinButton.d.ts +9 -0
- package/dist/esm/types/buttons/index.d.ts +2 -1
- package/dist/esm/types/column.utils.d.ts +1 -0
- package/dist/esm/types/types.d.ts +15 -9
- package/dist/index.d.ts +68 -47
- package/locales/en.esm.js +1 -0
- package/locales/en.esm.js.map +1 -1
- package/locales/en.js +1 -0
- package/locales/en.js.map +1 -1
- package/package.json +9 -9
- package/src/body/MRT_TableBody.tsx +178 -74
- package/src/body/MRT_TableBodyCell.tsx +23 -21
- package/src/body/MRT_TableBodyRow.tsx +104 -16
- package/src/body/MRT_TableBodyRowGrabHandle.tsx +5 -4
- package/src/body/MRT_TableBodyRowPinButton.tsx +46 -0
- package/src/body/MRT_TableDetailPanel.tsx +13 -19
- package/src/body/index.ts +2 -1
- package/src/buttons/MRT_CopyButton.tsx +14 -20
- package/src/buttons/MRT_ExpandAllButton.tsx +5 -7
- package/src/buttons/MRT_ExpandButton.tsx +6 -7
- package/src/buttons/MRT_GrabHandleButton.tsx +2 -3
- package/src/buttons/MRT_RowPinButton.tsx +74 -0
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +2 -3
- package/src/buttons/index.ts +2 -1
- package/src/column.utils.ts +11 -5
- package/src/footer/MRT_TableFooter.tsx +13 -7
- package/src/footer/MRT_TableFooterCell.tsx +7 -20
- package/src/footer/MRT_TableFooterRow.tsx +6 -7
- package/src/head/MRT_TableHead.tsx +11 -7
- package/src/head/MRT_TableHeadCell.tsx +9 -20
- package/src/head/MRT_TableHeadCellColumnActionsButton.tsx +10 -18
- package/src/head/MRT_TableHeadCellGrabHandle.tsx +6 -13
- package/src/head/MRT_TableHeadRow.tsx +6 -7
- package/src/hooks/useMRT_DisplayColumns.tsx +13 -0
- package/src/hooks/useMRT_TableInstance.ts +6 -0
- package/src/hooks/useMRT_TableOptions.ts +6 -2
- package/src/inputs/MRT_EditCellTextField.tsx +14 -22
- package/src/inputs/MRT_FilterCheckbox.tsx +11 -23
- package/src/inputs/MRT_FilterRangeSlider.tsx +6 -23
- package/src/inputs/MRT_FilterTextField.tsx +9 -25
- package/src/inputs/MRT_GlobalFilterTextField.tsx +4 -4
- package/src/inputs/MRT_SelectCheckbox.tsx +31 -17
- package/src/locales/en.ts +1 -1
- package/src/menus/MRT_RowActionMenu.tsx +11 -12
- package/src/modals/MRT_EditRowModal.tsx +5 -13
- package/src/table/MRT_Table.tsx +8 -13
- package/src/table/MRT_TableContainer.tsx +6 -12
- package/src/table/MRT_TablePaper.tsx +9 -13
- package/src/toolbar/MRT_BottomToolbar.tsx +14 -20
- package/src/toolbar/MRT_LinearProgressBar.tsx +5 -4
- package/src/toolbar/MRT_TablePagination.tsx +5 -7
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +8 -11
- package/src/toolbar/MRT_TopToolbar.tsx +8 -14
- package/src/types.ts +25 -8
- package/locales/tr.d.ts +0 -2
- package/locales/tr.esm.d.ts +0 -2
- package/locales/tr.esm.js +0 -93
- package/locales/tr.esm.js.map +0 -1
- package/locales/tr.js +0 -97
- package/locales/tr.js.map +0 -1
- package/locales/uk.d.ts +0 -2
- package/locales/uk.esm.d.ts +0 -2
- package/locales/uk.esm.js +0 -93
- package/locales/uk.esm.js.map +0 -1
- package/locales/uk.js +0 -97
- package/locales/uk.js.map +0 -1
- package/locales/vi.d.ts +0 -2
- package/locales/vi.esm.d.ts +0 -2
- package/locales/vi.esm.js +0 -93
- package/locales/vi.esm.js.map +0 -1
- package/locales/vi.js +0 -97
- package/locales/vi.js.map +0 -1
- package/locales/zh-Hans.d.ts +0 -2
- package/locales/zh-Hans.esm.d.ts +0 -2
- package/locales/zh-Hans.esm.js +0 -93
- package/locales/zh-Hans.esm.js.map +0 -1
- package/locales/zh-Hans.js +0 -97
- package/locales/zh-Hans.js.map +0 -1
- package/locales/zh-Hant.d.ts +0 -2
- package/locales/zh-Hant.esm.d.ts +0 -2
- package/locales/zh-Hant.esm.js +0 -93
- package/locales/zh-Hant.esm.js.map +0 -1
- package/locales/zh-Hant.js +0 -97
- package/locales/zh-Hant.js.map +0 -1
@@ -9,6 +9,7 @@ import Typography from '@mui/material/Typography';
|
|
9
9
|
import { Memo_MRT_TableBodyRow, MRT_TableBodyRow } from './MRT_TableBodyRow';
|
10
10
|
import { rankGlobalFuzzy } from '../sortingFns';
|
11
11
|
import { type MRT_Row, type MRT_TableInstance } from '../types';
|
12
|
+
import { parseFromValuesOrFunc } from '../column.utils';
|
12
13
|
|
13
14
|
interface Props<TData extends Record<string, any>> {
|
14
15
|
columnVirtualizer?: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
|
@@ -26,13 +27,20 @@ export const MRT_TableBody = <TData extends Record<string, any>>({
|
|
26
27
|
virtualPaddingRight,
|
27
28
|
}: Props<TData>) => {
|
28
29
|
const {
|
29
|
-
|
30
|
+
getBottomRows,
|
31
|
+
getCenterRows,
|
30
32
|
getPrePaginationRowModel,
|
33
|
+
getRowModel,
|
31
34
|
getState,
|
35
|
+
getIsSomeRowsPinned,
|
36
|
+
getTopRows,
|
32
37
|
options: {
|
33
38
|
enableGlobalFilterRankedResults,
|
34
39
|
enablePagination,
|
40
|
+
enableRowPinning,
|
35
41
|
enableRowVirtualization,
|
42
|
+
enableStickyHeader,
|
43
|
+
enableStickyFooter,
|
36
44
|
layoutMode,
|
37
45
|
localization,
|
38
46
|
manualExpanding,
|
@@ -43,10 +51,11 @@ export const MRT_TableBody = <TData extends Record<string, any>>({
|
|
43
51
|
memoMode,
|
44
52
|
muiTableBodyProps,
|
45
53
|
renderEmptyRowsFallback,
|
54
|
+
rowPinningDisplayMode,
|
46
55
|
rowVirtualizerInstanceRef,
|
47
56
|
rowVirtualizerOptions,
|
48
57
|
},
|
49
|
-
refs: { tableContainerRef, tablePaperRef },
|
58
|
+
refs: { tableContainerRef, tablePaperRef, tableFooterRef, tableHeadRef },
|
50
59
|
} = table;
|
51
60
|
const {
|
52
61
|
columnFilters,
|
@@ -56,17 +65,21 @@ export const MRT_TableBody = <TData extends Record<string, any>>({
|
|
56
65
|
globalFilterFn,
|
57
66
|
pagination,
|
58
67
|
sorting,
|
68
|
+
rowPinning,
|
69
|
+
isFullScreen,
|
59
70
|
} = getState();
|
60
71
|
|
61
|
-
const tableBodyProps =
|
62
|
-
|
63
|
-
|
64
|
-
|
72
|
+
const tableBodyProps = parseFromValuesOrFunc(muiTableBodyProps, { table });
|
73
|
+
const rowVirtualizerProps = parseFromValuesOrFunc(rowVirtualizerOptions, {
|
74
|
+
table,
|
75
|
+
});
|
65
76
|
|
66
|
-
const
|
67
|
-
|
68
|
-
|
69
|
-
|
77
|
+
const tableHeadHeight =
|
78
|
+
((enableStickyHeader || isFullScreen) &&
|
79
|
+
tableHeadRef.current?.clientHeight) ||
|
80
|
+
0;
|
81
|
+
const tableFooterHeight =
|
82
|
+
(enableStickyFooter && tableFooterRef.current?.clientHeight) || 0;
|
70
83
|
|
71
84
|
const shouldRankResults = useMemo(
|
72
85
|
() =>
|
@@ -92,21 +105,45 @@ export const MRT_TableBody = <TData extends Record<string, any>>({
|
|
92
105
|
],
|
93
106
|
);
|
94
107
|
|
108
|
+
const pinnedRowIds = useMemo(
|
109
|
+
() =>
|
110
|
+
getRowModel()
|
111
|
+
.rows.filter((row) => row.getIsPinned())
|
112
|
+
.map((r) => r.id),
|
113
|
+
[rowPinning, table.getRowModel().rows],
|
114
|
+
);
|
115
|
+
|
95
116
|
const rows = useMemo(() => {
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
117
|
+
let rows = [];
|
118
|
+
if (!shouldRankResults) {
|
119
|
+
rows =
|
120
|
+
!enableRowPinning || rowPinningDisplayMode?.includes('sticky')
|
121
|
+
? getRowModel().rows
|
122
|
+
: getCenterRows();
|
123
|
+
} else {
|
124
|
+
rows = getPrePaginationRowModel().rows.sort((a, b) =>
|
125
|
+
rankGlobalFuzzy(a, b),
|
126
|
+
);
|
127
|
+
if (enablePagination && !manualPagination) {
|
128
|
+
const start = pagination.pageIndex * pagination.pageSize;
|
129
|
+
rows = rows.slice(start, start + pagination.pageSize);
|
130
|
+
}
|
131
|
+
}
|
132
|
+
if (enableRowPinning && rowPinningDisplayMode?.includes('sticky')) {
|
133
|
+
rows = [
|
134
|
+
...getTopRows().filter((row) => !pinnedRowIds.includes(row.id)),
|
135
|
+
...rows,
|
136
|
+
...getBottomRows().filter((row) => !pinnedRowIds.includes(row.id)),
|
137
|
+
];
|
103
138
|
}
|
104
|
-
|
139
|
+
|
140
|
+
return rows;
|
105
141
|
}, [
|
106
142
|
shouldRankResults,
|
107
143
|
shouldRankResults ? getPrePaginationRowModel().rows : getRowModel().rows,
|
108
144
|
pagination.pageIndex,
|
109
145
|
pagination.pageSize,
|
146
|
+
rowPinning,
|
110
147
|
]);
|
111
148
|
|
112
149
|
const rowVirtualizer:
|
@@ -123,7 +160,7 @@ export const MRT_TableBody = <TData extends Record<string, any>>({
|
|
123
160
|
? (element) => element?.getBoundingClientRect().height
|
124
161
|
: undefined,
|
125
162
|
overscan: 4,
|
126
|
-
...
|
163
|
+
...rowVirtualizerProps,
|
127
164
|
})
|
128
165
|
: undefined;
|
129
166
|
|
@@ -136,68 +173,135 @@ export const MRT_TableBody = <TData extends Record<string, any>>({
|
|
136
173
|
: undefined;
|
137
174
|
|
138
175
|
return (
|
139
|
-
|
140
|
-
{
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
176
|
+
<>
|
177
|
+
{!rowPinningDisplayMode?.includes('sticky') &&
|
178
|
+
getIsSomeRowsPinned('top') && (
|
179
|
+
<TableBody
|
180
|
+
{...tableBodyProps}
|
181
|
+
sx={(theme) => ({
|
182
|
+
display: layoutMode === 'grid' ? 'grid' : 'table-row-group',
|
183
|
+
position: 'sticky',
|
184
|
+
top: tableHeadHeight - 1,
|
185
|
+
zIndex: 1,
|
186
|
+
...(parseFromValuesOrFunc(tableBodyProps?.sx, theme) as any),
|
187
|
+
})}
|
188
|
+
>
|
189
|
+
{getTopRows().map((row, rowIndex) => {
|
190
|
+
const props = {
|
191
|
+
columnVirtualizer,
|
192
|
+
measureElement: rowVirtualizer?.measureElement,
|
193
|
+
numRows: rows.length,
|
194
|
+
row,
|
195
|
+
rowIndex,
|
196
|
+
table,
|
197
|
+
virtualColumns,
|
198
|
+
virtualPaddingLeft,
|
199
|
+
virtualPaddingRight,
|
200
|
+
};
|
201
|
+
return memoMode === 'rows' ? (
|
202
|
+
<Memo_MRT_TableBodyRow key={row.id} {...props} />
|
203
|
+
) : (
|
204
|
+
<MRT_TableBodyRow key={row.id} {...props} />
|
205
|
+
);
|
206
|
+
})}
|
207
|
+
</TableBody>
|
208
|
+
)}
|
209
|
+
<TableBody
|
210
|
+
{...tableBodyProps}
|
211
|
+
sx={(theme) => ({
|
212
|
+
display: layoutMode === 'grid' ? 'grid' : 'table-row-group',
|
213
|
+
height: rowVirtualizer
|
214
|
+
? `${rowVirtualizer.getTotalSize()}px`
|
215
|
+
: 'inherit',
|
216
|
+
minHeight: !rows.length ? '100px' : undefined,
|
217
|
+
position: 'relative',
|
218
|
+
...(parseFromValuesOrFunc(tableBodyProps?.sx, theme) as any),
|
219
|
+
})}
|
220
|
+
>
|
221
|
+
{tableBodyProps?.children ??
|
222
|
+
(!rows.length ? (
|
223
|
+
<tr
|
224
|
+
style={{ display: layoutMode === 'grid' ? 'grid' : 'table-row' }}
|
161
225
|
>
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
226
|
+
<td
|
227
|
+
colSpan={table.getVisibleLeafColumns().length}
|
228
|
+
style={{
|
229
|
+
display: layoutMode === 'grid' ? 'grid' : 'table-cell',
|
230
|
+
}}
|
231
|
+
>
|
232
|
+
{renderEmptyRowsFallback?.({ table }) ?? (
|
233
|
+
<Typography
|
234
|
+
sx={{
|
235
|
+
color: 'text.secondary',
|
236
|
+
fontStyle: 'italic',
|
237
|
+
maxWidth: `min(100vw, ${
|
238
|
+
tablePaperRef.current?.clientWidth ?? 360
|
239
|
+
}px)`,
|
240
|
+
py: '2rem',
|
241
|
+
textAlign: 'center',
|
242
|
+
width: '100%',
|
243
|
+
}}
|
244
|
+
>
|
245
|
+
{globalFilter || columnFilters.length
|
246
|
+
? localization.noResultsFound
|
247
|
+
: localization.noRecordsToDisplay}
|
248
|
+
</Typography>
|
249
|
+
)}
|
250
|
+
</td>
|
251
|
+
</tr>
|
252
|
+
) : (
|
253
|
+
<>
|
254
|
+
{(virtualRows ?? rows).map((rowOrVirtualRow, rowIndex) => {
|
255
|
+
const row = rowVirtualizer
|
256
|
+
? rows[rowOrVirtualRow.index]
|
257
|
+
: (rowOrVirtualRow as MRT_Row<TData>);
|
258
|
+
const props = {
|
259
|
+
columnVirtualizer,
|
260
|
+
measureElement: rowVirtualizer?.measureElement,
|
261
|
+
numRows: rows.length,
|
262
|
+
pinnedRowIds,
|
263
|
+
row,
|
264
|
+
rowIndex: rowVirtualizer ? rowOrVirtualRow.index : rowIndex,
|
265
|
+
table,
|
266
|
+
virtualColumns,
|
267
|
+
virtualPaddingLeft,
|
268
|
+
virtualPaddingRight,
|
269
|
+
virtualRow: rowVirtualizer
|
270
|
+
? (rowOrVirtualRow as VirtualItem)
|
271
|
+
: undefined,
|
272
|
+
};
|
273
|
+
return memoMode === 'rows' ? (
|
274
|
+
<Memo_MRT_TableBodyRow key={row.id} {...props} />
|
275
|
+
) : (
|
276
|
+
<MRT_TableBodyRow key={row.id} {...props} />
|
277
|
+
);
|
278
|
+
})}
|
279
|
+
</>
|
280
|
+
))}
|
281
|
+
</TableBody>
|
282
|
+
{!rowPinningDisplayMode?.includes('sticky') &&
|
283
|
+
getIsSomeRowsPinned('bottom') && (
|
284
|
+
<TableBody
|
285
|
+
{...tableBodyProps}
|
286
|
+
sx={(theme) => ({
|
287
|
+
display: layoutMode === 'grid' ? 'grid' : 'table-row-group',
|
288
|
+
position: 'sticky',
|
289
|
+
bottom: tableFooterHeight - 1,
|
290
|
+
zIndex: 1,
|
291
|
+
...(parseFromValuesOrFunc(tableBodyProps?.sx, theme) as any),
|
292
|
+
})}
|
293
|
+
>
|
294
|
+
{getBottomRows().map((row, rowIndex) => {
|
188
295
|
const props = {
|
189
296
|
columnVirtualizer,
|
190
297
|
measureElement: rowVirtualizer?.measureElement,
|
191
298
|
numRows: rows.length,
|
192
299
|
row,
|
193
|
-
rowIndex
|
300
|
+
rowIndex,
|
194
301
|
table,
|
195
302
|
virtualColumns,
|
196
303
|
virtualPaddingLeft,
|
197
304
|
virtualPaddingRight,
|
198
|
-
virtualRow: rowVirtualizer
|
199
|
-
? (rowOrVirtualRow as VirtualItem)
|
200
|
-
: undefined,
|
201
305
|
};
|
202
306
|
return memoMode === 'rows' ? (
|
203
307
|
<Memo_MRT_TableBodyRow key={row.id} {...props} />
|
@@ -205,9 +309,9 @@ export const MRT_TableBody = <TData extends Record<string, any>>({
|
|
205
309
|
<MRT_TableBodyRow key={row.id} {...props} />
|
206
310
|
);
|
207
311
|
})}
|
208
|
-
|
209
|
-
)
|
210
|
-
|
312
|
+
</TableBody>
|
313
|
+
)}
|
314
|
+
</>
|
211
315
|
);
|
212
316
|
};
|
213
317
|
|
@@ -18,6 +18,7 @@ import {
|
|
18
18
|
getCommonCellStyles,
|
19
19
|
getIsFirstColumn,
|
20
20
|
getIsLastColumn,
|
21
|
+
parseFromValuesOrFunc,
|
21
22
|
} from '../column.utils';
|
22
23
|
import { type VirtualItem } from '@tanstack/react-virtual';
|
23
24
|
import { type MRT_Cell, type MRT_TableInstance } from '../types';
|
@@ -77,25 +78,27 @@ export const MRT_TableBodyCell = <TData extends Record<string, any>>({
|
|
77
78
|
const { columnDef } = column;
|
78
79
|
const { columnDefType } = columnDef;
|
79
80
|
|
80
|
-
const mTableCellBodyProps =
|
81
|
-
muiTableBodyCellProps instanceof Function
|
82
|
-
? muiTableBodyCellProps({ cell, column, row, table })
|
83
|
-
: muiTableBodyCellProps;
|
84
|
-
|
85
|
-
const mcTableCellBodyProps =
|
86
|
-
columnDef.muiTableBodyCellProps instanceof Function
|
87
|
-
? columnDef.muiTableBodyCellProps({ cell, column, row, table })
|
88
|
-
: columnDef.muiTableBodyCellProps;
|
89
|
-
|
90
81
|
const tableCellProps = {
|
91
|
-
...
|
92
|
-
|
82
|
+
...parseFromValuesOrFunc(muiTableBodyCellProps, {
|
83
|
+
cell,
|
84
|
+
column,
|
85
|
+
row,
|
86
|
+
table,
|
87
|
+
}),
|
88
|
+
...parseFromValuesOrFunc(columnDef.muiTableBodyCellProps, {
|
89
|
+
cell,
|
90
|
+
column,
|
91
|
+
row,
|
92
|
+
table,
|
93
|
+
}),
|
93
94
|
};
|
94
95
|
|
95
|
-
const skeletonProps =
|
96
|
-
|
97
|
-
|
98
|
-
|
96
|
+
const skeletonProps = parseFromValuesOrFunc(muiSkeletonProps, {
|
97
|
+
cell,
|
98
|
+
column,
|
99
|
+
row,
|
100
|
+
table,
|
101
|
+
});
|
99
102
|
|
100
103
|
const [skeletonWidth, setSkeletonWidth] = useState(100);
|
101
104
|
useEffect(() => {
|
@@ -148,10 +151,8 @@ export const MRT_TableBodyCell = <TData extends Record<string, any>>({
|
|
148
151
|
}, [draggingColumn, draggingRow, hoveredColumn, hoveredRow, rowIndex]);
|
149
152
|
|
150
153
|
const isEditable =
|
151
|
-
(enableEditing
|
152
|
-
(columnDef.enableEditing
|
153
|
-
? columnDef.enableEditing(row)
|
154
|
-
: columnDef.enableEditing) !== false;
|
154
|
+
parseFromValuesOrFunc(enableEditing, row) &&
|
155
|
+
parseFromValuesOrFunc(columnDef.enableEditing, row) !== false;
|
155
156
|
|
156
157
|
const isEditing =
|
157
158
|
isEditable &&
|
@@ -232,7 +233,8 @@ export const MRT_TableBodyCell = <TData extends Record<string, any>>({
|
|
232
233
|
}rem`
|
233
234
|
: undefined,
|
234
235
|
textOverflow: columnDefType !== 'display' ? 'ellipsis' : undefined,
|
235
|
-
whiteSpace:
|
236
|
+
whiteSpace:
|
237
|
+
row.getIsPinned() || density === 'compact' ? 'nowrap' : 'normal',
|
236
238
|
zIndex:
|
237
239
|
draggingColumn?.id === column.id ? 2 : column.getIsPinned() ? 1 : 0,
|
238
240
|
'&:hover': {
|
@@ -1,15 +1,23 @@
|
|
1
|
-
import { type DragEvent, memo, useRef } from 'react';
|
1
|
+
import { type DragEvent, memo, useRef, useMemo } from 'react';
|
2
2
|
import TableRow from '@mui/material/TableRow';
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
type Theme,
|
5
|
+
alpha,
|
6
|
+
darken,
|
7
|
+
lighten,
|
8
|
+
useTheme,
|
9
|
+
} from '@mui/material/styles';
|
4
10
|
import { Memo_MRT_TableBodyCell, MRT_TableBodyCell } from './MRT_TableBodyCell';
|
5
11
|
import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
|
6
12
|
import { type VirtualItem, type Virtualizer } from '@tanstack/react-virtual';
|
13
|
+
import { parseFromValuesOrFunc } from '../column.utils';
|
7
14
|
import { type MRT_Cell, type MRT_Row, type MRT_TableInstance } from '../types';
|
8
15
|
|
9
16
|
interface Props<TData extends Record<string, any>> {
|
10
17
|
columnVirtualizer?: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
|
11
18
|
measureElement?: (element: HTMLTableRowElement) => void;
|
12
19
|
numRows: number;
|
20
|
+
pinnedRowIds?: string[];
|
13
21
|
row: MRT_Row<TData>;
|
14
22
|
rowIndex: number;
|
15
23
|
table: MRT_TableInstance<TData>;
|
@@ -23,6 +31,7 @@ export const MRT_TableBodyRow = <TData extends Record<string, any>>({
|
|
23
31
|
columnVirtualizer,
|
24
32
|
measureElement,
|
25
33
|
numRows,
|
34
|
+
pinnedRowIds,
|
26
35
|
row,
|
27
36
|
rowIndex,
|
28
37
|
table,
|
@@ -31,24 +40,70 @@ export const MRT_TableBodyRow = <TData extends Record<string, any>>({
|
|
31
40
|
virtualPaddingRight,
|
32
41
|
virtualRow,
|
33
42
|
}: Props<TData>) => {
|
43
|
+
const theme = useTheme();
|
44
|
+
|
34
45
|
const {
|
35
46
|
getState,
|
36
47
|
options: {
|
37
48
|
enableRowOrdering,
|
49
|
+
enableRowPinning,
|
50
|
+
enableStickyFooter,
|
51
|
+
enableStickyHeader,
|
38
52
|
layoutMode,
|
53
|
+
rowPinningDisplayMode,
|
39
54
|
memoMode,
|
40
55
|
muiTableBodyRowProps,
|
41
56
|
renderDetailPanel,
|
42
57
|
},
|
58
|
+
refs: { tableHeadRef, tableFooterRef },
|
43
59
|
setHoveredRow,
|
44
60
|
} = table;
|
45
|
-
const {
|
46
|
-
|
61
|
+
const {
|
62
|
+
density,
|
63
|
+
draggingColumn,
|
64
|
+
draggingRow,
|
65
|
+
editingCell,
|
66
|
+
editingRow,
|
67
|
+
hoveredRow,
|
68
|
+
isFullScreen,
|
69
|
+
rowPinning,
|
70
|
+
} = getState();
|
71
|
+
|
72
|
+
const isPinned = enableRowPinning && row.getIsPinned();
|
73
|
+
|
74
|
+
const tableRowProps = parseFromValuesOrFunc(muiTableBodyRowProps, {
|
75
|
+
row,
|
76
|
+
staticRowIndex: rowIndex,
|
77
|
+
table,
|
78
|
+
});
|
79
|
+
|
80
|
+
const [bottomPinnedIndex, topPinnedIndex] = useMemo(() => {
|
81
|
+
if (
|
82
|
+
!enableRowPinning ||
|
83
|
+
!rowPinningDisplayMode?.includes('sticky') ||
|
84
|
+
!pinnedRowIds ||
|
85
|
+
!row.getIsPinned()
|
86
|
+
)
|
87
|
+
return [];
|
88
|
+
return [
|
89
|
+
[...pinnedRowIds].reverse().indexOf(row.id),
|
90
|
+
pinnedRowIds.indexOf(row.id),
|
91
|
+
];
|
92
|
+
}, [pinnedRowIds, rowPinning]);
|
93
|
+
|
94
|
+
const tableHeadHeight =
|
95
|
+
((enableStickyHeader || isFullScreen) &&
|
96
|
+
tableHeadRef.current?.clientHeight) ||
|
97
|
+
0;
|
98
|
+
const tableFooterHeight =
|
99
|
+
(enableStickyFooter && tableFooterRef.current?.clientHeight) || 0;
|
100
|
+
|
101
|
+
const sx = parseFromValuesOrFunc(tableRowProps?.sx, theme as any);
|
47
102
|
|
48
|
-
const
|
49
|
-
|
50
|
-
|
51
|
-
|
103
|
+
const rowHeight =
|
104
|
+
// @ts-ignore
|
105
|
+
parseInt(tableRowProps?.style?.height ?? sx?.height, 10) ||
|
106
|
+
(density === 'compact' ? 37 : density === 'comfortable' ? 53 : 69);
|
52
107
|
|
53
108
|
const handleDragEnter = (_e: DragEvent) => {
|
54
109
|
if (enableRowOrdering && draggingRow) {
|
@@ -72,15 +127,50 @@ export const MRT_TableBodyRow = <TData extends Record<string, any>>({
|
|
72
127
|
}}
|
73
128
|
{...tableRowProps}
|
74
129
|
sx={(theme: Theme) => ({
|
75
|
-
backgroundColor: lighten(
|
130
|
+
backgroundColor: `${lighten(
|
131
|
+
theme.palette.background.default,
|
132
|
+
0.06,
|
133
|
+
)} !important`,
|
76
134
|
boxSizing: 'border-box',
|
135
|
+
bottom:
|
136
|
+
bottomPinnedIndex !== undefined && isPinned
|
137
|
+
? `${
|
138
|
+
bottomPinnedIndex * rowHeight +
|
139
|
+
(enableStickyFooter ? tableFooterHeight - 1 : 0)
|
140
|
+
}px`
|
141
|
+
: undefined,
|
77
142
|
display: layoutMode === 'grid' ? 'flex' : 'table-row',
|
78
|
-
opacity:
|
79
|
-
|
80
|
-
|
143
|
+
opacity: isPinned
|
144
|
+
? 0.98
|
145
|
+
: draggingRow?.id === row.id || hoveredRow?.id === row.id
|
146
|
+
? 0.5
|
147
|
+
: 1,
|
148
|
+
position: virtualRow
|
149
|
+
? 'absolute'
|
150
|
+
: rowPinningDisplayMode?.includes('sticky') && isPinned
|
151
|
+
? 'sticky'
|
152
|
+
: undefined,
|
81
153
|
transition: virtualRow ? 'none' : 'all 150ms ease-in-out',
|
82
|
-
top: virtualRow
|
154
|
+
top: virtualRow
|
155
|
+
? 0
|
156
|
+
: topPinnedIndex !== undefined && isPinned
|
157
|
+
? `${
|
158
|
+
topPinnedIndex * rowHeight +
|
159
|
+
(enableStickyHeader || isFullScreen ? tableHeadHeight - 1 : 0)
|
160
|
+
}px`
|
161
|
+
: undefined,
|
83
162
|
width: '100%',
|
163
|
+
zIndex:
|
164
|
+
rowPinningDisplayMode?.includes('sticky') && isPinned
|
165
|
+
? 1
|
166
|
+
: undefined,
|
167
|
+
td: {
|
168
|
+
backgroundColor: row.getIsSelected()
|
169
|
+
? alpha(theme.palette.primary.main, 0.2)
|
170
|
+
: isPinned
|
171
|
+
? alpha(theme.palette.primary.main, 0.1)
|
172
|
+
: undefined,
|
173
|
+
},
|
84
174
|
'&:hover td': {
|
85
175
|
backgroundColor:
|
86
176
|
tableRowProps?.hover !== false
|
@@ -91,9 +181,7 @@ export const MRT_TableBodyRow = <TData extends Record<string, any>>({
|
|
91
181
|
: `${darken(theme.palette.background.default, 0.05)}`
|
92
182
|
: undefined,
|
93
183
|
},
|
94
|
-
...(
|
95
|
-
? tableRowProps.sx(theme)
|
96
|
-
: (tableRowProps?.sx as any)),
|
184
|
+
...(sx as any),
|
97
185
|
})}
|
98
186
|
style={{
|
99
187
|
transform: virtualRow
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { type DragEvent, type RefObject } from 'react';
|
2
2
|
import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
|
3
3
|
import { type MRT_Row, type MRT_TableInstance } from '../types';
|
4
|
+
import { parseFromValuesOrFunc } from '../column.utils';
|
4
5
|
|
5
6
|
interface Props<TData extends Record<string, any>> {
|
6
7
|
row: MRT_Row<TData>;
|
@@ -17,10 +18,10 @@ export const MRT_TableBodyRowGrabHandle = <TData extends Record<string, any>>({
|
|
17
18
|
options: { muiRowDragHandleProps },
|
18
19
|
} = table;
|
19
20
|
|
20
|
-
const iconButtonProps =
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
const iconButtonProps = parseFromValuesOrFunc(muiRowDragHandleProps, {
|
22
|
+
row,
|
23
|
+
table,
|
24
|
+
});
|
24
25
|
|
25
26
|
const handleDragStart = (event: DragEvent<HTMLButtonElement>) => {
|
26
27
|
iconButtonProps?.onDragStart?.(event);
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import Box from '@mui/material/Box';
|
2
|
+
import { MRT_RowPinButton } from '../buttons/MRT_RowPinButton';
|
3
|
+
import { parseFromValuesOrFunc } from '../column.utils';
|
4
|
+
import { type MRT_Row, type MRT_TableInstance } from '../types';
|
5
|
+
|
6
|
+
interface Props<TData extends Record<string, any>> {
|
7
|
+
row: MRT_Row<TData>;
|
8
|
+
table: MRT_TableInstance<TData>;
|
9
|
+
}
|
10
|
+
|
11
|
+
export const MRT_TableBodyRowPinButton = <TData extends Record<string, any>>({
|
12
|
+
row,
|
13
|
+
table,
|
14
|
+
}: Props<TData>) => {
|
15
|
+
const {
|
16
|
+
getState,
|
17
|
+
options: { enableRowPinning, rowPinningDisplayMode },
|
18
|
+
} = table;
|
19
|
+
const { density } = getState();
|
20
|
+
|
21
|
+
const canPin = parseFromValuesOrFunc(enableRowPinning, row as any);
|
22
|
+
|
23
|
+
if (!canPin) return null;
|
24
|
+
|
25
|
+
if (rowPinningDisplayMode === 'top-and-bottom' && !row.getIsPinned()) {
|
26
|
+
return (
|
27
|
+
<Box
|
28
|
+
sx={{
|
29
|
+
display: 'flex',
|
30
|
+
flexDirection: density === 'compact' ? 'row' : 'column',
|
31
|
+
}}
|
32
|
+
>
|
33
|
+
<MRT_RowPinButton row={row} table={table} pinningPosition="top" />
|
34
|
+
<MRT_RowPinButton row={row} table={table} pinningPosition="bottom" />
|
35
|
+
</Box>
|
36
|
+
);
|
37
|
+
}
|
38
|
+
|
39
|
+
return (
|
40
|
+
<MRT_RowPinButton
|
41
|
+
row={row}
|
42
|
+
table={table}
|
43
|
+
pinningPosition={rowPinningDisplayMode === 'bottom' ? 'bottom' : 'top'}
|
44
|
+
/>
|
45
|
+
);
|
46
|
+
};
|