@ackplus/react-tanstack-data-table 1.0.19-beta-0.6 → 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/package.json +3 -11
- package/{index.js → src/index.d.ts} +3 -26
- 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/{lib → src/lib}/components/filters/index.js +6 -2
- package/src/lib/components/headers/draggable-header.d.ts +12 -0
- package/{lib → src/lib}/components/headers/draggable-header.js +35 -49
- package/{lib/components/headers/index.js → src/lib/components/headers/index.d.ts} +0 -3
- 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/{lib/components/rows/index.js → src/lib/components/rows/index.d.ts} +0 -3
- 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/{lib/components/table/index.js → src/lib/components/table/index.d.ts} +0 -3
- 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/{lib/components/toolbar/index.js → src/lib/components/toolbar/index.d.ts} +1 -6
- 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/{lib → src/lib}/contexts/data-table-context.js +12 -8
- 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/{lib → src/lib}/examples/custom-column-filter-example.js +10 -10
- 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/{lib → src/lib}/examples/simple-local-example.js +14 -18
- package/src/lib/features/custom-column-filter.feature.d.ts +45 -0
- package/{lib → src/lib}/features/custom-column-filter.feature.js +40 -99
- package/src/lib/features/custom-selection.feature.d.ts +46 -0
- package/{lib → src/lib}/features/custom-selection.feature.js +18 -70
- 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/{lib → src/lib}/hooks/use-data-table-api.js +79 -136
- 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.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/{lib → src/lib}/utils/debounced-fetch.utils.js +15 -17
- package/src/lib/utils/export-utils.d.ts +30 -0
- package/src/lib/utils/export-utils.js +152 -0
- package/{lib/utils/index.js → src/lib/utils/index.d.ts} +0 -10
- 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/{lib → src/lib}/utils/table-helpers.js +16 -31
- package/tsconfig.tsbuildinfo +1 -0
- package/LICENSE +0 -21
- package/index.d.ts.map +0 -1
- package/lib/components/droupdown/menu-dropdown.d.ts.map +0 -1
- package/lib/components/droupdown/menu-dropdown.js +0 -47
- package/lib/components/export-progress-dialog.d.ts.map +0 -1
- package/lib/components/export-progress-dialog.js +0 -30
- package/lib/components/filters/filter-value-input.d.ts.map +0 -1
- package/lib/components/filters/filter-value-input.js +0 -64
- package/lib/components/filters/index.d.ts.map +0 -1
- package/lib/components/headers/draggable-header.d.ts.map +0 -1
- package/lib/components/headers/index.d.ts.map +0 -1
- package/lib/components/headers/table-header.d.ts.map +0 -1
- package/lib/components/headers/table-header.js +0 -59
- package/lib/components/index.d.ts.map +0 -1
- package/lib/components/index.js +0 -18
- package/lib/components/pagination/data-table-pagination.d.ts.map +0 -1
- package/lib/components/pagination/data-table-pagination.js +0 -24
- package/lib/components/pagination/index.d.ts.map +0 -1
- package/lib/components/pagination/index.js +0 -4
- package/lib/components/rows/data-table-row.d.ts.map +0 -1
- package/lib/components/rows/data-table-row.js +0 -42
- package/lib/components/rows/empty-data-row.d.ts.map +0 -1
- package/lib/components/rows/empty-data-row.js +0 -8
- package/lib/components/rows/index.d.ts.map +0 -1
- package/lib/components/rows/loading-rows.d.ts.map +0 -1
- package/lib/components/rows/loading-rows.js +0 -46
- package/lib/components/table/data-table.d.ts.map +0 -1
- package/lib/components/table/data-table.js +0 -663
- package/lib/components/table/data-table.types.d.ts.map +0 -1
- package/lib/components/table/data-table.types.js +0 -6
- package/lib/components/table/index.d.ts.map +0 -1
- package/lib/components/toolbar/bulk-actions-toolbar.d.ts.map +0 -1
- package/lib/components/toolbar/bulk-actions-toolbar.js +0 -31
- package/lib/components/toolbar/column-custom-filter-control.d.ts.map +0 -1
- package/lib/components/toolbar/column-custom-filter-control.js +0 -149
- package/lib/components/toolbar/column-custum-filter-control.d.ts.map +0 -1
- package/lib/components/toolbar/column-custum-filter-control.js +0 -150
- package/lib/components/toolbar/column-pinning-control.d.ts.map +0 -1
- package/lib/components/toolbar/column-pinning-control.js +0 -103
- package/lib/components/toolbar/column-reset-control.d.ts.map +0 -1
- package/lib/components/toolbar/column-reset-control.js +0 -13
- package/lib/components/toolbar/column-visibility-control.d.ts.map +0 -1
- package/lib/components/toolbar/column-visibility-control.js +0 -27
- package/lib/components/toolbar/data-table-toolbar.d.ts.map +0 -1
- package/lib/components/toolbar/data-table-toolbar.js +0 -23
- package/lib/components/toolbar/index.d.ts.map +0 -1
- package/lib/components/toolbar/table-export-control.d.ts.map +0 -1
- package/lib/components/toolbar/table-export-control.js +0 -94
- package/lib/components/toolbar/table-search-control.d.ts.map +0 -1
- package/lib/components/toolbar/table-search-control.js +0 -61
- package/lib/components/toolbar/table-size-control.d.ts.map +0 -1
- package/lib/components/toolbar/table-size-control.js +0 -33
- package/lib/contexts/data-table-context.d.ts.map +0 -1
- package/lib/examples/advanced-features-example.d.ts.map +0 -1
- package/lib/examples/advanced-features-example.js +0 -282
- package/lib/examples/basic-example.d.ts.map +0 -1
- package/lib/examples/basic-example.js +0 -323
- package/lib/examples/bulk-actions-test.d.ts.map +0 -1
- package/lib/examples/bulk-actions-test.js +0 -47
- package/lib/examples/crud-api-example.d.ts.map +0 -1
- package/lib/examples/crud-api-example.js +0 -321
- package/lib/examples/custom-column-filter-example.d.ts.map +0 -1
- package/lib/examples/custom-selection-example.d.ts.map +0 -1
- package/lib/examples/custom-selection-example.js +0 -184
- package/lib/examples/export-callbacks-example.d.ts.map +0 -1
- package/lib/examples/export-callbacks-example.js +0 -155
- package/lib/examples/improved-export-example.d.ts.map +0 -1
- package/lib/examples/improved-export-example.js +0 -153
- package/lib/examples/improved-server-selection-example.d.ts.map +0 -1
- package/lib/examples/improved-server-selection-example.js +0 -118
- package/lib/examples/index.d.ts.map +0 -1
- package/lib/examples/selection-test-example.d.ts.map +0 -1
- package/lib/examples/selection-test-example.js +0 -111
- package/lib/examples/simple-local-example.d.ts.map +0 -1
- package/lib/examples/simple-server-selection-example.d.ts.map +0 -1
- package/lib/examples/simple-server-selection-example.js +0 -178
- package/lib/examples/virtualized-example.d.ts.map +0 -1
- package/lib/examples/virtualized-example.js +0 -119
- package/lib/features/custom-column-filter.feature.d.ts.map +0 -1
- package/lib/features/custom-selection.feature.d.ts.map +0 -1
- package/lib/features/index.d.ts.map +0 -1
- package/lib/features/index.js +0 -9
- package/lib/hooks/index.d.ts.map +0 -1
- package/lib/hooks/index.js +0 -6
- package/lib/hooks/use-data-table-api.d.ts.map +0 -1
- package/lib/hooks/use-table-state.d.ts.map +0 -1
- package/lib/hooks/use-table-state.js +0 -74
- package/lib/icons/add-icon.d.ts.map +0 -1
- package/lib/icons/add-icon.js +0 -5
- package/lib/icons/csv-icon.d.ts.map +0 -1
- package/lib/icons/csv-icon.js +0 -5
- package/lib/icons/delete-icon.d.ts.map +0 -1
- package/lib/icons/delete-icon.js +0 -5
- package/lib/icons/excel-icon.d.ts.map +0 -1
- package/lib/icons/excel-icon.js +0 -5
- package/lib/icons/index.d.ts.map +0 -1
- package/lib/icons/unpin-icon.d.ts.map +0 -1
- package/lib/icons/unpin-icon.js +0 -5
- package/lib/icons/view-comfortable-icon.d.ts.map +0 -1
- package/lib/icons/view-comfortable-icon.js +0 -5
- package/lib/icons/view-compact-icon.d.ts.map +0 -1
- package/lib/icons/view-compact-icon.js +0 -5
- package/lib/types/column.types.d.ts.map +0 -1
- package/lib/types/column.types.js +0 -2
- package/lib/types/data-table-api.d.ts.map +0 -1
- package/lib/types/data-table-api.js +0 -1
- package/lib/types/export.types.d.ts.map +0 -1
- package/lib/types/export.types.js +0 -5
- package/lib/types/hooks.types.d.ts.map +0 -1
- package/lib/types/hooks.types.js +0 -1
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/index.js +0 -14
- package/lib/types/slots.types.d.ts.map +0 -1
- package/lib/types/slots.types.js +0 -1
- package/lib/types/table.types.d.ts.map +0 -1
- package/lib/types/table.types.js +0 -1
- package/lib/utils/column-helpers.d.ts.map +0 -1
- package/lib/utils/column-helpers.js +0 -46
- package/lib/utils/debounced-fetch.utils.d.ts.map +0 -1
- package/lib/utils/export-utils.d.ts.map +0 -1
- package/lib/utils/export-utils.js +0 -181
- package/lib/utils/index.d.ts.map +0 -1
- package/lib/utils/selection-helpers.d.ts.map +0 -1
- package/lib/utils/selection-helpers.js +0 -162
- package/lib/utils/slot-helpers.d.ts.map +0 -1
- package/lib/utils/slot-helpers.js +0 -27
- package/lib/utils/special-columns.utils.d.ts.map +0 -1
- package/lib/utils/special-columns.utils.js +0 -77
- package/lib/utils/styling-helpers.d.ts.map +0 -1
- package/lib/utils/styling-helpers.js +0 -97
- package/lib/utils/table-helpers.d.ts.map +0 -1
- package/lib/utils/value-helpers.d.ts.map +0 -1
- package/lib/utils/value-helpers.js +0 -48
- package/tsconfig.lib.tsbuildinfo +0 -1
- /package/{lib/examples/index.js → src/lib/examples/index.d.ts} +0 -0
- /package/{lib/icons/index.js → src/lib/icons/index.d.ts} +0 -0
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Row, SortingState, ColumnResizeMode, ColumnPinningState, RowData } from '@tanstack/react-table';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import type { CustomColumnFilterState, TableFilters, TableState } from '../../types';
|
|
4
|
+
import { DataTableColumn } from '../../types';
|
|
5
|
+
import { DataTableSlots, PartialSlotProps } from '../../types/slots.types';
|
|
6
|
+
import { DataTableSize } from '../../utils/table-helpers';
|
|
7
|
+
import { SelectionState } from '../../features/custom-selection.feature';
|
|
8
|
+
export type SelectMode = 'page' | 'all';
|
|
9
|
+
declare module '@tanstack/table-core' {
|
|
10
|
+
interface ColumnMeta<TData extends RowData, TValue> {
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export interface DataTableProps<T> {
|
|
14
|
+
columns: DataTableColumn<T>[];
|
|
15
|
+
data?: T[];
|
|
16
|
+
totalRow?: number;
|
|
17
|
+
idKey?: keyof T;
|
|
18
|
+
extraFilter?: ReactNode | null;
|
|
19
|
+
footerFilter?: ReactNode | null;
|
|
20
|
+
dataMode?: 'client' | 'server';
|
|
21
|
+
initialState?: Partial<TableState>;
|
|
22
|
+
initialLoadData?: boolean;
|
|
23
|
+
onDataStateChange?: (filters: Partial<TableState>) => void;
|
|
24
|
+
onFetchData?: (filters: Partial<TableFilters>) => Promise<{
|
|
25
|
+
data: T[];
|
|
26
|
+
total: number;
|
|
27
|
+
}>;
|
|
28
|
+
exportFilename?: string;
|
|
29
|
+
onExportProgress?: (progress: {
|
|
30
|
+
processedRows: number;
|
|
31
|
+
totalRows: number;
|
|
32
|
+
percentage: number;
|
|
33
|
+
}) => void;
|
|
34
|
+
onExportComplete?: (result: {
|
|
35
|
+
success: boolean;
|
|
36
|
+
filename: string;
|
|
37
|
+
totalRows: number;
|
|
38
|
+
}) => void;
|
|
39
|
+
onExportError?: (error: {
|
|
40
|
+
message: string;
|
|
41
|
+
code: string;
|
|
42
|
+
}) => void;
|
|
43
|
+
onServerExport?: (filters?: Partial<TableState>, selection?: SelectionState) => Promise<{
|
|
44
|
+
data: any[];
|
|
45
|
+
total: number;
|
|
46
|
+
}>;
|
|
47
|
+
onExportCancel?: () => void;
|
|
48
|
+
enableRowSelection?: boolean | ((row: Row<T>) => boolean);
|
|
49
|
+
enableMultiRowSelection?: boolean;
|
|
50
|
+
selectMode?: SelectMode;
|
|
51
|
+
isRowSelectable?: (params: {
|
|
52
|
+
row: T;
|
|
53
|
+
id: string;
|
|
54
|
+
}) => boolean;
|
|
55
|
+
onRowSelectionChange?: (selectedRows: T[], selection?: SelectionState) => void;
|
|
56
|
+
onSelectionChange?: (selection: SelectionState) => void;
|
|
57
|
+
enableBulkActions?: boolean;
|
|
58
|
+
bulkActions?: (selectionState: SelectionState) => ReactNode;
|
|
59
|
+
enableColumnResizing?: boolean;
|
|
60
|
+
columnResizeMode?: ColumnResizeMode;
|
|
61
|
+
enableColumnDragging?: boolean;
|
|
62
|
+
onColumnDragEnd?: (columnOrder: string[]) => void;
|
|
63
|
+
enableColumnPinning?: boolean;
|
|
64
|
+
onColumnPinningChange?: (pinning: ColumnPinningState) => void;
|
|
65
|
+
enableExpanding?: boolean;
|
|
66
|
+
getRowCanExpand?: (row: Row<T>) => boolean;
|
|
67
|
+
renderSubComponent?: (row: Row<T>) => ReactNode;
|
|
68
|
+
enablePagination?: boolean;
|
|
69
|
+
paginationMode?: 'client' | 'server';
|
|
70
|
+
enableGlobalFilter?: boolean;
|
|
71
|
+
enableColumnFilter?: boolean;
|
|
72
|
+
filterMode?: 'client' | 'server';
|
|
73
|
+
enableSorting?: boolean;
|
|
74
|
+
sortingMode?: 'client' | 'server';
|
|
75
|
+
onSortingChange?: (sorting: SortingState) => void;
|
|
76
|
+
enableHover?: boolean;
|
|
77
|
+
enableStripes?: boolean;
|
|
78
|
+
tableContainerProps?: any;
|
|
79
|
+
tableProps?: any;
|
|
80
|
+
fitToScreen?: boolean;
|
|
81
|
+
tableSize?: DataTableSize;
|
|
82
|
+
enableStickyHeaderOrFooter?: boolean;
|
|
83
|
+
maxHeight?: string | number;
|
|
84
|
+
enableVirtualization?: boolean;
|
|
85
|
+
estimateRowHeight?: number;
|
|
86
|
+
enableColumnVisibility?: boolean;
|
|
87
|
+
enableTableSizeControl?: boolean;
|
|
88
|
+
enableExport?: boolean;
|
|
89
|
+
enableReset?: boolean;
|
|
90
|
+
loading?: boolean;
|
|
91
|
+
emptyMessage?: string;
|
|
92
|
+
skeletonRows?: number;
|
|
93
|
+
onColumnFiltersChange?: (filterState: CustomColumnFilterState) => void;
|
|
94
|
+
onDataChange?: (data: T[]) => void;
|
|
95
|
+
selectionColumn?: {
|
|
96
|
+
width?: number;
|
|
97
|
+
pinLeft?: boolean;
|
|
98
|
+
customColumn?: DataTableColumn<any>;
|
|
99
|
+
id?: string;
|
|
100
|
+
};
|
|
101
|
+
actionColumn?: {
|
|
102
|
+
pinRight?: boolean;
|
|
103
|
+
customColumn?: DataTableColumn<any>;
|
|
104
|
+
id?: string;
|
|
105
|
+
};
|
|
106
|
+
expandingColumn?: {
|
|
107
|
+
width?: number;
|
|
108
|
+
pinLeft?: boolean;
|
|
109
|
+
customColumn?: DataTableColumn<any>;
|
|
110
|
+
id?: string;
|
|
111
|
+
};
|
|
112
|
+
slots?: Partial<DataTableSlots<T>>;
|
|
113
|
+
slotProps?: PartialSlotProps<T>;
|
|
114
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { SelectionState } from '../../features/custom-selection.feature';
|
|
3
|
+
export interface BulkActionsToolbarProps<T = any> {
|
|
4
|
+
selectionState: SelectionState;
|
|
5
|
+
selectedRowCount: number;
|
|
6
|
+
bulkActions?: (selectionState: SelectionState) => ReactNode;
|
|
7
|
+
sx?: any;
|
|
8
|
+
}
|
|
9
|
+
export declare function BulkActionsToolbar<T = any>({ selectionState, selectedRowCount, bulkActions, sx, }: BulkActionsToolbarProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BulkActionsToolbar = BulkActionsToolbar;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const data_table_context_1 = require("../../contexts/data-table-context");
|
|
8
|
+
const slot_helpers_1 = require("../../utils/slot-helpers");
|
|
9
|
+
function BulkActionsToolbar({ selectionState, selectedRowCount, bulkActions, sx, }) {
|
|
10
|
+
const { slots, slotProps } = (0, data_table_context_1.useDataTableContext)();
|
|
11
|
+
const ToolbarSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'toolbar', material_1.Toolbar);
|
|
12
|
+
const renderedBulkActions = (0, react_1.useMemo)(() => {
|
|
13
|
+
if (!bulkActions)
|
|
14
|
+
return null;
|
|
15
|
+
return bulkActions(selectionState);
|
|
16
|
+
}, [bulkActions, selectionState]);
|
|
17
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Fade, { in: selectedRowCount > 0, children: (0, jsx_runtime_1.jsxs)(ToolbarSlot, Object.assign({ sx: Object.assign({ pl: { sm: 2 }, pr: {
|
|
18
|
+
xs: 1,
|
|
19
|
+
sm: 1,
|
|
20
|
+
}, bgcolor: (theme) => (0, material_1.alpha)(theme.palette.primary.main, 0.05), mb: 1, position: 'relative', zIndex: 1 }, sx) }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.bulkActionsToolbar, { children: [(0, jsx_runtime_1.jsx)(material_1.Box, { sx: { flex: '1 1 100%' }, children: (0, jsx_runtime_1.jsx)(material_1.Typography, { color: "inherit", variant: "subtitle1", component: "div", children: (0, jsx_runtime_1.jsx)(material_1.Chip, { label: `${selectedRowCount} selected`, size: "small", color: "primary", variant: "outlined" }) }) }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
21
|
+
display: 'flex',
|
|
22
|
+
alignItems: 'center',
|
|
23
|
+
gap: 1,
|
|
24
|
+
}, children: renderedBulkActions })] })) }));
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ColumnCustomFilterControl(): import("react/jsx-runtime").JSX.Element;
|