@ackplus/react-tanstack-data-table 1.0.33 → 1.0.35
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/package.json +1 -1
- package/src/lib/components/headers/draggable-header.js +10 -3
- package/src/lib/components/headers/table-header.d.ts +0 -1
- package/src/lib/components/headers/table-header.js +7 -25
- package/src/lib/components/rows/data-table-row.d.ts +2 -0
- package/src/lib/components/rows/data-table-row.js +26 -5
- package/src/lib/components/table/data-table.js +27 -11
- package/src/lib/components/table/data-table.types.d.ts +2 -0
- package/src/lib/components/toolbar/column-pinning-control.js +3 -2
- package/src/lib/components/toolbar/column-reset-control.js +0 -1
- package/src/lib/types/column.types.d.ts +1 -0
- package/src/lib/types/export.types.d.ts +1 -0
- package/src/lib/utils/styling-helpers.d.ts +47 -8
- package/src/lib/utils/styling-helpers.js +23 -16
package/package.json
CHANGED
|
@@ -185,8 +185,15 @@ function DraggableHeader(props) {
|
|
|
185
185
|
};
|
|
186
186
|
const mergedContainerProps = (0, slot_helpers_1.mergeSlotProps)({
|
|
187
187
|
ref: headerElementRef,
|
|
188
|
-
sx: Object.assign({ display: 'flex', alignItems: 'center', justifyContent: justifyContent, gap: 1, cursor: getCursor(), userSelect: 'none', opacity: isDragging ? 0.5 : 1, backgroundColor: dragOver ? 'rgba(25, 118, 210, 0.08)' : 'transparent', borderLeft: dragOver ? '2px solid #1976d2' : 'none', padding: dragOver ? '0 0 0 -2px' : '0', width: '100%', height: '100%', '&:active': {
|
|
188
|
+
sx: Object.assign({ display: 'flex', alignItems: 'center', justifyContent: justifyContent, gap: 1, cursor: getCursor(), userSelect: 'none', opacity: isDragging ? 0.5 : 1, backgroundColor: dragOver ? 'rgba(25, 118, 210, 0.08)' : 'transparent', borderLeft: dragOver ? '2px solid #1976d2' : 'none', padding: dragOver ? '0 0 0 -2px' : '0', width: '100%', height: '100%', minWidth: '0', '&:active': {
|
|
189
189
|
cursor: draggable ? 'grabbing' : 'pointer',
|
|
190
|
+
}, '.header-content': {
|
|
191
|
+
display: 'block',
|
|
192
|
+
flex: 1,
|
|
193
|
+
minWidth: 0,
|
|
194
|
+
overflow: 'hidden',
|
|
195
|
+
whiteSpace: 'nowrap',
|
|
196
|
+
textOverflow: 'ellipsis',
|
|
190
197
|
} }, containerSx),
|
|
191
198
|
draggable: draggable,
|
|
192
199
|
onDragStart: handleDragStart,
|
|
@@ -200,9 +207,9 @@ function DraggableHeader(props) {
|
|
|
200
207
|
if (!draggable && !enableSorting) {
|
|
201
208
|
return (0, react_table_1.flexRender)(header.column.columnDef.header, header.getContext());
|
|
202
209
|
}
|
|
203
|
-
return ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({}, mergedContainerProps, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "span", sx: {
|
|
210
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({}, mergedContainerProps, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "span", className: 'header-wrapper', sx: {
|
|
204
211
|
display: 'inline-flex',
|
|
205
212
|
gap: 1,
|
|
206
|
-
}, children: [(0, react_table_1.flexRender)(header.column.columnDef.header, header.getContext()), getSortIcon()] }) })));
|
|
213
|
+
}, children: [(0, jsx_runtime_1.jsx)(material_1.Box, { component: "span", className: 'header-content', children: (0, react_table_1.flexRender)(header.column.columnDef.header, header.getContext()) }), getSortIcon()] }) })));
|
|
207
214
|
}
|
|
208
215
|
exports.DraggableHeaderMemo = react_1.default.memo(DraggableHeader);
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TableHeaderMemo = void 0;
|
|
4
3
|
exports.TableHeader = TableHeader;
|
|
5
4
|
const tslib_1 = require("tslib");
|
|
6
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
-
const react_1 = tslib_1.__importStar(require("react"));
|
|
8
6
|
const material_1 = require("@mui/material");
|
|
9
7
|
const draggable_header_1 = require("./draggable-header");
|
|
10
8
|
const data_table_context_1 = require("../../contexts/data-table-context");
|
|
@@ -24,21 +22,18 @@ function TableHeader(props) {
|
|
|
24
22
|
sx: containerSx,
|
|
25
23
|
}, headerSlotProps, otherProps);
|
|
26
24
|
const mergedHeaderRowProps = (0, slot_helpers_1.mergeSlotProps)({}, headerRowSlotProps, headerRowProps || {});
|
|
27
|
-
const renderHeaderCell = (
|
|
25
|
+
const renderHeaderCell = (header) => {
|
|
26
|
+
var _a;
|
|
28
27
|
const isPinned = header.column.getIsPinned();
|
|
29
28
|
const pinnedPosition = isPinned ? header.column.getStart('left') : undefined;
|
|
30
29
|
const pinnedRightPosition = isPinned === 'right' ? header.column.getAfter('right') : undefined;
|
|
31
30
|
const alignment = (0, utils_1.getColumnAlignment)(header.column.columnDef);
|
|
32
31
|
const enableSorting = header.column.getCanSort();
|
|
33
|
-
const
|
|
34
|
-
const maxSize = header.column.columnDef.maxSize;
|
|
35
|
-
const columnSize = enableColumnResizing ? header.getSize() : (fitToScreen ? 'auto' : header.getSize());
|
|
32
|
+
const wrapText = (_a = header.column.columnDef.wrapText) !== null && _a !== void 0 ? _a : false;
|
|
36
33
|
const mergedHeaderCellProps = (0, slot_helpers_1.mergeSlotProps)({
|
|
37
34
|
align: alignment,
|
|
38
35
|
sx: Object.assign({}, (0, utils_1.getPinnedColumnStyle)({
|
|
39
|
-
width:
|
|
40
|
-
minWidth: minSize !== undefined ? minSize : undefined,
|
|
41
|
-
maxWidth: maxSize !== undefined ? maxSize : undefined,
|
|
36
|
+
width: (fitToScreen && !enableColumnResizing) ? 'auto' : header.getSize(),
|
|
42
37
|
isPinned,
|
|
43
38
|
pinnedPosition,
|
|
44
39
|
isLastLeftPinnedColumn: isPinned === 'left' && header.column.getIsLastColumn('left'),
|
|
@@ -46,6 +41,7 @@ function TableHeader(props) {
|
|
|
46
41
|
pinnedRightPosition,
|
|
47
42
|
zIndex: isPinned ? 10 : 1,
|
|
48
43
|
disableStickyHeader: enableStickyHeader,
|
|
44
|
+
wrapText,
|
|
49
45
|
})),
|
|
50
46
|
}, headerCellSlotProps, headerCellProps || {});
|
|
51
47
|
const mergedResizeHandleProps = (0, slot_helpers_1.mergeSlotProps)({
|
|
@@ -56,20 +52,6 @@ function TableHeader(props) {
|
|
|
56
52
|
} }, resizeHandleSx),
|
|
57
53
|
});
|
|
58
54
|
return ((0, jsx_runtime_1.jsxs)(HeaderCellSlot, Object.assign({}, mergedHeaderCellProps, { children: [(0, jsx_runtime_1.jsx)(draggable_header_1.DraggableHeader, { header: header, enableSorting: enableSorting, draggable: !!(draggable && !isPinned), onColumnReorder: onColumnReorder, slots: slots, slotProps: slotProps, alignment: alignment }), enableColumnResizing && header.column.getCanResize() ? ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({}, mergedResizeHandleProps))) : null] }), header.id));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
enableColumnResizing,
|
|
62
|
-
enableStickyHeader,
|
|
63
|
-
headerCellSlotProps,
|
|
64
|
-
headerCellProps,
|
|
65
|
-
resizeHandleSx,
|
|
66
|
-
theme,
|
|
67
|
-
draggable,
|
|
68
|
-
onColumnReorder,
|
|
69
|
-
slots,
|
|
70
|
-
slotProps,
|
|
71
|
-
]);
|
|
72
|
-
const headerGroups = (0, react_1.useMemo)(() => table.getHeaderGroups(), [table]);
|
|
73
|
-
return ((0, jsx_runtime_1.jsx)(HeaderSlot, Object.assign({}, mergedHeaderProps, { children: headerGroups.map(headerGroup => ((0, jsx_runtime_1.jsx)(HeaderRowSlot, Object.assign({}, mergedHeaderRowProps, { children: headerGroup.headers.map(renderHeaderCell) }), headerGroup.id))) })));
|
|
55
|
+
};
|
|
56
|
+
return ((0, jsx_runtime_1.jsx)(HeaderSlot, Object.assign({}, mergedHeaderProps, { children: table.getHeaderGroups().map(headerGroup => ((0, jsx_runtime_1.jsx)(HeaderRowSlot, Object.assign({}, mergedHeaderRowProps, { children: headerGroup.headers.map(renderHeaderCell) }), headerGroup.id))) })));
|
|
74
57
|
}
|
|
75
|
-
exports.TableHeaderMemo = react_1.default.memo(TableHeader);
|
|
@@ -8,6 +8,8 @@ export interface DataTableRowProps<T> extends TableRowProps {
|
|
|
8
8
|
isOdd?: boolean;
|
|
9
9
|
renderSubComponent?: (row: Row<T>) => ReactNode;
|
|
10
10
|
disableStickyHeader?: boolean;
|
|
11
|
+
onRowClick?: (event: React.MouseEvent<HTMLTableRowElement>, row: Row<T>) => void;
|
|
12
|
+
selectOnRowClick?: boolean;
|
|
11
13
|
cellProps?: TableCellProps;
|
|
12
14
|
expandedRowProps?: TableRowProps;
|
|
13
15
|
expandedCellProps?: TableCellProps;
|
|
@@ -7,36 +7,56 @@ const material_1 = require("@mui/material");
|
|
|
7
7
|
const react_table_1 = require("@tanstack/react-table");
|
|
8
8
|
const utils_1 = require("../../utils");
|
|
9
9
|
const slot_helpers_1 = require("../../utils/slot-helpers");
|
|
10
|
+
const data_table_context_1 = require("../../contexts/data-table-context");
|
|
10
11
|
function DataTableRow(props) {
|
|
11
|
-
|
|
12
|
+
var _a;
|
|
13
|
+
const { row, enableHover = true, enableStripes = false, isOdd = false, renderSubComponent, disableStickyHeader = false, onRowClick, selectOnRowClick = false, cellProps, expandedRowProps, expandedCellProps, containerSx, expandedContainerSx, slots, slotProps } = props, otherProps = tslib_1.__rest(props, ["row", "enableHover", "enableStripes", "isOdd", "renderSubComponent", "disableStickyHeader", "onRowClick", "selectOnRowClick", "cellProps", "expandedRowProps", "expandedCellProps", "containerSx", "expandedContainerSx", "slots", "slotProps"]);
|
|
14
|
+
const { table } = (0, data_table_context_1.useDataTableContext)();
|
|
12
15
|
const cellSlotProps = (0, slot_helpers_1.extractSlotProps)(slotProps, 'cell');
|
|
13
16
|
const expandedRowSlotProps = (0, slot_helpers_1.extractSlotProps)(slotProps, 'expandedRow');
|
|
14
17
|
const rowSlotProps = (0, slot_helpers_1.extractSlotProps)(slotProps, 'row');
|
|
15
18
|
const CellSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'cell', material_1.TableCell);
|
|
16
19
|
const ExpandedRowSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'expandedRow', material_1.TableRow);
|
|
17
20
|
const TableRowSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'row', material_1.TableRow);
|
|
21
|
+
const handleRowClick = (event) => {
|
|
22
|
+
const target = event.target;
|
|
23
|
+
const isCheckboxClick = target.closest('input[type="checkbox"]') !== null;
|
|
24
|
+
const isButtonClick = target.closest('button') !== null;
|
|
25
|
+
const isLinkClick = target.closest('a') !== null;
|
|
26
|
+
if (selectOnRowClick && !isCheckboxClick && !isButtonClick && !isLinkClick && (table === null || table === void 0 ? void 0 : table.toggleRowSelected)) {
|
|
27
|
+
table.toggleRowSelected(row.id);
|
|
28
|
+
}
|
|
29
|
+
if (onRowClick) {
|
|
30
|
+
onRowClick(event, row);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
18
33
|
const mergedRowProps = (0, slot_helpers_1.mergeSlotProps)({
|
|
19
34
|
hover: enableHover,
|
|
20
|
-
|
|
35
|
+
selected: !!((_a = table === null || table === void 0 ? void 0 : table.getIsRowSelected) === null || _a === void 0 ? void 0 : _a.call(table, row.id)),
|
|
36
|
+
onClick: (onRowClick || selectOnRowClick) ? handleRowClick : undefined,
|
|
37
|
+
sx: (theme) => (Object.assign(Object.assign(Object.assign(Object.assign({ '--row-bg': enableStripes && isOdd
|
|
21
38
|
? theme.palette.action.hover
|
|
22
39
|
: theme.palette.background.paper, backgroundColor: 'var(--row-bg)' }, (enableHover && {
|
|
23
40
|
'&:hover': { '--row-bg': theme.palette.action.hover },
|
|
24
41
|
})), { [`&.${material_1.tableRowClasses.selected}`]: {
|
|
25
|
-
'--row-bg':
|
|
42
|
+
'--row-bg': theme.palette.action.selected,
|
|
26
43
|
backgroundColor: 'var(--row-bg)',
|
|
27
|
-
} }),
|
|
44
|
+
} }), ((onRowClick || selectOnRowClick) && {
|
|
45
|
+
cursor: 'pointer',
|
|
46
|
+
})), containerSx)),
|
|
28
47
|
}, rowSlotProps, otherProps);
|
|
29
48
|
const mergedExpandedRowProps = (0, slot_helpers_1.mergeSlotProps)({
|
|
30
49
|
sx: expandedContainerSx,
|
|
31
50
|
}, expandedRowSlotProps, expandedRowProps || {});
|
|
32
51
|
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(TableRowSlot, Object.assign({}, mergedRowProps, { children: row.getVisibleCells().map(cell => {
|
|
33
|
-
var _a;
|
|
52
|
+
var _a, _b;
|
|
34
53
|
const isPinned = cell.column.getIsPinned();
|
|
35
54
|
const pinnedPosition = isPinned ? cell.column.getStart('left') : undefined;
|
|
36
55
|
const pinnedRightPosition = isPinned === 'right' ? cell.column.getAfter('right') : undefined;
|
|
37
56
|
const alignment = (0, utils_1.getColumnAlignment)(cell.column.columnDef);
|
|
38
57
|
const minSize = (_a = cell.column.columnDef) === null || _a === void 0 ? void 0 : _a.minSize;
|
|
39
58
|
const maxSize = cell.column.columnDef.maxSize;
|
|
59
|
+
const wrapText = (_b = cell.column.columnDef.wrapText) !== null && _b !== void 0 ? _b : false;
|
|
40
60
|
const mergedCellProps = (0, slot_helpers_1.mergeSlotProps)({
|
|
41
61
|
align: alignment,
|
|
42
62
|
sx: Object.assign({}, (0, utils_1.getPinnedColumnStyle)({
|
|
@@ -50,6 +70,7 @@ function DataTableRow(props) {
|
|
|
50
70
|
disableStickyHeader,
|
|
51
71
|
isLastLeftPinnedColumn: isPinned === 'left' && cell.column.getIsLastColumn('left'),
|
|
52
72
|
isFirstRightPinnedColumn: isPinned === 'right' && cell.column.getIsFirstColumn('right'),
|
|
73
|
+
wrapText,
|
|
53
74
|
})),
|
|
54
75
|
}, cellSlotProps, cellProps || {});
|
|
55
76
|
return ((0, jsx_runtime_1.jsx)(CellSlot, Object.assign({}, mergedCellProps, { children: (0, react_table_1.flexRender)(cell.column.columnDef.cell, cell.getContext()) }), cell.id));
|
|
@@ -41,7 +41,7 @@ const DEFAULT_INITIAL_STATE = {
|
|
|
41
41
|
pendingLogic: 'AND',
|
|
42
42
|
},
|
|
43
43
|
};
|
|
44
|
-
exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, columns, data = [], totalRow = 0, idKey = 'id', extraFilter = null, footerFilter = null, dataMode = 'client', initialLoadData = true, onFetchData, onDataStateChange, enableRowSelection = false, enableMultiRowSelection = true, selectMode = 'page', isRowSelectable, onSelectionChange, enableBulkActions = false, bulkActions, enableColumnResizing = false, columnResizeMode = 'onChange', onColumnSizingChange, enableColumnDragging = false, onColumnDragEnd, enableColumnPinning = false, onColumnPinningChange, onColumnVisibilityChange, enableColumnVisibility = true, enableExpanding = false, getRowCanExpand, renderSubComponent, enablePagination = false, paginationMode = 'client', enableGlobalFilter = true, enableColumnFilter = false, filterMode = 'client', enableSorting = true, sortingMode = 'client', onSortingChange, exportFilename = 'export', onExportProgress, onExportComplete, onExportError, onServerExport, onExportCancel, enableHover = true, enableStripes = false, tableProps = {}, fitToScreen = true, tableSize: initialTableSize = 'medium', enableStickyHeaderOrFooter = false, maxHeight = '400px', enableVirtualization = false, estimateRowHeight = 52, enableTableSizeControl = true, enableExport = false, enableReset = true, loading = false, emptyMessage = 'No data available', skeletonRows = 5, onColumnFiltersChange, onPaginationChange, onGlobalFilterChange, slots = {}, slotProps = {}, logging, }, ref) {
|
|
44
|
+
exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, columns, data = [], totalRow = 0, idKey = 'id', extraFilter = null, footerFilter = null, dataMode = 'client', initialLoadData = true, onFetchData, onDataStateChange, enableRowSelection = false, enableMultiRowSelection = true, selectMode = 'page', isRowSelectable, onSelectionChange, onRowClick, selectOnRowClick = false, enableBulkActions = false, bulkActions, enableColumnResizing = false, columnResizeMode = 'onChange', onColumnSizingChange, enableColumnDragging = false, onColumnDragEnd, enableColumnPinning = false, onColumnPinningChange, onColumnVisibilityChange, enableColumnVisibility = true, enableExpanding = false, getRowCanExpand, renderSubComponent, enablePagination = false, paginationMode = 'client', enableGlobalFilter = true, enableColumnFilter = false, filterMode = 'client', enableSorting = true, sortingMode = 'client', onSortingChange, exportFilename = 'export', onExportProgress, onExportComplete, onExportError, onServerExport, onExportCancel, enableHover = true, enableStripes = false, tableProps = {}, fitToScreen = true, tableSize: initialTableSize = 'medium', enableStickyHeaderOrFooter = false, maxHeight = '400px', enableVirtualization = false, estimateRowHeight = 52, enableTableSizeControl = true, enableExport = false, enableReset = true, loading = false, emptyMessage = 'No data available', skeletonRows = 5, onColumnFiltersChange, onPaginationChange, onGlobalFilterChange, slots = {}, slotProps = {}, logging, }, ref) {
|
|
45
45
|
var _a;
|
|
46
46
|
const isServerMode = dataMode === 'server';
|
|
47
47
|
const isServerPagination = paginationMode === 'server' || isServerMode;
|
|
@@ -540,7 +540,9 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
540
540
|
table.toggleAllColumnsVisible(false);
|
|
541
541
|
},
|
|
542
542
|
resetColumnVisibility: () => {
|
|
543
|
-
|
|
543
|
+
const initialVisibility = initialStateConfig.columnVisibility || {};
|
|
544
|
+
table.setColumnVisibility(initialVisibility);
|
|
545
|
+
handleColumnVisibilityChange(initialVisibility);
|
|
544
546
|
},
|
|
545
547
|
},
|
|
546
548
|
columnOrdering: {
|
|
@@ -568,6 +570,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
568
570
|
return `column_${index}`;
|
|
569
571
|
});
|
|
570
572
|
table.setColumnOrder(initialOrder);
|
|
573
|
+
handleColumnOrderChange(initialOrder);
|
|
571
574
|
},
|
|
572
575
|
},
|
|
573
576
|
columnPinning: {
|
|
@@ -582,7 +585,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
582
585
|
const currentPinning = table.getState().columnPinning;
|
|
583
586
|
const newPinning = Object.assign({}, currentPinning);
|
|
584
587
|
newPinning.left = (newPinning.left || []).filter(id => id !== columnId);
|
|
585
|
-
newPinning.right = [...(newPinning.right || []).filter(id => id !== columnId)
|
|
588
|
+
newPinning.right = [columnId, ...(newPinning.right || []).filter(id => id !== columnId)];
|
|
586
589
|
table.setColumnPinning(newPinning);
|
|
587
590
|
},
|
|
588
591
|
unpinColumn: (columnId) => {
|
|
@@ -597,7 +600,9 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
597
600
|
table.setColumnPinning(pinning);
|
|
598
601
|
},
|
|
599
602
|
resetColumnPinning: () => {
|
|
600
|
-
|
|
603
|
+
const initialPinning = initialStateConfig.columnPinning || { left: [], right: [] };
|
|
604
|
+
table.setColumnPinning(initialPinning);
|
|
605
|
+
handleColumnPinningChange(initialPinning);
|
|
601
606
|
},
|
|
602
607
|
},
|
|
603
608
|
columnResizing: {
|
|
@@ -610,10 +615,14 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
610
615
|
(_a = table.getColumn(columnId)) === null || _a === void 0 ? void 0 : _a.resetSize();
|
|
611
616
|
},
|
|
612
617
|
autoSizeAllColumns: () => {
|
|
613
|
-
|
|
618
|
+
const initialSizing = initialStateConfig.columnSizing || {};
|
|
619
|
+
table.setColumnSizing(initialSizing);
|
|
620
|
+
handleColumnSizingChange(initialSizing);
|
|
614
621
|
},
|
|
615
622
|
resetColumnSizing: () => {
|
|
616
|
-
|
|
623
|
+
const initialSizing = initialStateConfig.columnSizing || {};
|
|
624
|
+
table.setColumnSizing(initialSizing);
|
|
625
|
+
handleColumnSizingChange(initialSizing);
|
|
617
626
|
},
|
|
618
627
|
},
|
|
619
628
|
filtering: {
|
|
@@ -700,10 +709,13 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
700
709
|
}
|
|
701
710
|
},
|
|
702
711
|
clearSorting: () => {
|
|
703
|
-
table.
|
|
712
|
+
table.setSorting([]);
|
|
713
|
+
handleSortingChange([]);
|
|
704
714
|
},
|
|
705
715
|
resetSorting: () => {
|
|
706
|
-
|
|
716
|
+
const initialSorting = initialStateConfig.sorting || [];
|
|
717
|
+
table.setSorting(initialSorting);
|
|
718
|
+
handleSortingChange(initialSorting);
|
|
707
719
|
},
|
|
708
720
|
},
|
|
709
721
|
pagination: {
|
|
@@ -747,7 +759,9 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
747
759
|
}
|
|
748
760
|
},
|
|
749
761
|
resetPagination: () => {
|
|
750
|
-
|
|
762
|
+
const initialPagination = initialStateConfig.pagination || { pageIndex: 0, pageSize: 10 };
|
|
763
|
+
table.setPagination(initialPagination);
|
|
764
|
+
handlePaginationChange(initialPagination);
|
|
751
765
|
},
|
|
752
766
|
},
|
|
753
767
|
selection: {
|
|
@@ -1206,7 +1220,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1206
1220
|
const row = rows[virtualRow.index];
|
|
1207
1221
|
if (!row)
|
|
1208
1222
|
return null;
|
|
1209
|
-
return ((0, jsx_runtime_1.jsx)(rows_1.DataTableRow, { row: row, enableHover: enableHover, enableStripes: enableStripes, isOdd: virtualRow.index % 2 === 1, renderSubComponent: renderSubComponent, disableStickyHeader: enableStickyHeaderOrFooter, slots: slots, slotProps: slotProps }, row.id));
|
|
1223
|
+
return ((0, jsx_runtime_1.jsx)(rows_1.DataTableRow, { row: row, enableHover: enableHover, enableStripes: enableStripes, isOdd: virtualRow.index % 2 === 1, renderSubComponent: renderSubComponent, disableStickyHeader: enableStickyHeaderOrFooter, onRowClick: onRowClick, selectOnRowClick: selectOnRowClick, slots: slots, slotProps: slotProps }, row.id));
|
|
1210
1224
|
}), virtualItems.length > 0 && ((0, jsx_runtime_1.jsx)("tr", { children: (0, jsx_runtime_1.jsx)("td", { colSpan: table.getAllColumns().length, style: {
|
|
1211
1225
|
height: `${rowVirtualizer.getTotalSize() -
|
|
1212
1226
|
((_d = (_c = virtualItems[virtualItems.length - 1]) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : 0)}px`,
|
|
@@ -1214,7 +1228,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1214
1228
|
border: 0,
|
|
1215
1229
|
} }) }))] }));
|
|
1216
1230
|
}
|
|
1217
|
-
return rows.map((row, index) => ((0, jsx_runtime_1.jsx)(rows_1.DataTableRow, { row: row, enableHover: enableHover, enableStripes: enableStripes, isOdd: index % 2 === 1, renderSubComponent: renderSubComponent, disableStickyHeader: enableStickyHeaderOrFooter, slots: slots, slotProps: slotProps }, row.id)));
|
|
1231
|
+
return rows.map((row, index) => ((0, jsx_runtime_1.jsx)(rows_1.DataTableRow, { row: row, enableHover: enableHover, enableStripes: enableStripes, isOdd: index % 2 === 1, renderSubComponent: renderSubComponent, disableStickyHeader: enableStickyHeaderOrFooter, onRowClick: onRowClick, selectOnRowClick: selectOnRowClick, slots: slots, slotProps: slotProps }, row.id)));
|
|
1218
1232
|
}, [
|
|
1219
1233
|
tableLoading,
|
|
1220
1234
|
rows,
|
|
@@ -1230,6 +1244,8 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1230
1244
|
enableStripes,
|
|
1231
1245
|
renderSubComponent,
|
|
1232
1246
|
enableStickyHeaderOrFooter,
|
|
1247
|
+
onRowClick,
|
|
1248
|
+
selectOnRowClick,
|
|
1233
1249
|
slots,
|
|
1234
1250
|
]);
|
|
1235
1251
|
const handleCancelExport = (0, react_1.useCallback)(() => {
|
|
@@ -53,6 +53,8 @@ export interface DataTableProps<T> {
|
|
|
53
53
|
id: string;
|
|
54
54
|
}) => boolean;
|
|
55
55
|
onSelectionChange?: (selection: SelectionState) => void;
|
|
56
|
+
onRowClick?: (event: React.MouseEvent<HTMLTableRowElement>, row: Row<T>) => void;
|
|
57
|
+
selectOnRowClick?: boolean;
|
|
56
58
|
enableBulkActions?: boolean;
|
|
57
59
|
bulkActions?: (selectionState: SelectionState) => ReactNode;
|
|
58
60
|
enableColumnResizing?: boolean;
|
|
@@ -37,7 +37,7 @@ function ColumnPinningControl(props = {}) {
|
|
|
37
37
|
newPinning.left = [...(newPinning.left || []), columnId];
|
|
38
38
|
}
|
|
39
39
|
else if (position === 'right') {
|
|
40
|
-
newPinning.right = [...(newPinning.right || [])
|
|
40
|
+
newPinning.right = [columnId, ...(newPinning.right || [])];
|
|
41
41
|
}
|
|
42
42
|
table === null || table === void 0 ? void 0 : table.setColumnPinning(newPinning);
|
|
43
43
|
};
|
|
@@ -56,7 +56,8 @@ function ColumnPinningControl(props = {}) {
|
|
|
56
56
|
return column.id;
|
|
57
57
|
};
|
|
58
58
|
const handleUnpinAll = (0, react_1.useCallback)(() => {
|
|
59
|
-
|
|
59
|
+
var _a;
|
|
60
|
+
table === null || table === void 0 ? void 0 : table.setColumnPinning(((_a = table === null || table === void 0 ? void 0 : table.initialState) === null || _a === void 0 ? void 0 : _a.columnPinning) || {});
|
|
60
61
|
}, [table]);
|
|
61
62
|
const userPinnedLeft = (((_a = columnPinning.left) === null || _a === void 0 ? void 0 : _a.filter((id) => allColumns.some((column) => column.id === id))) || []);
|
|
62
63
|
const userPinnedRight = (((_b = columnPinning.right) === null || _b === void 0 ? void 0 : _b.filter((id) => allColumns.some((column) => column.id === id))) || []);
|
|
@@ -13,7 +13,6 @@ function ColumnResetControl(props = {}) {
|
|
|
13
13
|
const handleResetLayout = () => {
|
|
14
14
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
15
15
|
const actions = props.resetActions || ['columnOrder', 'columnPinning', 'columnSizing'];
|
|
16
|
-
console.log('actions', actions);
|
|
17
16
|
if (!(apiRef === null || apiRef === void 0 ? void 0 : apiRef.current))
|
|
18
17
|
return;
|
|
19
18
|
if (actions.includes('columnOrder')) {
|
|
@@ -1,17 +1,56 @@
|
|
|
1
1
|
import type { DataTableColumn, PinnedColumnStyleOptions } from '../types';
|
|
2
2
|
export declare function getPinnedColumnStyle(options: PinnedColumnStyleOptions): {
|
|
3
|
-
backgroundColor:
|
|
4
|
-
|
|
3
|
+
backgroundColor: (theme: any) => any;
|
|
4
|
+
backgroundImage: (theme: any) => string;
|
|
5
5
|
boxShadow: string;
|
|
6
|
-
willChange: string;
|
|
7
|
-
transform: string;
|
|
8
6
|
left?: number;
|
|
9
7
|
right?: number;
|
|
10
8
|
zIndex?: number;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
whiteSpace: "normal";
|
|
10
|
+
wordBreak: "break-word";
|
|
11
|
+
overflow: "visible";
|
|
12
|
+
textOverflow?: undefined;
|
|
13
|
+
maxWidth: string | number;
|
|
14
|
+
minWidth: number;
|
|
15
|
+
width: string | number;
|
|
16
|
+
} | {
|
|
17
|
+
backgroundColor: (theme: any) => string;
|
|
18
|
+
boxShadow: string;
|
|
19
|
+
left?: number;
|
|
20
|
+
right?: number;
|
|
21
|
+
zIndex?: number;
|
|
22
|
+
whiteSpace: "normal";
|
|
23
|
+
wordBreak: "break-word";
|
|
24
|
+
overflow: "visible";
|
|
25
|
+
textOverflow?: undefined;
|
|
26
|
+
maxWidth: string | number;
|
|
27
|
+
minWidth: number;
|
|
28
|
+
width: string | number;
|
|
29
|
+
} | {
|
|
30
|
+
backgroundColor: (theme: any) => any;
|
|
31
|
+
backgroundImage: (theme: any) => string;
|
|
32
|
+
boxShadow: string;
|
|
33
|
+
left?: number;
|
|
34
|
+
right?: number;
|
|
35
|
+
zIndex?: number;
|
|
36
|
+
overflow: "hidden";
|
|
37
|
+
whiteSpace: "nowrap";
|
|
38
|
+
textOverflow: "ellipsis";
|
|
39
|
+
wordBreak?: undefined;
|
|
40
|
+
maxWidth: string | number;
|
|
41
|
+
minWidth: number;
|
|
42
|
+
width: string | number;
|
|
43
|
+
} | {
|
|
44
|
+
backgroundColor: (theme: any) => string;
|
|
45
|
+
boxShadow: string;
|
|
46
|
+
left?: number;
|
|
47
|
+
right?: number;
|
|
48
|
+
zIndex?: number;
|
|
49
|
+
overflow: "hidden";
|
|
50
|
+
whiteSpace: "nowrap";
|
|
51
|
+
textOverflow: "ellipsis";
|
|
52
|
+
wordBreak?: undefined;
|
|
53
|
+
maxWidth: string | number;
|
|
15
54
|
minWidth: number;
|
|
16
55
|
width: string | number;
|
|
17
56
|
};
|
|
@@ -3,19 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.tableRowStyles = exports.tableCellStyles = void 0;
|
|
4
4
|
exports.getPinnedColumnStyle = getPinnedColumnStyle;
|
|
5
5
|
exports.getColumnAlignment = getColumnAlignment;
|
|
6
|
-
const getBoxShadow = (isPinned, isLastLeftPinnedColumn, isFirstRightPinnedColumn) => {
|
|
7
|
-
if (isPinned === 'left' && isLastLeftPinnedColumn) {
|
|
8
|
-
return '1px 0 3px rgba(0, 0, 0, 0.12)';
|
|
9
|
-
}
|
|
10
|
-
if (isPinned === 'right' && isFirstRightPinnedColumn) {
|
|
11
|
-
return '-1px 0 3px rgba(0, 0, 0, 0.12)';
|
|
12
|
-
}
|
|
13
|
-
return 'none';
|
|
14
|
-
};
|
|
15
6
|
function getPinnedColumnStyle(options) {
|
|
16
|
-
const { width = 'auto', minWidth, maxWidth, isPinned, pinnedPosition, pinnedRightPosition, isLastLeftPinnedColumn, isFirstRightPinnedColumn, zIndex = 1, disableStickyHeader = false, } = options;
|
|
7
|
+
const { width = 'auto', minWidth, maxWidth, isPinned, pinnedPosition, pinnedRightPosition, isLastLeftPinnedColumn, isFirstRightPinnedColumn, zIndex = 1, disableStickyHeader = false, wrapText = false, } = options;
|
|
17
8
|
const needsPinnedPositioning = isPinned;
|
|
18
|
-
const shouldBeSticky =
|
|
9
|
+
const shouldBeSticky = isPinned;
|
|
19
10
|
let positionStyle = {};
|
|
20
11
|
if (shouldBeSticky) {
|
|
21
12
|
positionStyle = { position: 'sticky' };
|
|
@@ -23,15 +14,31 @@ function getPinnedColumnStyle(options) {
|
|
|
23
14
|
else if (!disableStickyHeader) {
|
|
24
15
|
positionStyle = { position: 'relative' };
|
|
25
16
|
}
|
|
26
|
-
|
|
17
|
+
const textWrappingStyles = wrapText
|
|
18
|
+
? {
|
|
19
|
+
whiteSpace: 'normal',
|
|
20
|
+
wordBreak: 'break-word',
|
|
21
|
+
overflow: 'visible',
|
|
22
|
+
}
|
|
23
|
+
: {
|
|
24
|
+
overflow: 'hidden',
|
|
25
|
+
whiteSpace: 'nowrap',
|
|
26
|
+
textOverflow: 'ellipsis',
|
|
27
|
+
};
|
|
28
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ width }, (minWidth !== undefined && { minWidth })), (maxWidth !== undefined ? { maxWidth } : { maxWidth: width })), textWrappingStyles), positionStyle), (needsPinnedPositioning ? {
|
|
27
29
|
left: isPinned === 'left' ? pinnedPosition : undefined,
|
|
28
30
|
right: isPinned === 'right' ? pinnedRightPosition : undefined,
|
|
29
31
|
zIndex,
|
|
30
|
-
} : {})), {
|
|
31
|
-
? 'inset -1px 0 0 var(--palette-TableCell-border),
|
|
32
|
+
} : {})), { boxShadow: isPinned === 'left' && isLastLeftPinnedColumn
|
|
33
|
+
? 'inset -1px 0 0 var(--palette-TableCell-border), 2px 0 2px -4px rgba(0,0,0,.18)'
|
|
32
34
|
: isPinned === 'right' && isFirstRightPinnedColumn
|
|
33
|
-
? 'inset 1px 0 0 var(--palette-TableCell-border), -
|
|
34
|
-
: undefined
|
|
35
|
+
? 'inset 1px 0 0 var(--palette-TableCell-border), -1px 0 2px -4px rgba(0,0,0,.18)'
|
|
36
|
+
: undefined }), (isPinned ? {
|
|
37
|
+
backgroundColor: (theme) => theme.palette.background.paper,
|
|
38
|
+
backgroundImage: (theme) => `linear-gradient(var(--row-bg, ${theme.palette.background.paper}), var(--row-bg, ${theme.palette.background.paper}))`,
|
|
39
|
+
} : {
|
|
40
|
+
backgroundColor: (theme) => `var(--row-bg, ${theme.palette.background.paper})`,
|
|
41
|
+
}));
|
|
35
42
|
}
|
|
36
43
|
exports.tableCellStyles = {
|
|
37
44
|
sticky: {
|