@ackplus/react-tanstack-data-table 1.0.19-beta-0.7 → 1.0.19-beta-0.8
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 +599 -0
- package/package.json +1 -1
- package/src/index.d.ts +19 -0
- package/src/index.js +31 -0
- package/src/lib/components/droupdown/menu-dropdown.d.ts +17 -0
- package/src/lib/components/droupdown/menu-dropdown.js +52 -0
- package/src/lib/components/filters/filter-value-input.d.ts +9 -0
- package/src/lib/components/filters/filter-value-input.js +58 -0
- package/src/lib/components/filters/index.d.ts +23 -0
- package/src/lib/components/filters/index.js +129 -0
- package/src/lib/components/headers/draggable-header.d.ts +12 -0
- package/src/lib/components/headers/draggable-header.js +212 -0
- package/src/lib/components/headers/index.d.ts +2 -0
- package/src/lib/components/headers/index.js +5 -0
- package/src/lib/components/headers/table-header.d.ts +10 -0
- package/src/lib/components/headers/table-header.js +48 -0
- package/src/lib/components/index.d.ts +7 -0
- package/src/lib/components/index.js +10 -0
- package/src/lib/components/pagination/data-table-pagination.d.ts +11 -0
- package/src/lib/components/pagination/data-table-pagination.js +25 -0
- package/src/lib/components/pagination/index.d.ts +1 -0
- package/src/lib/components/pagination/index.js +4 -0
- package/src/lib/components/rows/data-table-row.d.ts +13 -0
- package/src/lib/components/rows/data-table-row.js +31 -0
- package/src/lib/components/rows/empty-data-row.d.ts +6 -0
- package/src/lib/components/rows/empty-data-row.js +11 -0
- package/src/lib/components/rows/index.d.ts +3 -0
- package/src/lib/components/rows/index.js +6 -0
- package/src/lib/components/rows/loading-rows.d.ts +5 -0
- package/src/lib/components/rows/loading-rows.js +49 -0
- package/src/lib/components/table/data-table.d.ts +3 -0
- package/src/lib/components/table/data-table.js +492 -0
- package/src/lib/components/table/data-table.types.d.ts +114 -0
- package/src/lib/components/table/data-table.types.js +2 -0
- package/src/lib/components/table/index.d.ts +2 -0
- package/src/lib/components/table/index.js +5 -0
- package/src/lib/components/toolbar/bulk-actions-toolbar.d.ts +9 -0
- package/src/lib/components/toolbar/bulk-actions-toolbar.js +25 -0
- package/src/lib/components/toolbar/column-custom-filter-control.d.ts +1 -0
- package/src/lib/components/toolbar/column-custom-filter-control.js +137 -0
- package/src/lib/components/toolbar/column-pinning-control.d.ts +1 -0
- package/src/lib/components/toolbar/column-pinning-control.js +105 -0
- package/src/lib/components/toolbar/column-reset-control.d.ts +1 -0
- package/src/lib/components/toolbar/column-reset-control.js +16 -0
- package/src/lib/components/toolbar/column-visibility-control.d.ts +1 -0
- package/src/lib/components/toolbar/column-visibility-control.js +31 -0
- package/src/lib/components/toolbar/data-table-toolbar.d.ts +14 -0
- package/src/lib/components/toolbar/data-table-toolbar.js +26 -0
- package/src/lib/components/toolbar/index.d.ts +8 -0
- package/src/lib/components/toolbar/index.js +17 -0
- package/src/lib/components/toolbar/table-export-control.d.ts +25 -0
- package/src/lib/components/toolbar/table-export-control.js +93 -0
- package/src/lib/components/toolbar/table-search-control.d.ts +1 -0
- package/src/lib/components/toolbar/table-search-control.js +61 -0
- package/src/lib/components/toolbar/table-size-control.d.ts +1 -0
- package/src/lib/components/toolbar/table-size-control.js +36 -0
- package/src/lib/contexts/data-table-context.d.ts +43 -0
- package/src/lib/contexts/data-table-context.js +54 -0
- package/src/lib/examples/advanced-features-example.d.ts +1 -0
- package/src/lib/examples/advanced-features-example.js +264 -0
- package/src/lib/examples/bulk-actions-test.d.ts +1 -0
- package/src/lib/examples/bulk-actions-test.js +44 -0
- package/src/lib/examples/custom-column-filter-example.d.ts +1 -0
- package/src/lib/examples/custom-column-filter-example.js +60 -0
- package/src/lib/examples/index.d.ts +5 -0
- package/src/lib/examples/index.js +13 -0
- package/src/lib/examples/selection-test-example.d.ts +1 -0
- package/src/lib/examples/selection-test-example.js +101 -0
- package/src/lib/examples/simple-local-example.d.ts +1 -0
- package/src/lib/examples/simple-local-example.js +97 -0
- package/src/lib/features/custom-column-filter.feature.d.ts +45 -0
- package/src/lib/features/custom-column-filter.feature.js +247 -0
- package/src/lib/features/custom-selection.feature.d.ts +46 -0
- package/src/lib/features/custom-selection.feature.js +172 -0
- package/src/lib/features/index.d.ts +2 -0
- package/src/lib/features/index.js +8 -0
- package/src/lib/hooks/index.d.ts +1 -0
- package/src/lib/hooks/index.js +4 -0
- package/src/lib/hooks/use-data-table-api.d.ts +56 -0
- package/src/lib/hooks/use-data-table-api.js +616 -0
- package/src/lib/icons/add-icon.d.ts +2 -0
- package/src/lib/icons/add-icon.js +8 -0
- package/src/lib/icons/csv-icon.d.ts +2 -0
- package/src/lib/icons/csv-icon.js +8 -0
- package/src/lib/icons/delete-icon.d.ts +2 -0
- package/src/lib/icons/delete-icon.js +8 -0
- package/src/lib/icons/excel-icon.d.ts +2 -0
- package/src/lib/icons/excel-icon.js +8 -0
- package/src/lib/icons/index.d.ts +7 -0
- package/src/lib/icons/index.js +17 -0
- package/src/lib/icons/unpin-icon.d.ts +2 -0
- package/src/lib/icons/unpin-icon.js +8 -0
- package/src/lib/icons/view-comfortable-icon.d.ts +2 -0
- package/src/lib/icons/view-comfortable-icon.js +8 -0
- package/src/lib/icons/view-compact-icon.d.ts +2 -0
- package/src/lib/icons/view-compact-icon.js +8 -0
- package/src/lib/types/column.types.d.ts +29 -0
- package/src/lib/types/column.types.js +5 -0
- package/src/lib/types/data-table-api.d.ts +134 -0
- package/src/lib/types/data-table-api.js +2 -0
- package/src/lib/types/export.types.d.ts +99 -0
- package/src/lib/types/export.types.js +2 -0
- package/src/lib/types/index.d.ts +6 -0
- package/src/lib/types/index.js +8 -0
- package/src/lib/types/slots.types.d.ts +272 -0
- package/src/lib/types/slots.types.js +2 -0
- package/src/lib/types/table.types.d.ts +63 -0
- package/src/lib/types/table.types.js +2 -0
- package/src/lib/utils/column-helpers.d.ts +7 -0
- package/src/lib/utils/column-helpers.js +43 -0
- package/src/lib/utils/debounced-fetch.utils.d.ts +11 -0
- package/src/lib/utils/debounced-fetch.utils.js +49 -0
- package/src/lib/utils/export-utils.d.ts +30 -0
- package/src/lib/utils/export-utils.js +152 -0
- package/src/lib/utils/index.d.ts +7 -0
- package/src/lib/utils/index.js +10 -0
- package/src/lib/utils/slot-helpers.d.ts +9 -0
- package/src/lib/utils/slot-helpers.js +21 -0
- package/src/lib/utils/special-columns.utils.d.ts +6 -0
- package/src/lib/utils/special-columns.utils.js +52 -0
- package/src/lib/utils/styling-helpers.d.ts +36 -0
- package/src/lib/utils/styling-helpers.js +61 -0
- package/src/lib/utils/table-helpers.d.ts +9 -0
- package/src/lib/utils/table-helpers.js +57 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataTableRow = DataTableRow;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
const react_table_1 = require("@tanstack/react-table");
|
|
7
|
+
const utils_1 = require("../../utils");
|
|
8
|
+
const slot_helpers_1 = require("../../utils/slot-helpers");
|
|
9
|
+
function DataTableRow({ row, enableHover = true, enableStripes = false, isOdd = false, renderSubComponent, disableStickyHeader = false, slots, slotProps, }) {
|
|
10
|
+
const CellSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'cell', material_1.TableCell);
|
|
11
|
+
const ExpandedRowSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'expandedRow', material_1.TableRow);
|
|
12
|
+
const TableRowSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'row', material_1.TableRow);
|
|
13
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(TableRowSlot, { hover: enableHover, sx: {
|
|
14
|
+
backgroundColor: enableStripes && isOdd ? 'action.hover' : 'transparent',
|
|
15
|
+
}, children: row.getVisibleCells().map(cell => {
|
|
16
|
+
const isPinned = cell.column.getIsPinned();
|
|
17
|
+
const pinnedPosition = isPinned ? cell.column.getStart('left') : undefined;
|
|
18
|
+
const pinnedRightPosition = isPinned === 'right' ? cell.column.getAfter('right') : undefined;
|
|
19
|
+
const alignment = (0, utils_1.getColumnAlignment)(cell.column.columnDef);
|
|
20
|
+
return ((0, jsx_runtime_1.jsx)(CellSlot, Object.assign({ align: alignment, sx: Object.assign({}, (0, utils_1.getPinnedColumnStyle)({
|
|
21
|
+
width: cell.column.getSize() || 'auto',
|
|
22
|
+
isPinned,
|
|
23
|
+
pinnedPosition,
|
|
24
|
+
pinnedRightPosition,
|
|
25
|
+
zIndex: isPinned ? 9 : 1,
|
|
26
|
+
disableStickyHeader,
|
|
27
|
+
isLastLeftPinnedColumn: isPinned === 'left' && cell.column.getIsLastColumn('left'),
|
|
28
|
+
isFirstRightPinnedColumn: isPinned === 'right' && cell.column.getIsFirstColumn('right'),
|
|
29
|
+
})) }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.cell, { children: (0, react_table_1.flexRender)(cell.column.columnDef.cell, cell.getContext()) }), cell.id));
|
|
30
|
+
}) }), row.getIsExpanded() && renderSubComponent ? ((0, jsx_runtime_1.jsx)(ExpandedRowSlot, { children: (0, jsx_runtime_1.jsx)(CellSlot, { colSpan: row.getVisibleCells().length + 1, sx: { py: 0 }, children: (0, jsx_runtime_1.jsx)(material_1.Collapse, { in: row.getIsExpanded(), timeout: "auto", unmountOnExit: true, children: renderSubComponent(row) }) }) })) : null] }));
|
|
31
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmptyDataRow = EmptyDataRow;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
const slot_helpers_1 = require("../../utils/slot-helpers");
|
|
7
|
+
function EmptyDataRow({ colSpan, message, slots, slotProps }) {
|
|
8
|
+
const EmptyRowSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'emptyRow', material_1.TableRow);
|
|
9
|
+
const EmptyCellSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'cell', material_1.TableCell);
|
|
10
|
+
return ((0, jsx_runtime_1.jsx)(EmptyRowSlot, { children: (0, jsx_runtime_1.jsx)(EmptyCellSlot, Object.assign({ colSpan: colSpan, align: "center", sx: { py: 4 } }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.emptyCell, { children: message })) }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./data-table-row"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./empty-data-row"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./loading-rows"), exports);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoadingRows = LoadingRows;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
const material_2 = require("@mui/material");
|
|
7
|
+
const data_table_context_1 = require("../../contexts/data-table-context");
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
9
|
+
const slot_helpers_1 = require("../../utils/slot-helpers");
|
|
10
|
+
function LoadingRows({ rowCount = 5, slots, slotProps, }) {
|
|
11
|
+
const { table } = (0, data_table_context_1.useDataTableContext)();
|
|
12
|
+
const visibleColumns = table.getVisibleLeafColumns();
|
|
13
|
+
const CellSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'cell', material_1.TableCell);
|
|
14
|
+
const TableRowSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'row', material_1.TableRow);
|
|
15
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: Array.from({ length: rowCount }, (_, rowIndex) => ((0, jsx_runtime_1.jsx)(TableRowSlot, Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.row, { children: visibleColumns.map((column, colIndex) => {
|
|
16
|
+
var _a;
|
|
17
|
+
const isPinned = column.getIsPinned();
|
|
18
|
+
const pinnedPosition = isPinned ? column.getStart('left') : undefined;
|
|
19
|
+
const pinnedRightPosition = isPinned === 'right' ? column.getAfter('right') : undefined;
|
|
20
|
+
const columnMeta = (_a = column.columnDef) === null || _a === void 0 ? void 0 : _a.meta;
|
|
21
|
+
const isDateColumn = (columnMeta === null || columnMeta === void 0 ? void 0 : columnMeta.type) === 'date';
|
|
22
|
+
const isBooleanColumn = (columnMeta === null || columnMeta === void 0 ? void 0 : columnMeta.type) === 'boolean';
|
|
23
|
+
const isNumberColumn = (columnMeta === null || columnMeta === void 0 ? void 0 : columnMeta.type) === 'number';
|
|
24
|
+
const isSelectionColumn = column.id === 'select';
|
|
25
|
+
return ((0, jsx_runtime_1.jsx)(CellSlot, Object.assign({ sx: (0, utils_1.getPinnedColumnStyle)({
|
|
26
|
+
width: column.getSize() || 'auto',
|
|
27
|
+
isPinned,
|
|
28
|
+
pinnedPosition,
|
|
29
|
+
pinnedRightPosition,
|
|
30
|
+
zIndex: isPinned ? 9 : 1,
|
|
31
|
+
isLastLeftPinnedColumn: isPinned === 'left' && column.getIsLastColumn('left'),
|
|
32
|
+
isFirstRightPinnedColumn: isPinned === 'right' && column.getIsFirstColumn('right'),
|
|
33
|
+
}) }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.cell, { children: (() => {
|
|
34
|
+
if (isSelectionColumn) {
|
|
35
|
+
return ((0, jsx_runtime_1.jsx)(material_2.Skeleton, { variant: "rectangular", width: 20, height: 20 }));
|
|
36
|
+
}
|
|
37
|
+
if (isBooleanColumn) {
|
|
38
|
+
return ((0, jsx_runtime_1.jsx)(material_2.Skeleton, { variant: "circular", width: 20, height: 20 }));
|
|
39
|
+
}
|
|
40
|
+
if (isDateColumn) {
|
|
41
|
+
return ((0, jsx_runtime_1.jsx)(material_2.Skeleton, { variant: "text", width: "80%", height: 20, animation: "wave" }));
|
|
42
|
+
}
|
|
43
|
+
if (isNumberColumn) {
|
|
44
|
+
return ((0, jsx_runtime_1.jsx)(material_2.Skeleton, { variant: "text", width: "60%", height: 20, animation: "wave" }));
|
|
45
|
+
}
|
|
46
|
+
return ((0, jsx_runtime_1.jsx)(material_2.Skeleton, { variant: "text", width: `${Math.random() * 40 + 60}%`, height: 20, animation: "wave" }));
|
|
47
|
+
})() }), `skeleton-${column.id || colIndex}-${rowIndex}`));
|
|
48
|
+
}) }), `skeleton-row-${rowIndex}`))) }));
|
|
49
|
+
}
|
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataTable = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const material_1 = require("@mui/material");
|
|
7
|
+
const react_table_1 = require("@tanstack/react-table");
|
|
8
|
+
const custom_column_filter_feature_1 = require("../../features/custom-column-filter.feature");
|
|
9
|
+
const features_1 = require("../../features");
|
|
10
|
+
const react_virtual_1 = require("@tanstack/react-virtual");
|
|
11
|
+
const react_1 = require("react");
|
|
12
|
+
const data_table_context_1 = require("../../contexts/data-table-context");
|
|
13
|
+
const use_data_table_api_1 = require("../../hooks/use-data-table-api");
|
|
14
|
+
const utils_1 = require("../../utils");
|
|
15
|
+
const debounced_fetch_utils_1 = require("../../utils/debounced-fetch.utils");
|
|
16
|
+
const slot_helpers_1 = require("../../utils/slot-helpers");
|
|
17
|
+
const headers_1 = require("../headers");
|
|
18
|
+
const pagination_1 = require("../pagination");
|
|
19
|
+
const rows_1 = require("../rows");
|
|
20
|
+
const toolbar_1 = require("../toolbar");
|
|
21
|
+
const special_columns_utils_1 = require("../../utils/special-columns.utils");
|
|
22
|
+
const DEFAULT_INITIAL_STATE = {
|
|
23
|
+
sorting: [],
|
|
24
|
+
pagination: {
|
|
25
|
+
pageIndex: 0,
|
|
26
|
+
pageSize: 10,
|
|
27
|
+
},
|
|
28
|
+
rowSelection: {},
|
|
29
|
+
globalFilter: '',
|
|
30
|
+
expanded: {},
|
|
31
|
+
columnOrder: [],
|
|
32
|
+
columnPinning: {
|
|
33
|
+
left: [],
|
|
34
|
+
right: [],
|
|
35
|
+
},
|
|
36
|
+
customColumnFilter: {
|
|
37
|
+
filters: [],
|
|
38
|
+
logic: 'AND',
|
|
39
|
+
pendingFilters: [],
|
|
40
|
+
pendingLogic: 'AND',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
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 = null, enableColumnResizing = false, columnResizeMode = 'onChange', enableColumnDragging = false, onColumnDragEnd, enableColumnPinning = false, onColumnPinningChange, enableExpanding = false, getRowCanExpand, renderSubComponent, enablePagination = true, paginationMode = 'client', enableGlobalFilter = true, enableColumnFilter = false, filterMode = 'client', enableSorting = true, sortingMode = 'client', onSortingChange, exportFilename = 'export', onExportProgress, onExportComplete, onExportError, onServerExport, onExportCancel, enableHover = true, enableStripes = false, tableContainerProps = {}, tableProps = {}, fitToScreen = true, tableSize: initialTableSize = 'medium', enableStickyHeaderOrFooter = false, maxHeight = '400px', enableVirtualization = false, estimateRowHeight = 52, enableColumnVisibility = true, enableTableSizeControl = true, enableExport = true, enableReset = true, loading = false, emptyMessage = 'No data available', skeletonRows = 5, onColumnFiltersChange, onDataChange, slots = {}, slotProps = {}, }, ref) {
|
|
44
|
+
var _a;
|
|
45
|
+
const isServerMode = dataMode === 'server';
|
|
46
|
+
const isServerPagination = paginationMode === 'server' || isServerMode;
|
|
47
|
+
const isServerFiltering = filterMode === 'server' || isServerMode;
|
|
48
|
+
const isServerSorting = sortingMode === 'server' || isServerMode;
|
|
49
|
+
const tableContainerRef = (0, react_1.useRef)(null);
|
|
50
|
+
const initialStateConfig = (0, react_1.useMemo)(() => {
|
|
51
|
+
return Object.assign(Object.assign({}, DEFAULT_INITIAL_STATE), initialState);
|
|
52
|
+
}, [initialState]);
|
|
53
|
+
const [sorting, setSorting] = (0, react_1.useState)(initialStateConfig.sorting);
|
|
54
|
+
const [pagination, setPagination] = (0, react_1.useState)(initialStateConfig.pagination);
|
|
55
|
+
const [globalFilter, setGlobalFilter] = (0, react_1.useState)(initialStateConfig.globalFilter);
|
|
56
|
+
const [selectionState, setSelectionState] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.selectionState) || { ids: [], type: 'include' });
|
|
57
|
+
const [customColumnsFilter, setCustomColumnsFilter] = (0, react_1.useState)({
|
|
58
|
+
filters: [],
|
|
59
|
+
logic: 'AND',
|
|
60
|
+
pendingFilters: [],
|
|
61
|
+
pendingLogic: 'AND'
|
|
62
|
+
});
|
|
63
|
+
const [expanded, setExpanded] = (0, react_1.useState)(initialStateConfig.expanded);
|
|
64
|
+
const [tableSize, setTableSize] = (0, react_1.useState)(initialTableSize);
|
|
65
|
+
const [columnOrder, setColumnOrder] = (0, react_1.useState)(initialStateConfig.columnOrder);
|
|
66
|
+
const [columnPinning, setColumnPinning] = (0, react_1.useState)(initialStateConfig.columnPinning);
|
|
67
|
+
const internalApiRef = (0, react_1.useRef)(null);
|
|
68
|
+
const { debouncedFetch, isLoading: fetchLoading } = (0, debounced_fetch_utils_1.useDebouncedFetch)(onFetchData);
|
|
69
|
+
const [serverData, setServerData] = (0, react_1.useState)([]);
|
|
70
|
+
const [serverTotal, setServerTotal] = (0, react_1.useState)(0);
|
|
71
|
+
const fetchData = (0, react_1.useCallback)((...args_1) => tslib_1.__awaiter(this, [...args_1], void 0, function* (overrides = {}) {
|
|
72
|
+
if (!onFetchData)
|
|
73
|
+
return;
|
|
74
|
+
const filters = Object.assign({ globalFilter,
|
|
75
|
+
pagination,
|
|
76
|
+
customColumnsFilter,
|
|
77
|
+
sorting }, overrides);
|
|
78
|
+
const result = yield debouncedFetch(filters);
|
|
79
|
+
if ((result === null || result === void 0 ? void 0 : result.data) && (result === null || result === void 0 ? void 0 : result.total) !== undefined) {
|
|
80
|
+
setServerData(result.data);
|
|
81
|
+
setServerTotal(result.total);
|
|
82
|
+
}
|
|
83
|
+
}), [
|
|
84
|
+
onFetchData,
|
|
85
|
+
globalFilter,
|
|
86
|
+
pagination,
|
|
87
|
+
customColumnsFilter,
|
|
88
|
+
sorting,
|
|
89
|
+
debouncedFetch,
|
|
90
|
+
]);
|
|
91
|
+
const fetchDataRef = (0, react_1.useRef)(fetchData);
|
|
92
|
+
fetchDataRef.current = fetchData;
|
|
93
|
+
const tableData = (0, react_1.useMemo)(() => onFetchData ? serverData : data, [onFetchData, serverData, data]);
|
|
94
|
+
const tableTotalRow = (0, react_1.useMemo)(() => onFetchData ? serverTotal : totalRow, [onFetchData, serverTotal, totalRow]);
|
|
95
|
+
const tableLoading = (0, react_1.useMemo)(() => onFetchData ? (loading || fetchLoading) : loading, [onFetchData, loading, fetchLoading]);
|
|
96
|
+
const handleSelectionStateChange = (0, react_1.useCallback)((updaterOrValue) => {
|
|
97
|
+
setSelectionState((prevState) => {
|
|
98
|
+
const newSelectionState = typeof updaterOrValue === 'function'
|
|
99
|
+
? updaterOrValue(prevState)
|
|
100
|
+
: updaterOrValue;
|
|
101
|
+
if (onSelectionChange) {
|
|
102
|
+
onSelectionChange(newSelectionState);
|
|
103
|
+
}
|
|
104
|
+
return newSelectionState;
|
|
105
|
+
});
|
|
106
|
+
}, [onSelectionChange]);
|
|
107
|
+
const handleColumnFilterStateChange = (0, react_1.useCallback)((filterState) => {
|
|
108
|
+
if (filterState && typeof filterState === 'object') {
|
|
109
|
+
setCustomColumnsFilter(filterState);
|
|
110
|
+
if (onColumnFiltersChange) {
|
|
111
|
+
onColumnFiltersChange(filterState);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}, [
|
|
115
|
+
onColumnFiltersChange,
|
|
116
|
+
]);
|
|
117
|
+
const enhancedColumns = (0, react_1.useMemo)(() => {
|
|
118
|
+
let columnsMap = [...columns];
|
|
119
|
+
if (enableExpanding) {
|
|
120
|
+
const expandingColumnMap = (0, special_columns_utils_1.createExpandingColumn)(Object.assign({}, ((slotProps === null || slotProps === void 0 ? void 0 : slotProps.expandColumn) || {})));
|
|
121
|
+
columnsMap = [expandingColumnMap, ...columnsMap];
|
|
122
|
+
}
|
|
123
|
+
if (enableRowSelection) {
|
|
124
|
+
const selectionColumnMap = (0, special_columns_utils_1.createSelectionColumn)(Object.assign(Object.assign({}, ((slotProps === null || slotProps === void 0 ? void 0 : slotProps.selectionColumn) || {})), { multiSelect: enableMultiRowSelection }));
|
|
125
|
+
columnsMap = [selectionColumnMap, ...columnsMap];
|
|
126
|
+
}
|
|
127
|
+
return columnsMap;
|
|
128
|
+
}, [
|
|
129
|
+
columns,
|
|
130
|
+
slotProps === null || slotProps === void 0 ? void 0 : slotProps.selectionColumn,
|
|
131
|
+
slotProps === null || slotProps === void 0 ? void 0 : slotProps.expandColumn,
|
|
132
|
+
enableRowSelection,
|
|
133
|
+
enableExpanding,
|
|
134
|
+
enableMultiRowSelection,
|
|
135
|
+
]);
|
|
136
|
+
const notifyDataStateChange = (0, react_1.useCallback)((overrides = {}) => {
|
|
137
|
+
if (onDataStateChange) {
|
|
138
|
+
const currentState = Object.assign({ globalFilter,
|
|
139
|
+
customColumnsFilter,
|
|
140
|
+
sorting,
|
|
141
|
+
pagination,
|
|
142
|
+
columnOrder,
|
|
143
|
+
columnPinning }, overrides);
|
|
144
|
+
onDataStateChange(currentState);
|
|
145
|
+
}
|
|
146
|
+
}, [
|
|
147
|
+
onDataStateChange,
|
|
148
|
+
globalFilter,
|
|
149
|
+
customColumnsFilter,
|
|
150
|
+
sorting,
|
|
151
|
+
pagination,
|
|
152
|
+
columnOrder,
|
|
153
|
+
columnPinning,
|
|
154
|
+
]);
|
|
155
|
+
const stateChangeRef = (0, react_1.useRef)(notifyDataStateChange);
|
|
156
|
+
stateChangeRef.current = notifyDataStateChange;
|
|
157
|
+
const handleSortingChange = (0, react_1.useCallback)((updaterOrValue) => {
|
|
158
|
+
let newSorting = typeof updaterOrValue === 'function'
|
|
159
|
+
? updaterOrValue(sorting)
|
|
160
|
+
: updaterOrValue;
|
|
161
|
+
console.log('handleSortingChange', newSorting);
|
|
162
|
+
newSorting = newSorting.filter((sort) => sort.id);
|
|
163
|
+
setSorting(newSorting);
|
|
164
|
+
if (onSortingChange) {
|
|
165
|
+
onSortingChange(newSorting);
|
|
166
|
+
}
|
|
167
|
+
if (isServerMode || isServerSorting) {
|
|
168
|
+
stateChangeRef.current({ sorting: newSorting });
|
|
169
|
+
fetchDataRef === null || fetchDataRef === void 0 ? void 0 : fetchDataRef.current({
|
|
170
|
+
sorting: newSorting,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
else if (onDataStateChange) {
|
|
174
|
+
stateChangeRef.current({ sorting: newSorting });
|
|
175
|
+
}
|
|
176
|
+
}, [
|
|
177
|
+
sorting,
|
|
178
|
+
onSortingChange,
|
|
179
|
+
isServerMode,
|
|
180
|
+
isServerSorting,
|
|
181
|
+
onDataStateChange,
|
|
182
|
+
]);
|
|
183
|
+
const handleColumnOrderChange = (0, react_1.useCallback)((updatedColumnOrder) => {
|
|
184
|
+
setColumnOrder(updatedColumnOrder);
|
|
185
|
+
if (onColumnDragEnd) {
|
|
186
|
+
onColumnDragEnd(updatedColumnOrder);
|
|
187
|
+
}
|
|
188
|
+
}, [onColumnDragEnd]);
|
|
189
|
+
const handleColumnPinningChange = (0, react_1.useCallback)((updatedColumnPinning) => {
|
|
190
|
+
setColumnPinning(updatedColumnPinning);
|
|
191
|
+
if (onColumnPinningChange) {
|
|
192
|
+
onColumnPinningChange(updatedColumnPinning);
|
|
193
|
+
}
|
|
194
|
+
}, [onColumnPinningChange]);
|
|
195
|
+
const handlePaginationChange = (0, react_1.useCallback)((updater) => {
|
|
196
|
+
setPagination(updater);
|
|
197
|
+
const newPagination = typeof updater === 'function' ? updater(pagination) : updater;
|
|
198
|
+
if (isServerMode || isServerPagination) {
|
|
199
|
+
setTimeout(() => {
|
|
200
|
+
stateChangeRef.current({ pagination: newPagination });
|
|
201
|
+
fetchDataRef === null || fetchDataRef === void 0 ? void 0 : fetchDataRef.current({ pagination: newPagination });
|
|
202
|
+
}, 0);
|
|
203
|
+
}
|
|
204
|
+
else if (onDataStateChange) {
|
|
205
|
+
setTimeout(() => {
|
|
206
|
+
stateChangeRef.current({ pagination: newPagination });
|
|
207
|
+
}, 0);
|
|
208
|
+
}
|
|
209
|
+
}, [pagination, isServerMode, isServerPagination, onDataStateChange]);
|
|
210
|
+
const handleGlobalFilterChange = (0, react_1.useCallback)((updaterOrValue) => {
|
|
211
|
+
const newFilter = typeof updaterOrValue === 'function'
|
|
212
|
+
? updaterOrValue(globalFilter)
|
|
213
|
+
: updaterOrValue;
|
|
214
|
+
setGlobalFilter(newFilter);
|
|
215
|
+
if (isServerMode || isServerFiltering) {
|
|
216
|
+
stateChangeRef.current({ globalFilter: newFilter });
|
|
217
|
+
fetchDataRef === null || fetchDataRef === void 0 ? void 0 : fetchDataRef.current({ globalFilter: newFilter });
|
|
218
|
+
}
|
|
219
|
+
else if (onDataStateChange) {
|
|
220
|
+
stateChangeRef.current({ globalFilter: newFilter });
|
|
221
|
+
}
|
|
222
|
+
}, [globalFilter, isServerMode, isServerFiltering, onDataStateChange]);
|
|
223
|
+
const onCustomColumnFilterChangeHandler = (0, react_1.useCallback)((updater) => {
|
|
224
|
+
const currentState = customColumnsFilter;
|
|
225
|
+
const newState = typeof updater === 'function'
|
|
226
|
+
? updater(currentState)
|
|
227
|
+
: updater;
|
|
228
|
+
const legacyFilterState = {
|
|
229
|
+
filters: newState.filters,
|
|
230
|
+
logic: newState.logic,
|
|
231
|
+
pendingFilters: newState.pendingFilters,
|
|
232
|
+
pendingLogic: newState.pendingLogic
|
|
233
|
+
};
|
|
234
|
+
handleColumnFilterStateChange(legacyFilterState);
|
|
235
|
+
}, [customColumnsFilter, handleColumnFilterStateChange]);
|
|
236
|
+
const onCustomColumnFilterApplyHandler = (0, react_1.useCallback)((appliedState) => {
|
|
237
|
+
if (isServerFiltering) {
|
|
238
|
+
const serverFilterState = {
|
|
239
|
+
filters: appliedState.filters,
|
|
240
|
+
logic: appliedState.logic,
|
|
241
|
+
pendingFilters: appliedState.pendingFilters,
|
|
242
|
+
pendingLogic: appliedState.pendingLogic,
|
|
243
|
+
};
|
|
244
|
+
stateChangeRef.current({
|
|
245
|
+
customColumnsFilter: serverFilterState,
|
|
246
|
+
});
|
|
247
|
+
fetchDataRef === null || fetchDataRef === void 0 ? void 0 : fetchDataRef.current({
|
|
248
|
+
customColumnsFilter: serverFilterState,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}, [isServerFiltering]);
|
|
252
|
+
const table = (0, react_table_1.useReactTable)({
|
|
253
|
+
_features: [custom_column_filter_feature_1.CustomColumnFilterFeature, features_1.CustomSelectionFeature],
|
|
254
|
+
data: tableData,
|
|
255
|
+
columns: enhancedColumns,
|
|
256
|
+
initialState: Object.assign({}, initialStateConfig),
|
|
257
|
+
state: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ sorting }, (enablePagination ? { pagination } : {})), (enableGlobalFilter ? { globalFilter } : {})), (enableExpanding ? { expanded } : {})), (enableColumnDragging ? { columnOrder } : {})), (enableColumnPinning ? { columnPinning } : {})), (enableColumnFilter ? { customColumnFilter: customColumnsFilter } : {})), (enableRowSelection ? { selectionState } : {})),
|
|
258
|
+
selectMode: selectMode,
|
|
259
|
+
enableCustomSelection: !!enableRowSelection,
|
|
260
|
+
isRowSelectable: isRowSelectable,
|
|
261
|
+
onSelectionStateChange: enableRowSelection ? handleSelectionStateChange : undefined,
|
|
262
|
+
onSortingChange: enableSorting ? handleSortingChange : undefined,
|
|
263
|
+
onPaginationChange: enablePagination ? handlePaginationChange : undefined,
|
|
264
|
+
onRowSelectionChange: enableRowSelection ? handleSelectionStateChange : undefined,
|
|
265
|
+
onGlobalFilterChange: enableGlobalFilter ? handleGlobalFilterChange : undefined,
|
|
266
|
+
onExpandedChange: enableExpanding ? setExpanded : undefined,
|
|
267
|
+
onColumnOrderChange: enableColumnDragging ? handleColumnOrderChange : undefined,
|
|
268
|
+
onColumnPinningChange: enableColumnPinning ? handleColumnPinningChange : undefined,
|
|
269
|
+
onCustomColumnFilterChange: onCustomColumnFilterChangeHandler,
|
|
270
|
+
onCustomColumnFilterApply: onCustomColumnFilterApplyHandler,
|
|
271
|
+
getCoreRowModel: (0, react_table_1.getCoreRowModel)(),
|
|
272
|
+
getSortedRowModel: (enableSorting && !isServerSorting) ? (0, react_table_1.getSortedRowModel)() : undefined,
|
|
273
|
+
getFilteredRowModel: (enableColumnFilter && !isServerFiltering) ? (0, custom_column_filter_feature_1.getCombinedFilteredRowModel)() : undefined,
|
|
274
|
+
getPaginationRowModel: (enablePagination && !isServerPagination) ? (0, react_table_1.getPaginationRowModel)() : undefined,
|
|
275
|
+
enableSorting: enableSorting,
|
|
276
|
+
manualSorting: isServerSorting,
|
|
277
|
+
manualFiltering: isServerFiltering,
|
|
278
|
+
enableColumnResizing: enableColumnResizing,
|
|
279
|
+
columnResizeMode: columnResizeMode,
|
|
280
|
+
enableColumnPinning: enableColumnPinning,
|
|
281
|
+
getRowCanExpand: enableExpanding ? getRowCanExpand : undefined,
|
|
282
|
+
manualPagination: isServerPagination,
|
|
283
|
+
autoResetPageIndex: false,
|
|
284
|
+
rowCount: tableTotalRow,
|
|
285
|
+
getRowId: (row, index) => (0, utils_1.generateRowId)(row, index, idKey),
|
|
286
|
+
debugAll: false,
|
|
287
|
+
});
|
|
288
|
+
const rows = ((_a = table.getRowModel()) === null || _a === void 0 ? void 0 : _a.rows) || [];
|
|
289
|
+
const rowVirtualizer = (0, react_virtual_1.useVirtualizer)({
|
|
290
|
+
count: rows.length,
|
|
291
|
+
getScrollElement: () => tableContainerRef.current,
|
|
292
|
+
estimateSize: () => estimateRowHeight,
|
|
293
|
+
overscan: 10,
|
|
294
|
+
enabled: enableVirtualization && !enablePagination && rows.length > 0,
|
|
295
|
+
});
|
|
296
|
+
const tableWidth = (0, react_1.useMemo)(() => {
|
|
297
|
+
if (fitToScreen) {
|
|
298
|
+
return '100%';
|
|
299
|
+
}
|
|
300
|
+
if (enableColumnResizing) {
|
|
301
|
+
return table.getCenterTotalSize();
|
|
302
|
+
}
|
|
303
|
+
return '100%';
|
|
304
|
+
}, [
|
|
305
|
+
table,
|
|
306
|
+
enableColumnResizing,
|
|
307
|
+
fitToScreen,
|
|
308
|
+
]);
|
|
309
|
+
const tableStyle = (0, react_1.useMemo)(() => ({
|
|
310
|
+
width: tableWidth,
|
|
311
|
+
minWidth: '100%',
|
|
312
|
+
}), [tableWidth]);
|
|
313
|
+
const handleColumnReorder = (0, react_1.useCallback)((draggedColumnId, targetColumnId) => {
|
|
314
|
+
const currentOrder = columnOrder.length > 0 ? columnOrder : enhancedColumns.map((col, index) => {
|
|
315
|
+
if (col.id)
|
|
316
|
+
return col.id;
|
|
317
|
+
const anyCol = col;
|
|
318
|
+
if (anyCol.accessorKey && typeof anyCol.accessorKey === 'string') {
|
|
319
|
+
return anyCol.accessorKey;
|
|
320
|
+
}
|
|
321
|
+
return `column_${index}`;
|
|
322
|
+
});
|
|
323
|
+
const draggedIndex = currentOrder.indexOf(draggedColumnId);
|
|
324
|
+
const targetIndex = currentOrder.indexOf(targetColumnId);
|
|
325
|
+
if (draggedIndex === -1 || targetIndex === -1)
|
|
326
|
+
return;
|
|
327
|
+
const newOrder = [...currentOrder];
|
|
328
|
+
newOrder.splice(draggedIndex, 1);
|
|
329
|
+
newOrder.splice(targetIndex, 0, draggedColumnId);
|
|
330
|
+
handleColumnOrderChange(newOrder);
|
|
331
|
+
}, [columnOrder, enhancedColumns, handleColumnOrderChange]);
|
|
332
|
+
(0, react_1.useEffect)(() => {
|
|
333
|
+
if (initialLoadData && onFetchData) {
|
|
334
|
+
fetchDataRef.current();
|
|
335
|
+
}
|
|
336
|
+
}, [initialLoadData]);
|
|
337
|
+
(0, react_1.useEffect)(() => {
|
|
338
|
+
if (enableColumnDragging && columnOrder.length === 0) {
|
|
339
|
+
const initialOrder = enhancedColumns.map((col, index) => {
|
|
340
|
+
if (col.id)
|
|
341
|
+
return col.id;
|
|
342
|
+
const anyCol = col;
|
|
343
|
+
if (anyCol.accessorKey && typeof anyCol.accessorKey === 'string') {
|
|
344
|
+
return anyCol.accessorKey;
|
|
345
|
+
}
|
|
346
|
+
return `column_${index}`;
|
|
347
|
+
});
|
|
348
|
+
setColumnOrder(initialOrder);
|
|
349
|
+
}
|
|
350
|
+
}, [
|
|
351
|
+
enableColumnDragging,
|
|
352
|
+
enhancedColumns,
|
|
353
|
+
columnOrder.length,
|
|
354
|
+
]);
|
|
355
|
+
const LoadingRowSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'loadingRow', rows_1.LoadingRows);
|
|
356
|
+
const EmptyRowSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'emptyRow', rows_1.EmptyDataRow);
|
|
357
|
+
const renderTableRows = (0, react_1.useCallback)(() => {
|
|
358
|
+
var _a, _b, _c, _d;
|
|
359
|
+
if (tableLoading) {
|
|
360
|
+
return ((0, jsx_runtime_1.jsx)(LoadingRowSlot, Object.assign({ rowCount: enablePagination ? Math.min(pagination.pageSize, skeletonRows) : skeletonRows, colSpan: table.getAllColumns().length, slots: slots, slotProps: slotProps }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.loadingRow)));
|
|
361
|
+
}
|
|
362
|
+
if (rows.length === 0) {
|
|
363
|
+
return ((0, jsx_runtime_1.jsx)(EmptyRowSlot, Object.assign({ colSpan: table.getAllColumns().length, message: emptyMessage, slots: slots, slotProps: slotProps }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.emptyRow)));
|
|
364
|
+
}
|
|
365
|
+
if (enableVirtualization && !enablePagination && rows.length > 0) {
|
|
366
|
+
const virtualItems = rowVirtualizer.getVirtualItems();
|
|
367
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [virtualItems.length > 0 && ((0, jsx_runtime_1.jsx)("tr", { children: (0, jsx_runtime_1.jsx)("td", { colSpan: table.getAllColumns().length, style: {
|
|
368
|
+
height: `${(_b = (_a = virtualItems[0]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0}px`,
|
|
369
|
+
padding: 0,
|
|
370
|
+
border: 0,
|
|
371
|
+
} }) })), virtualItems.map((virtualRow) => {
|
|
372
|
+
const row = rows[virtualRow.index];
|
|
373
|
+
if (!row)
|
|
374
|
+
return null;
|
|
375
|
+
return ((0, jsx_runtime_1.jsx)(rows_1.DataTableRow, Object.assign({ row: row, enableHover: enableHover, enableStripes: enableStripes, isOdd: virtualRow.index % 2 === 1, renderSubComponent: renderSubComponent, disableStickyHeader: enableStickyHeaderOrFooter }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.row), row.id));
|
|
376
|
+
}), virtualItems.length > 0 && ((0, jsx_runtime_1.jsx)("tr", { children: (0, jsx_runtime_1.jsx)("td", { colSpan: table.getAllColumns().length, style: {
|
|
377
|
+
height: `${rowVirtualizer.getTotalSize() -
|
|
378
|
+
((_d = (_c = virtualItems[virtualItems.length - 1]) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : 0)}px`,
|
|
379
|
+
padding: 0,
|
|
380
|
+
border: 0,
|
|
381
|
+
} }) }))] }));
|
|
382
|
+
}
|
|
383
|
+
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)));
|
|
384
|
+
}, [
|
|
385
|
+
tableLoading,
|
|
386
|
+
rows,
|
|
387
|
+
enableVirtualization,
|
|
388
|
+
enablePagination,
|
|
389
|
+
LoadingRowSlot,
|
|
390
|
+
pagination.pageSize,
|
|
391
|
+
skeletonRows,
|
|
392
|
+
table,
|
|
393
|
+
slotProps,
|
|
394
|
+
EmptyRowSlot,
|
|
395
|
+
emptyMessage,
|
|
396
|
+
rowVirtualizer,
|
|
397
|
+
enableHover,
|
|
398
|
+
enableStripes,
|
|
399
|
+
renderSubComponent,
|
|
400
|
+
enableStickyHeaderOrFooter,
|
|
401
|
+
slots,
|
|
402
|
+
]);
|
|
403
|
+
const [exportController, setExportController] = (0, react_1.useState)(null);
|
|
404
|
+
const isExporting = (0, react_1.useMemo)(() => exportController !== null, [exportController]);
|
|
405
|
+
const handleCancelExport = (0, react_1.useCallback)(() => {
|
|
406
|
+
if (exportController) {
|
|
407
|
+
exportController.abort();
|
|
408
|
+
setExportController(null);
|
|
409
|
+
if (onExportCancel) {
|
|
410
|
+
onExportCancel();
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}, [exportController, onExportCancel]);
|
|
414
|
+
(0, use_data_table_api_1.useDataTableApi)({
|
|
415
|
+
table,
|
|
416
|
+
data: tableData,
|
|
417
|
+
idKey,
|
|
418
|
+
globalFilter,
|
|
419
|
+
customColumnsFilter,
|
|
420
|
+
sorting,
|
|
421
|
+
pagination,
|
|
422
|
+
columnOrder,
|
|
423
|
+
columnPinning,
|
|
424
|
+
enhancedColumns,
|
|
425
|
+
enablePagination,
|
|
426
|
+
enableColumnPinning,
|
|
427
|
+
initialPageIndex: pagination.pageIndex,
|
|
428
|
+
initialPageSize: pagination.pageSize,
|
|
429
|
+
pageSize: pagination.pageSize,
|
|
430
|
+
selectMode,
|
|
431
|
+
onSelectionChange: handleSelectionStateChange,
|
|
432
|
+
handleColumnFilterStateChange,
|
|
433
|
+
onDataStateChange,
|
|
434
|
+
onFetchData: onFetchData,
|
|
435
|
+
onDataChange,
|
|
436
|
+
exportFilename,
|
|
437
|
+
onExportProgress,
|
|
438
|
+
onExportComplete,
|
|
439
|
+
onExportError,
|
|
440
|
+
onServerExport,
|
|
441
|
+
exportController,
|
|
442
|
+
setExportController,
|
|
443
|
+
isExporting,
|
|
444
|
+
dataMode,
|
|
445
|
+
}, internalApiRef);
|
|
446
|
+
(0, react_1.useImperativeHandle)(ref, () => internalApiRef.current, []);
|
|
447
|
+
const isSomeRowsSelected = (0, react_1.useMemo)(() => {
|
|
448
|
+
if (!enableBulkActions || !enableRowSelection)
|
|
449
|
+
return false;
|
|
450
|
+
if (selectionState.type === 'exclude') {
|
|
451
|
+
return selectionState.ids.length < tableTotalRow;
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
return selectionState.ids.length > 0;
|
|
455
|
+
}
|
|
456
|
+
}, [enableBulkActions, enableRowSelection, selectionState, tableTotalRow]);
|
|
457
|
+
const selectedRowCount = (0, react_1.useMemo)(() => {
|
|
458
|
+
if (!enableBulkActions || !enableRowSelection)
|
|
459
|
+
return 0;
|
|
460
|
+
if (selectionState.type === 'exclude') {
|
|
461
|
+
return tableTotalRow - selectionState.ids.length;
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
return selectionState.ids.length;
|
|
465
|
+
}
|
|
466
|
+
}, [enableBulkActions, enableRowSelection, selectionState, tableTotalRow]);
|
|
467
|
+
const RootSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'root', material_1.Box);
|
|
468
|
+
const ToolbarSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'toolbar', toolbar_1.DataTableToolbar);
|
|
469
|
+
const BulkActionsSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'bulkActionsToolbar', toolbar_1.BulkActionsToolbar);
|
|
470
|
+
const TableContainerSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'tableContainer', material_1.TableContainer);
|
|
471
|
+
const TableSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'table', material_1.Table);
|
|
472
|
+
const BodySlot = (0, slot_helpers_1.getSlotComponent)(slots, 'body', material_1.TableBody);
|
|
473
|
+
const FooterSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'footer', material_1.Box);
|
|
474
|
+
const PaginationSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'pagination', pagination_1.DataTablePagination);
|
|
475
|
+
return ((0, jsx_runtime_1.jsx)(data_table_context_1.DataTableProvider, { table: table, children: (0, jsx_runtime_1.jsxs)(RootSlot, Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.root, { children: [(enableGlobalFilter || extraFilter) ? ((0, jsx_runtime_1.jsx)(ToolbarSlot, Object.assign({ extraFilter: extraFilter, enableGlobalFilter: enableGlobalFilter, enableColumnVisibility: enableColumnVisibility, enableColumnFilter: enableColumnFilter, enableExport: enableExport, enableReset: enableReset, enableTableSizeControl: enableTableSizeControl, enableColumnPinning: enableColumnPinning }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.toolbar))) : null, enableBulkActions && enableRowSelection && isSomeRowsSelected ? ((0, jsx_runtime_1.jsx)(BulkActionsSlot, Object.assign({ selectionState: selectionState, selectedRowCount: selectedRowCount, bulkActions: bulkActions, sx: {
|
|
476
|
+
position: 'relative',
|
|
477
|
+
zIndex: 2,
|
|
478
|
+
} }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.bulkActionsToolbar))) : null, (0, jsx_runtime_1.jsx)(TableContainerSlot, Object.assign({ component: material_1.Paper, ref: tableContainerRef, sx: Object.assign(Object.assign(Object.assign({ width: '100%', overflowX: 'auto' }, (enableStickyHeaderOrFooter && {
|
|
479
|
+
maxHeight: maxHeight,
|
|
480
|
+
overflowY: 'auto',
|
|
481
|
+
})), (enableVirtualization && {
|
|
482
|
+
maxHeight: maxHeight,
|
|
483
|
+
overflowY: 'auto',
|
|
484
|
+
})), tableContainerProps === null || tableContainerProps === void 0 ? void 0 : tableContainerProps.sx) }, tableContainerProps, slotProps === null || slotProps === void 0 ? void 0 : slotProps.tableContainer, { children: (0, jsx_runtime_1.jsxs)(TableSlot, Object.assign({ size: tableSize, stickyHeader: enableStickyHeaderOrFooter, style: Object.assign(Object.assign(Object.assign({}, tableStyle), { tableLayout: fitToScreen ? 'fixed' : 'auto' }), tableProps === null || tableProps === void 0 ? void 0 : tableProps.style) }, tableProps, slotProps === null || slotProps === void 0 ? void 0 : slotProps.table, { children: [(0, jsx_runtime_1.jsx)(headers_1.TableHeader, { draggable: enableColumnDragging, enableColumnResizing: enableColumnResizing, enableStickyHeader: enableStickyHeaderOrFooter, fitToScreen: fitToScreen, onColumnReorder: handleColumnReorder, slots: slots, slotProps: slotProps }), (0, jsx_runtime_1.jsx)(BodySlot, Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.body, { children: renderTableRows() }))] })) })), enablePagination ? ((0, jsx_runtime_1.jsx)(FooterSlot, Object.assign({ sx: Object.assign({}, (enableStickyHeaderOrFooter && {
|
|
485
|
+
position: 'sticky',
|
|
486
|
+
bottom: 0,
|
|
487
|
+
backgroundColor: 'background.paper',
|
|
488
|
+
borderTop: '1px solid',
|
|
489
|
+
borderColor: 'divider',
|
|
490
|
+
zIndex: 1,
|
|
491
|
+
})) }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.footer, { children: (0, jsx_runtime_1.jsx)(PaginationSlot, Object.assign({ footerFilter: footerFilter }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.pagination, { pagination: pagination, totalRow: tableTotalRow })) }))) : null] })) }));
|
|
492
|
+
});
|