@ackplus/react-tanstack-data-table 1.0.34 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/{src → dist}/index.d.ts +21 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -0
- package/{src → dist}/lib/components/droupdown/menu-dropdown.d.ts +2 -1
- package/dist/lib/components/droupdown/menu-dropdown.d.ts.map +1 -0
- package/{src → dist}/lib/components/droupdown/menu-dropdown.js +38 -7
- package/{src → dist}/lib/components/filters/filter-value-input.d.ts +3 -1
- package/dist/lib/components/filters/filter-value-input.d.ts.map +1 -0
- package/dist/lib/components/filters/filter-value-input.js +83 -0
- package/{src → dist}/lib/components/filters/index.d.ts +1 -0
- package/dist/lib/components/filters/index.d.ts.map +1 -0
- package/dist/lib/components/filters/index.js +142 -0
- package/{src → dist}/lib/components/headers/draggable-header.d.ts +2 -2
- package/dist/lib/components/headers/draggable-header.d.ts.map +1 -0
- package/{src → dist}/lib/components/headers/draggable-header.js +81 -17
- package/dist/lib/components/headers/index.d.ts +6 -0
- package/dist/lib/components/headers/index.d.ts.map +1 -0
- package/dist/lib/components/headers/index.js +21 -0
- package/{src → dist}/lib/components/headers/table-header.d.ts +15 -1
- package/dist/lib/components/headers/table-header.d.ts.map +1 -0
- package/{src → dist}/lib/components/headers/table-header.js +50 -17
- package/{src → dist}/lib/components/index.d.ts +6 -1
- package/dist/lib/components/index.d.ts.map +1 -0
- package/dist/lib/components/index.js +32 -0
- package/{src → dist}/lib/components/pagination/data-table-pagination.d.ts +2 -1
- package/dist/lib/components/pagination/data-table-pagination.d.ts.map +1 -0
- package/{src → dist}/lib/components/pagination/data-table-pagination.js +20 -6
- package/dist/lib/components/pagination/index.d.ts +5 -0
- package/dist/lib/components/pagination/index.d.ts.map +1 -0
- package/dist/lib/components/pagination/index.js +20 -0
- package/{src → dist}/lib/components/rows/data-table-row.d.ts +15 -2
- package/dist/lib/components/rows/data-table-row.d.ts.map +1 -0
- package/{src → dist}/lib/components/rows/data-table-row.js +58 -25
- package/{src → dist}/lib/components/rows/empty-data-row.d.ts +3 -3
- package/dist/lib/components/rows/empty-data-row.d.ts.map +1 -0
- package/{src → dist}/lib/components/rows/empty-data-row.js +12 -4
- package/dist/lib/components/rows/index.d.ts +7 -0
- package/dist/lib/components/rows/index.d.ts.map +1 -0
- package/dist/lib/components/rows/index.js +22 -0
- package/{src → dist}/lib/components/rows/loading-rows.d.ts +3 -1
- package/dist/lib/components/rows/loading-rows.d.ts.map +1 -0
- package/{src → dist}/lib/components/rows/loading-rows.js +27 -19
- package/{src → dist}/lib/components/toolbar/bulk-actions-toolbar.d.ts +4 -3
- package/dist/lib/components/toolbar/bulk-actions-toolbar.d.ts.map +1 -0
- package/dist/lib/components/toolbar/bulk-actions-toolbar.js +49 -0
- package/{src → dist}/lib/components/toolbar/column-filter-control.d.ts +3 -1
- package/dist/lib/components/toolbar/column-filter-control.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/column-filter-control.js +73 -4
- package/{src → dist}/lib/components/toolbar/column-pinning-control.d.ts +2 -1
- package/dist/lib/components/toolbar/column-pinning-control.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/column-pinning-control.js +71 -7
- package/{src → dist}/lib/components/toolbar/column-reset-control.d.ts +3 -1
- package/dist/lib/components/toolbar/column-reset-control.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/column-reset-control.js +9 -3
- package/{src → dist}/lib/components/toolbar/column-visibility-control.d.ts +2 -1
- package/dist/lib/components/toolbar/column-visibility-control.d.ts.map +1 -0
- package/dist/lib/components/toolbar/column-visibility-control.js +77 -0
- package/{src → dist}/lib/components/toolbar/data-table-toolbar.d.ts +3 -2
- package/dist/lib/components/toolbar/data-table-toolbar.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/data-table-toolbar.js +17 -4
- package/{src → dist}/lib/components/toolbar/index.d.ts +4 -0
- package/dist/lib/components/toolbar/index.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/index.js +6 -0
- package/dist/lib/components/toolbar/table-export-control.d.ts +12 -0
- package/dist/lib/components/toolbar/table-export-control.d.ts.map +1 -0
- package/dist/lib/components/toolbar/table-export-control.js +67 -0
- package/{src → dist}/lib/components/toolbar/table-search-control.d.ts +3 -1
- package/dist/lib/components/toolbar/table-search-control.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/table-search-control.js +45 -2
- package/{src → dist}/lib/components/toolbar/table-size-control.d.ts +3 -1
- package/dist/lib/components/toolbar/table-size-control.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/table-size-control.js +20 -8
- package/{src → dist}/lib/contexts/data-table-context.d.ts +6 -2
- package/dist/lib/contexts/data-table-context.d.ts.map +1 -0
- package/{src → dist}/lib/contexts/data-table-context.js +34 -1
- package/dist/lib/data-table.d.ts +5 -0
- package/dist/lib/data-table.d.ts.map +1 -0
- package/{src/lib/components/table → dist/lib}/data-table.js +449 -151
- package/dist/lib/features/column-filter.feature.d.ts +55 -0
- package/dist/lib/features/column-filter.feature.d.ts.map +1 -0
- package/{src → dist}/lib/features/column-filter.feature.js +116 -18
- package/dist/lib/features/index.d.ts +9 -0
- package/dist/lib/features/index.d.ts.map +1 -0
- package/{src → dist}/lib/features/index.js +7 -0
- package/{src → dist}/lib/features/selection.feature.d.ts +8 -1
- package/dist/lib/features/selection.feature.d.ts.map +1 -0
- package/{src → dist}/lib/features/selection.feature.js +76 -15
- package/dist/lib/icons/add-icon.d.ts +4 -0
- package/dist/lib/icons/add-icon.d.ts.map +1 -0
- package/dist/lib/icons/add-icon.js +12 -0
- package/dist/lib/icons/csv-icon.d.ts +4 -0
- package/dist/lib/icons/csv-icon.d.ts.map +1 -0
- package/dist/lib/icons/csv-icon.js +12 -0
- package/dist/lib/icons/delete-icon.d.ts +4 -0
- package/dist/lib/icons/delete-icon.d.ts.map +1 -0
- package/dist/lib/icons/delete-icon.js +12 -0
- package/dist/lib/icons/excel-icon.d.ts +4 -0
- package/dist/lib/icons/excel-icon.d.ts.map +1 -0
- package/dist/lib/icons/excel-icon.js +12 -0
- package/dist/lib/icons/index.d.ts +8 -0
- package/dist/lib/icons/index.d.ts.map +1 -0
- package/dist/lib/icons/unpin-icon.d.ts +4 -0
- package/dist/lib/icons/unpin-icon.d.ts.map +1 -0
- package/dist/lib/icons/unpin-icon.js +12 -0
- package/{src → dist}/lib/icons/view-comfortable-icon.d.ts +3 -1
- package/dist/lib/icons/view-comfortable-icon.d.ts.map +1 -0
- package/dist/lib/icons/view-comfortable-icon.js +12 -0
- package/dist/lib/icons/view-compact-icon.d.ts +4 -0
- package/dist/lib/icons/view-compact-icon.d.ts.map +1 -0
- package/dist/lib/icons/view-compact-icon.js +12 -0
- package/{src → dist}/lib/types/column.types.d.ts +10 -1
- package/dist/lib/types/column.types.d.ts.map +1 -0
- package/{src → dist}/lib/types/data-table-api.d.ts +2 -1
- package/dist/lib/types/data-table-api.d.ts.map +1 -0
- package/{src/lib/components/table → dist/lib/types}/data-table.types.d.ts +10 -10
- package/dist/lib/types/data-table.types.d.ts.map +1 -0
- package/{src → dist}/lib/types/export.types.d.ts +38 -0
- package/dist/lib/types/export.types.d.ts.map +1 -0
- package/dist/lib/types/export.types.js +6 -0
- package/{src → dist}/lib/types/index.d.ts +5 -0
- package/dist/lib/types/index.d.ts.map +1 -0
- package/dist/lib/types/index.js +30 -0
- package/{src → dist}/lib/types/slots.types.d.ts +50 -3
- package/dist/lib/types/slots.types.d.ts.map +1 -0
- package/{src → dist}/lib/types/table.types.d.ts +14 -0
- package/dist/lib/types/table.types.d.ts.map +1 -0
- package/{src → dist}/lib/utils/column-helpers.d.ts +10 -0
- package/dist/lib/utils/column-helpers.d.ts.map +1 -0
- package/{src → dist}/lib/utils/column-helpers.js +20 -4
- package/{src → dist}/lib/utils/debounced-fetch.utils.d.ts +3 -5
- package/dist/lib/utils/debounced-fetch.utils.d.ts.map +1 -0
- package/{src → dist}/lib/utils/debounced-fetch.utils.js +12 -6
- package/{src → dist}/lib/utils/export-utils.d.ts +13 -0
- package/dist/lib/utils/export-utils.d.ts.map +1 -0
- package/dist/lib/utils/export-utils.js +252 -0
- package/{src → dist}/lib/utils/index.d.ts +4 -0
- package/dist/lib/utils/index.d.ts.map +1 -0
- package/dist/lib/utils/index.js +35 -0
- package/{src → dist}/lib/utils/logger.d.ts +43 -0
- package/dist/lib/utils/logger.d.ts.map +1 -0
- package/{src → dist}/lib/utils/logger.js +22 -2
- package/{src → dist}/lib/utils/slot-helpers.d.ts +39 -1
- package/dist/lib/utils/slot-helpers.d.ts.map +1 -0
- package/{src → dist}/lib/utils/slot-helpers.js +55 -6
- package/{src → dist}/lib/utils/special-columns.utils.d.ts +10 -0
- package/dist/lib/utils/special-columns.utils.d.ts.map +1 -0
- package/{src → dist}/lib/utils/special-columns.utils.js +41 -5
- package/{src → dist}/lib/utils/styling-helpers.d.ts +20 -0
- package/dist/lib/utils/styling-helpers.d.ts.map +1 -0
- package/dist/lib/utils/styling-helpers.js +108 -0
- package/{src → dist}/lib/utils/table-helpers.d.ts +25 -0
- package/dist/lib/utils/table-helpers.d.ts.map +1 -0
- package/{src → dist}/lib/utils/table-helpers.js +24 -0
- package/package.json +36 -11
- package/src/index.ts +71 -0
- package/src/lib/components/droupdown/menu-dropdown.tsx +97 -0
- package/src/lib/components/filters/filter-value-input.tsx +225 -0
- package/src/lib/components/filters/{index.js → index.ts} +3 -6
- package/src/lib/components/headers/draggable-header.tsx +326 -0
- package/src/lib/components/headers/{index.d.ts → index.ts} +4 -0
- package/src/lib/components/headers/table-header.tsx +173 -0
- package/src/lib/components/index.ts +21 -0
- package/src/lib/components/pagination/data-table-pagination.tsx +99 -0
- package/src/lib/components/pagination/index.ts +5 -0
- package/src/lib/components/rows/data-table-row.tsx +208 -0
- package/src/lib/components/rows/empty-data-row.tsx +69 -0
- package/src/lib/components/rows/{index.d.ts → index.ts} +4 -0
- package/src/lib/components/rows/loading-rows.tsx +160 -0
- package/src/lib/components/toolbar/bulk-actions-toolbar.tsx +125 -0
- package/src/lib/components/toolbar/column-filter-control.tsx +374 -0
- package/src/lib/components/toolbar/column-pinning-control.tsx +275 -0
- package/src/lib/components/toolbar/column-reset-control.tsx +74 -0
- package/src/lib/components/toolbar/column-visibility-control.tsx +105 -0
- package/src/lib/components/toolbar/data-table-toolbar.tsx +229 -0
- package/src/lib/components/toolbar/index.ts +17 -0
- package/src/lib/components/toolbar/table-export-control.tsx +179 -0
- package/src/lib/components/toolbar/table-search-control.tsx +155 -0
- package/src/lib/components/toolbar/table-size-control.tsx +102 -0
- package/src/lib/contexts/data-table-context.tsx +112 -0
- package/src/lib/data-table.tsx +1911 -0
- package/src/lib/features/README.md +161 -0
- package/src/lib/features/column-filter.feature.ts +456 -0
- package/src/lib/features/index.ts +23 -0
- package/src/lib/features/selection.feature.ts +318 -0
- package/src/lib/icons/add-icon.tsx +23 -0
- package/src/lib/icons/csv-icon.tsx +15 -0
- package/src/lib/icons/delete-icon.tsx +30 -0
- package/src/lib/icons/excel-icon.tsx +15 -0
- package/src/lib/icons/unpin-icon.tsx +18 -0
- package/src/lib/icons/view-comfortable-icon.tsx +45 -0
- package/src/lib/icons/view-compact-icon.tsx +55 -0
- package/src/lib/types/column.types.ts +44 -0
- package/src/lib/types/data-table-api.ts +169 -0
- package/src/lib/types/data-table.types.ts +139 -0
- package/src/lib/types/export.types.ts +154 -0
- package/src/lib/types/index.ts +22 -0
- package/src/lib/types/slots.types.ts +332 -0
- package/src/lib/types/table.types.ts +90 -0
- package/src/lib/utils/column-helpers.ts +72 -0
- package/src/lib/utils/debounced-fetch.utils.ts +54 -0
- package/src/lib/utils/export-utils.ts +285 -0
- package/src/lib/utils/index.ts +27 -0
- package/src/lib/utils/logger.ts +203 -0
- package/src/lib/utils/slot-helpers.tsx +194 -0
- package/src/lib/utils/special-columns.utils.ts +94 -0
- package/src/lib/utils/styling-helpers.ts +126 -0
- package/src/lib/utils/table-helpers.ts +106 -0
- package/src/index.js +0 -27
- package/src/lib/components/filters/filter-value-input.js +0 -41
- package/src/lib/components/headers/index.js +0 -5
- package/src/lib/components/index.js +0 -10
- package/src/lib/components/pagination/index.d.ts +0 -1
- package/src/lib/components/pagination/index.js +0 -4
- package/src/lib/components/rows/index.js +0 -6
- package/src/lib/components/table/data-table.d.ts +0 -4
- package/src/lib/components/table/index.d.ts +0 -2
- package/src/lib/components/table/index.js +0 -5
- package/src/lib/components/toolbar/bulk-actions-toolbar.js +0 -30
- package/src/lib/components/toolbar/column-visibility-control.js +0 -31
- package/src/lib/components/toolbar/table-export-control.d.ts +0 -31
- package/src/lib/components/toolbar/table-export-control.js +0 -56
- package/src/lib/examples/advanced-features-example.d.ts +0 -1
- package/src/lib/examples/advanced-features-example.js +0 -269
- package/src/lib/examples/bulk-actions-test.d.ts +0 -1
- package/src/lib/examples/bulk-actions-test.js +0 -44
- package/src/lib/examples/custom-column-filter-example.d.ts +0 -1
- package/src/lib/examples/custom-column-filter-example.js +0 -60
- package/src/lib/examples/index.d.ts +0 -8
- package/src/lib/examples/index.js +0 -19
- package/src/lib/examples/selection-test-example.d.ts +0 -1
- package/src/lib/examples/selection-test-example.js +0 -101
- package/src/lib/examples/server-side-fetching-example.d.ts +0 -1
- package/src/lib/examples/server-side-fetching-example.js +0 -245
- package/src/lib/examples/server-side-test.d.ts +0 -1
- package/src/lib/examples/server-side-test.js +0 -9
- package/src/lib/examples/simple-local-example.d.ts +0 -1
- package/src/lib/examples/simple-local-example.js +0 -95
- package/src/lib/examples/simple-slots-example.d.ts +0 -1
- package/src/lib/examples/simple-slots-example.js +0 -115
- package/src/lib/features/column-filter.feature.d.ts +0 -45
- package/src/lib/features/index.d.ts +0 -2
- package/src/lib/hooks/index.d.ts +0 -1
- package/src/lib/hooks/index.js +0 -4
- package/src/lib/hooks/use-data-table-api.d.ts +0 -46
- package/src/lib/hooks/use-data-table-api.js +0 -690
- package/src/lib/icons/add-icon.d.ts +0 -2
- package/src/lib/icons/add-icon.js +0 -8
- package/src/lib/icons/csv-icon.d.ts +0 -2
- package/src/lib/icons/csv-icon.js +0 -8
- package/src/lib/icons/delete-icon.d.ts +0 -2
- package/src/lib/icons/delete-icon.js +0 -8
- package/src/lib/icons/excel-icon.d.ts +0 -2
- package/src/lib/icons/excel-icon.js +0 -8
- package/src/lib/icons/unpin-icon.d.ts +0 -2
- package/src/lib/icons/unpin-icon.js +0 -8
- package/src/lib/icons/view-comfortable-icon.js +0 -8
- package/src/lib/icons/view-compact-icon.d.ts +0 -2
- package/src/lib/icons/view-compact-icon.js +0 -8
- package/src/lib/types/export.types.js +0 -2
- package/src/lib/types/index.js +0 -8
- package/src/lib/utils/export-utils.js +0 -175
- package/src/lib/utils/index.js +0 -11
- package/src/lib/utils/styling-helpers.js +0 -70
- package/tsconfig.tsbuildinfo +0 -1
- /package/{src → dist}/lib/icons/index.js +0 -0
- /package/{src → dist}/lib/types/column.types.js +0 -0
- /package/{src → dist}/lib/types/data-table-api.js +0 -0
- /package/{src/lib/components/table → dist/lib/types}/data-table.types.js +0 -0
- /package/{src → dist}/lib/types/slots.types.js +0 -0
- /package/{src → dist}/lib/types/table.types.js +0 -0
- /package/src/lib/icons/{index.d.ts → index.ts} +0 -0
|
@@ -1,23 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.DataTable = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
37
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
38
|
+
/**
|
|
39
|
+
* Main DataTable Component
|
|
40
|
+
*
|
|
41
|
+
* A comprehensive, highly customizable data table component built with:
|
|
42
|
+
* - Material-UI (MUI) for styling
|
|
43
|
+
* - TanStack Table for table logic
|
|
44
|
+
* - TypeScript for type safety
|
|
45
|
+
*/
|
|
6
46
|
const material_1 = require("@mui/material");
|
|
7
47
|
const react_table_1 = require("@tanstack/react-table");
|
|
8
|
-
|
|
9
|
-
const
|
|
48
|
+
// Import custom features
|
|
49
|
+
const column_filter_feature_1 = require("./features/column-filter.feature");
|
|
50
|
+
const features_1 = require("./features");
|
|
10
51
|
const react_virtual_1 = require("@tanstack/react-virtual");
|
|
11
|
-
const react_1 = require("react");
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
52
|
+
const react_1 = __importStar(require("react"));
|
|
53
|
+
// Import from new organized structure
|
|
54
|
+
const data_table_context_1 = require("./contexts/data-table-context");
|
|
55
|
+
const utils_1 = require("./utils");
|
|
56
|
+
const debounced_fetch_utils_1 = require("./utils/debounced-fetch.utils");
|
|
57
|
+
const slot_helpers_1 = require("./utils/slot-helpers");
|
|
58
|
+
const headers_1 = require("./components/headers");
|
|
59
|
+
const pagination_1 = require("./components/pagination");
|
|
60
|
+
const rows_1 = require("./components/rows");
|
|
61
|
+
const toolbar_1 = require("./components/toolbar");
|
|
62
|
+
const special_columns_utils_1 = require("./utils/special-columns.utils");
|
|
63
|
+
// Static default initial state - defined outside component
|
|
21
64
|
const DEFAULT_INITIAL_STATE = {
|
|
22
65
|
sorting: [],
|
|
23
66
|
pagination: {
|
|
@@ -41,8 +84,51 @@ const DEFAULT_INITIAL_STATE = {
|
|
|
41
84
|
pendingLogic: 'AND',
|
|
42
85
|
},
|
|
43
86
|
};
|
|
44
|
-
|
|
45
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Main DataTable component with all features
|
|
89
|
+
*/
|
|
90
|
+
exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, columns, data = [], totalRow = 0, idKey = 'id', extraFilter = null, footerFilter = null,
|
|
91
|
+
// Data management mode (MUI DataGrid style)
|
|
92
|
+
dataMode = 'client', initialLoadData = true, onFetchData, onDataStateChange,
|
|
93
|
+
// Selection props
|
|
94
|
+
enableRowSelection = false, enableMultiRowSelection = true, selectMode = 'page', isRowSelectable, onSelectionChange,
|
|
95
|
+
// Row click props
|
|
96
|
+
onRowClick, selectOnRowClick = false,
|
|
97
|
+
// Bulk action props
|
|
98
|
+
enableBulkActions = false, bulkActions,
|
|
99
|
+
// Column resizing props
|
|
100
|
+
enableColumnResizing = false, columnResizeMode = 'onChange', onColumnSizingChange,
|
|
101
|
+
// Column ordering props
|
|
102
|
+
enableColumnDragging = false, onColumnDragEnd,
|
|
103
|
+
// Column pinning props
|
|
104
|
+
enableColumnPinning = false, onColumnPinningChange,
|
|
105
|
+
// Column visibility props
|
|
106
|
+
onColumnVisibilityChange, enableColumnVisibility = true,
|
|
107
|
+
// Expandable rows props
|
|
108
|
+
enableExpanding = false, getRowCanExpand, renderSubComponent,
|
|
109
|
+
// Pagination props
|
|
110
|
+
enablePagination = false, paginationMode = 'client',
|
|
111
|
+
// Filtering props
|
|
112
|
+
enableGlobalFilter = true, enableColumnFilter = false, filterMode = 'client',
|
|
113
|
+
// Sorting props
|
|
114
|
+
enableSorting = true, sortingMode = 'client', onSortingChange, exportFilename = 'export', onExportProgress, onExportComplete, onExportError, onServerExport, onExportCancel,
|
|
115
|
+
// Styling props
|
|
116
|
+
enableHover = true, enableStripes = false, tableProps = {}, fitToScreen = true, tableSize: initialTableSize = 'medium',
|
|
117
|
+
// Sticky header/footer props
|
|
118
|
+
enableStickyHeaderOrFooter = false, maxHeight = '400px',
|
|
119
|
+
// Virtualization props
|
|
120
|
+
enableVirtualization = false, estimateRowHeight = 52,
|
|
121
|
+
// Toolbar props
|
|
122
|
+
enableTableSizeControl = true, enableExport = false, enableReset = true,
|
|
123
|
+
// Loading and empty states
|
|
124
|
+
loading = false, emptyMessage = 'No data available', skeletonRows = 5,
|
|
125
|
+
// Column filters props
|
|
126
|
+
onColumnFiltersChange, onPaginationChange, onGlobalFilterChange,
|
|
127
|
+
// Slots
|
|
128
|
+
slots = {}, slotProps = {},
|
|
129
|
+
// Logging
|
|
130
|
+
logging, }, ref) {
|
|
131
|
+
// Convert mode-based props to boolean flags for internal use
|
|
46
132
|
const isServerMode = dataMode === 'server';
|
|
47
133
|
const isServerPagination = paginationMode === 'server' || isServerMode;
|
|
48
134
|
const isServerFiltering = filterMode === 'server' || isServerMode;
|
|
@@ -63,13 +149,26 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
63
149
|
}
|
|
64
150
|
};
|
|
65
151
|
}, [logger, dataMode, paginationMode, filterMode, sortingMode]);
|
|
152
|
+
// -------------------------------
|
|
153
|
+
// Memoized values (grouped together)
|
|
154
|
+
// -------------------------------
|
|
66
155
|
const initialStateConfig = (0, react_1.useMemo)(() => {
|
|
67
|
-
const config =
|
|
156
|
+
const config = {
|
|
157
|
+
...DEFAULT_INITIAL_STATE,
|
|
158
|
+
...initialState,
|
|
159
|
+
};
|
|
68
160
|
if (logger.isLevelEnabled('info')) {
|
|
69
161
|
logger.info('initialStateConfig', { config });
|
|
70
162
|
}
|
|
71
163
|
return config;
|
|
72
164
|
}, [initialState, logger]);
|
|
165
|
+
const initialSelectionState = (0, react_1.useMemo)(() => {
|
|
166
|
+
return initialStateConfig.selectionState || DEFAULT_INITIAL_STATE.selectionState;
|
|
167
|
+
}, [initialStateConfig.selectionState]);
|
|
168
|
+
// -------------------------------
|
|
169
|
+
// State hooks (grouped together)
|
|
170
|
+
// -------------------------------
|
|
171
|
+
// const [fetchLoading, setFetchLoading] = useState(false);
|
|
73
172
|
const [sorting, setSorting] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.sorting) || DEFAULT_INITIAL_STATE.sorting);
|
|
74
173
|
const [pagination, setPagination] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.pagination) || DEFAULT_INITIAL_STATE.pagination);
|
|
75
174
|
const [globalFilter, setGlobalFilter] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.globalFilter) || DEFAULT_INITIAL_STATE.globalFilter);
|
|
@@ -84,20 +183,28 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
84
183
|
const [serverData, setServerData] = (0, react_1.useState)(null);
|
|
85
184
|
const [serverTotal, setServerTotal] = (0, react_1.useState)(0);
|
|
86
185
|
const [exportController, setExportController] = (0, react_1.useState)(null);
|
|
186
|
+
// -------------------------------
|
|
187
|
+
// Ref hooks (grouped together)
|
|
188
|
+
// -------------------------------
|
|
87
189
|
const tableContainerRef = (0, react_1.useRef)(null);
|
|
88
190
|
const internalApiRef = (0, react_1.useRef)(null);
|
|
89
191
|
const { debouncedFetch, isLoading: fetchLoading } = (0, debounced_fetch_utils_1.useDebouncedFetch)(onFetchData);
|
|
90
|
-
const tableData = (0, react_1.useMemo)(() => serverData ? serverData : data, [
|
|
91
|
-
const tableTotalRow = (0, react_1.useMemo)(() => serverData ? serverTotal : totalRow, [
|
|
192
|
+
const tableData = (0, react_1.useMemo)(() => serverData ? serverData : data, [serverData, data]);
|
|
193
|
+
const tableTotalRow = (0, react_1.useMemo)(() => serverData ? serverTotal : totalRow || data.length, [serverData, serverTotal, totalRow, data]);
|
|
92
194
|
const tableLoading = (0, react_1.useMemo)(() => onFetchData ? (loading || fetchLoading) : loading, [onFetchData, loading, fetchLoading]);
|
|
93
195
|
const enhancedColumns = (0, react_1.useMemo)(() => {
|
|
94
196
|
let columnsMap = [...columns];
|
|
95
197
|
if (enableExpanding) {
|
|
96
|
-
const expandingColumnMap = (0, special_columns_utils_1.createExpandingColumn)(
|
|
198
|
+
const expandingColumnMap = (0, special_columns_utils_1.createExpandingColumn)({
|
|
199
|
+
...((slotProps === null || slotProps === void 0 ? void 0 : slotProps.expandColumn) && typeof slotProps.expandColumn === 'object' ? slotProps.expandColumn : {}),
|
|
200
|
+
});
|
|
97
201
|
columnsMap = [expandingColumnMap, ...columnsMap];
|
|
98
202
|
}
|
|
99
203
|
if (enableRowSelection) {
|
|
100
|
-
const selectionColumnMap = (0, special_columns_utils_1.createSelectionColumn)(
|
|
204
|
+
const selectionColumnMap = (0, special_columns_utils_1.createSelectionColumn)({
|
|
205
|
+
...((slotProps === null || slotProps === void 0 ? void 0 : slotProps.selectionColumn) && typeof slotProps.selectionColumn === 'object' ? slotProps.selectionColumn : {}),
|
|
206
|
+
multiSelect: enableMultiRowSelection,
|
|
207
|
+
});
|
|
101
208
|
columnsMap = [selectionColumnMap, ...columnsMap];
|
|
102
209
|
}
|
|
103
210
|
const enhancedColumns = (0, utils_1.withIdsDeep)(columnsMap);
|
|
@@ -105,7 +212,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
105
212
|
logger.info('enhancedColumns', { enhancedColumns });
|
|
106
213
|
}
|
|
107
214
|
return enhancedColumns;
|
|
108
|
-
}, [columns, enableExpanding, enableRowSelection,
|
|
215
|
+
}, [columns, enableExpanding, enableRowSelection, logger, slotProps.expandColumn, slotProps.selectionColumn, enableMultiRowSelection]);
|
|
109
216
|
const isExporting = (0, react_1.useMemo)(() => exportController !== null, [exportController]);
|
|
110
217
|
const isSomeRowsSelected = (0, react_1.useMemo)(() => {
|
|
111
218
|
if (!enableBulkActions || !enableRowSelection)
|
|
@@ -127,23 +234,10 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
127
234
|
return selectionState.ids.length;
|
|
128
235
|
}
|
|
129
236
|
}, [enableBulkActions, enableRowSelection, selectionState, tableTotalRow]);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (enableColumnResizing) {
|
|
135
|
-
return table.getCenterTotalSize();
|
|
136
|
-
}
|
|
137
|
-
return '100%';
|
|
138
|
-
}, [
|
|
139
|
-
fitToScreen,
|
|
140
|
-
enableColumnResizing,
|
|
141
|
-
]);
|
|
142
|
-
const tableStyle = (0, react_1.useMemo)(() => ({
|
|
143
|
-
width: tableWidth,
|
|
144
|
-
minWidth: '100%',
|
|
145
|
-
}), [tableWidth]);
|
|
146
|
-
const fetchData = (0, react_1.useCallback)((...args_1) => tslib_1.__awaiter(this, [...args_1], void 0, function* (overrides = {}) {
|
|
237
|
+
// -------------------------------
|
|
238
|
+
// Callback hooks (grouped together)
|
|
239
|
+
// -------------------------------
|
|
240
|
+
const fetchData = (0, react_1.useCallback)(async (overrides = {}) => {
|
|
147
241
|
var _a, _b;
|
|
148
242
|
if (!onFetchData) {
|
|
149
243
|
if (logger.isLevelEnabled('debug')) {
|
|
@@ -151,15 +245,18 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
151
245
|
}
|
|
152
246
|
return;
|
|
153
247
|
}
|
|
154
|
-
const filters =
|
|
248
|
+
const filters = {
|
|
249
|
+
globalFilter,
|
|
155
250
|
pagination,
|
|
156
251
|
columnFilter,
|
|
157
|
-
sorting
|
|
252
|
+
sorting,
|
|
253
|
+
...overrides,
|
|
254
|
+
};
|
|
158
255
|
if (logger.isLevelEnabled('info')) {
|
|
159
256
|
logger.info('Requesting data', { filters });
|
|
160
257
|
}
|
|
161
258
|
try {
|
|
162
|
-
const result =
|
|
259
|
+
const result = await debouncedFetch(filters);
|
|
163
260
|
if (logger.isLevelEnabled('info')) {
|
|
164
261
|
logger.info('Fetch resolved', {
|
|
165
262
|
rows: (_b = (_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0,
|
|
@@ -179,7 +276,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
179
276
|
logger.error('Fetch failed', error);
|
|
180
277
|
throw error;
|
|
181
278
|
}
|
|
182
|
-
}
|
|
279
|
+
}, [
|
|
183
280
|
onFetchData,
|
|
184
281
|
globalFilter,
|
|
185
282
|
pagination,
|
|
@@ -188,24 +285,6 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
188
285
|
debouncedFetch,
|
|
189
286
|
logger,
|
|
190
287
|
]);
|
|
191
|
-
const handleSelectionStateChange = (0, react_1.useCallback)((updaterOrValue) => {
|
|
192
|
-
setSelectionState((prevState) => {
|
|
193
|
-
const newSelectionState = typeof updaterOrValue === 'function'
|
|
194
|
-
? updaterOrValue(prevState)
|
|
195
|
-
: updaterOrValue;
|
|
196
|
-
setTimeout(() => {
|
|
197
|
-
if (onSelectionChange) {
|
|
198
|
-
onSelectionChange(newSelectionState);
|
|
199
|
-
}
|
|
200
|
-
}, 0);
|
|
201
|
-
return newSelectionState;
|
|
202
|
-
});
|
|
203
|
-
}, [onSelectionChange]);
|
|
204
|
-
const handleColumnFilterStateChange = (0, react_1.useCallback)((filterState) => {
|
|
205
|
-
if (filterState && typeof filterState === 'object') {
|
|
206
|
-
setColumnFilter(filterState);
|
|
207
|
-
}
|
|
208
|
-
}, [onColumnFiltersChange]);
|
|
209
288
|
const tableStateChange = (0, react_1.useCallback)((overrides = {}) => {
|
|
210
289
|
if (!onDataStateChange) {
|
|
211
290
|
if (logger.isLevelEnabled('debug')) {
|
|
@@ -213,14 +292,17 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
213
292
|
}
|
|
214
293
|
return;
|
|
215
294
|
}
|
|
216
|
-
const currentState =
|
|
295
|
+
const currentState = {
|
|
296
|
+
globalFilter,
|
|
217
297
|
columnFilter,
|
|
218
298
|
sorting,
|
|
219
299
|
pagination,
|
|
220
300
|
columnOrder,
|
|
221
301
|
columnPinning,
|
|
222
302
|
columnVisibility,
|
|
223
|
-
columnSizing
|
|
303
|
+
columnSizing,
|
|
304
|
+
...overrides,
|
|
305
|
+
};
|
|
224
306
|
if (logger.isLevelEnabled('debug')) {
|
|
225
307
|
logger.debug('Emitting tableStateChange', currentState);
|
|
226
308
|
}
|
|
@@ -237,6 +319,45 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
237
319
|
columnSizing,
|
|
238
320
|
logger,
|
|
239
321
|
]);
|
|
322
|
+
const handleSelectionStateChange = (0, react_1.useCallback)((updaterOrValue) => {
|
|
323
|
+
setSelectionState((prevState) => {
|
|
324
|
+
const newSelectionState = typeof updaterOrValue === 'function'
|
|
325
|
+
? updaterOrValue(prevState)
|
|
326
|
+
: updaterOrValue;
|
|
327
|
+
setTimeout(() => {
|
|
328
|
+
if (onSelectionChange) {
|
|
329
|
+
onSelectionChange(newSelectionState);
|
|
330
|
+
}
|
|
331
|
+
if (onDataStateChange) {
|
|
332
|
+
tableStateChange({ selectionState: newSelectionState });
|
|
333
|
+
}
|
|
334
|
+
}, 0);
|
|
335
|
+
return newSelectionState;
|
|
336
|
+
});
|
|
337
|
+
}, [onSelectionChange, onDataStateChange, tableStateChange]);
|
|
338
|
+
const handleColumnFilterStateChange = (0, react_1.useCallback)((filterState) => {
|
|
339
|
+
if (!filterState || typeof filterState !== 'object')
|
|
340
|
+
return;
|
|
341
|
+
setColumnFilter(filterState);
|
|
342
|
+
if (onColumnFiltersChange) {
|
|
343
|
+
setTimeout(() => onColumnFiltersChange(filterState), 0);
|
|
344
|
+
}
|
|
345
|
+
if (onDataStateChange) {
|
|
346
|
+
setTimeout(() => tableStateChange({ columnFilter: filterState }), 0);
|
|
347
|
+
}
|
|
348
|
+
}, [onColumnFiltersChange, onDataStateChange, tableStateChange]);
|
|
349
|
+
const resetPageToFirst = (0, react_1.useCallback)(() => {
|
|
350
|
+
if (logger.isLevelEnabled('info')) {
|
|
351
|
+
logger.info('Resetting to first page due to state change', {
|
|
352
|
+
previousPageIndex: pagination.pageIndex,
|
|
353
|
+
pageSize: pagination.pageSize,
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
const newPagination = { pageIndex: 0, pageSize: pagination.pageSize };
|
|
357
|
+
setPagination(newPagination);
|
|
358
|
+
onPaginationChange === null || onPaginationChange === void 0 ? void 0 : onPaginationChange(newPagination);
|
|
359
|
+
return newPagination;
|
|
360
|
+
}, [pagination, logger, onPaginationChange]);
|
|
240
361
|
const handleSortingChange = (0, react_1.useCallback)((updaterOrValue) => {
|
|
241
362
|
let newSorting = typeof updaterOrValue === 'function'
|
|
242
363
|
? updaterOrValue(sorting)
|
|
@@ -271,16 +392,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
271
392
|
tableStateChange({ sorting: newSorting, pagination });
|
|
272
393
|
}, 0);
|
|
273
394
|
}
|
|
274
|
-
}, [
|
|
275
|
-
sorting,
|
|
276
|
-
onSortingChange,
|
|
277
|
-
fetchData,
|
|
278
|
-
isServerMode,
|
|
279
|
-
isServerSorting,
|
|
280
|
-
onDataStateChange,
|
|
281
|
-
tableStateChange,
|
|
282
|
-
logger,
|
|
283
|
-
]);
|
|
395
|
+
}, [sorting, onSortingChange, logger, isServerMode, isServerSorting, onDataStateChange, resetPageToFirst, tableStateChange, fetchData]);
|
|
284
396
|
const handleColumnOrderChange = (0, react_1.useCallback)((updatedColumnOrder) => {
|
|
285
397
|
const newColumnOrder = typeof updatedColumnOrder === 'function'
|
|
286
398
|
? updatedColumnOrder(columnOrder)
|
|
@@ -299,6 +411,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
299
411
|
onColumnPinningChange(newColumnPinning);
|
|
300
412
|
}
|
|
301
413
|
}, [onColumnPinningChange, columnPinning]);
|
|
414
|
+
// Column visibility change handler - same pattern as column order
|
|
302
415
|
const handleColumnVisibilityChange = (0, react_1.useCallback)((updater) => {
|
|
303
416
|
const newVisibility = typeof updater === 'function'
|
|
304
417
|
? updater(columnVisibility)
|
|
@@ -315,6 +428,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
315
428
|
}, 0);
|
|
316
429
|
}
|
|
317
430
|
}, [onColumnVisibilityChange, onDataStateChange, tableStateChange, columnVisibility]);
|
|
431
|
+
// Column sizing change handler - same pattern as column order
|
|
318
432
|
const handleColumnSizingChange = (0, react_1.useCallback)((updater) => {
|
|
319
433
|
const newSizing = typeof updater === 'function'
|
|
320
434
|
? updater(columnSizing)
|
|
@@ -340,11 +454,13 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
340
454
|
serverSide: isServerMode || isServerPagination,
|
|
341
455
|
});
|
|
342
456
|
}
|
|
457
|
+
// Update pagination state
|
|
343
458
|
setPagination(newPagination);
|
|
344
459
|
onPaginationChange === null || onPaginationChange === void 0 ? void 0 : onPaginationChange(newPagination);
|
|
345
460
|
if (logger.isLevelEnabled('debug')) {
|
|
346
461
|
logger.debug('Pagination state updated', newPagination);
|
|
347
462
|
}
|
|
463
|
+
// Notify state change and fetch data if needed
|
|
348
464
|
if (isServerMode || isServerPagination) {
|
|
349
465
|
setTimeout(() => {
|
|
350
466
|
if (logger.isLevelEnabled('debug')) {
|
|
@@ -410,7 +526,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
410
526
|
}, 0);
|
|
411
527
|
}
|
|
412
528
|
onGlobalFilterChange === null || onGlobalFilterChange === void 0 ? void 0 : onGlobalFilterChange(newFilter);
|
|
413
|
-
}, [globalFilter, isServerMode, isServerFiltering, onDataStateChange,
|
|
529
|
+
}, [globalFilter, logger, isServerMode, isServerFiltering, onDataStateChange, onGlobalFilterChange, resetPageToFirst, tableStateChange, fetchData]);
|
|
414
530
|
const onColumnFilterChangeHandler = (0, react_1.useCallback)((updater) => {
|
|
415
531
|
const currentState = columnFilter;
|
|
416
532
|
const newState = typeof updater === 'function'
|
|
@@ -427,29 +543,107 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
427
543
|
const onColumnFilterApplyHandler = (0, react_1.useCallback)((appliedState) => {
|
|
428
544
|
const pagination = resetPageToFirst();
|
|
429
545
|
if (isServerFiltering) {
|
|
430
|
-
const serverFilterState = {
|
|
431
|
-
filters: appliedState.filters,
|
|
432
|
-
logic: appliedState.logic,
|
|
433
|
-
pendingFilters: appliedState.pendingFilters,
|
|
434
|
-
pendingLogic: appliedState.pendingLogic,
|
|
435
|
-
};
|
|
436
546
|
tableStateChange({
|
|
437
|
-
columnFilter:
|
|
547
|
+
columnFilter: appliedState,
|
|
438
548
|
pagination,
|
|
439
549
|
});
|
|
440
550
|
fetchData({
|
|
441
|
-
columnFilter:
|
|
551
|
+
columnFilter: appliedState,
|
|
442
552
|
pagination,
|
|
443
553
|
});
|
|
444
554
|
}
|
|
555
|
+
else if (onDataStateChange) {
|
|
556
|
+
setTimeout(() => tableStateChange({ columnFilter: appliedState, pagination }), 0);
|
|
557
|
+
}
|
|
445
558
|
setTimeout(() => {
|
|
446
|
-
|
|
447
|
-
onColumnFiltersChange(appliedState);
|
|
448
|
-
}
|
|
559
|
+
onColumnFiltersChange === null || onColumnFiltersChange === void 0 ? void 0 : onColumnFiltersChange(appliedState);
|
|
449
560
|
}, 0);
|
|
450
|
-
}, [isServerFiltering, fetchData,
|
|
451
|
-
|
|
452
|
-
|
|
561
|
+
}, [resetPageToFirst, isServerFiltering, onDataStateChange, tableStateChange, fetchData, onColumnFiltersChange]);
|
|
562
|
+
// -------------------------------
|
|
563
|
+
// Table creation (after callbacks/memo)
|
|
564
|
+
// -------------------------------
|
|
565
|
+
const table = (0, react_table_1.useReactTable)({
|
|
566
|
+
_features: [column_filter_feature_1.ColumnFilterFeature, features_1.SelectionFeature],
|
|
567
|
+
data: tableData,
|
|
568
|
+
columns: enhancedColumns,
|
|
569
|
+
// Use merged initial state so built-in reset helpers align with our controlled state defaults
|
|
570
|
+
initialState: initialStateConfig,
|
|
571
|
+
state: {
|
|
572
|
+
...(enableSorting ? { sorting } : {}),
|
|
573
|
+
...(enablePagination ? { pagination } : {}),
|
|
574
|
+
...(enableGlobalFilter ? { globalFilter } : {}),
|
|
575
|
+
...(enableExpanding ? { expanded } : {}),
|
|
576
|
+
...(enableColumnDragging ? { columnOrder } : {}),
|
|
577
|
+
...(enableColumnPinning ? { columnPinning } : {}),
|
|
578
|
+
...(enableColumnVisibility ? { columnVisibility } : {}),
|
|
579
|
+
...(enableColumnResizing ? { columnSizing } : {}),
|
|
580
|
+
...(enableColumnFilter ? { columnFilter } : {}),
|
|
581
|
+
...(enableRowSelection ? { selectionState } : {}),
|
|
582
|
+
},
|
|
583
|
+
// Selection options (same pattern as column filter)
|
|
584
|
+
// Add custom features
|
|
585
|
+
selectMode: selectMode,
|
|
586
|
+
enableAdvanceSelection: !!enableRowSelection,
|
|
587
|
+
isRowSelectable: isRowSelectable,
|
|
588
|
+
...(enableRowSelection ? { onSelectionStateChange: handleSelectionStateChange } : {}),
|
|
589
|
+
// Column filter
|
|
590
|
+
enableAdvanceColumnFilter: enableColumnFilter,
|
|
591
|
+
onColumnFilterChange: onColumnFilterChangeHandler, // Handle column filters change
|
|
592
|
+
onColumnFilterApply: onColumnFilterApplyHandler, // Handle when filters are actually applied
|
|
593
|
+
...(enableSorting ? { onSortingChange: handleSortingChange } : {}),
|
|
594
|
+
...(enablePagination ? { onPaginationChange: handlePaginationChange } : {}),
|
|
595
|
+
...(enableGlobalFilter ? { onGlobalFilterChange: handleGlobalFilterChange } : {}),
|
|
596
|
+
...(enableExpanding ? { onExpandedChange: setExpanded } : {}),
|
|
597
|
+
...(enableColumnDragging ? { onColumnOrderChange: handleColumnOrderChange } : {}),
|
|
598
|
+
...(enableColumnPinning ? { onColumnPinningChange: handleColumnPinningChange } : {}),
|
|
599
|
+
...(enableColumnVisibility ? { onColumnVisibilityChange: handleColumnVisibilityChange } : {}),
|
|
600
|
+
...(enableColumnResizing ? { onColumnSizingChange: handleColumnSizingChange } : {}),
|
|
601
|
+
// Row model
|
|
602
|
+
getCoreRowModel: (0, react_table_1.getCoreRowModel)(),
|
|
603
|
+
...(enableSorting ? { getSortedRowModel: (0, react_table_1.getSortedRowModel)() } : {}),
|
|
604
|
+
...(enableColumnFilter ? { getFilteredRowModel: (0, column_filter_feature_1.getCombinedFilteredRowModel)() } : {}),
|
|
605
|
+
...(enablePagination ? { getPaginationRowModel: (0, react_table_1.getPaginationRowModel)() } : {}),
|
|
606
|
+
// Sorting
|
|
607
|
+
enableSorting: enableSorting,
|
|
608
|
+
manualSorting: isServerSorting,
|
|
609
|
+
// Filtering
|
|
610
|
+
manualFiltering: isServerFiltering,
|
|
611
|
+
// Column resizing
|
|
612
|
+
enableColumnResizing: enableColumnResizing,
|
|
613
|
+
columnResizeMode: columnResizeMode,
|
|
614
|
+
// Column pinning
|
|
615
|
+
enableColumnPinning: enableColumnPinning,
|
|
616
|
+
// Expanding
|
|
617
|
+
...(enableExpanding ? { getRowCanExpand: getRowCanExpand } : {}),
|
|
618
|
+
// Pagination
|
|
619
|
+
manualPagination: isServerPagination,
|
|
620
|
+
autoResetPageIndex: false, // Prevent automatic page reset on state changes
|
|
621
|
+
// pageCount: enablePagination ? Math.ceil(tableTotalRow / pagination.pageSize) : -1,
|
|
622
|
+
rowCount: enablePagination ? (tableTotalRow !== null && tableTotalRow !== void 0 ? tableTotalRow : tableData.length) : tableData.length,
|
|
623
|
+
// Row ID
|
|
624
|
+
getRowId: (row, index) => (0, utils_1.generateRowId)(row, index, idKey),
|
|
625
|
+
// Debug
|
|
626
|
+
debugAll: false, // Disabled for production
|
|
627
|
+
});
|
|
628
|
+
// Compute width after table is created so column resizing is safe and reflects changes
|
|
629
|
+
const tableWidth = (0, react_1.useMemo)(() => {
|
|
630
|
+
if (fitToScreen) {
|
|
631
|
+
return '100%';
|
|
632
|
+
}
|
|
633
|
+
if (enableColumnResizing) {
|
|
634
|
+
return table.getCenterTotalSize();
|
|
635
|
+
}
|
|
636
|
+
return '100%';
|
|
637
|
+
}, [fitToScreen, enableColumnResizing, table]);
|
|
638
|
+
const tableStyle = (0, react_1.useMemo)(() => ({
|
|
639
|
+
width: tableWidth,
|
|
640
|
+
minWidth: '100%',
|
|
641
|
+
}), [tableWidth]);
|
|
642
|
+
// -------------------------------
|
|
643
|
+
// Virtualization and row memo
|
|
644
|
+
// -------------------------------
|
|
645
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
646
|
+
const rows = (0, react_1.useMemo)(() => { var _a; return ((_a = table.getRowModel()) === null || _a === void 0 ? void 0 : _a.rows) || []; }, [table, tableData]);
|
|
453
647
|
const rowVirtualizer = (0, react_virtual_1.useVirtualizer)({
|
|
454
648
|
count: rows.length,
|
|
455
649
|
getScrollElement: () => tableContainerRef.current,
|
|
@@ -457,18 +651,9 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
457
651
|
overscan: 10,
|
|
458
652
|
enabled: enableVirtualization && !enablePagination && rows.length > 0,
|
|
459
653
|
});
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
previousPageIndex: pagination.pageIndex,
|
|
464
|
-
pageSize: pagination.pageSize,
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
const newPagination = { pageIndex: 0, pageSize: pagination.pageSize };
|
|
468
|
-
setPagination(newPagination);
|
|
469
|
-
onPaginationChange === null || onPaginationChange === void 0 ? void 0 : onPaginationChange(newPagination);
|
|
470
|
-
return newPagination;
|
|
471
|
-
};
|
|
654
|
+
// -------------------------------
|
|
655
|
+
// Callbacks (after table creation)
|
|
656
|
+
// -------------------------------
|
|
472
657
|
const handleColumnReorder = (0, react_1.useCallback)((draggedColumnId, targetColumnId) => {
|
|
473
658
|
const currentOrder = columnOrder.length > 0 ? columnOrder : enhancedColumns.map((col, index) => {
|
|
474
659
|
if (col.id)
|
|
@@ -488,6 +673,9 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
488
673
|
newOrder.splice(targetIndex, 0, draggedColumnId);
|
|
489
674
|
handleColumnOrderChange(newOrder);
|
|
490
675
|
}, [columnOrder, enhancedColumns, handleColumnOrderChange]);
|
|
676
|
+
// -------------------------------
|
|
677
|
+
// Effects (after callbacks)
|
|
678
|
+
// -------------------------------
|
|
491
679
|
(0, react_1.useEffect)(() => {
|
|
492
680
|
if (initialLoadData && onFetchData) {
|
|
493
681
|
if (logger.isLevelEnabled('info')) {
|
|
@@ -501,6 +689,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
501
689
|
hasOnFetchData: !!onFetchData
|
|
502
690
|
});
|
|
503
691
|
}
|
|
692
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
504
693
|
}, []);
|
|
505
694
|
(0, react_1.useEffect)(() => {
|
|
506
695
|
if (enableColumnDragging && columnOrder.length === 0) {
|
|
@@ -520,6 +709,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
520
709
|
table: {
|
|
521
710
|
getTable: () => table,
|
|
522
711
|
},
|
|
712
|
+
// Column Management
|
|
523
713
|
columnVisibility: {
|
|
524
714
|
showColumn: (columnId) => {
|
|
525
715
|
var _a;
|
|
@@ -540,9 +730,13 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
540
730
|
table.toggleAllColumnsVisible(false);
|
|
541
731
|
},
|
|
542
732
|
resetColumnVisibility: () => {
|
|
543
|
-
|
|
733
|
+
const initialVisibility = initialStateConfig.columnVisibility || {};
|
|
734
|
+
table.setColumnVisibility(initialVisibility);
|
|
735
|
+
// Manually trigger handler to ensure callbacks are called
|
|
736
|
+
handleColumnVisibilityChange(initialVisibility);
|
|
544
737
|
},
|
|
545
738
|
},
|
|
739
|
+
// Column Ordering
|
|
546
740
|
columnOrdering: {
|
|
547
741
|
setColumnOrder: (columnOrder) => {
|
|
548
742
|
table.setColumnOrder(columnOrder);
|
|
@@ -568,21 +762,29 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
568
762
|
return `column_${index}`;
|
|
569
763
|
});
|
|
570
764
|
table.setColumnOrder(initialOrder);
|
|
765
|
+
// Manually trigger handler to ensure callbacks are called
|
|
766
|
+
handleColumnOrderChange(initialOrder);
|
|
571
767
|
},
|
|
572
768
|
},
|
|
769
|
+
// Column Pinning
|
|
573
770
|
columnPinning: {
|
|
574
771
|
pinColumnLeft: (columnId) => {
|
|
575
772
|
const currentPinning = table.getState().columnPinning;
|
|
576
|
-
const newPinning =
|
|
773
|
+
const newPinning = { ...currentPinning };
|
|
774
|
+
// Remove from right if exists
|
|
577
775
|
newPinning.right = (newPinning.right || []).filter(id => id !== columnId);
|
|
776
|
+
// Add to left if not exists
|
|
578
777
|
newPinning.left = [...(newPinning.left || []).filter(id => id !== columnId), columnId];
|
|
579
778
|
table.setColumnPinning(newPinning);
|
|
580
779
|
},
|
|
581
780
|
pinColumnRight: (columnId) => {
|
|
582
781
|
const currentPinning = table.getState().columnPinning;
|
|
583
|
-
const newPinning =
|
|
782
|
+
const newPinning = { ...currentPinning };
|
|
783
|
+
// Remove from left if exists
|
|
584
784
|
newPinning.left = (newPinning.left || []).filter(id => id !== columnId);
|
|
585
|
-
|
|
785
|
+
// Add to right if not exists - prepend to beginning (appears rightmost to leftmost)
|
|
786
|
+
// First column pinned appears rightmost, second appears to its left, etc.
|
|
787
|
+
newPinning.right = [columnId, ...(newPinning.right || []).filter(id => id !== columnId)];
|
|
586
788
|
table.setColumnPinning(newPinning);
|
|
587
789
|
},
|
|
588
790
|
unpinColumn: (columnId) => {
|
|
@@ -597,25 +799,41 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
597
799
|
table.setColumnPinning(pinning);
|
|
598
800
|
},
|
|
599
801
|
resetColumnPinning: () => {
|
|
600
|
-
|
|
802
|
+
const initialPinning = initialStateConfig.columnPinning || { left: [], right: [] };
|
|
803
|
+
table.setColumnPinning(initialPinning);
|
|
804
|
+
// Manually trigger handler to ensure callbacks are called
|
|
805
|
+
handleColumnPinningChange(initialPinning);
|
|
601
806
|
},
|
|
602
807
|
},
|
|
808
|
+
// Column Resizing
|
|
603
809
|
columnResizing: {
|
|
604
810
|
resizeColumn: (columnId, width) => {
|
|
811
|
+
// Use table's setColumnSizing method
|
|
605
812
|
const currentSizing = table.getState().columnSizing;
|
|
606
|
-
table.setColumnSizing(
|
|
813
|
+
table.setColumnSizing({
|
|
814
|
+
...currentSizing,
|
|
815
|
+
[columnId]: width,
|
|
816
|
+
});
|
|
607
817
|
},
|
|
608
818
|
autoSizeColumn: (columnId) => {
|
|
609
819
|
var _a;
|
|
820
|
+
// TanStack doesn't have built-in auto-size, so reset to default
|
|
610
821
|
(_a = table.getColumn(columnId)) === null || _a === void 0 ? void 0 : _a.resetSize();
|
|
611
822
|
},
|
|
612
823
|
autoSizeAllColumns: () => {
|
|
613
|
-
|
|
824
|
+
const initialSizing = initialStateConfig.columnSizing || {};
|
|
825
|
+
table.setColumnSizing(initialSizing);
|
|
826
|
+
// Manually trigger handler to ensure callbacks are called
|
|
827
|
+
handleColumnSizingChange(initialSizing);
|
|
614
828
|
},
|
|
615
829
|
resetColumnSizing: () => {
|
|
616
|
-
|
|
830
|
+
const initialSizing = initialStateConfig.columnSizing || {};
|
|
831
|
+
table.setColumnSizing(initialSizing);
|
|
832
|
+
// Manually trigger handler to ensure callbacks are called
|
|
833
|
+
handleColumnSizingChange(initialSizing);
|
|
617
834
|
},
|
|
618
835
|
},
|
|
836
|
+
// Filtering
|
|
619
837
|
filtering: {
|
|
620
838
|
setGlobalFilter: (filter) => {
|
|
621
839
|
table.setGlobalFilter(filter);
|
|
@@ -681,6 +899,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
681
899
|
}
|
|
682
900
|
},
|
|
683
901
|
},
|
|
902
|
+
// Sorting
|
|
684
903
|
sorting: {
|
|
685
904
|
setSorting: (sortingState) => {
|
|
686
905
|
table.setSorting(sortingState);
|
|
@@ -700,12 +919,18 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
700
919
|
}
|
|
701
920
|
},
|
|
702
921
|
clearSorting: () => {
|
|
703
|
-
table.
|
|
922
|
+
table.setSorting([]);
|
|
923
|
+
// Manually trigger handler to ensure callbacks are called
|
|
924
|
+
handleSortingChange([]);
|
|
704
925
|
},
|
|
705
926
|
resetSorting: () => {
|
|
706
|
-
|
|
927
|
+
const initialSorting = initialStateConfig.sorting || [];
|
|
928
|
+
table.setSorting(initialSorting);
|
|
929
|
+
// Manually trigger handler to ensure callbacks are called
|
|
930
|
+
handleSortingChange(initialSorting);
|
|
707
931
|
},
|
|
708
932
|
},
|
|
933
|
+
// Pagination
|
|
709
934
|
pagination: {
|
|
710
935
|
goToPage: (pageIndex) => {
|
|
711
936
|
table.setPageIndex(pageIndex);
|
|
@@ -747,9 +972,13 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
747
972
|
}
|
|
748
973
|
},
|
|
749
974
|
resetPagination: () => {
|
|
750
|
-
|
|
975
|
+
const initialPagination = initialStateConfig.pagination || { pageIndex: 0, pageSize: 10 };
|
|
976
|
+
table.setPagination(initialPagination);
|
|
977
|
+
// Manually trigger handler to ensure callbacks are called
|
|
978
|
+
handlePaginationChange(initialPagination);
|
|
751
979
|
},
|
|
752
980
|
},
|
|
981
|
+
// Access via table methods: table.selectRow(), table.getIsRowSelected(), etc.
|
|
753
982
|
selection: {
|
|
754
983
|
selectRow: (rowId) => { var _a; return (_a = table.selectRow) === null || _a === void 0 ? void 0 : _a.call(table, rowId); },
|
|
755
984
|
deselectRow: (rowId) => { var _a; return (_a = table.deselectRow) === null || _a === void 0 ? void 0 : _a.call(table, rowId); },
|
|
@@ -762,6 +991,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
762
991
|
getSelectedCount: () => table.getSelectedCount(),
|
|
763
992
|
isRowSelected: (rowId) => table.getIsRowSelected(rowId) || false,
|
|
764
993
|
},
|
|
994
|
+
// Data Management
|
|
765
995
|
data: {
|
|
766
996
|
refresh: (resetPagination = false) => {
|
|
767
997
|
var _a, _b, _c;
|
|
@@ -772,7 +1002,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
772
1002
|
};
|
|
773
1003
|
const allState = table.getState();
|
|
774
1004
|
setPagination(pagination);
|
|
775
|
-
onDataStateChange === null || onDataStateChange === void 0 ? void 0 : onDataStateChange(
|
|
1005
|
+
onDataStateChange === null || onDataStateChange === void 0 ? void 0 : onDataStateChange({ ...allState, pagination });
|
|
776
1006
|
fetchData === null || fetchData === void 0 ? void 0 : fetchData({ pagination });
|
|
777
1007
|
if (logger.isLevelEnabled('debug')) {
|
|
778
1008
|
logger.debug('Refreshing data using Ref', { pagination, allState });
|
|
@@ -786,6 +1016,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
786
1016
|
logger.info('Reloading data', allState);
|
|
787
1017
|
}
|
|
788
1018
|
},
|
|
1019
|
+
// Data CRUD operations
|
|
789
1020
|
getAllData: () => {
|
|
790
1021
|
var _a;
|
|
791
1022
|
return ((_a = table.getRowModel().rows) === null || _a === void 0 ? void 0 : _a.map(row => row.original)) || [];
|
|
@@ -801,7 +1032,11 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
801
1032
|
updateRow: (rowId, updates) => {
|
|
802
1033
|
var _a;
|
|
803
1034
|
const newData = (_a = table.getRowModel().rows) === null || _a === void 0 ? void 0 : _a.map(row => String(row.original[idKey]) === rowId
|
|
804
|
-
?
|
|
1035
|
+
? {
|
|
1036
|
+
...row.original,
|
|
1037
|
+
...updates,
|
|
1038
|
+
}
|
|
1039
|
+
: row.original);
|
|
805
1040
|
setServerData === null || setServerData === void 0 ? void 0 : setServerData(newData || []);
|
|
806
1041
|
if (logger.isLevelEnabled('debug')) {
|
|
807
1042
|
logger.debug(`Updating row ${rowId}`, updates);
|
|
@@ -811,7 +1046,10 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
811
1046
|
var _a;
|
|
812
1047
|
const newData = (_a = table.getRowModel().rows) === null || _a === void 0 ? void 0 : _a.map(row => row.original);
|
|
813
1048
|
if (newData === null || newData === void 0 ? void 0 : newData[index]) {
|
|
814
|
-
newData[index] =
|
|
1049
|
+
newData[index] = {
|
|
1050
|
+
...newData[index],
|
|
1051
|
+
...updates,
|
|
1052
|
+
};
|
|
815
1053
|
setServerData(newData);
|
|
816
1054
|
if (logger.isLevelEnabled('debug')) {
|
|
817
1055
|
logger.debug(`Updating row by index ${index}`, updates);
|
|
@@ -850,12 +1088,14 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
850
1088
|
}
|
|
851
1089
|
},
|
|
852
1090
|
deleteSelectedRows: () => {
|
|
853
|
-
var _a;
|
|
854
|
-
const
|
|
855
|
-
|
|
856
|
-
|
|
1091
|
+
var _a, _b, _c;
|
|
1092
|
+
const selectedRows = ((_a = table.getSelectedRows) === null || _a === void 0 ? void 0 : _a.call(table)) || [];
|
|
1093
|
+
if (selectedRows.length === 0)
|
|
1094
|
+
return;
|
|
1095
|
+
const selectedIds = new Set(selectedRows.map(row => String(row.original[idKey])));
|
|
1096
|
+
const newData = (_b = (table.getRowModel().rows || [])) === null || _b === void 0 ? void 0 : _b.filter(row => !selectedIds.has(String(row.original[idKey])));
|
|
857
1097
|
setServerData((newData === null || newData === void 0 ? void 0 : newData.map(row => row.original)) || []);
|
|
858
|
-
table.
|
|
1098
|
+
(_c = table.deselectAll) === null || _c === void 0 ? void 0 : _c.call(table);
|
|
859
1099
|
if (logger.isLevelEnabled('debug')) {
|
|
860
1100
|
logger.debug('Deleting selected rows');
|
|
861
1101
|
}
|
|
@@ -863,13 +1103,17 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
863
1103
|
replaceAllData: (newData) => {
|
|
864
1104
|
setServerData === null || setServerData === void 0 ? void 0 : setServerData(newData);
|
|
865
1105
|
},
|
|
1106
|
+
// Bulk operations
|
|
866
1107
|
updateMultipleRows: (updates) => {
|
|
867
1108
|
var _a;
|
|
868
1109
|
const updateMap = new Map(updates.map(u => [u.rowId, u.data]));
|
|
869
1110
|
const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.map(row => {
|
|
870
1111
|
const rowId = String(row.original[idKey]);
|
|
871
1112
|
const updateData = updateMap.get(rowId);
|
|
872
|
-
return updateData ?
|
|
1113
|
+
return updateData ? {
|
|
1114
|
+
...row.original,
|
|
1115
|
+
...updateData,
|
|
1116
|
+
} : row.original;
|
|
873
1117
|
});
|
|
874
1118
|
setServerData(newData || []);
|
|
875
1119
|
},
|
|
@@ -890,20 +1134,29 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
890
1134
|
const newData = (_b = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.filter(row => !idsToDelete.has(String(row.original[idKey])))) === null || _b === void 0 ? void 0 : _b.map(row => row.original);
|
|
891
1135
|
setServerData(newData);
|
|
892
1136
|
},
|
|
1137
|
+
// Field-specific updates
|
|
893
1138
|
updateField: (rowId, fieldName, value) => {
|
|
894
1139
|
var _a;
|
|
895
1140
|
const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.map(row => String(row.original[idKey]) === rowId
|
|
896
|
-
?
|
|
1141
|
+
? {
|
|
1142
|
+
...row.original,
|
|
1143
|
+
[fieldName]: value,
|
|
1144
|
+
}
|
|
1145
|
+
: row.original);
|
|
897
1146
|
setServerData === null || setServerData === void 0 ? void 0 : setServerData(newData);
|
|
898
1147
|
},
|
|
899
1148
|
updateFieldByIndex: (index, fieldName, value) => {
|
|
900
1149
|
var _a;
|
|
901
1150
|
const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.map(row => row.original);
|
|
902
1151
|
if (newData[index]) {
|
|
903
|
-
newData[index] =
|
|
1152
|
+
newData[index] = {
|
|
1153
|
+
...newData[index],
|
|
1154
|
+
[fieldName]: value,
|
|
1155
|
+
};
|
|
904
1156
|
setServerData === null || setServerData === void 0 ? void 0 : setServerData(newData);
|
|
905
1157
|
}
|
|
906
1158
|
},
|
|
1159
|
+
// Data queries
|
|
907
1160
|
findRows: (predicate) => {
|
|
908
1161
|
var _a, _b;
|
|
909
1162
|
return (_b = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.filter(row => predicate(row.original))) === null || _b === void 0 ? void 0 : _b.map(row => row.original);
|
|
@@ -920,6 +1173,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
920
1173
|
return table.getFilteredRowModel().rows.length;
|
|
921
1174
|
},
|
|
922
1175
|
},
|
|
1176
|
+
// Layout Management
|
|
923
1177
|
layout: {
|
|
924
1178
|
resetLayout: () => {
|
|
925
1179
|
table.resetColumnSizing();
|
|
@@ -928,13 +1182,14 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
928
1182
|
table.resetGlobalFilter();
|
|
929
1183
|
},
|
|
930
1184
|
resetAll: () => {
|
|
1185
|
+
// Reset everything to initial state
|
|
931
1186
|
table.resetColumnSizing();
|
|
932
1187
|
table.resetColumnVisibility();
|
|
933
1188
|
table.resetSorting();
|
|
934
1189
|
table.resetGlobalFilter();
|
|
935
1190
|
table.resetColumnOrder();
|
|
936
1191
|
table.resetExpanded();
|
|
937
|
-
|
|
1192
|
+
handleSelectionStateChange(initialSelectionState);
|
|
938
1193
|
table.resetColumnPinning();
|
|
939
1194
|
handleColumnFilterStateChange(initialStateConfig.columnFilter || { filters: [], logic: 'AND', pendingFilters: [], pendingLogic: 'AND' });
|
|
940
1195
|
if (enablePagination) {
|
|
@@ -983,6 +1238,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
983
1238
|
}
|
|
984
1239
|
},
|
|
985
1240
|
},
|
|
1241
|
+
// Table State
|
|
986
1242
|
state: {
|
|
987
1243
|
getTableState: () => {
|
|
988
1244
|
return table.getState();
|
|
@@ -996,19 +1252,23 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
996
1252
|
getCurrentPagination: () => {
|
|
997
1253
|
return table.getState().pagination;
|
|
998
1254
|
},
|
|
1255
|
+
// Backward compatibility: expose the raw selection array expected by older consumers
|
|
999
1256
|
getCurrentSelection: () => {
|
|
1000
|
-
|
|
1001
|
-
|
|
1257
|
+
var _a;
|
|
1258
|
+
return (_a = table.getSelectionState) === null || _a === void 0 ? void 0 : _a.call(table);
|
|
1002
1259
|
},
|
|
1003
1260
|
},
|
|
1261
|
+
// Simplified Export
|
|
1004
1262
|
export: {
|
|
1005
|
-
exportCSV:
|
|
1263
|
+
exportCSV: async (options = {}) => {
|
|
1006
1264
|
var _a;
|
|
1007
1265
|
const { filename = exportFilename, } = options;
|
|
1008
1266
|
try {
|
|
1267
|
+
// Create abort controller for this export
|
|
1009
1268
|
const controller = new AbortController();
|
|
1010
1269
|
setExportController === null || setExportController === void 0 ? void 0 : setExportController(controller);
|
|
1011
1270
|
if (dataMode === 'server' && onServerExport) {
|
|
1271
|
+
// Server export with selection data
|
|
1012
1272
|
const currentFilters = {
|
|
1013
1273
|
globalFilter: table.getState().globalFilter,
|
|
1014
1274
|
columnFilter: table.getState().columnFilter,
|
|
@@ -1018,7 +1278,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1018
1278
|
if (logger.isLevelEnabled('debug')) {
|
|
1019
1279
|
logger.debug('Server export CSV', { currentFilters });
|
|
1020
1280
|
}
|
|
1021
|
-
|
|
1281
|
+
await (0, utils_1.exportServerData)(table, {
|
|
1022
1282
|
format: 'csv',
|
|
1023
1283
|
filename,
|
|
1024
1284
|
fetchData: (filters, selection) => onServerExport(filters, selection),
|
|
@@ -1030,7 +1290,8 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1030
1290
|
});
|
|
1031
1291
|
}
|
|
1032
1292
|
else {
|
|
1033
|
-
|
|
1293
|
+
// Client export - auto-detect selected rows if not specified
|
|
1294
|
+
await (0, utils_1.exportClientData)(table, {
|
|
1034
1295
|
format: 'csv',
|
|
1035
1296
|
filename,
|
|
1036
1297
|
onProgress: onExportProgress,
|
|
@@ -1051,14 +1312,16 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1051
1312
|
finally {
|
|
1052
1313
|
setExportController === null || setExportController === void 0 ? void 0 : setExportController(null);
|
|
1053
1314
|
}
|
|
1054
|
-
}
|
|
1055
|
-
exportExcel:
|
|
1315
|
+
},
|
|
1316
|
+
exportExcel: async (options = {}) => {
|
|
1056
1317
|
var _a;
|
|
1057
1318
|
const { filename = exportFilename } = options;
|
|
1058
1319
|
try {
|
|
1320
|
+
// Create abort controller for this export
|
|
1059
1321
|
const controller = new AbortController();
|
|
1060
1322
|
setExportController === null || setExportController === void 0 ? void 0 : setExportController(controller);
|
|
1061
1323
|
if (dataMode === 'server' && onServerExport) {
|
|
1324
|
+
// Server export with selection data
|
|
1062
1325
|
const currentFilters = {
|
|
1063
1326
|
globalFilter: table.getState().globalFilter,
|
|
1064
1327
|
columnFilter: table.getState().columnFilter,
|
|
@@ -1068,7 +1331,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1068
1331
|
if (logger.isLevelEnabled('debug')) {
|
|
1069
1332
|
logger.debug('Server export Excel', { currentFilters });
|
|
1070
1333
|
}
|
|
1071
|
-
|
|
1334
|
+
await (0, utils_1.exportServerData)(table, {
|
|
1072
1335
|
format: 'excel',
|
|
1073
1336
|
filename,
|
|
1074
1337
|
fetchData: (filters, selection) => onServerExport(filters, selection),
|
|
@@ -1080,7 +1343,8 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1080
1343
|
});
|
|
1081
1344
|
}
|
|
1082
1345
|
else {
|
|
1083
|
-
|
|
1346
|
+
// Client export - auto-detect selected rows if not specified
|
|
1347
|
+
await (0, utils_1.exportClientData)(table, {
|
|
1084
1348
|
format: 'excel',
|
|
1085
1349
|
filename,
|
|
1086
1350
|
onProgress: onExportProgress,
|
|
@@ -1104,8 +1368,8 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1104
1368
|
finally {
|
|
1105
1369
|
setExportController === null || setExportController === void 0 ? void 0 : setExportController(null);
|
|
1106
1370
|
}
|
|
1107
|
-
}
|
|
1108
|
-
exportServerData: (options) =>
|
|
1371
|
+
},
|
|
1372
|
+
exportServerData: async (options) => {
|
|
1109
1373
|
var _a;
|
|
1110
1374
|
const { format, filename = exportFilename, fetchData = onServerExport, } = options;
|
|
1111
1375
|
if (!fetchData) {
|
|
@@ -1119,6 +1383,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1119
1383
|
return;
|
|
1120
1384
|
}
|
|
1121
1385
|
try {
|
|
1386
|
+
// Create abort controller for this export
|
|
1122
1387
|
const controller = new AbortController();
|
|
1123
1388
|
setExportController === null || setExportController === void 0 ? void 0 : setExportController(controller);
|
|
1124
1389
|
const currentFilters = {
|
|
@@ -1130,7 +1395,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1130
1395
|
if (logger.isLevelEnabled('debug')) {
|
|
1131
1396
|
logger.debug('Server export data', { currentFilters });
|
|
1132
1397
|
}
|
|
1133
|
-
|
|
1398
|
+
await (0, utils_1.exportServerData)(table, {
|
|
1134
1399
|
format,
|
|
1135
1400
|
filename,
|
|
1136
1401
|
fetchData: (filters, selection) => fetchData(filters, selection),
|
|
@@ -1153,7 +1418,8 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1153
1418
|
finally {
|
|
1154
1419
|
setExportController === null || setExportController === void 0 ? void 0 : setExportController(null);
|
|
1155
1420
|
}
|
|
1156
|
-
}
|
|
1421
|
+
},
|
|
1422
|
+
// Export state
|
|
1157
1423
|
isExporting: () => isExporting || false,
|
|
1158
1424
|
cancelExport: () => {
|
|
1159
1425
|
exportController === null || exportController === void 0 ? void 0 : exportController.abort();
|
|
@@ -1163,6 +1429,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1163
1429
|
}
|
|
1164
1430
|
},
|
|
1165
1431
|
},
|
|
1432
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1166
1433
|
}), [
|
|
1167
1434
|
table,
|
|
1168
1435
|
enhancedColumns,
|
|
@@ -1172,6 +1439,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1172
1439
|
onFetchData,
|
|
1173
1440
|
enableColumnPinning,
|
|
1174
1441
|
enablePagination,
|
|
1442
|
+
// Export dependencies
|
|
1175
1443
|
exportFilename,
|
|
1176
1444
|
onExportProgress,
|
|
1177
1445
|
onExportComplete,
|
|
@@ -1183,18 +1451,22 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1183
1451
|
dataMode,
|
|
1184
1452
|
selectMode,
|
|
1185
1453
|
onSelectionChange,
|
|
1454
|
+
// Note: custom selection removed from dependency array
|
|
1186
1455
|
]);
|
|
1187
1456
|
internalApiRef.current = dataTableApi;
|
|
1188
1457
|
(0, react_1.useImperativeHandle)(ref, () => dataTableApi, [dataTableApi]);
|
|
1458
|
+
// -------------------------------
|
|
1459
|
+
// Render table rows with slot support (callback)
|
|
1460
|
+
// -------------------------------
|
|
1189
1461
|
const renderTableRows = (0, react_1.useCallback)(() => {
|
|
1190
1462
|
var _a, _b, _c, _d;
|
|
1191
1463
|
if (tableLoading) {
|
|
1192
1464
|
const { component: LoadingRowComponent, props: loadingRowProps } = (0, slot_helpers_1.getSlotComponentWithProps)(slots, slotProps || {}, 'loadingRow', rows_1.LoadingRows, {});
|
|
1193
|
-
return ((0, jsx_runtime_1.jsx)(LoadingRowComponent,
|
|
1465
|
+
return ((0, jsx_runtime_1.jsx)(LoadingRowComponent, { rowCount: enablePagination ? Math.min(pagination.pageSize, skeletonRows) : skeletonRows, colSpan: table.getAllColumns().length, slots: slots, slotProps: slotProps, ...loadingRowProps }));
|
|
1194
1466
|
}
|
|
1195
1467
|
if (rows.length === 0) {
|
|
1196
1468
|
const { component: EmptyRowComponent, props: emptyRowProps } = (0, slot_helpers_1.getSlotComponentWithProps)(slots, slotProps || {}, 'emptyRow', rows_1.EmptyDataRow, {});
|
|
1197
|
-
return ((0, jsx_runtime_1.jsx)(EmptyRowComponent,
|
|
1469
|
+
return ((0, jsx_runtime_1.jsx)(EmptyRowComponent, { colSpan: table.getAllColumns().length, message: emptyMessage, slots: slots, slotProps: slotProps, ...emptyRowProps }));
|
|
1198
1470
|
}
|
|
1199
1471
|
if (enableVirtualization && !enablePagination && rows.length > 0) {
|
|
1200
1472
|
const virtualItems = rowVirtualizer.getVirtualItems();
|
|
@@ -1234,6 +1506,9 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1234
1506
|
selectOnRowClick,
|
|
1235
1507
|
slots,
|
|
1236
1508
|
]);
|
|
1509
|
+
// -------------------------------
|
|
1510
|
+
// Export cancel callback
|
|
1511
|
+
// -------------------------------
|
|
1237
1512
|
const handleCancelExport = (0, react_1.useCallback)(() => {
|
|
1238
1513
|
if (exportController) {
|
|
1239
1514
|
exportController.abort();
|
|
@@ -1243,6 +1518,9 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1243
1518
|
}
|
|
1244
1519
|
}
|
|
1245
1520
|
}, [exportController, onExportCancel]);
|
|
1521
|
+
// -------------------------------
|
|
1522
|
+
// Slot components
|
|
1523
|
+
// -------------------------------
|
|
1246
1524
|
const { component: RootComponent, props: rootSlotProps } = (0, slot_helpers_1.getSlotComponentWithProps)(slots, slotProps || {}, 'root', material_1.Box, {});
|
|
1247
1525
|
const { component: ToolbarComponent, props: toolbarSlotProps } = (0, slot_helpers_1.getSlotComponentWithProps)(slots, slotProps || {}, 'toolbar', toolbar_1.DataTableToolbar, {});
|
|
1248
1526
|
const { component: BulkActionsComponent, props: bulkActionsSlotProps } = (0, slot_helpers_1.getSlotComponentWithProps)(slots, slotProps || {}, 'bulkActionsToolbar', toolbar_1.BulkActionsToolbar, {});
|
|
@@ -1251,20 +1529,40 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1251
1529
|
const { component: BodyComponent, props: bodySlotProps } = (0, slot_helpers_1.getSlotComponentWithProps)(slots, slotProps || {}, 'body', material_1.TableBody, {});
|
|
1252
1530
|
const { component: FooterComponent, props: footerSlotProps } = (0, slot_helpers_1.getSlotComponentWithProps)(slots, slotProps || {}, 'footer', material_1.Box, {});
|
|
1253
1531
|
const { component: PaginationComponent, props: paginationSlotProps } = (0, slot_helpers_1.getSlotComponentWithProps)(slots, slotProps || {}, 'pagination', pagination_1.DataTablePagination, {});
|
|
1532
|
+
// -------------------------------
|
|
1533
|
+
// Render
|
|
1534
|
+
// -------------------------------
|
|
1254
1535
|
return ((0, jsx_runtime_1.jsx)(data_table_context_1.DataTableProvider, { table: table, apiRef: internalApiRef, dataMode: dataMode, tableSize: tableSize, onTableSizeChange: (size) => {
|
|
1255
1536
|
setTableSize(size);
|
|
1256
|
-
}, columnFilter: columnFilter, onChangeColumnFilter: handleColumnFilterStateChange, slots: slots, slotProps: slotProps, isExporting: isExporting, exportController: exportController, onCancelExport: handleCancelExport, exportFilename: exportFilename, onExportProgress: onExportProgress, onExportComplete: onExportComplete, onExportError: onExportError, onServerExport: onServerExport, children: (0, jsx_runtime_1.jsxs)(RootComponent,
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1537
|
+
}, columnFilter: columnFilter, onChangeColumnFilter: handleColumnFilterStateChange, slots: slots, slotProps: slotProps, isExporting: isExporting, exportController: exportController, onCancelExport: handleCancelExport, exportFilename: exportFilename, onExportProgress: onExportProgress, onExportComplete: onExportComplete, onExportError: onExportError, onServerExport: onServerExport, children: (0, jsx_runtime_1.jsxs)(RootComponent, { ...rootSlotProps, children: [(enableGlobalFilter || extraFilter) ? ((0, jsx_runtime_1.jsx)(ToolbarComponent, { extraFilter: extraFilter, enableGlobalFilter: enableGlobalFilter, enableColumnVisibility: enableColumnVisibility, enableColumnFilter: enableColumnFilter, enableExport: enableExport, enableReset: enableReset, enableTableSizeControl: enableTableSizeControl, enableColumnPinning: enableColumnPinning, ...toolbarSlotProps })) : null, enableBulkActions && enableRowSelection && isSomeRowsSelected ? ((0, jsx_runtime_1.jsx)(BulkActionsComponent, { selectionState: selectionState, selectedRowCount: selectedRowCount, bulkActions: bulkActions, sx: {
|
|
1538
|
+
position: 'relative',
|
|
1539
|
+
zIndex: 2,
|
|
1540
|
+
...bulkActionsSlotProps.sx,
|
|
1541
|
+
}, ...bulkActionsSlotProps })) : null, (0, jsx_runtime_1.jsx)(TableContainerComponent, { component: material_1.Paper, ref: tableContainerRef, sx: {
|
|
1542
|
+
width: '100%',
|
|
1543
|
+
overflowX: 'auto',
|
|
1544
|
+
...(enableStickyHeaderOrFooter && {
|
|
1545
|
+
maxHeight: maxHeight,
|
|
1546
|
+
overflowY: 'auto',
|
|
1547
|
+
}),
|
|
1548
|
+
...(enableVirtualization && {
|
|
1549
|
+
maxHeight: maxHeight,
|
|
1550
|
+
overflowY: 'auto',
|
|
1551
|
+
}),
|
|
1552
|
+
...tableContainerSlotProps === null || tableContainerSlotProps === void 0 ? void 0 : tableContainerSlotProps.sx,
|
|
1553
|
+
}, ...tableContainerSlotProps, children: (0, jsx_runtime_1.jsxs)(TableComponent, { size: tableSize, stickyHeader: enableStickyHeaderOrFooter, style: {
|
|
1554
|
+
...tableStyle,
|
|
1555
|
+
tableLayout: fitToScreen ? 'fixed' : 'auto',
|
|
1556
|
+
...tableProps === null || tableProps === void 0 ? void 0 : tableProps.style,
|
|
1557
|
+
}, ...(0, slot_helpers_1.mergeSlotProps)(tableProps || {}, tableComponentSlotProps), 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)(BodyComponent, { ...bodySlotProps, children: renderTableRows() })] }) }), enablePagination ? ((0, jsx_runtime_1.jsx)(FooterComponent, { sx: {
|
|
1558
|
+
...(enableStickyHeaderOrFooter && {
|
|
1559
|
+
position: 'sticky',
|
|
1560
|
+
bottom: 0,
|
|
1561
|
+
backgroundColor: 'background.paper',
|
|
1562
|
+
borderTop: '1px solid',
|
|
1563
|
+
borderColor: 'divider',
|
|
1564
|
+
zIndex: 1,
|
|
1565
|
+
}),
|
|
1566
|
+
...footerSlotProps.sx,
|
|
1567
|
+
}, ...footerSlotProps, children: (0, jsx_runtime_1.jsx)(PaginationComponent, { footerFilter: footerFilter, pagination: pagination, totalRow: tableTotalRow, ...paginationSlotProps }) })) : null] }) }));
|
|
1270
1568
|
});
|