material-react-table 1.9.4 → 1.10.0
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 +42 -31
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/MaterialReactTable.d.ts +4 -0
- package/dist/cjs/types/body/MRT_TableDetailPanel.d.ts +2 -1
- package/dist/cjs/types/column.utils.d.ts +1 -1
- package/dist/esm/material-react-table.esm.js +42 -31
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/MaterialReactTable.d.ts +4 -0
- package/dist/esm/types/body/MRT_TableDetailPanel.d.ts +2 -1
- package/dist/esm/types/column.utils.d.ts +1 -1
- package/dist/index.d.ts +4 -0
- package/package.json +5 -3
- package/src/MaterialReactTable.tsx +4 -0
- package/src/body/MRT_TableBody.tsx +22 -17
- package/src/body/MRT_TableBodyRow.tsx +2 -1
- package/src/body/MRT_TableDetailPanel.tsx +3 -1
- package/src/column.utils.ts +95 -83
- package/src/toolbar/MRT_ToolbarDropZone.tsx +1 -0
@@ -567,6 +567,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> = Pr
|
|
567
567
|
muiTableBodyRowProps?: TableRowProps | ((props: {
|
568
568
|
isDetailPanel?: boolean;
|
569
569
|
row: MRT_Row<TData>;
|
570
|
+
staticRowIndex: number;
|
570
571
|
table: MRT_TableInstance<TData>;
|
571
572
|
}) => TableRowProps);
|
572
573
|
muiTableContainerProps?: TableContainerProps | ((props: {
|
@@ -691,6 +692,9 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> = Pr
|
|
691
692
|
onSelectFilterMode: (filterMode: MRT_FilterOption) => void;
|
692
693
|
table: MRT_TableInstance<TData>;
|
693
694
|
}) => ReactNode[];
|
695
|
+
renderEmptyRowsFallback?: (props: {
|
696
|
+
table: MRT_TableInstance<TData>;
|
697
|
+
}) => ReactNode;
|
694
698
|
renderRowActionMenuItems?: (props: {
|
695
699
|
closeMenu: () => void;
|
696
700
|
row: MRT_Row<TData>;
|
@@ -4,8 +4,9 @@ import type { MRT_Row, MRT_TableInstance } from '..';
|
|
4
4
|
interface Props {
|
5
5
|
parentRowRef: React.RefObject<HTMLTableRowElement>;
|
6
6
|
row: MRT_Row;
|
7
|
+
rowIndex: number;
|
7
8
|
table: MRT_TableInstance;
|
8
9
|
virtualRow?: VirtualItem;
|
9
10
|
}
|
10
|
-
export declare const MRT_TableDetailPanel: ({ parentRowRef, row, table, virtualRow, }: Props) => JSX.Element;
|
11
|
+
export declare const MRT_TableDetailPanel: ({ parentRowRef, row, rowIndex, table, virtualRow, }: Props) => JSX.Element;
|
11
12
|
export {};
|
@@ -103,7 +103,7 @@ export declare const prepareColumns: <TData extends Record<string, any> = {}>({
|
|
103
103
|
export declare const reorderColumn: <TData extends Record<string, any> = {}>(draggedColumn: MRT_Column<TData>, targetColumn: MRT_Column<TData>, columnOrder: MRT_ColumnOrderState) => MRT_ColumnOrderState;
|
104
104
|
export declare const showExpandColumn: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>, grouping?: MRT_GroupingState) => boolean;
|
105
105
|
export declare const getLeadingDisplayColumnIds: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>) => MRT_DisplayColumnIds[];
|
106
|
-
export declare const getTrailingDisplayColumnIds: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>) =>
|
106
|
+
export declare const getTrailingDisplayColumnIds: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>) => MRT_DisplayColumnIds[];
|
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
109
|
export declare const getIsFirstColumn: (column: MRT_Column, table: MRT_TableInstance) => boolean;
|
@@ -200,13 +200,17 @@ const getTrailingDisplayColumnIds = (props) => {
|
|
200
200
|
props.positionExpandColumn === 'last' &&
|
201
201
|
showExpandColumn(props) &&
|
202
202
|
'mrt-row-expand',
|
203
|
-
];
|
203
|
+
].filter(Boolean);
|
204
|
+
};
|
205
|
+
const getDefaultColumnOrderIds = (props) => {
|
206
|
+
const leadingDisplayCols = getLeadingDisplayColumnIds(props);
|
207
|
+
const trailingDisplayCols = getTrailingDisplayColumnIds(props);
|
208
|
+
const allLeafColumnDefs = getAllLeafColumnDefs(props.columns)
|
209
|
+
.map((columnDef) => getColumnId(columnDef))
|
210
|
+
.filter((columnId) => !leadingDisplayCols.includes(columnId) &&
|
211
|
+
!trailingDisplayCols.includes(columnId));
|
212
|
+
return [...leadingDisplayCols, ...allLeafColumnDefs, ...trailingDisplayCols];
|
204
213
|
};
|
205
|
-
const getDefaultColumnOrderIds = (props) => [
|
206
|
-
...getLeadingDisplayColumnIds(props),
|
207
|
-
...getAllLeafColumnDefs(props.columns).map((columnDef) => getColumnId(columnDef)),
|
208
|
-
...getTrailingDisplayColumnIds(props),
|
209
|
-
].filter(Boolean);
|
210
214
|
const getDefaultColumnFilterFn = (columnDef) => {
|
211
215
|
if (columnDef.filterVariant === 'multi-select')
|
212
216
|
return 'arrIncludesSome';
|
@@ -236,28 +240,33 @@ const getTotalRight = (table, column) => {
|
|
236
240
|
};
|
237
241
|
const getCommonCellStyles = ({ column, header, table, tableCellProps, theme, }) => {
|
238
242
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
239
|
-
|
243
|
+
const widthStyles = {
|
244
|
+
minWidth: `max(calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId((_a = header === null || header === void 0 ? void 0 : header.id) !== null && _a !== void 0 ? _a : column.id)}-size) * 1px), ${(_b = column.columnDef.minSize) !== null && _b !== void 0 ? _b : 30}px)`,
|
245
|
+
width: `calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId((_c = header === null || header === void 0 ? void 0 : header.id) !== null && _c !== void 0 ? _c : column.id)}-size) * 1px)`,
|
246
|
+
};
|
247
|
+
return Object.assign(Object.assign(Object.assign({ backgroundColor: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
|
240
248
|
? alpha(lighten(theme.palette.background.default, 0.04), 0.97)
|
241
249
|
: 'inherit', backgroundImage: 'inherit', boxShadow: getIsLastLeftPinnedColumn(table, column)
|
242
250
|
? `-4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
|
243
251
|
: getIsFirstRightPinnedColumn(column)
|
244
252
|
? `4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
|
245
253
|
: undefined, display: table.options.layoutMode === 'grid' ? 'flex' : 'table-cell', flex: table.options.layoutMode === 'grid'
|
246
|
-
? `var(--${header ? 'header' : 'col'}-${parseCSSVarId((
|
254
|
+
? `var(--${header ? 'header' : 'col'}-${parseCSSVarId((_d = header === null || header === void 0 ? void 0 : header.id) !== null && _d !== void 0 ? _d : column.id)}-size) 0 auto`
|
247
255
|
: undefined, left: column.getIsPinned() === 'left'
|
248
256
|
? `${column.getStart('left')}px`
|
249
257
|
: undefined, ml: table.options.enableColumnVirtualization &&
|
250
258
|
column.getIsPinned() === 'left' &&
|
251
259
|
column.getPinnedIndex() === 0
|
252
|
-
? `-${column.getSize() *
|
260
|
+
? `-${column.getSize() *
|
261
|
+
((_f = (_e = table.getState().columnPinning.left) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 1)}px`
|
253
262
|
: undefined, mr: table.options.enableColumnVirtualization &&
|
254
263
|
column.getIsPinned() === 'right' &&
|
255
264
|
column.getPinnedIndex() === table.getVisibleLeafColumns().length - 1
|
256
265
|
? `-${column.getSize() *
|
257
|
-
((
|
266
|
+
((_h = (_g = table.getState().columnPinning.right) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 1) *
|
258
267
|
1.2}px`
|
259
|
-
: undefined, opacity: ((
|
260
|
-
((
|
268
|
+
: undefined, opacity: ((_j = table.getState().draggingColumn) === null || _j === void 0 ? void 0 : _j.id) === column.id ||
|
269
|
+
((_k = table.getState().hoveredColumn) === null || _k === void 0 ? void 0 : _k.id) === column.id
|
261
270
|
? 0.5
|
262
271
|
: 1, position: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
|
263
272
|
? 'sticky'
|
@@ -265,9 +274,9 @@ const getCommonCellStyles = ({ column, header, table, tableCellProps, theme, })
|
|
265
274
|
? `${getTotalRight(table, column)}px`
|
266
275
|
: undefined, transition: table.options.enableColumnVirtualization
|
267
276
|
? 'none'
|
268
|
-
: `padding 150ms ease-in-out` }, ((tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx) instanceof Function
|
277
|
+
: `padding 150ms ease-in-out` }, (!table.options.enableColumnResizing && widthStyles)), ((tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx) instanceof Function
|
269
278
|
? tableCellProps.sx(theme)
|
270
|
-
: tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx)),
|
279
|
+
: tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx)), (table.options.enableColumnResizing && widthStyles));
|
271
280
|
};
|
272
281
|
const MRT_DefaultColumn = {
|
273
282
|
filterVariant: 'text',
|
@@ -1370,6 +1379,7 @@ const MRT_ToolbarDropZone = ({ table, }) => {
|
|
1370
1379
|
if (((_a = table.options.state) === null || _a === void 0 ? void 0 : _a.showToolbarDropZone) !== undefined) {
|
1371
1380
|
setShowToolbarDropZone(!!enableGrouping &&
|
1372
1381
|
!!draggingColumn &&
|
1382
|
+
draggingColumn.columnDef.enableGrouping !== false &&
|
1373
1383
|
!grouping.includes(draggingColumn.id));
|
1374
1384
|
}
|
1375
1385
|
}, [enableGrouping, draggingColumn, grouping]);
|
@@ -2436,11 +2446,11 @@ const MRT_TableBodyCell = ({ cell, measureElement, numRows, rowIndex, rowRef, ta
|
|
2436
2446
|
};
|
2437
2447
|
const Memo_MRT_TableBodyCell = memo(MRT_TableBodyCell, (prev, next) => next.cell === prev.cell);
|
2438
2448
|
|
2439
|
-
const MRT_TableDetailPanel = ({ parentRowRef, row, table, virtualRow, }) => {
|
2449
|
+
const MRT_TableDetailPanel = ({ parentRowRef, row, rowIndex, table, virtualRow, }) => {
|
2440
2450
|
const { getVisibleLeafColumns, getState, options: { layoutMode, muiTableBodyRowProps, muiTableDetailPanelProps, renderDetailPanel, }, } = table;
|
2441
2451
|
const { isLoading } = getState();
|
2442
2452
|
const tableRowProps = muiTableBodyRowProps instanceof Function
|
2443
|
-
? muiTableBodyRowProps({ isDetailPanel: true, row, table })
|
2453
|
+
? muiTableBodyRowProps({ isDetailPanel: true, row, staticRowIndex: rowIndex, table })
|
2444
2454
|
: muiTableBodyRowProps;
|
2445
2455
|
const tableCellProps = muiTableDetailPanelProps instanceof Function
|
2446
2456
|
? muiTableDetailPanelProps({ row, table })
|
@@ -2466,7 +2476,7 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, row, row
|
|
2466
2476
|
const { getState, options: { enableRowOrdering, layoutMode, memoMode, muiTableBodyRowProps, renderDetailPanel, }, setHoveredRow, } = table;
|
2467
2477
|
const { draggingColumn, draggingRow, editingCell, editingRow, hoveredRow } = getState();
|
2468
2478
|
const tableRowProps = muiTableBodyRowProps instanceof Function
|
2469
|
-
? muiTableBodyRowProps({ row, table })
|
2479
|
+
? muiTableBodyRowProps({ row, staticRowIndex: rowIndex, table })
|
2470
2480
|
: muiTableBodyRowProps;
|
2471
2481
|
const handleDragEnter = (_e) => {
|
2472
2482
|
if (enableRowOrdering && draggingRow) {
|
@@ -2518,13 +2528,13 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, row, row
|
|
2518
2528
|
(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)));
|
2519
2529
|
}),
|
2520
2530
|
virtualPaddingRight ? (React.createElement("td", { style: { display: 'flex', width: virtualPaddingRight } })) : null),
|
2521
|
-
renderDetailPanel && !row.getIsGrouped() && (React.createElement(MRT_TableDetailPanel, { parentRowRef: rowRef, row: row, table: table, virtualRow: virtualRow }))));
|
2531
|
+
renderDetailPanel && !row.getIsGrouped() && (React.createElement(MRT_TableDetailPanel, { parentRowRef: rowRef, row: row, rowIndex: rowIndex, table: table, virtualRow: virtualRow }))));
|
2522
2532
|
};
|
2523
2533
|
const Memo_MRT_TableBodyRow = memo(MRT_TableBodyRow, (prev, next) => prev.row === next.row && prev.rowIndex === next.rowIndex);
|
2524
2534
|
|
2525
2535
|
const MRT_TableBody = ({ columnVirtualizer, table, virtualColumns, virtualPaddingLeft, virtualPaddingRight, }) => {
|
2526
|
-
var _a, _b, _c;
|
2527
|
-
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;
|
2536
|
+
var _a, _b, _c, _d;
|
2537
|
+
const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, layoutMode, localization, manualExpanding, manualFiltering, manualGrouping, manualPagination, manualSorting, memoMode, muiTableBodyProps, renderEmptyRowsFallback, rowVirtualizerInstanceRef, rowVirtualizerProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef, tablePaperRef }, } = table;
|
2528
2538
|
const { columnFilters, density, expanded, globalFilter, globalFilterFn, pagination, sorting, } = getState();
|
2529
2539
|
const tableBodyProps = muiTableBodyProps instanceof Function
|
2530
2540
|
? muiTableBodyProps({ table })
|
@@ -2587,17 +2597,18 @@ const MRT_TableBody = ({ columnVirtualizer, table, virtualColumns, virtualPaddin
|
|
2587
2597
|
: 'inherit', minHeight: !rows.length ? '100px' : undefined, position: 'relative' }, ((tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx) instanceof Function
|
2588
2598
|
? tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx(theme)
|
2589
2599
|
: 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' } },
|
2590
|
-
React.createElement("td", { colSpan: table.getVisibleLeafColumns().length, style: {
|
2591
|
-
|
2592
|
-
|
2593
|
-
|
2594
|
-
|
2595
|
-
|
2596
|
-
|
2597
|
-
|
2598
|
-
|
2599
|
-
|
2600
|
-
|
2600
|
+
React.createElement("td", { colSpan: table.getVisibleLeafColumns().length, style: {
|
2601
|
+
display: layoutMode === 'grid' ? 'grid' : 'table-cell',
|
2602
|
+
} }, (_b = renderEmptyRowsFallback === null || renderEmptyRowsFallback === void 0 ? void 0 : renderEmptyRowsFallback({ table })) !== null && _b !== void 0 ? _b : (React.createElement(Typography, { sx: {
|
2603
|
+
color: 'text.secondary',
|
2604
|
+
fontStyle: 'italic',
|
2605
|
+
maxWidth: `min(100vw, ${(_d = (_c = tablePaperRef.current) === null || _c === void 0 ? void 0 : _c.clientWidth) !== null && _d !== void 0 ? _d : 360}px)`,
|
2606
|
+
py: '2rem',
|
2607
|
+
textAlign: 'center',
|
2608
|
+
width: '100%',
|
2609
|
+
} }, globalFilter || columnFilters.length
|
2610
|
+
? localization.noResultsFound
|
2611
|
+
: localization.noRecordsToDisplay))))) : (React.createElement(React.Fragment, null, (virtualRows !== null && virtualRows !== void 0 ? virtualRows : rows).map((rowOrVirtualRow, rowIndex) => {
|
2601
2612
|
const row = rowVirtualizer
|
2602
2613
|
? rows[rowOrVirtualRow.index]
|
2603
2614
|
: rowOrVirtualRow;
|