material-react-table 0.37.0 → 0.37.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/README.md +6 -3
- package/dist/cjs/column.utils.d.ts +2 -1
- package/dist/cjs/index.js +22 -18
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/column.utils.d.ts +2 -1
- package/dist/esm/material-react-table.esm.js +22 -18
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/package.json +4 -4
- package/src/column.utils.ts +13 -7
- package/src/table/MRT_TableRoot.tsx +24 -14
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ColumnOrderState } from '@tanstack/react-table';
|
|
1
|
+
import { ColumnOrderState, GroupingState } from '@tanstack/react-table';
|
|
2
2
|
import { MaterialReactTableProps, MRT_Column, MRT_ColumnDef, MRT_DefinedColumnDef, MRT_DisplayColumnIds, MRT_FilterOption } from '.';
|
|
3
3
|
import { MRT_FilterFns } from './filterFns';
|
|
4
4
|
import { MRT_SortingFns } from './sortingFns';
|
|
@@ -81,6 +81,7 @@ export declare const prepareColumns: <TData extends Record<string, any> = {}>(co
|
|
|
81
81
|
basic: import("@tanstack/table-core").SortingFn<any>;
|
|
82
82
|
} & Record<string, import("@tanstack/table-core").SortingFn<any>>) => MRT_DefinedColumnDef<TData>[];
|
|
83
83
|
export declare const reorderColumn: <TData extends Record<string, any> = {}>(draggedColumn: MRT_Column<TData>, targetColumn: MRT_Column<TData>, columnOrder: ColumnOrderState) => ColumnOrderState;
|
|
84
|
+
export declare const showExpandColumn: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>, grouping?: GroupingState) => boolean;
|
|
84
85
|
export declare const getLeadingDisplayColumnIds: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>) => MRT_DisplayColumnIds[];
|
|
85
86
|
export declare const getTrailingDisplayColumnIds: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>) => (string | false | undefined)[];
|
|
86
87
|
export declare const getDefaultColumnOrderIds: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>) => string[];
|
|
@@ -521,6 +521,9 @@ const reorderColumn = (draggedColumn, targetColumn, columnOrder) => {
|
|
|
521
521
|
columnOrder.splice(columnOrder.indexOf(targetColumn.id), 0, columnOrder.splice(columnOrder.indexOf(draggedColumn.id), 1)[0]);
|
|
522
522
|
return [...columnOrder];
|
|
523
523
|
};
|
|
524
|
+
const showExpandColumn = (props, grouping) => !!(props.enableExpanding ||
|
|
525
|
+
(props.enableGrouping && (grouping === undefined || (grouping === null || grouping === void 0 ? void 0 : grouping.length))) ||
|
|
526
|
+
props.renderDetailPanel);
|
|
524
527
|
const getLeadingDisplayColumnIds = (props) => {
|
|
525
528
|
var _a;
|
|
526
529
|
return [
|
|
@@ -530,9 +533,7 @@ const getLeadingDisplayColumnIds = (props) => {
|
|
|
530
533
|
['row', 'modal'].includes((_a = props.editingMode) !== null && _a !== void 0 ? _a : ''))) &&
|
|
531
534
|
'mrt-row-actions',
|
|
532
535
|
props.positionExpandColumn === 'first' &&
|
|
533
|
-
(props
|
|
534
|
-
props.enableGrouping ||
|
|
535
|
-
props.renderDetailPanel) &&
|
|
536
|
+
showExpandColumn(props) &&
|
|
536
537
|
'mrt-row-expand',
|
|
537
538
|
props.enableRowSelection && 'mrt-row-select',
|
|
538
539
|
props.enableRowNumbers && 'mrt-row-numbers',
|
|
@@ -546,9 +547,7 @@ const getTrailingDisplayColumnIds = (props) => {
|
|
|
546
547
|
['row', 'modal'].includes((_a = props.editingMode) !== null && _a !== void 0 ? _a : ''))) &&
|
|
547
548
|
'mrt-row-actions',
|
|
548
549
|
props.positionExpandColumn === 'last' &&
|
|
549
|
-
(props
|
|
550
|
-
props.enableGrouping ||
|
|
551
|
-
props.renderDetailPanel) &&
|
|
550
|
+
showExpandColumn(props) &&
|
|
552
551
|
'mrt-row-expand',
|
|
553
552
|
];
|
|
554
553
|
};
|
|
@@ -2263,7 +2262,7 @@ const MRT_EditRowModal = ({ open, row, table, }) => {
|
|
|
2263
2262
|
};
|
|
2264
2263
|
|
|
2265
2264
|
const MRT_TableRoot = (props) => {
|
|
2266
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7;
|
|
2265
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8;
|
|
2267
2266
|
const bottomToolbarRef = useRef(null);
|
|
2268
2267
|
const editInputRefs = useRef({});
|
|
2269
2268
|
const filterInputRefs = useRef({});
|
|
@@ -2296,23 +2295,26 @@ const MRT_TableRoot = (props) => {
|
|
|
2296
2295
|
const [editingCell, setEditingCell] = useState((_e = initialState.editingCell) !== null && _e !== void 0 ? _e : null);
|
|
2297
2296
|
const [editingRow, setEditingRow] = useState((_f = initialState.editingRow) !== null && _f !== void 0 ? _f : null);
|
|
2298
2297
|
const [globalFilterFn, setGlobalFilterFn] = useState((_g = initialState.globalFilterFn) !== null && _g !== void 0 ? _g : 'fuzzy');
|
|
2299
|
-
const [
|
|
2300
|
-
const [
|
|
2301
|
-
const [
|
|
2302
|
-
const [
|
|
2303
|
-
const [
|
|
2304
|
-
const [
|
|
2298
|
+
const [grouping, setGrouping] = useState((_h = initialState.grouping) !== null && _h !== void 0 ? _h : []);
|
|
2299
|
+
const [hoveredColumn, setHoveredColumn] = useState((_j = initialState.hoveredColumn) !== null && _j !== void 0 ? _j : null);
|
|
2300
|
+
const [hoveredRow, setHoveredRow] = useState((_k = initialState.hoveredRow) !== null && _k !== void 0 ? _k : null);
|
|
2301
|
+
const [isFullScreen, setIsFullScreen] = useState((_l = initialState === null || initialState === void 0 ? void 0 : initialState.isFullScreen) !== null && _l !== void 0 ? _l : false);
|
|
2302
|
+
const [showAlertBanner, setShowAlertBanner] = useState((_o = (_m = props.initialState) === null || _m === void 0 ? void 0 : _m.showAlertBanner) !== null && _o !== void 0 ? _o : false);
|
|
2303
|
+
const [showColumnFilters, setShowFilters] = useState((_p = initialState === null || initialState === void 0 ? void 0 : initialState.showColumnFilters) !== null && _p !== void 0 ? _p : false);
|
|
2304
|
+
const [showGlobalFilter, setShowGlobalFilter] = useState((_q = initialState === null || initialState === void 0 ? void 0 : initialState.showGlobalFilter) !== null && _q !== void 0 ? _q : false);
|
|
2305
2305
|
const displayColumns = useMemo(() => {
|
|
2306
2306
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
2307
2307
|
return [
|
|
2308
2308
|
columnOrder.includes('mrt-row-drag') && Object.assign(Object.assign(Object.assign({ header: (_a = props.localization) === null || _a === void 0 ? void 0 : _a.move, size: 60 }, defaultDisplayColumnDefOptions), (_b = props.displayColumnDefOptions) === null || _b === void 0 ? void 0 : _b['mrt-row-drag']), { id: 'mrt-row-drag' }),
|
|
2309
2309
|
columnOrder.includes('mrt-row-actions') && Object.assign(Object.assign(Object.assign({ Cell: ({ row }) => (React.createElement(MRT_ToggleRowActionMenuButton, { row: row, table: table })), header: (_c = props.localization) === null || _c === void 0 ? void 0 : _c.actions, size: 70 }, defaultDisplayColumnDefOptions), (_d = props.displayColumnDefOptions) === null || _d === void 0 ? void 0 : _d['mrt-row-actions']), { id: 'mrt-row-actions' }),
|
|
2310
|
-
columnOrder.includes('mrt-row-expand') &&
|
|
2310
|
+
columnOrder.includes('mrt-row-expand') &&
|
|
2311
|
+
showExpandColumn(props, grouping) && Object.assign(Object.assign(Object.assign({ Cell: ({ row }) => (React.createElement(MRT_ExpandButton, { row: row, table: table })), Header: () => props.enableExpandAll ? (React.createElement(MRT_ExpandAllButton, { table: table })) : null, header: (_e = props.localization) === null || _e === void 0 ? void 0 : _e.expand, size: 60 }, defaultDisplayColumnDefOptions), (_f = props.displayColumnDefOptions) === null || _f === void 0 ? void 0 : _f['mrt-row-expand']), { id: 'mrt-row-expand' }),
|
|
2311
2312
|
columnOrder.includes('mrt-row-select') && Object.assign(Object.assign(Object.assign({ Cell: ({ row }) => (React.createElement(MRT_SelectCheckbox, { row: row, table: table })), Header: () => props.enableSelectAll ? (React.createElement(MRT_SelectCheckbox, { selectAll: true, table: table })) : null, header: (_g = props.localization) === null || _g === void 0 ? void 0 : _g.select, size: 60 }, defaultDisplayColumnDefOptions), (_h = props.displayColumnDefOptions) === null || _h === void 0 ? void 0 : _h['mrt-row-select']), { id: 'mrt-row-select' }),
|
|
2312
2313
|
columnOrder.includes('mrt-row-numbers') && Object.assign(Object.assign(Object.assign({ Cell: ({ row }) => row.index + 1, Header: () => { var _a; return (_a = props.localization) === null || _a === void 0 ? void 0 : _a.rowNumber; }, header: (_j = props.localization) === null || _j === void 0 ? void 0 : _j.rowNumbers, size: 60 }, defaultDisplayColumnDefOptions), (_k = props.displayColumnDefOptions) === null || _k === void 0 ? void 0 : _k['mrt-row-numbers']), { id: 'mrt-row-numbers' }),
|
|
2313
2314
|
].filter(Boolean);
|
|
2314
2315
|
}, [
|
|
2315
2316
|
columnOrder,
|
|
2317
|
+
grouping,
|
|
2316
2318
|
props.displayColumnDefOptions,
|
|
2317
2319
|
props.editingMode,
|
|
2318
2320
|
props.enableColumnDragging,
|
|
@@ -2329,6 +2331,7 @@ const MRT_TableRoot = (props) => {
|
|
|
2329
2331
|
props.enableSelectAll,
|
|
2330
2332
|
props.localization,
|
|
2331
2333
|
props.positionActionsColumn,
|
|
2334
|
+
props.renderDetailPanel,
|
|
2332
2335
|
]);
|
|
2333
2336
|
const columnDefs = useMemo(() => prepareColumns([...displayColumns, ...props.columns], columnFilterFns, props.filterFns, props.sortingFns), [columnFilterFns, displayColumns, props.columns]);
|
|
2334
2337
|
const data = useMemo(() => {
|
|
@@ -2346,11 +2349,11 @@ const MRT_TableRoot = (props) => {
|
|
|
2346
2349
|
});
|
|
2347
2350
|
})))
|
|
2348
2351
|
: props.data;
|
|
2349
|
-
}, [props.data, (
|
|
2352
|
+
}, [props.data, (_r = props.state) === null || _r === void 0 ? void 0 : _r.isLoading, (_s = props.state) === null || _s === void 0 ? void 0 : _s.showSkeletons]);
|
|
2350
2353
|
//@ts-ignore
|
|
2351
|
-
const table = Object.assign(Object.assign({}, useReactTable(Object.assign(Object.assign({ getCoreRowModel: getCoreRowModel(), getExpandedRowModel: getExpandedRowModel(), getFacetedRowModel: getFacetedRowModel(), getFilteredRowModel: getFilteredRowModel(), getGroupedRowModel: getGroupedRowModel(), getPaginationRowModel: getPaginationRowModel(), getSortedRowModel: getSortedRowModel(), onColumnOrderChange: setColumnOrder, getSubRows: (row) => row === null || row === void 0 ? void 0 : row.subRows }, props), {
|
|
2354
|
+
const table = Object.assign(Object.assign({}, useReactTable(Object.assign(Object.assign({ getCoreRowModel: getCoreRowModel(), getExpandedRowModel: getExpandedRowModel(), getFacetedRowModel: getFacetedRowModel(), getFilteredRowModel: getFilteredRowModel(), getGroupedRowModel: getGroupedRowModel(), getPaginationRowModel: getPaginationRowModel(), getSortedRowModel: getSortedRowModel(), onColumnOrderChange: setColumnOrder, onGroupingChange: setGrouping, getSubRows: (row) => row === null || row === void 0 ? void 0 : row.subRows }, props), {
|
|
2352
2355
|
//@ts-ignore
|
|
2353
|
-
columns: columnDefs, data, globalFilterFn: (
|
|
2356
|
+
columns: columnDefs, data, globalFilterFn: (_u = (_t = props.filterFns) === null || _t === void 0 ? void 0 : _t[globalFilterFn]) !== null && _u !== void 0 ? _u : (_v = props.filterFns) === null || _v === void 0 ? void 0 : _v.fuzzy, initialState, state: Object.assign({ columnFilterFns,
|
|
2354
2357
|
columnOrder,
|
|
2355
2358
|
density,
|
|
2356
2359
|
draggingColumn,
|
|
@@ -2358,6 +2361,7 @@ const MRT_TableRoot = (props) => {
|
|
|
2358
2361
|
editingCell,
|
|
2359
2362
|
editingRow,
|
|
2360
2363
|
globalFilterFn,
|
|
2364
|
+
grouping,
|
|
2361
2365
|
hoveredColumn,
|
|
2362
2366
|
hoveredRow,
|
|
2363
2367
|
isFullScreen,
|
|
@@ -2370,7 +2374,7 @@ const MRT_TableRoot = (props) => {
|
|
|
2370
2374
|
searchInputRef,
|
|
2371
2375
|
tableContainerRef,
|
|
2372
2376
|
topToolbarRef,
|
|
2373
|
-
}, setColumnFilterFns: (
|
|
2377
|
+
}, setColumnFilterFns: (_w = props.onFilterFnsChange) !== null && _w !== void 0 ? _w : setColumnFilterFns, setDensity: (_x = props.onDensityChange) !== null && _x !== void 0 ? _x : setDensity, setDraggingColumn: (_y = props.onDraggingColumnChange) !== null && _y !== void 0 ? _y : setDraggingColumn, setDraggingRow: (_z = props.onDraggingRowChange) !== null && _z !== void 0 ? _z : setDraggingRow, setEditingCell: (_0 = props.onEditingCellChange) !== null && _0 !== void 0 ? _0 : setEditingCell, setEditingRow: (_1 = props.onEditingRowChange) !== null && _1 !== void 0 ? _1 : setEditingRow, setGlobalFilterFn: (_2 = props.onGlobalFilterFnChange) !== null && _2 !== void 0 ? _2 : setGlobalFilterFn, setHoveredColumn: (_3 = props.onHoveredColumnChange) !== null && _3 !== void 0 ? _3 : setHoveredColumn, setHoveredRow: (_4 = props.onHoveredRowChange) !== null && _4 !== void 0 ? _4 : setHoveredRow, setIsFullScreen: (_5 = props.onIsFullScreenChange) !== null && _5 !== void 0 ? _5 : setIsFullScreen, setShowAlertBanner: (_6 = props.onShowAlertBannerChange) !== null && _6 !== void 0 ? _6 : setShowAlertBanner, setShowFilters: (_7 = props.onShowFiltersChange) !== null && _7 !== void 0 ? _7 : setShowFilters, setShowGlobalFilter: (_8 = props.onShowGlobalFilterChange) !== null && _8 !== void 0 ? _8 : setShowGlobalFilter });
|
|
2374
2378
|
return (React.createElement(React.Fragment, null,
|
|
2375
2379
|
React.createElement(Dialog, { PaperComponent: Box, TransitionComponent: Grow, disablePortal: true, fullScreen: true, keepMounted: false, onClose: () => setIsFullScreen(false), open: isFullScreen, transitionDuration: 400 },
|
|
2376
2380
|
React.createElement(MRT_TablePaper, { table: table })),
|