material-react-table 1.4.3 → 1.5.0-beta.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 +183 -71
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/MaterialReactTable.d.ts +19 -6
- package/dist/cjs/types/body/MRT_TableBody.d.ts +5 -0
- package/dist/cjs/types/body/MRT_TableBodyCell.d.ts +3 -0
- package/dist/cjs/types/body/MRT_TableBodyRow.d.ts +5 -1
- package/dist/cjs/types/footer/MRT_TableFooter.d.ts +4 -0
- package/dist/cjs/types/footer/MRT_TableFooterRow.d.ts +4 -0
- package/dist/cjs/types/head/MRT_TableHead.d.ts +4 -0
- package/dist/cjs/types/head/MRT_TableHeadRow.d.ts +4 -0
- package/dist/cjs/types/table/MRT_TableRoot.d.ts +12 -5
- package/dist/cjs/types/toolbar/MRT_TablePagination.d.ts +1 -1
- package/dist/esm/material-react-table.esm.js +179 -67
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/MaterialReactTable.d.ts +19 -6
- package/dist/esm/types/body/MRT_TableBody.d.ts +5 -0
- package/dist/esm/types/body/MRT_TableBodyCell.d.ts +3 -0
- package/dist/esm/types/body/MRT_TableBodyRow.d.ts +5 -1
- package/dist/esm/types/footer/MRT_TableFooter.d.ts +4 -0
- package/dist/esm/types/footer/MRT_TableFooterRow.d.ts +4 -0
- package/dist/esm/types/head/MRT_TableHead.d.ts +4 -0
- package/dist/esm/types/head/MRT_TableHeadRow.d.ts +4 -0
- package/dist/esm/types/table/MRT_TableRoot.d.ts +12 -5
- package/dist/esm/types/toolbar/MRT_TablePagination.d.ts +1 -1
- package/dist/index.d.ts +21 -8
- package/locales/ru.esm.js +1 -1
- package/locales/ru.js +1 -1
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +48 -11
- package/src/_locales/ru.ts +1 -1
- package/src/body/MRT_TableBody.tsx +42 -13
- package/src/body/MRT_TableBodyCell.tsx +17 -1
- package/src/body/MRT_TableBodyRow.tsx +24 -3
- package/src/column.utils.ts +4 -1
- package/src/footer/MRT_TableFooter.tsx +13 -1
- package/src/footer/MRT_TableFooterCell.tsx +6 -1
- package/src/footer/MRT_TableFooterRow.tsx +27 -4
- package/src/head/MRT_TableHead.tsx +13 -1
- package/src/head/MRT_TableHeadCell.tsx +2 -2
- package/src/head/MRT_TableHeadRow.tsx +26 -4
- package/src/table/MRT_Table.tsx +105 -7
- package/src/table/MRT_TableRoot.tsx +1 -1
- package/src/toolbar/MRT_TablePagination.tsx +2 -2
@@ -62,12 +62,12 @@ import AlertTitle from '@mui/material/AlertTitle';
|
|
62
62
|
import Chip from '@mui/material/Chip';
|
63
63
|
import Fade from '@mui/material/Fade';
|
64
64
|
import TableContainer from '@mui/material/TableContainer';
|
65
|
+
import { useVirtualizer, defaultRangeExtractor } from '@tanstack/react-virtual';
|
65
66
|
import Table from '@mui/material/Table';
|
66
67
|
import TableHead from '@mui/material/TableHead';
|
67
68
|
import TableRow from '@mui/material/TableRow';
|
68
69
|
import TableCell from '@mui/material/TableCell';
|
69
70
|
import TableSortLabel from '@mui/material/TableSortLabel';
|
70
|
-
import { useVirtualizer } from '@tanstack/react-virtual';
|
71
71
|
import TableBody from '@mui/material/TableBody';
|
72
72
|
import Skeleton from '@mui/material/Skeleton';
|
73
73
|
import TableFooter from '@mui/material/TableFooter';
|
@@ -245,7 +245,9 @@ const getCommonCellStyles = ({ column, header, table, tableCellProps, theme, })
|
|
245
245
|
? 'sticky'
|
246
246
|
: undefined, right: column.getIsPinned() === 'right'
|
247
247
|
? `${getTotalRight(table, column)}px`
|
248
|
-
: undefined, transition:
|
248
|
+
: undefined, transition: table.options.enableColumnVirtualization || column.getIsResizing()
|
249
|
+
? 'none'
|
250
|
+
: `all 150ms ease-in-out` }, ((tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx) instanceof Function
|
249
251
|
? tableCellProps.sx(theme)
|
250
252
|
: tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx)), { flex: table.options.layoutMode === 'grid'
|
251
253
|
? `${column.getSize()} 0 auto`
|
@@ -1131,7 +1133,7 @@ const MRT_LinearProgressBar = ({ isTopToolbar, table }) => {
|
|
1131
1133
|
React.createElement(LinearProgress, Object.assign({ "aria-label": "Loading", "aria-busy": "true", sx: { position: 'relative' } }, linearProgressProps))));
|
1132
1134
|
};
|
1133
1135
|
|
1134
|
-
const MRT_TablePagination = ({ table, position, }) => {
|
1136
|
+
const MRT_TablePagination = ({ table, position = 'bottom', }) => {
|
1135
1137
|
const { getPrePaginationRowModel, getState, setPageIndex, setPageSize, options: { muiTablePaginationProps, enableToolbarInternalActions, localization, rowCount, }, } = table;
|
1136
1138
|
const { pagination: { pageSize = 10, pageIndex = 0 }, showGlobalFilter, } = getState();
|
1137
1139
|
const totalRowCount = rowCount !== null && rowCount !== void 0 ? rowCount : getPrePaginationRowModel().rows.length;
|
@@ -1962,17 +1964,25 @@ const MRT_TableHeadCell = ({ header, table }) => {
|
|
1962
1964
|
column.getCanFilter() && (React.createElement(MRT_TableHeadCellFilterContainer, { header: header, table: table }))));
|
1963
1965
|
};
|
1964
1966
|
|
1965
|
-
const MRT_TableHeadRow = ({ headerGroup, table }) => {
|
1967
|
+
const MRT_TableHeadRow = ({ headerGroup, table, virtualColumns, virtualPaddingLeft, virtualPaddingRight, }) => {
|
1966
1968
|
const { options: { layoutMode, muiTableHeadRowProps }, } = table;
|
1967
1969
|
const tableRowProps = muiTableHeadRowProps instanceof Function
|
1968
1970
|
? muiTableHeadRowProps({ headerGroup, table })
|
1969
1971
|
: muiTableHeadRowProps;
|
1970
1972
|
return (React.createElement(TableRow, Object.assign({}, tableRowProps, { sx: (theme) => (Object.assign({ backgroundColor: lighten(theme.palette.background.default, 0.04), boxShadow: `4px 0 8px ${alpha(theme.palette.common.black, 0.1)}`, display: layoutMode === 'grid' ? 'flex' : 'table-row', top: 0 }, ((tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx) instanceof Function
|
1971
1973
|
? tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx(theme)
|
1972
|
-
: tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx))) }),
|
1974
|
+
: tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx))) }),
|
1975
|
+
virtualPaddingLeft ? (React.createElement("th", { style: { display: 'flex', width: virtualPaddingLeft } })) : null,
|
1976
|
+
(virtualColumns !== null && virtualColumns !== void 0 ? virtualColumns : headerGroup.headers).map((headerOrVirtualHeader) => {
|
1977
|
+
const header = virtualColumns
|
1978
|
+
? headerGroup.headers[headerOrVirtualHeader.index]
|
1979
|
+
: headerOrVirtualHeader;
|
1980
|
+
return (React.createElement(MRT_TableHeadCell, { header: header, key: header.id, table: table }));
|
1981
|
+
}),
|
1982
|
+
virtualPaddingRight ? (React.createElement("th", { style: { display: 'flex', width: virtualPaddingRight } })) : null));
|
1973
1983
|
};
|
1974
1984
|
|
1975
|
-
const MRT_TableHead = ({ table }) => {
|
1985
|
+
const MRT_TableHead = ({ table, virtualColumns, virtualPaddingLeft, virtualPaddingRight, }) => {
|
1976
1986
|
const { getHeaderGroups, getState, options: { enableStickyHeader, layoutMode, muiTableHeadProps }, } = table;
|
1977
1987
|
const { isFullScreen } = getState();
|
1978
1988
|
const tableHeadProps = muiTableHeadProps instanceof Function
|
@@ -1981,7 +1991,7 @@ const MRT_TableHead = ({ table }) => {
|
|
1981
1991
|
const stickyHeader = enableStickyHeader || isFullScreen;
|
1982
1992
|
return (React.createElement(TableHead, Object.assign({}, tableHeadProps, { sx: (theme) => (Object.assign({ display: layoutMode === 'grid' ? 'grid' : 'table-row-group', opacity: 0.97, position: stickyHeader ? 'sticky' : 'relative', top: stickyHeader && layoutMode === 'grid' ? 0 : undefined, zIndex: stickyHeader ? 2 : undefined }, ((tableHeadProps === null || tableHeadProps === void 0 ? void 0 : tableHeadProps.sx) instanceof Function
|
1983
1993
|
? tableHeadProps === null || tableHeadProps === void 0 ? void 0 : tableHeadProps.sx(theme)
|
1984
|
-
: tableHeadProps === null || tableHeadProps === void 0 ? void 0 : tableHeadProps.sx))) }), getHeaderGroups().map((headerGroup) => (React.createElement(MRT_TableHeadRow, { headerGroup: headerGroup, key: headerGroup.id, table: table })))));
|
1994
|
+
: tableHeadProps === null || tableHeadProps === void 0 ? void 0 : tableHeadProps.sx))) }), getHeaderGroups().map((headerGroup) => (React.createElement(MRT_TableHeadRow, { headerGroup: headerGroup, key: headerGroup.id, table: table, virtualColumns: virtualColumns, virtualPaddingLeft: virtualPaddingLeft, virtualPaddingRight: virtualPaddingRight })))));
|
1985
1995
|
};
|
1986
1996
|
|
1987
1997
|
const MRT_EditCellTextField = ({ cell, showLabel, table, }) => {
|
@@ -2120,7 +2130,7 @@ const MRT_TableBodyCellValue = ({ cell, table }) => {
|
|
2120
2130
|
: (_b = (_a = columnDef === null || columnDef === void 0 ? void 0 : columnDef.Cell) === null || _a === void 0 ? void 0 : _a.call(columnDef, { cell, column, row, table })) !== null && _b !== void 0 ? _b : cell.renderValue()));
|
2121
2131
|
};
|
2122
2132
|
|
2123
|
-
const MRT_TableBodyCell = ({ cell, enableHover, numRows, rowIndex, rowRef, table, }) => {
|
2133
|
+
const MRT_TableBodyCell = ({ cell, enableHover, measureElement, numRows, rowIndex, rowRef, table, virtualCell, }) => {
|
2124
2134
|
var _a, _b;
|
2125
2135
|
const theme = useTheme();
|
2126
2136
|
const { getState, options: { editingMode, enableClickToCopy, enableColumnOrdering, enableEditing, enableGrouping, enableRowNumbers, layoutMode, muiTableBodyCellProps, muiTableBodyCellSkeletonProps, rowNumberMode, }, refs: { editInputRefs }, setEditingCell, setHoveredColumn, } = table;
|
@@ -2192,7 +2202,11 @@ const MRT_TableBodyCell = ({ cell, enableHover, numRows, rowIndex, rowRef, table
|
|
2192
2202
|
setHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
|
2193
2203
|
}
|
2194
2204
|
};
|
2195
|
-
return (React.createElement(TableCell, Object.assign({
|
2205
|
+
return (React.createElement(TableCell, Object.assign({ "data-index": virtualCell === null || virtualCell === void 0 ? void 0 : virtualCell.index, ref: (node) => {
|
2206
|
+
if (node) {
|
2207
|
+
measureElement === null || measureElement === void 0 ? void 0 : measureElement(node);
|
2208
|
+
}
|
2209
|
+
} }, tableCellProps, { onDragEnter: handleDragEnter, onDoubleClick: handleDoubleClick, sx: (theme) => (Object.assign(Object.assign({ alignItems: layoutMode === 'grid' ? 'center' : undefined, cursor: isEditable && editingMode === 'cell' ? 'pointer' : 'inherit', overflow: 'hidden', p: density === 'compact'
|
2196
2210
|
? columnDefType === 'display'
|
2197
2211
|
? '0 0.5rem'
|
2198
2212
|
: '0.5rem'
|
@@ -2218,7 +2232,12 @@ const MRT_TableBodyCell = ({ cell, enableHover, numRows, rowIndex, rowRef, table
|
|
2218
2232
|
? `${lighten(theme.palette.background.default, 0.2)} !important`
|
2219
2233
|
: `${darken(theme.palette.background.default, 0.1)} !important`
|
2220
2234
|
: undefined,
|
2221
|
-
} }, getCommonCellStyles({
|
2235
|
+
} }, getCommonCellStyles({
|
2236
|
+
column,
|
2237
|
+
table,
|
2238
|
+
theme,
|
2239
|
+
tableCellProps,
|
2240
|
+
})), draggingBorders)) }),
|
2222
2241
|
React.createElement(React.Fragment, null, cell.getIsPlaceholder() ? null : isLoading || showSkeletons ? (React.createElement(Skeleton, Object.assign({ animation: "wave", height: 20, width: skeletonWidth }, skeletonProps))) : enableRowNumbers &&
|
2223
2242
|
rowNumberMode === 'static' &&
|
2224
2243
|
column.id === 'mrt-row-numbers' ? (rowIndex + 1) : column.id === 'mrt-row-drag' ? (React.createElement(MRT_TableBodyRowGrabHandle, { cell: cell, rowRef: rowRef, table: table })) : columnDefType === 'display' &&
|
@@ -2260,7 +2279,7 @@ const MRT_TableDetailPanel = ({ parentRowRef, row, table, virtualRow, }) => {
|
|
2260
2279
|
: tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx))) }), renderDetailPanel && (React.createElement(Collapse, { in: row.getIsExpanded(), mountOnEnter: true, unmountOnExit: true }, !isLoading && renderDetailPanel({ row, table }))))));
|
2261
2280
|
};
|
2262
2281
|
|
2263
|
-
const MRT_TableBodyRow = ({ measureElement, numRows, row, rowIndex, table, virtualRow, }) => {
|
2282
|
+
const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, row, rowIndex, table, virtualColumns, virtualPaddingLeft, virtualPaddingRight, virtualRow, }) => {
|
2264
2283
|
const theme = useTheme();
|
2265
2284
|
const { getIsSomeColumnsPinned, getState, options: { enableRowOrdering, layoutMode, memoMode, muiTableBodyRowProps, renderDetailPanel, }, setHoveredRow, } = table;
|
2266
2285
|
const { draggingColumn, draggingRow, editingCell, editingRow, hoveredRow } = getState();
|
@@ -2299,37 +2318,50 @@ const MRT_TableBodyRow = ({ measureElement, numRows, row, rowIndex, table, virtu
|
|
2299
2318
|
: undefined,
|
2300
2319
|
} }, ((tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx) instanceof Function
|
2301
2320
|
? tableRowProps.sx(theme)
|
2302
|
-
: tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx)), draggingBorders)) }),
|
2303
|
-
|
2304
|
-
|
2305
|
-
|
2306
|
-
|
2307
|
-
|
2308
|
-
|
2309
|
-
|
2310
|
-
|
2311
|
-
|
2312
|
-
|
2313
|
-
|
2314
|
-
|
2315
|
-
|
2316
|
-
|
2317
|
-
|
2318
|
-
|
2321
|
+
: tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx)), draggingBorders)) }),
|
2322
|
+
virtualPaddingLeft ? (React.createElement("td", { style: { display: 'flex', width: virtualPaddingLeft } })) : null,
|
2323
|
+
(virtualColumns !== null && virtualColumns !== void 0 ? virtualColumns : row.getVisibleCells()).map((cellOrVirtualCell) => {
|
2324
|
+
const cell = columnVirtualizer
|
2325
|
+
? row.getVisibleCells()[cellOrVirtualCell.index]
|
2326
|
+
: cellOrVirtualCell;
|
2327
|
+
const props = {
|
2328
|
+
cell,
|
2329
|
+
enableHover: (tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.hover) !== false,
|
2330
|
+
key: cell.id,
|
2331
|
+
measureElement: columnVirtualizer === null || columnVirtualizer === void 0 ? void 0 : columnVirtualizer.measureElement,
|
2332
|
+
numRows,
|
2333
|
+
rowIndex,
|
2334
|
+
rowRef,
|
2335
|
+
table,
|
2336
|
+
virtualCell: columnVirtualizer
|
2337
|
+
? cellOrVirtualCell
|
2338
|
+
: undefined,
|
2339
|
+
};
|
2340
|
+
return memoMode === 'cells' &&
|
2341
|
+
cell.column.columnDef.columnDefType === 'data' &&
|
2342
|
+
!draggingColumn &&
|
2343
|
+
!draggingRow &&
|
2344
|
+
(editingCell === null || editingCell === void 0 ? void 0 : editingCell.id) !== cell.id &&
|
2345
|
+
(editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) !== row.id ? (React.createElement(Memo_MRT_TableBodyCell, Object.assign({}, props))) : (React.createElement(MRT_TableBodyCell, Object.assign({}, props)));
|
2346
|
+
}),
|
2347
|
+
virtualPaddingRight ? (React.createElement("td", { style: { display: 'flex', width: virtualPaddingRight } })) : null),
|
2319
2348
|
renderDetailPanel && !row.getIsGrouped() && (React.createElement(MRT_TableDetailPanel, { parentRowRef: rowRef, row: row, table: table, virtualRow: virtualRow }))));
|
2320
2349
|
};
|
2321
2350
|
const Memo_MRT_TableBodyRow = memo(MRT_TableBodyRow, (prev, next) => prev.row === next.row);
|
2322
2351
|
|
2323
|
-
const MRT_TableBody = ({ table }) => {
|
2352
|
+
const MRT_TableBody = ({ columnVirtualizer, table, virtualColumns, virtualPaddingLeft, virtualPaddingRight, }) => {
|
2324
2353
|
var _a, _b, _c;
|
2325
|
-
const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, layoutMode, localization, manualFiltering, manualSorting, memoMode, muiTableBodyProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef, tablePaperRef }, } = table;
|
2354
|
+
const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, layoutMode, localization, manualFiltering, manualSorting, memoMode, muiTableBodyProps, rowVirtualizerInstanceRef, rowVirtualizerProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef, tablePaperRef }, } = table;
|
2326
2355
|
const { columnFilters, density, globalFilter, pagination, sorting } = getState();
|
2327
2356
|
const tableBodyProps = muiTableBodyProps instanceof Function
|
2328
2357
|
? muiTableBodyProps({ table })
|
2329
2358
|
: muiTableBodyProps;
|
2330
|
-
const
|
2359
|
+
const vProps_old = virtualizerProps instanceof Function
|
2331
2360
|
? virtualizerProps({ table })
|
2332
2361
|
: virtualizerProps;
|
2362
|
+
const vProps = rowVirtualizerProps instanceof Function
|
2363
|
+
? rowVirtualizerProps({ table })
|
2364
|
+
: rowVirtualizerProps;
|
2333
2365
|
const rows = useMemo(() => {
|
2334
2366
|
if (enableGlobalFilterRankedResults &&
|
2335
2367
|
globalFilter &&
|
@@ -2355,14 +2387,22 @@ const MRT_TableBody = ({ table }) => {
|
|
2355
2387
|
pagination.pageIndex,
|
2356
2388
|
pagination.pageSize,
|
2357
2389
|
]);
|
2358
|
-
const
|
2359
|
-
? useVirtualizer(Object.assign({ count: rows.length, estimateSize: () => density === 'compact' ? 37 : density === 'comfortable' ? 58 : 73, getScrollElement: () => tableContainerRef.current, measureElement: (element) => element === null || element === void 0 ? void 0 : element.getBoundingClientRect().height, overscan: 4 }, vProps))
|
2390
|
+
const rowVirtualizer = enableRowVirtualization
|
2391
|
+
? useVirtualizer(Object.assign(Object.assign({ count: rows.length, estimateSize: () => density === 'compact' ? 37 : density === 'comfortable' ? 58 : 73, getScrollElement: () => tableContainerRef.current, measureElement: (element) => element === null || element === void 0 ? void 0 : element.getBoundingClientRect().height, overscan: 4 }, vProps_old), vProps))
|
2360
2392
|
: undefined;
|
2361
|
-
if (
|
2362
|
-
|
2393
|
+
if (rowVirtualizerInstanceRef && rowVirtualizer) {
|
2394
|
+
rowVirtualizerInstanceRef.current = rowVirtualizer;
|
2363
2395
|
}
|
2364
|
-
|
2365
|
-
|
2396
|
+
//deprecated
|
2397
|
+
if (virtualizerInstanceRef && rowVirtualizer) {
|
2398
|
+
virtualizerInstanceRef.current = rowVirtualizer;
|
2399
|
+
}
|
2400
|
+
const virtualRows = rowVirtualizer
|
2401
|
+
? rowVirtualizer.getVirtualItems()
|
2402
|
+
: undefined;
|
2403
|
+
return (React.createElement(TableBody, Object.assign({}, tableBodyProps, { sx: (theme) => (Object.assign({ display: layoutMode === 'grid' ? 'grid' : 'table-row-group', height: rowVirtualizer
|
2404
|
+
? `${rowVirtualizer.getTotalSize()}px`
|
2405
|
+
: 'inherit', minHeight: !rows.length ? '100px' : undefined, position: 'relative' }, ((tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx) instanceof Function
|
2366
2406
|
? tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx(theme)
|
2367
2407
|
: tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx))) }), (_a = tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.children) !== null && _a !== void 0 ? _a : (!rows.length ? (React.createElement("tr", { style: { display: layoutMode === 'grid' ? 'grid' : 'table-row' } },
|
2368
2408
|
React.createElement("td", { colSpan: table.getVisibleLeafColumns().length, style: { display: layoutMode === 'grid' ? 'grid' : 'table-cell' } },
|
@@ -2376,19 +2416,21 @@ const MRT_TableBody = ({ table }) => {
|
|
2376
2416
|
} }, globalFilter || columnFilters.length
|
2377
2417
|
? localization.noResultsFound
|
2378
2418
|
: localization.noRecordsToDisplay)))) : (React.createElement(React.Fragment, null, (virtualRows !== null && virtualRows !== void 0 ? virtualRows : rows).map((rowOrVirtualRow, rowIndex) => {
|
2379
|
-
const row =
|
2419
|
+
const row = rowVirtualizer
|
2380
2420
|
? rows[rowOrVirtualRow.index]
|
2381
2421
|
: rowOrVirtualRow;
|
2382
2422
|
const props = {
|
2423
|
+
columnVirtualizer,
|
2383
2424
|
key: row.id,
|
2384
|
-
measureElement:
|
2385
|
-
? virtualizer.measureElement
|
2386
|
-
: undefined,
|
2425
|
+
measureElement: rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.measureElement,
|
2387
2426
|
numRows: rows.length,
|
2388
2427
|
row,
|
2389
|
-
rowIndex:
|
2428
|
+
rowIndex: rowVirtualizer ? rowOrVirtualRow.index : rowIndex,
|
2390
2429
|
table,
|
2391
|
-
|
2430
|
+
virtualColumns,
|
2431
|
+
virtualPaddingLeft,
|
2432
|
+
virtualPaddingRight,
|
2433
|
+
virtualRow: rowVirtualizer
|
2392
2434
|
? rowOrVirtualRow
|
2393
2435
|
: undefined,
|
2394
2436
|
};
|
@@ -2415,7 +2457,12 @@ const MRT_TableFooterCell = ({ footer, table }) => {
|
|
2415
2457
|
? '0.5rem'
|
2416
2458
|
: density === 'comfortable'
|
2417
2459
|
? '1rem'
|
2418
|
-
: '1.5rem', verticalAlign: 'top', zIndex: column.getIsPinned() && columnDefType !== 'group' ? 2 : 1 }, getCommonCellStyles({
|
2460
|
+
: '1.5rem', verticalAlign: 'top', zIndex: column.getIsPinned() && columnDefType !== 'group' ? 2 : 1 }, getCommonCellStyles({
|
2461
|
+
column,
|
2462
|
+
table,
|
2463
|
+
theme,
|
2464
|
+
tableCellProps,
|
2465
|
+
}))) }),
|
2419
2466
|
React.createElement(React.Fragment, null, footer.isPlaceholder
|
2420
2467
|
? null
|
2421
2468
|
: (_c = (_b = (columnDef.Footer instanceof Function
|
@@ -2427,7 +2474,7 @@ const MRT_TableFooterCell = ({ footer, table }) => {
|
|
2427
2474
|
: columnDef.Footer)) !== null && _b !== void 0 ? _b : columnDef.footer) !== null && _c !== void 0 ? _c : null)));
|
2428
2475
|
};
|
2429
2476
|
|
2430
|
-
const MRT_TableFooterRow = ({ footerGroup, table }) => {
|
2477
|
+
const MRT_TableFooterRow = ({ footerGroup, table, virtualColumns, virtualPaddingLeft, virtualPaddingRight, }) => {
|
2431
2478
|
var _a;
|
2432
2479
|
const { options: { layoutMode, muiTableFooterRowProps }, } = table;
|
2433
2480
|
// if no content in row, skip row
|
@@ -2438,12 +2485,20 @@ const MRT_TableFooterRow = ({ footerGroup, table }) => {
|
|
2438
2485
|
const tableRowProps = muiTableFooterRowProps instanceof Function
|
2439
2486
|
? muiTableFooterRowProps({ footerGroup, table })
|
2440
2487
|
: muiTableFooterRowProps;
|
2441
|
-
return (React.createElement(TableRow, Object.assign({}, tableRowProps, { sx: (theme) => (Object.assign({ display: layoutMode === 'grid' ? 'flex' : 'table-row' }, ((tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx) instanceof Function
|
2488
|
+
return (React.createElement(TableRow, Object.assign({}, tableRowProps, { sx: (theme) => (Object.assign({ display: layoutMode === 'grid' ? 'flex' : 'table-row', width: '100%' }, ((tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx) instanceof Function
|
2442
2489
|
? tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx(theme)
|
2443
|
-
: tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx))) }),
|
2490
|
+
: tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx))) }),
|
2491
|
+
virtualPaddingLeft ? (React.createElement("th", { style: { display: 'flex', width: virtualPaddingLeft } })) : null,
|
2492
|
+
(virtualColumns !== null && virtualColumns !== void 0 ? virtualColumns : footerGroup.headers).map((footerOrVirtualFooter) => {
|
2493
|
+
const footer = virtualColumns
|
2494
|
+
? footerGroup.headers[footerOrVirtualFooter.index]
|
2495
|
+
: footerOrVirtualFooter;
|
2496
|
+
return (React.createElement(MRT_TableFooterCell, { footer: footer, key: footer.id, table: table }));
|
2497
|
+
}),
|
2498
|
+
virtualPaddingRight ? (React.createElement("th", { style: { display: 'flex', width: virtualPaddingRight } })) : null));
|
2444
2499
|
};
|
2445
2500
|
|
2446
|
-
const MRT_TableFooter = ({ table }) => {
|
2501
|
+
const MRT_TableFooter = ({ table, virtualColumns, virtualPaddingLeft, virtualPaddingRight, }) => {
|
2447
2502
|
const { getFooterGroups, getState, options: { enableStickyFooter, layoutMode, muiTableFooterProps }, } = table;
|
2448
2503
|
const { isFullScreen } = getState();
|
2449
2504
|
const tableFooterProps = muiTableFooterProps instanceof Function
|
@@ -2456,21 +2511,74 @@ const MRT_TableFooter = ({ table }) => {
|
|
2456
2511
|
: `1px solid ${theme.palette.grey[700]}`
|
2457
2512
|
: undefined, position: stickFooter ? 'sticky' : undefined }, ((tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx) instanceof Function
|
2458
2513
|
? tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx(theme)
|
2459
|
-
: tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx))) }), getFooterGroups().map((footerGroup) => (React.createElement(MRT_TableFooterRow, { footerGroup: footerGroup, key: footerGroup.id, table: table })))));
|
2514
|
+
: tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx))) }), getFooterGroups().map((footerGroup) => (React.createElement(MRT_TableFooterRow, { footerGroup: footerGroup, key: footerGroup.id, table: table, virtualColumns: virtualColumns, virtualPaddingLeft: virtualPaddingLeft, virtualPaddingRight: virtualPaddingRight })))));
|
2460
2515
|
};
|
2461
2516
|
|
2462
2517
|
const MRT_Table = ({ table }) => {
|
2463
|
-
|
2464
|
-
const {
|
2518
|
+
var _a, _b;
|
2519
|
+
const { getState, options: { columnVirtualizerInstanceRef, columnVirtualizerProps, enableColumnResizing, enableColumnVirtualization, enablePinning, enableStickyHeader, enableTableFooter, enableTableHead, layoutMode, memoMode, muiTableProps, }, refs: { tableContainerRef }, } = table;
|
2520
|
+
const { isFullScreen, columnPinning, columnVisibility } = getState();
|
2465
2521
|
const tableProps = muiTableProps instanceof Function
|
2466
2522
|
? muiTableProps({ table })
|
2467
2523
|
: muiTableProps;
|
2468
|
-
|
2524
|
+
const vProps = columnVirtualizerProps instanceof Function
|
2525
|
+
? columnVirtualizerProps({ table })
|
2526
|
+
: columnVirtualizerProps;
|
2527
|
+
//get first 16 column widths and average them
|
2528
|
+
const averageColumnWidth = useMemo(() => {
|
2529
|
+
var _a, _b, _c, _d;
|
2530
|
+
const columnsWidths = (_d = (_c = (_b = (_a = table
|
2531
|
+
.getRowModel()
|
2532
|
+
.rows[0]) === null || _a === void 0 ? void 0 : _a.getCenterVisibleCells()) === null || _b === void 0 ? void 0 : _b.slice(0, 16)) === null || _c === void 0 ? void 0 : _c.map((cell) => cell.column.getSize() * 1.25)) !== null && _d !== void 0 ? _d : [];
|
2533
|
+
return columnsWidths.reduce((a, b) => a + b, 0) / columnsWidths.length;
|
2534
|
+
}, [table.getRowModel().rows, columnPinning, columnVisibility]);
|
2535
|
+
const pinnedColumnIndexes = useMemo(() => enableColumnVirtualization && enablePinning
|
2536
|
+
? [
|
2537
|
+
...table.getLeftFlatHeaders().map((h) => h.column.getPinnedIndex()),
|
2538
|
+
...table
|
2539
|
+
.getRightFlatHeaders()
|
2540
|
+
.map((h) => table.getVisibleFlatColumns().length -
|
2541
|
+
h.column.getPinnedIndex() -
|
2542
|
+
1),
|
2543
|
+
]
|
2544
|
+
: [], [columnPinning, enableColumnVirtualization, enablePinning]);
|
2545
|
+
const columnVirtualizer = enableColumnVirtualization
|
2546
|
+
? useVirtualizer(Object.assign({ count: table.getRowModel().rows[0].getVisibleCells().length, estimateSize: () => averageColumnWidth, getScrollElement: () => tableContainerRef.current, horizontal: true, measureElement: (element) => element === null || element === void 0 ? void 0 : element.getBoundingClientRect().width, overscan: 3, rangeExtractor: useCallback((range) => [
|
2547
|
+
...new Set([
|
2548
|
+
...pinnedColumnIndexes,
|
2549
|
+
...defaultRangeExtractor(range),
|
2550
|
+
]),
|
2551
|
+
].sort((a, b) => a - b), [pinnedColumnIndexes]) }, vProps))
|
2552
|
+
: undefined;
|
2553
|
+
if (columnVirtualizerInstanceRef && columnVirtualizer) {
|
2554
|
+
columnVirtualizerInstanceRef.current = columnVirtualizer;
|
2555
|
+
}
|
2556
|
+
const virtualColumns = columnVirtualizer
|
2557
|
+
? columnVirtualizer.getVirtualItems()
|
2558
|
+
: undefined;
|
2559
|
+
let virtualPaddingLeft;
|
2560
|
+
let virtualPaddingRight;
|
2561
|
+
if (columnVirtualizer && (virtualColumns === null || virtualColumns === void 0 ? void 0 : virtualColumns.length)) {
|
2562
|
+
virtualPaddingLeft = (virtualColumns === null || virtualColumns === void 0 ? void 0 : virtualColumns.length)
|
2563
|
+
? ((_a = virtualColumns[0]) === null || _a === void 0 ? void 0 : _a.start) || 0
|
2564
|
+
: 0;
|
2565
|
+
virtualPaddingRight = (virtualColumns === null || virtualColumns === void 0 ? void 0 : virtualColumns.length)
|
2566
|
+
? columnVirtualizer.getTotalSize() -
|
2567
|
+
(((_b = virtualColumns[virtualColumns.length - 1]) === null || _b === void 0 ? void 0 : _b.end) || 0)
|
2568
|
+
: 0;
|
2569
|
+
}
|
2570
|
+
const props = {
|
2571
|
+
table,
|
2572
|
+
virtualColumns,
|
2573
|
+
virtualPaddingLeft,
|
2574
|
+
virtualPaddingRight,
|
2575
|
+
};
|
2576
|
+
return (React.createElement(Table, Object.assign({ stickyHeader: enableStickyHeader || isFullScreen }, tableProps, { sx: (theme) => (Object.assign({ display: layoutMode === 'grid' ? 'grid' : 'table', tableLayout: layoutMode !== 'grid' && enableColumnResizing ? 'fixed' : undefined }, ((tableProps === null || tableProps === void 0 ? void 0 : tableProps.sx) instanceof Function
|
2469
2577
|
? tableProps.sx(theme)
|
2470
2578
|
: tableProps === null || tableProps === void 0 ? void 0 : tableProps.sx))) }),
|
2471
|
-
enableTableHead && React.createElement(MRT_TableHead, {
|
2472
|
-
memoMode === 'table-body' ? (React.createElement(Memo_MRT_TableBody, {
|
2473
|
-
enableTableFooter && React.createElement(MRT_TableFooter, {
|
2579
|
+
enableTableHead && React.createElement(MRT_TableHead, Object.assign({}, props)),
|
2580
|
+
memoMode === 'table-body' ? (React.createElement(Memo_MRT_TableBody, Object.assign({ columnVirtualizer: columnVirtualizer }, props))) : (React.createElement(MRT_TableBody, Object.assign({ columnVirtualizer: columnVirtualizer }, props))),
|
2581
|
+
enableTableFooter && React.createElement(MRT_TableFooter, Object.assign({}, props))));
|
2474
2582
|
};
|
2475
2583
|
|
2476
2584
|
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
@@ -2663,12 +2771,9 @@ const MRT_TableRoot = (props) => {
|
|
2663
2771
|
...Array(((_d = (_c = props.state) === null || _c === void 0 ? void 0 : _c.pagination) === null || _d === void 0 ? void 0 : _d.pageSize) ||
|
2664
2772
|
((_e = initialState === null || initialState === void 0 ? void 0 : initialState.pagination) === null || _e === void 0 ? void 0 : _e.pageSize) ||
|
2665
2773
|
10).fill(null),
|
2666
|
-
].map(() => Object.assign({}, ...getAllLeafColumnDefs(props.columns).map((col) => {
|
2667
|
-
|
2668
|
-
|
2669
|
-
[(_b = (_a = col.id) !== null && _a !== void 0 ? _a : col.accessorKey) !== null && _b !== void 0 ? _b : '']: null,
|
2670
|
-
});
|
2671
|
-
})))
|
2774
|
+
].map(() => Object.assign({}, ...getAllLeafColumnDefs(props.columns).map((col) => ({
|
2775
|
+
[getColumnId(col)]: null,
|
2776
|
+
}))))
|
2672
2777
|
: props.data;
|
2673
2778
|
}, [props.data, (_s = props.state) === null || _s === void 0 ? void 0 : _s.isLoading, (_t = props.state) === null || _t === void 0 ? void 0 : _t.showSkeletons]);
|
2674
2779
|
//@ts-ignore
|
@@ -2817,19 +2922,26 @@ const MRT_Localization_EN = {
|
|
2817
2922
|
};
|
2818
2923
|
|
2819
2924
|
const MaterialReactTable = (_a) => {
|
2820
|
-
var
|
2821
|
-
|
2925
|
+
var _b;
|
2926
|
+
var { aggregationFns, autoResetExpanded = false, columnResizeMode = 'onEnd', defaultColumn, defaultDisplayColumn, editingMode = 'modal', enableBottomToolbar = true, enableColumnActions = true, enableColumnFilters = true, enableColumnOrdering = false, enableColumnResizing = false, enableDensityToggle = true, enableExpandAll = true, enableFilters = true, enableFullScreenToggle = true, enableGlobalFilter = true, enableGlobalFilterRankedResults = true, enableGrouping = false, enableHiding = true, enableMultiRowSelection = true, enableMultiSort = true, enablePagination = true, enablePinning = false, enableRowSelection = false, enableSelectAll = true, enableSorting = true, enableStickyHeader = false, enableTableFooter = true, enableTableHead = true, enableToolbarInternalActions = true, enableTopToolbar = true, filterFns, icons, layoutMode = 'semantic', localization, manualFiltering, manualGrouping, manualPagination, manualSorting, positionActionsColumn = 'first', positionExpandColumn = 'first', positionGlobalFilter = 'right', positionPagination = 'bottom', positionToolbarAlertBanner = 'top', positionToolbarDropZone = 'top', rowNumberMode = 'original', selectAllMode = 'page', sortingFns } = _a, rest = __rest(_a, ["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", "manualFiltering", "manualGrouping", "manualPagination", "manualSorting", "positionActionsColumn", "positionExpandColumn", "positionGlobalFilter", "positionPagination", "positionToolbarAlertBanner", "positionToolbarDropZone", "rowNumberMode", "selectAllMode", "sortingFns"]);
|
2927
|
+
const _icons = useMemo(() => (Object.assign(Object.assign({}, MRT_Default_Icons), icons)), [icons]);
|
2822
2928
|
const _localization = useMemo(() => (Object.assign(Object.assign({}, MRT_Localization_EN), localization)), [localization]);
|
2823
2929
|
const _aggregationFns = useMemo(() => (Object.assign(Object.assign({}, MRT_AggregationFns), aggregationFns)), []);
|
2824
2930
|
const _filterFns = useMemo(() => (Object.assign(Object.assign({}, MRT_FilterFns), filterFns)), []);
|
2825
2931
|
const _sortingFns = useMemo(() => (Object.assign(Object.assign({}, MRT_SortingFns), sortingFns)), []);
|
2826
|
-
const _defaultColumn = useMemo(() => (Object.assign(Object.assign({}, MRT_DefaultColumn), defaultColumn)), []);
|
2827
|
-
const _defaultDisplayColumn = useMemo(() => (Object.assign(Object.assign({}, MRT_DefaultDisplayColumn), defaultDisplayColumn)), []);
|
2828
|
-
if (rest.enableRowVirtualization) {
|
2932
|
+
const _defaultColumn = useMemo(() => (Object.assign(Object.assign({}, MRT_DefaultColumn), defaultColumn)), [defaultColumn]);
|
2933
|
+
const _defaultDisplayColumn = useMemo(() => (Object.assign(Object.assign({}, MRT_DefaultDisplayColumn), defaultDisplayColumn)), [defaultDisplayColumn]);
|
2934
|
+
if (rest.enableRowVirtualization || rest.enableColumnVirtualization) {
|
2829
2935
|
layoutMode = 'grid';
|
2830
2936
|
enableStickyHeader = true;
|
2831
2937
|
}
|
2832
|
-
|
2938
|
+
if (!((_b = rest.data) === null || _b === void 0 ? void 0 : _b.length)) {
|
2939
|
+
manualFiltering = true;
|
2940
|
+
manualGrouping = true;
|
2941
|
+
manualPagination = true;
|
2942
|
+
manualSorting = true;
|
2943
|
+
}
|
2944
|
+
return (React.createElement(MRT_TableRoot, Object.assign({ aggregationFns: _aggregationFns, autoResetExpanded: autoResetExpanded, columnResizeMode: columnResizeMode, defaultColumn: _defaultColumn, defaultDisplayColumn: _defaultDisplayColumn, editingMode: editingMode, enableBottomToolbar: enableBottomToolbar, enableColumnActions: enableColumnActions, enableColumnFilters: enableColumnFilters, enableColumnOrdering: enableColumnOrdering, enableColumnResizing: enableColumnResizing, enableDensityToggle: enableDensityToggle, enableExpandAll: enableExpandAll, enableFilters: enableFilters, enableFullScreenToggle: enableFullScreenToggle, enableGlobalFilter: enableGlobalFilter, enableGlobalFilterRankedResults: enableGlobalFilterRankedResults, enableGrouping: enableGrouping, enableHiding: enableHiding, enableMultiRowSelection: enableMultiRowSelection, enableMultiSort: enableMultiSort, enablePagination: enablePagination, enablePinning: enablePinning, enableRowSelection: enableRowSelection, enableSelectAll: enableSelectAll, enableSorting: enableSorting, enableStickyHeader: enableStickyHeader, enableTableFooter: enableTableFooter, enableTableHead: enableTableHead, enableToolbarInternalActions: enableToolbarInternalActions, enableTopToolbar: enableTopToolbar, filterFns: _filterFns, icons: _icons, layoutMode: layoutMode, localization: _localization, manualFiltering: manualFiltering, manualGrouping: manualGrouping, manualPagination: manualPagination, manualSorting: manualSorting, positionActionsColumn: positionActionsColumn, positionExpandColumn: positionExpandColumn, positionGlobalFilter: positionGlobalFilter, positionPagination: positionPagination, positionToolbarAlertBanner: positionToolbarAlertBanner, positionToolbarDropZone: positionToolbarDropZone, rowNumberMode: rowNumberMode, selectAllMode: selectAllMode, sortingFns: _sortingFns }, rest)));
|
2833
2945
|
};
|
2834
2946
|
|
2835
2947
|
export { MRT_CopyButton, MRT_FilterOptionMenu, MRT_FullScreenToggleButton, MRT_GlobalFilterTextField, MRT_ShowHideColumnsButton, MRT_TablePagination, MRT_ToggleDensePaddingButton, MRT_ToggleFiltersButton, MRT_ToggleGlobalFilterButton, MRT_ToolbarAlertBanner, MRT_ToolbarDropZone, MRT_ToolbarInternalButtons, MaterialReactTable as default };
|