material-react-table 1.6.2 → 1.6.4
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 +72 -45
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/column.utils.d.ts +2 -0
- package/dist/esm/material-react-table.esm.js +72 -45
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/column.utils.d.ts +2 -0
- package/package.json +1 -1
- package/src/body/MRT_TableBody.tsx +44 -22
- package/src/body/MRT_TableBodyCell.tsx +44 -21
- package/src/body/MRT_TableBodyRow.tsx +2 -20
- package/src/column.utils.ts +15 -0
@@ -106,6 +106,8 @@ export declare const getLeadingDisplayColumnIds: <TData extends Record<string, a
|
|
106
106
|
export declare const getTrailingDisplayColumnIds: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>) => (string | false | undefined)[];
|
107
107
|
export declare const getDefaultColumnOrderIds: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>) => string[];
|
108
108
|
export declare const getDefaultColumnFilterFn: <TData extends Record<string, any> = {}>(columnDef: MRT_ColumnDef<TData>) => MRT_FilterOption;
|
109
|
+
export declare const getIsFirstColumn: (column: MRT_Column, table: MRT_TableInstance) => boolean;
|
110
|
+
export declare const getIsLastColumn: (column: MRT_Column, table: MRT_TableInstance) => boolean;
|
109
111
|
export declare const getIsLastLeftPinnedColumn: (table: MRT_TableInstance, column: MRT_Column) => boolean;
|
110
112
|
export declare const getIsFirstRightPinnedColumn: (column: MRT_Column) => boolean;
|
111
113
|
export declare const getTotalRight: (table: MRT_TableInstance, column: MRT_Column) => number;
|
@@ -217,6 +217,13 @@ const getDefaultColumnFilterFn = (columnDef) => {
|
|
217
217
|
return 'equals';
|
218
218
|
return 'fuzzy';
|
219
219
|
};
|
220
|
+
const getIsFirstColumn = (column, table) => {
|
221
|
+
return table.getVisibleLeafColumns()[0].id === column.id;
|
222
|
+
};
|
223
|
+
const getIsLastColumn = (column, table) => {
|
224
|
+
const columns = table.getVisibleLeafColumns();
|
225
|
+
return columns[columns.length - 1].id === column.id;
|
226
|
+
};
|
220
227
|
const getIsLastLeftPinnedColumn = (table, column) => {
|
221
228
|
return (column.getIsPinned() === 'left' &&
|
222
229
|
table.getLeftLeafHeaders().length - 1 === column.getPinnedIndex());
|
@@ -2203,7 +2210,7 @@ const MRT_TableBodyCell = ({ cell, enableHover, measureElement, numRows, rowInde
|
|
2203
2210
|
var _a, _b;
|
2204
2211
|
const theme = useTheme();
|
2205
2212
|
const { getState, options: { editingMode, enableClickToCopy, enableColumnOrdering, enableEditing, enableGrouping, enableRowNumbers, layoutMode, muiTableBodyCellProps, muiTableBodyCellSkeletonProps, rowNumberMode, }, refs: { editInputRefs }, setEditingCell, setHoveredColumn, } = table;
|
2206
|
-
const { draggingColumn, editingCell, editingRow, hoveredColumn, density, isLoading, showSkeletons, } = getState();
|
2213
|
+
const { draggingColumn, draggingRow, editingCell, editingRow, hoveredColumn, hoveredRow, density, isLoading, showSkeletons, } = getState();
|
2207
2214
|
const { column, row } = cell;
|
2208
2215
|
const { columnDef } = column;
|
2209
2216
|
const { columnDefType } = columnDef;
|
@@ -2224,18 +2231,38 @@ const MRT_TableBodyCell = ({ cell, enableHover, measureElement, numRows, rowInde
|
|
2224
2231
|
: Math.round(Math.random() * (column.getSize() - column.getSize() / 3) +
|
2225
2232
|
column.getSize() / 3)
|
2226
2233
|
: 100), []);
|
2227
|
-
const
|
2228
|
-
?
|
2229
|
-
|
2230
|
-
|
2231
|
-
|
2232
|
-
|
2233
|
-
|
2234
|
-
|
2235
|
-
|
2236
|
-
|
2237
|
-
|
2238
|
-
|
2234
|
+
const draggingBorders = useMemo(() => {
|
2235
|
+
const isDraggingColumn = (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id;
|
2236
|
+
const isHoveredColumn = (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id;
|
2237
|
+
const isDraggingRow = (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id;
|
2238
|
+
const isHoveredRow = (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id;
|
2239
|
+
const isFirstColumn = getIsFirstColumn(column, table);
|
2240
|
+
const isLastColumn = getIsLastColumn(column, table);
|
2241
|
+
const isLastRow = rowIndex === numRows - 1;
|
2242
|
+
const borderStyle = isDraggingColumn || isDraggingRow
|
2243
|
+
? `1px dashed ${theme.palette.text.secondary} !important`
|
2244
|
+
: isHoveredColumn || isHoveredRow
|
2245
|
+
? `2px dashed ${theme.palette.primary.main} !important`
|
2246
|
+
: undefined;
|
2247
|
+
return borderStyle
|
2248
|
+
? {
|
2249
|
+
borderLeft: isDraggingColumn ||
|
2250
|
+
isHoveredColumn ||
|
2251
|
+
((isDraggingRow || isHoveredRow) && isFirstColumn)
|
2252
|
+
? borderStyle
|
2253
|
+
: undefined,
|
2254
|
+
borderRight: isDraggingColumn ||
|
2255
|
+
isHoveredColumn ||
|
2256
|
+
((isDraggingRow || isHoveredRow) && isLastColumn)
|
2257
|
+
? borderStyle
|
2258
|
+
: undefined,
|
2259
|
+
borderBottom: isDraggingRow || isHoveredRow || isLastRow
|
2260
|
+
? borderStyle
|
2261
|
+
: undefined,
|
2262
|
+
borderTop: isDraggingRow || isHoveredRow ? borderStyle : undefined,
|
2263
|
+
}
|
2264
|
+
: undefined;
|
2265
|
+
}, [draggingColumn, draggingRow, hoveredColumn, hoveredRow, rowIndex]);
|
2239
2266
|
const isEditable = (enableEditing || columnDef.enableEditing) &&
|
2240
2267
|
columnDef.enableEditing !== false;
|
2241
2268
|
const isEditing = isEditable &&
|
@@ -2355,7 +2382,6 @@ const MRT_TableDetailPanel = ({ parentRowRef, row, table, virtualRow, }) => {
|
|
2355
2382
|
};
|
2356
2383
|
|
2357
2384
|
const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, row, rowIndex, table, virtualColumns, virtualPaddingLeft, virtualPaddingRight, virtualRow, }) => {
|
2358
|
-
const theme = useTheme();
|
2359
2385
|
const { getIsSomeColumnsPinned, getState, options: { enableRowOrdering, layoutMode, memoMode, muiTableBodyRowProps, renderDetailPanel, }, setHoveredRow, } = table;
|
2360
2386
|
const { draggingColumn, draggingRow, editingCell, editingRow, hoveredRow } = getState();
|
2361
2387
|
const tableRowProps = muiTableBodyRowProps instanceof Function
|
@@ -2367,23 +2393,13 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, row, row
|
|
2367
2393
|
}
|
2368
2394
|
};
|
2369
2395
|
const rowRef = useRef(null);
|
2370
|
-
const draggingBorder = useMemo(() => (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id
|
2371
|
-
? `1px dashed ${theme.palette.text.secondary}`
|
2372
|
-
: (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id
|
2373
|
-
? `2px dashed ${theme.palette.primary.main}`
|
2374
|
-
: undefined, [draggingRow, hoveredRow]);
|
2375
|
-
const draggingBorders = draggingBorder
|
2376
|
-
? {
|
2377
|
-
border: draggingBorder,
|
2378
|
-
}
|
2379
|
-
: undefined;
|
2380
2396
|
return (React.createElement(React.Fragment, null,
|
2381
2397
|
React.createElement(TableRow, Object.assign({ "data-index": virtualRow === null || virtualRow === void 0 ? void 0 : virtualRow.index, hover: true, onDragEnter: handleDragEnter, selected: row.getIsSelected(), ref: (node) => {
|
2382
2398
|
if (node) {
|
2383
2399
|
rowRef.current = node;
|
2384
2400
|
measureElement === null || measureElement === void 0 ? void 0 : measureElement(node);
|
2385
2401
|
}
|
2386
|
-
} }, tableRowProps, { sx: (theme) => (Object.assign(
|
2402
|
+
} }, tableRowProps, { sx: (theme) => (Object.assign({ backgroundColor: lighten(theme.palette.background.default, 0.06), display: layoutMode === 'grid' ? 'flex' : 'table-row', opacity: (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id || (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id ? 0.5 : 1, position: virtualRow ? 'absolute' : undefined, top: virtualRow ? 0 : undefined, transform: virtualRow
|
2387
2403
|
? `translateY(${virtualRow === null || virtualRow === void 0 ? void 0 : virtualRow.start}px)`
|
2388
2404
|
: undefined, transition: virtualRow ? 'none' : 'all 150ms ease-in-out', width: '100%', '&:hover td': {
|
2389
2405
|
backgroundColor: (tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.hover) !== false && getIsSomeColumnsPinned()
|
@@ -2393,7 +2409,7 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, row, row
|
|
2393
2409
|
: undefined,
|
2394
2410
|
} }, ((tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx) instanceof Function
|
2395
2411
|
? tableRowProps.sx(theme)
|
2396
|
-
: tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx))
|
2412
|
+
: tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx))) }),
|
2397
2413
|
virtualPaddingLeft ? (React.createElement("td", { style: { display: 'flex', width: virtualPaddingLeft } })) : null,
|
2398
2414
|
(virtualColumns !== null && virtualColumns !== void 0 ? virtualColumns : row.getVisibleCells()).map((cellOrVirtualCell) => {
|
2399
2415
|
const cell = columnVirtualizer
|
@@ -2426,8 +2442,8 @@ const Memo_MRT_TableBodyRow = memo(MRT_TableBodyRow, (prev, next) => prev.row ==
|
|
2426
2442
|
|
2427
2443
|
const MRT_TableBody = ({ columnVirtualizer, table, virtualColumns, virtualPaddingLeft, virtualPaddingRight, }) => {
|
2428
2444
|
var _a, _b, _c;
|
2429
|
-
const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, layoutMode, localization, manualFiltering, manualPagination, manualSorting, memoMode, muiTableBodyProps, rowVirtualizerInstanceRef, rowVirtualizerProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef, tablePaperRef }, } = table;
|
2430
|
-
const { columnFilters, density, globalFilter, pagination, sorting } = getState();
|
2445
|
+
const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, layoutMode, localization, manualExpanding, manualFiltering, manualGrouping, manualPagination, manualSorting, memoMode, muiTableBodyProps, rowVirtualizerInstanceRef, rowVirtualizerProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef, tablePaperRef }, } = table;
|
2446
|
+
const { columnFilters, density, expanded, globalFilter, globalFilterFn, pagination, sorting, } = getState();
|
2431
2447
|
const tableBodyProps = muiTableBodyProps instanceof Function
|
2432
2448
|
? muiTableBodyProps({ table })
|
2433
2449
|
: muiTableBodyProps;
|
@@ -2437,26 +2453,37 @@ const MRT_TableBody = ({ columnVirtualizer, table, virtualColumns, virtualPaddin
|
|
2437
2453
|
const vProps = rowVirtualizerProps instanceof Function
|
2438
2454
|
? rowVirtualizerProps({ table })
|
2439
2455
|
: rowVirtualizerProps;
|
2456
|
+
const shouldRankResults = useMemo(() => !manualExpanding &&
|
2457
|
+
!manualFiltering &&
|
2458
|
+
!manualGrouping &&
|
2459
|
+
!manualSorting &&
|
2460
|
+
enableGlobalFilterRankedResults &&
|
2461
|
+
globalFilter &&
|
2462
|
+
globalFilterFn === 'fuzzy' &&
|
2463
|
+
expanded !== true &&
|
2464
|
+
!Object.values(sorting).some(Boolean) &&
|
2465
|
+
!Object.values(expanded).some(Boolean), [
|
2466
|
+
enableGlobalFilterRankedResults,
|
2467
|
+
expanded,
|
2468
|
+
globalFilter,
|
2469
|
+
manualExpanding,
|
2470
|
+
manualFiltering,
|
2471
|
+
manualGrouping,
|
2472
|
+
manualSorting,
|
2473
|
+
sorting,
|
2474
|
+
]);
|
2440
2475
|
const rows = useMemo(() => {
|
2441
|
-
if (
|
2442
|
-
|
2443
|
-
|
2444
|
-
|
2445
|
-
|
2446
|
-
|
2447
|
-
if (enablePagination && !manualPagination) {
|
2448
|
-
const start = pagination.pageIndex * pagination.pageSize;
|
2449
|
-
return rankedRows.slice(start, start + pagination.pageSize);
|
2450
|
-
}
|
2451
|
-
return rankedRows;
|
2476
|
+
if (!shouldRankResults)
|
2477
|
+
return getRowModel().rows;
|
2478
|
+
const rankedRows = getPrePaginationRowModel().rows.sort((a, b) => rankGlobalFuzzy(a, b));
|
2479
|
+
if (enablePagination && !manualPagination) {
|
2480
|
+
const start = pagination.pageIndex * pagination.pageSize;
|
2481
|
+
return rankedRows.slice(start, start + pagination.pageSize);
|
2452
2482
|
}
|
2453
|
-
return
|
2483
|
+
return rankedRows;
|
2454
2484
|
}, [
|
2455
|
-
|
2456
|
-
|
2457
|
-
? getPrePaginationRowModel().rows
|
2458
|
-
: getRowModel().rows,
|
2459
|
-
globalFilter,
|
2485
|
+
shouldRankResults,
|
2486
|
+
shouldRankResults ? getPrePaginationRowModel().rows : getRowModel().rows,
|
2460
2487
|
pagination.pageIndex,
|
2461
2488
|
pagination.pageSize,
|
2462
2489
|
]);
|