@ackplus/react-tanstack-data-table 1.0.35 → 1.1.3
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 +70 -6
- 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 -2
- 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 +427 -143
- 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 -11
- 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 +6 -0
- package/dist/lib/types/index.d.ts.map +1 -0
- package/dist/lib/types/index.js +32 -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 +136 -0
- package/src/lib/types/export.types.ts +154 -0
- package/src/lib/types/index.ts +24 -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;
|
|
@@ -542,9 +732,11 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
542
732
|
resetColumnVisibility: () => {
|
|
543
733
|
const initialVisibility = initialStateConfig.columnVisibility || {};
|
|
544
734
|
table.setColumnVisibility(initialVisibility);
|
|
735
|
+
// Manually trigger handler to ensure callbacks are called
|
|
545
736
|
handleColumnVisibilityChange(initialVisibility);
|
|
546
737
|
},
|
|
547
738
|
},
|
|
739
|
+
// Column Ordering
|
|
548
740
|
columnOrdering: {
|
|
549
741
|
setColumnOrder: (columnOrder) => {
|
|
550
742
|
table.setColumnOrder(columnOrder);
|
|
@@ -570,21 +762,28 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
570
762
|
return `column_${index}`;
|
|
571
763
|
});
|
|
572
764
|
table.setColumnOrder(initialOrder);
|
|
765
|
+
// Manually trigger handler to ensure callbacks are called
|
|
573
766
|
handleColumnOrderChange(initialOrder);
|
|
574
767
|
},
|
|
575
768
|
},
|
|
769
|
+
// Column Pinning
|
|
576
770
|
columnPinning: {
|
|
577
771
|
pinColumnLeft: (columnId) => {
|
|
578
772
|
const currentPinning = table.getState().columnPinning;
|
|
579
|
-
const newPinning =
|
|
773
|
+
const newPinning = { ...currentPinning };
|
|
774
|
+
// Remove from right if exists
|
|
580
775
|
newPinning.right = (newPinning.right || []).filter(id => id !== columnId);
|
|
776
|
+
// Add to left if not exists
|
|
581
777
|
newPinning.left = [...(newPinning.left || []).filter(id => id !== columnId), columnId];
|
|
582
778
|
table.setColumnPinning(newPinning);
|
|
583
779
|
},
|
|
584
780
|
pinColumnRight: (columnId) => {
|
|
585
781
|
const currentPinning = table.getState().columnPinning;
|
|
586
|
-
const newPinning =
|
|
782
|
+
const newPinning = { ...currentPinning };
|
|
783
|
+
// Remove from left if exists
|
|
587
784
|
newPinning.left = (newPinning.left || []).filter(id => id !== columnId);
|
|
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.
|
|
588
787
|
newPinning.right = [columnId, ...(newPinning.right || []).filter(id => id !== columnId)];
|
|
589
788
|
table.setColumnPinning(newPinning);
|
|
590
789
|
},
|
|
@@ -602,29 +801,39 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
602
801
|
resetColumnPinning: () => {
|
|
603
802
|
const initialPinning = initialStateConfig.columnPinning || { left: [], right: [] };
|
|
604
803
|
table.setColumnPinning(initialPinning);
|
|
804
|
+
// Manually trigger handler to ensure callbacks are called
|
|
605
805
|
handleColumnPinningChange(initialPinning);
|
|
606
806
|
},
|
|
607
807
|
},
|
|
808
|
+
// Column Resizing
|
|
608
809
|
columnResizing: {
|
|
609
810
|
resizeColumn: (columnId, width) => {
|
|
811
|
+
// Use table's setColumnSizing method
|
|
610
812
|
const currentSizing = table.getState().columnSizing;
|
|
611
|
-
table.setColumnSizing(
|
|
813
|
+
table.setColumnSizing({
|
|
814
|
+
...currentSizing,
|
|
815
|
+
[columnId]: width,
|
|
816
|
+
});
|
|
612
817
|
},
|
|
613
818
|
autoSizeColumn: (columnId) => {
|
|
614
819
|
var _a;
|
|
820
|
+
// TanStack doesn't have built-in auto-size, so reset to default
|
|
615
821
|
(_a = table.getColumn(columnId)) === null || _a === void 0 ? void 0 : _a.resetSize();
|
|
616
822
|
},
|
|
617
823
|
autoSizeAllColumns: () => {
|
|
618
824
|
const initialSizing = initialStateConfig.columnSizing || {};
|
|
619
825
|
table.setColumnSizing(initialSizing);
|
|
826
|
+
// Manually trigger handler to ensure callbacks are called
|
|
620
827
|
handleColumnSizingChange(initialSizing);
|
|
621
828
|
},
|
|
622
829
|
resetColumnSizing: () => {
|
|
623
830
|
const initialSizing = initialStateConfig.columnSizing || {};
|
|
624
831
|
table.setColumnSizing(initialSizing);
|
|
832
|
+
// Manually trigger handler to ensure callbacks are called
|
|
625
833
|
handleColumnSizingChange(initialSizing);
|
|
626
834
|
},
|
|
627
835
|
},
|
|
836
|
+
// Filtering
|
|
628
837
|
filtering: {
|
|
629
838
|
setGlobalFilter: (filter) => {
|
|
630
839
|
table.setGlobalFilter(filter);
|
|
@@ -690,6 +899,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
690
899
|
}
|
|
691
900
|
},
|
|
692
901
|
},
|
|
902
|
+
// Sorting
|
|
693
903
|
sorting: {
|
|
694
904
|
setSorting: (sortingState) => {
|
|
695
905
|
table.setSorting(sortingState);
|
|
@@ -710,14 +920,17 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
710
920
|
},
|
|
711
921
|
clearSorting: () => {
|
|
712
922
|
table.setSorting([]);
|
|
923
|
+
// Manually trigger handler to ensure callbacks are called
|
|
713
924
|
handleSortingChange([]);
|
|
714
925
|
},
|
|
715
926
|
resetSorting: () => {
|
|
716
927
|
const initialSorting = initialStateConfig.sorting || [];
|
|
717
928
|
table.setSorting(initialSorting);
|
|
929
|
+
// Manually trigger handler to ensure callbacks are called
|
|
718
930
|
handleSortingChange(initialSorting);
|
|
719
931
|
},
|
|
720
932
|
},
|
|
933
|
+
// Pagination
|
|
721
934
|
pagination: {
|
|
722
935
|
goToPage: (pageIndex) => {
|
|
723
936
|
table.setPageIndex(pageIndex);
|
|
@@ -761,9 +974,11 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
761
974
|
resetPagination: () => {
|
|
762
975
|
const initialPagination = initialStateConfig.pagination || { pageIndex: 0, pageSize: 10 };
|
|
763
976
|
table.setPagination(initialPagination);
|
|
977
|
+
// Manually trigger handler to ensure callbacks are called
|
|
764
978
|
handlePaginationChange(initialPagination);
|
|
765
979
|
},
|
|
766
980
|
},
|
|
981
|
+
// Access via table methods: table.selectRow(), table.getIsRowSelected(), etc.
|
|
767
982
|
selection: {
|
|
768
983
|
selectRow: (rowId) => { var _a; return (_a = table.selectRow) === null || _a === void 0 ? void 0 : _a.call(table, rowId); },
|
|
769
984
|
deselectRow: (rowId) => { var _a; return (_a = table.deselectRow) === null || _a === void 0 ? void 0 : _a.call(table, rowId); },
|
|
@@ -776,6 +991,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
776
991
|
getSelectedCount: () => table.getSelectedCount(),
|
|
777
992
|
isRowSelected: (rowId) => table.getIsRowSelected(rowId) || false,
|
|
778
993
|
},
|
|
994
|
+
// Data Management
|
|
779
995
|
data: {
|
|
780
996
|
refresh: (resetPagination = false) => {
|
|
781
997
|
var _a, _b, _c;
|
|
@@ -786,7 +1002,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
786
1002
|
};
|
|
787
1003
|
const allState = table.getState();
|
|
788
1004
|
setPagination(pagination);
|
|
789
|
-
onDataStateChange === null || onDataStateChange === void 0 ? void 0 : onDataStateChange(
|
|
1005
|
+
onDataStateChange === null || onDataStateChange === void 0 ? void 0 : onDataStateChange({ ...allState, pagination });
|
|
790
1006
|
fetchData === null || fetchData === void 0 ? void 0 : fetchData({ pagination });
|
|
791
1007
|
if (logger.isLevelEnabled('debug')) {
|
|
792
1008
|
logger.debug('Refreshing data using Ref', { pagination, allState });
|
|
@@ -800,6 +1016,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
800
1016
|
logger.info('Reloading data', allState);
|
|
801
1017
|
}
|
|
802
1018
|
},
|
|
1019
|
+
// Data CRUD operations
|
|
803
1020
|
getAllData: () => {
|
|
804
1021
|
var _a;
|
|
805
1022
|
return ((_a = table.getRowModel().rows) === null || _a === void 0 ? void 0 : _a.map(row => row.original)) || [];
|
|
@@ -815,7 +1032,11 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
815
1032
|
updateRow: (rowId, updates) => {
|
|
816
1033
|
var _a;
|
|
817
1034
|
const newData = (_a = table.getRowModel().rows) === null || _a === void 0 ? void 0 : _a.map(row => String(row.original[idKey]) === rowId
|
|
818
|
-
?
|
|
1035
|
+
? {
|
|
1036
|
+
...row.original,
|
|
1037
|
+
...updates,
|
|
1038
|
+
}
|
|
1039
|
+
: row.original);
|
|
819
1040
|
setServerData === null || setServerData === void 0 ? void 0 : setServerData(newData || []);
|
|
820
1041
|
if (logger.isLevelEnabled('debug')) {
|
|
821
1042
|
logger.debug(`Updating row ${rowId}`, updates);
|
|
@@ -825,7 +1046,10 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
825
1046
|
var _a;
|
|
826
1047
|
const newData = (_a = table.getRowModel().rows) === null || _a === void 0 ? void 0 : _a.map(row => row.original);
|
|
827
1048
|
if (newData === null || newData === void 0 ? void 0 : newData[index]) {
|
|
828
|
-
newData[index] =
|
|
1049
|
+
newData[index] = {
|
|
1050
|
+
...newData[index],
|
|
1051
|
+
...updates,
|
|
1052
|
+
};
|
|
829
1053
|
setServerData(newData);
|
|
830
1054
|
if (logger.isLevelEnabled('debug')) {
|
|
831
1055
|
logger.debug(`Updating row by index ${index}`, updates);
|
|
@@ -864,12 +1088,14 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
864
1088
|
}
|
|
865
1089
|
},
|
|
866
1090
|
deleteSelectedRows: () => {
|
|
867
|
-
var _a;
|
|
868
|
-
const
|
|
869
|
-
|
|
870
|
-
|
|
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])));
|
|
871
1097
|
setServerData((newData === null || newData === void 0 ? void 0 : newData.map(row => row.original)) || []);
|
|
872
|
-
table.
|
|
1098
|
+
(_c = table.deselectAll) === null || _c === void 0 ? void 0 : _c.call(table);
|
|
873
1099
|
if (logger.isLevelEnabled('debug')) {
|
|
874
1100
|
logger.debug('Deleting selected rows');
|
|
875
1101
|
}
|
|
@@ -877,13 +1103,17 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
877
1103
|
replaceAllData: (newData) => {
|
|
878
1104
|
setServerData === null || setServerData === void 0 ? void 0 : setServerData(newData);
|
|
879
1105
|
},
|
|
1106
|
+
// Bulk operations
|
|
880
1107
|
updateMultipleRows: (updates) => {
|
|
881
1108
|
var _a;
|
|
882
1109
|
const updateMap = new Map(updates.map(u => [u.rowId, u.data]));
|
|
883
1110
|
const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.map(row => {
|
|
884
1111
|
const rowId = String(row.original[idKey]);
|
|
885
1112
|
const updateData = updateMap.get(rowId);
|
|
886
|
-
return updateData ?
|
|
1113
|
+
return updateData ? {
|
|
1114
|
+
...row.original,
|
|
1115
|
+
...updateData,
|
|
1116
|
+
} : row.original;
|
|
887
1117
|
});
|
|
888
1118
|
setServerData(newData || []);
|
|
889
1119
|
},
|
|
@@ -904,20 +1134,29 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
904
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);
|
|
905
1135
|
setServerData(newData);
|
|
906
1136
|
},
|
|
1137
|
+
// Field-specific updates
|
|
907
1138
|
updateField: (rowId, fieldName, value) => {
|
|
908
1139
|
var _a;
|
|
909
1140
|
const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.map(row => String(row.original[idKey]) === rowId
|
|
910
|
-
?
|
|
1141
|
+
? {
|
|
1142
|
+
...row.original,
|
|
1143
|
+
[fieldName]: value,
|
|
1144
|
+
}
|
|
1145
|
+
: row.original);
|
|
911
1146
|
setServerData === null || setServerData === void 0 ? void 0 : setServerData(newData);
|
|
912
1147
|
},
|
|
913
1148
|
updateFieldByIndex: (index, fieldName, value) => {
|
|
914
1149
|
var _a;
|
|
915
1150
|
const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.map(row => row.original);
|
|
916
1151
|
if (newData[index]) {
|
|
917
|
-
newData[index] =
|
|
1152
|
+
newData[index] = {
|
|
1153
|
+
...newData[index],
|
|
1154
|
+
[fieldName]: value,
|
|
1155
|
+
};
|
|
918
1156
|
setServerData === null || setServerData === void 0 ? void 0 : setServerData(newData);
|
|
919
1157
|
}
|
|
920
1158
|
},
|
|
1159
|
+
// Data queries
|
|
921
1160
|
findRows: (predicate) => {
|
|
922
1161
|
var _a, _b;
|
|
923
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);
|
|
@@ -934,6 +1173,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
934
1173
|
return table.getFilteredRowModel().rows.length;
|
|
935
1174
|
},
|
|
936
1175
|
},
|
|
1176
|
+
// Layout Management
|
|
937
1177
|
layout: {
|
|
938
1178
|
resetLayout: () => {
|
|
939
1179
|
table.resetColumnSizing();
|
|
@@ -942,13 +1182,14 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
942
1182
|
table.resetGlobalFilter();
|
|
943
1183
|
},
|
|
944
1184
|
resetAll: () => {
|
|
1185
|
+
// Reset everything to initial state
|
|
945
1186
|
table.resetColumnSizing();
|
|
946
1187
|
table.resetColumnVisibility();
|
|
947
1188
|
table.resetSorting();
|
|
948
1189
|
table.resetGlobalFilter();
|
|
949
1190
|
table.resetColumnOrder();
|
|
950
1191
|
table.resetExpanded();
|
|
951
|
-
|
|
1192
|
+
handleSelectionStateChange(initialSelectionState);
|
|
952
1193
|
table.resetColumnPinning();
|
|
953
1194
|
handleColumnFilterStateChange(initialStateConfig.columnFilter || { filters: [], logic: 'AND', pendingFilters: [], pendingLogic: 'AND' });
|
|
954
1195
|
if (enablePagination) {
|
|
@@ -997,6 +1238,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
997
1238
|
}
|
|
998
1239
|
},
|
|
999
1240
|
},
|
|
1241
|
+
// Table State
|
|
1000
1242
|
state: {
|
|
1001
1243
|
getTableState: () => {
|
|
1002
1244
|
return table.getState();
|
|
@@ -1010,19 +1252,23 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1010
1252
|
getCurrentPagination: () => {
|
|
1011
1253
|
return table.getState().pagination;
|
|
1012
1254
|
},
|
|
1255
|
+
// Backward compatibility: expose the raw selection array expected by older consumers
|
|
1013
1256
|
getCurrentSelection: () => {
|
|
1014
|
-
|
|
1015
|
-
|
|
1257
|
+
var _a;
|
|
1258
|
+
return (_a = table.getSelectionState) === null || _a === void 0 ? void 0 : _a.call(table);
|
|
1016
1259
|
},
|
|
1017
1260
|
},
|
|
1261
|
+
// Simplified Export
|
|
1018
1262
|
export: {
|
|
1019
|
-
exportCSV:
|
|
1263
|
+
exportCSV: async (options = {}) => {
|
|
1020
1264
|
var _a;
|
|
1021
1265
|
const { filename = exportFilename, } = options;
|
|
1022
1266
|
try {
|
|
1267
|
+
// Create abort controller for this export
|
|
1023
1268
|
const controller = new AbortController();
|
|
1024
1269
|
setExportController === null || setExportController === void 0 ? void 0 : setExportController(controller);
|
|
1025
1270
|
if (dataMode === 'server' && onServerExport) {
|
|
1271
|
+
// Server export with selection data
|
|
1026
1272
|
const currentFilters = {
|
|
1027
1273
|
globalFilter: table.getState().globalFilter,
|
|
1028
1274
|
columnFilter: table.getState().columnFilter,
|
|
@@ -1032,7 +1278,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1032
1278
|
if (logger.isLevelEnabled('debug')) {
|
|
1033
1279
|
logger.debug('Server export CSV', { currentFilters });
|
|
1034
1280
|
}
|
|
1035
|
-
|
|
1281
|
+
await (0, utils_1.exportServerData)(table, {
|
|
1036
1282
|
format: 'csv',
|
|
1037
1283
|
filename,
|
|
1038
1284
|
fetchData: (filters, selection) => onServerExport(filters, selection),
|
|
@@ -1044,7 +1290,8 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1044
1290
|
});
|
|
1045
1291
|
}
|
|
1046
1292
|
else {
|
|
1047
|
-
|
|
1293
|
+
// Client export - auto-detect selected rows if not specified
|
|
1294
|
+
await (0, utils_1.exportClientData)(table, {
|
|
1048
1295
|
format: 'csv',
|
|
1049
1296
|
filename,
|
|
1050
1297
|
onProgress: onExportProgress,
|
|
@@ -1065,14 +1312,16 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1065
1312
|
finally {
|
|
1066
1313
|
setExportController === null || setExportController === void 0 ? void 0 : setExportController(null);
|
|
1067
1314
|
}
|
|
1068
|
-
}
|
|
1069
|
-
exportExcel:
|
|
1315
|
+
},
|
|
1316
|
+
exportExcel: async (options = {}) => {
|
|
1070
1317
|
var _a;
|
|
1071
1318
|
const { filename = exportFilename } = options;
|
|
1072
1319
|
try {
|
|
1320
|
+
// Create abort controller for this export
|
|
1073
1321
|
const controller = new AbortController();
|
|
1074
1322
|
setExportController === null || setExportController === void 0 ? void 0 : setExportController(controller);
|
|
1075
1323
|
if (dataMode === 'server' && onServerExport) {
|
|
1324
|
+
// Server export with selection data
|
|
1076
1325
|
const currentFilters = {
|
|
1077
1326
|
globalFilter: table.getState().globalFilter,
|
|
1078
1327
|
columnFilter: table.getState().columnFilter,
|
|
@@ -1082,7 +1331,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1082
1331
|
if (logger.isLevelEnabled('debug')) {
|
|
1083
1332
|
logger.debug('Server export Excel', { currentFilters });
|
|
1084
1333
|
}
|
|
1085
|
-
|
|
1334
|
+
await (0, utils_1.exportServerData)(table, {
|
|
1086
1335
|
format: 'excel',
|
|
1087
1336
|
filename,
|
|
1088
1337
|
fetchData: (filters, selection) => onServerExport(filters, selection),
|
|
@@ -1094,7 +1343,8 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1094
1343
|
});
|
|
1095
1344
|
}
|
|
1096
1345
|
else {
|
|
1097
|
-
|
|
1346
|
+
// Client export - auto-detect selected rows if not specified
|
|
1347
|
+
await (0, utils_1.exportClientData)(table, {
|
|
1098
1348
|
format: 'excel',
|
|
1099
1349
|
filename,
|
|
1100
1350
|
onProgress: onExportProgress,
|
|
@@ -1118,8 +1368,8 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1118
1368
|
finally {
|
|
1119
1369
|
setExportController === null || setExportController === void 0 ? void 0 : setExportController(null);
|
|
1120
1370
|
}
|
|
1121
|
-
}
|
|
1122
|
-
exportServerData: (options) =>
|
|
1371
|
+
},
|
|
1372
|
+
exportServerData: async (options) => {
|
|
1123
1373
|
var _a;
|
|
1124
1374
|
const { format, filename = exportFilename, fetchData = onServerExport, } = options;
|
|
1125
1375
|
if (!fetchData) {
|
|
@@ -1133,6 +1383,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1133
1383
|
return;
|
|
1134
1384
|
}
|
|
1135
1385
|
try {
|
|
1386
|
+
// Create abort controller for this export
|
|
1136
1387
|
const controller = new AbortController();
|
|
1137
1388
|
setExportController === null || setExportController === void 0 ? void 0 : setExportController(controller);
|
|
1138
1389
|
const currentFilters = {
|
|
@@ -1144,7 +1395,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1144
1395
|
if (logger.isLevelEnabled('debug')) {
|
|
1145
1396
|
logger.debug('Server export data', { currentFilters });
|
|
1146
1397
|
}
|
|
1147
|
-
|
|
1398
|
+
await (0, utils_1.exportServerData)(table, {
|
|
1148
1399
|
format,
|
|
1149
1400
|
filename,
|
|
1150
1401
|
fetchData: (filters, selection) => fetchData(filters, selection),
|
|
@@ -1167,7 +1418,8 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1167
1418
|
finally {
|
|
1168
1419
|
setExportController === null || setExportController === void 0 ? void 0 : setExportController(null);
|
|
1169
1420
|
}
|
|
1170
|
-
}
|
|
1421
|
+
},
|
|
1422
|
+
// Export state
|
|
1171
1423
|
isExporting: () => isExporting || false,
|
|
1172
1424
|
cancelExport: () => {
|
|
1173
1425
|
exportController === null || exportController === void 0 ? void 0 : exportController.abort();
|
|
@@ -1177,6 +1429,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1177
1429
|
}
|
|
1178
1430
|
},
|
|
1179
1431
|
},
|
|
1432
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1180
1433
|
}), [
|
|
1181
1434
|
table,
|
|
1182
1435
|
enhancedColumns,
|
|
@@ -1186,6 +1439,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1186
1439
|
onFetchData,
|
|
1187
1440
|
enableColumnPinning,
|
|
1188
1441
|
enablePagination,
|
|
1442
|
+
// Export dependencies
|
|
1189
1443
|
exportFilename,
|
|
1190
1444
|
onExportProgress,
|
|
1191
1445
|
onExportComplete,
|
|
@@ -1197,18 +1451,22 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1197
1451
|
dataMode,
|
|
1198
1452
|
selectMode,
|
|
1199
1453
|
onSelectionChange,
|
|
1454
|
+
// Note: custom selection removed from dependency array
|
|
1200
1455
|
]);
|
|
1201
1456
|
internalApiRef.current = dataTableApi;
|
|
1202
1457
|
(0, react_1.useImperativeHandle)(ref, () => dataTableApi, [dataTableApi]);
|
|
1458
|
+
// -------------------------------
|
|
1459
|
+
// Render table rows with slot support (callback)
|
|
1460
|
+
// -------------------------------
|
|
1203
1461
|
const renderTableRows = (0, react_1.useCallback)(() => {
|
|
1204
1462
|
var _a, _b, _c, _d;
|
|
1205
1463
|
if (tableLoading) {
|
|
1206
1464
|
const { component: LoadingRowComponent, props: loadingRowProps } = (0, slot_helpers_1.getSlotComponentWithProps)(slots, slotProps || {}, 'loadingRow', rows_1.LoadingRows, {});
|
|
1207
|
-
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 }));
|
|
1208
1466
|
}
|
|
1209
1467
|
if (rows.length === 0) {
|
|
1210
1468
|
const { component: EmptyRowComponent, props: emptyRowProps } = (0, slot_helpers_1.getSlotComponentWithProps)(slots, slotProps || {}, 'emptyRow', rows_1.EmptyDataRow, {});
|
|
1211
|
-
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 }));
|
|
1212
1470
|
}
|
|
1213
1471
|
if (enableVirtualization && !enablePagination && rows.length > 0) {
|
|
1214
1472
|
const virtualItems = rowVirtualizer.getVirtualItems();
|
|
@@ -1248,6 +1506,9 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1248
1506
|
selectOnRowClick,
|
|
1249
1507
|
slots,
|
|
1250
1508
|
]);
|
|
1509
|
+
// -------------------------------
|
|
1510
|
+
// Export cancel callback
|
|
1511
|
+
// -------------------------------
|
|
1251
1512
|
const handleCancelExport = (0, react_1.useCallback)(() => {
|
|
1252
1513
|
if (exportController) {
|
|
1253
1514
|
exportController.abort();
|
|
@@ -1257,6 +1518,9 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1257
1518
|
}
|
|
1258
1519
|
}
|
|
1259
1520
|
}, [exportController, onExportCancel]);
|
|
1521
|
+
// -------------------------------
|
|
1522
|
+
// Slot components
|
|
1523
|
+
// -------------------------------
|
|
1260
1524
|
const { component: RootComponent, props: rootSlotProps } = (0, slot_helpers_1.getSlotComponentWithProps)(slots, slotProps || {}, 'root', material_1.Box, {});
|
|
1261
1525
|
const { component: ToolbarComponent, props: toolbarSlotProps } = (0, slot_helpers_1.getSlotComponentWithProps)(slots, slotProps || {}, 'toolbar', toolbar_1.DataTableToolbar, {});
|
|
1262
1526
|
const { component: BulkActionsComponent, props: bulkActionsSlotProps } = (0, slot_helpers_1.getSlotComponentWithProps)(slots, slotProps || {}, 'bulkActionsToolbar', toolbar_1.BulkActionsToolbar, {});
|
|
@@ -1265,20 +1529,40 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
1265
1529
|
const { component: BodyComponent, props: bodySlotProps } = (0, slot_helpers_1.getSlotComponentWithProps)(slots, slotProps || {}, 'body', material_1.TableBody, {});
|
|
1266
1530
|
const { component: FooterComponent, props: footerSlotProps } = (0, slot_helpers_1.getSlotComponentWithProps)(slots, slotProps || {}, 'footer', material_1.Box, {});
|
|
1267
1531
|
const { component: PaginationComponent, props: paginationSlotProps } = (0, slot_helpers_1.getSlotComponentWithProps)(slots, slotProps || {}, 'pagination', pagination_1.DataTablePagination, {});
|
|
1532
|
+
// -------------------------------
|
|
1533
|
+
// Render
|
|
1534
|
+
// -------------------------------
|
|
1268
1535
|
return ((0, jsx_runtime_1.jsx)(data_table_context_1.DataTableProvider, { table: table, apiRef: internalApiRef, dataMode: dataMode, tableSize: tableSize, onTableSizeChange: (size) => {
|
|
1269
1536
|
setTableSize(size);
|
|
1270
|
-
}, 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,
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
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] }) }));
|
|
1284
1568
|
});
|