@keenthemes/ktui 1.2.3 → 1.2.5
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/dist/ktui.js +2244 -1061
- package/dist/ktui.min.js +1 -1
- package/dist/ktui.min.js.map +1 -1
- package/dist/styles.css +185 -40
- package/lib/cjs/components/context-menu/context-menu.d.ts +66 -0
- package/lib/cjs/components/context-menu/context-menu.d.ts.map +1 -0
- package/lib/cjs/components/context-menu/context-menu.js +423 -0
- package/lib/cjs/components/context-menu/context-menu.js.map +1 -0
- package/lib/cjs/components/context-menu/index.d.ts +7 -0
- package/lib/cjs/components/context-menu/index.d.ts.map +1 -0
- package/lib/cjs/components/context-menu/index.js +10 -0
- package/lib/cjs/components/context-menu/index.js.map +1 -0
- package/lib/cjs/components/context-menu/types.d.ts +30 -0
- package/lib/cjs/components/context-menu/types.d.ts.map +1 -0
- package/lib/cjs/components/context-menu/types.js +7 -0
- package/lib/cjs/components/context-menu/types.js.map +1 -0
- package/lib/cjs/components/datatable/datatable-checkbox.d.ts.map +1 -1
- package/lib/cjs/components/datatable/datatable-checkbox.js +34 -15
- package/lib/cjs/components/datatable/datatable-checkbox.js.map +1 -1
- package/lib/cjs/components/datatable/datatable-contracts.d.ts +66 -0
- package/lib/cjs/components/datatable/datatable-contracts.d.ts.map +1 -0
- package/lib/cjs/components/datatable/datatable-contracts.js +7 -0
- package/lib/cjs/components/datatable/datatable-contracts.js.map +1 -0
- package/lib/cjs/components/datatable/datatable-event-adapter.d.ts +7 -0
- package/lib/cjs/components/datatable/datatable-event-adapter.d.ts.map +1 -0
- package/lib/cjs/components/datatable/datatable-event-adapter.js +16 -0
- package/lib/cjs/components/datatable/datatable-event-adapter.js.map +1 -0
- package/lib/cjs/components/datatable/datatable-local-provider.d.ts +25 -0
- package/lib/cjs/components/datatable/datatable-local-provider.d.ts.map +1 -0
- package/lib/cjs/components/datatable/datatable-local-provider.js +190 -0
- package/lib/cjs/components/datatable/datatable-local-provider.js.map +1 -0
- package/lib/cjs/components/datatable/datatable-pagination-renderer.d.ts +15 -0
- package/lib/cjs/components/datatable/datatable-pagination-renderer.d.ts.map +1 -0
- package/lib/cjs/components/datatable/datatable-pagination-renderer.js +144 -0
- package/lib/cjs/components/datatable/datatable-pagination-renderer.js.map +1 -0
- package/lib/cjs/components/datatable/datatable-remote-provider.d.ts +25 -0
- package/lib/cjs/components/datatable/datatable-remote-provider.d.ts.map +1 -0
- package/lib/cjs/components/datatable/datatable-remote-provider.js +191 -0
- package/lib/cjs/components/datatable/datatable-remote-provider.js.map +1 -0
- package/lib/cjs/components/datatable/datatable-state-store.d.ts +21 -0
- package/lib/cjs/components/datatable/datatable-state-store.d.ts.map +1 -0
- package/lib/cjs/components/datatable/datatable-state-store.js +81 -0
- package/lib/cjs/components/datatable/datatable-state-store.js.map +1 -0
- package/lib/cjs/components/datatable/datatable-table-renderer.d.ts +16 -0
- package/lib/cjs/components/datatable/datatable-table-renderer.d.ts.map +1 -0
- package/lib/cjs/components/datatable/datatable-table-renderer.js +141 -0
- package/lib/cjs/components/datatable/datatable-table-renderer.js.map +1 -0
- package/lib/cjs/components/datatable/datatable.d.ts +9 -87
- package/lib/cjs/components/datatable/datatable.d.ts.map +1 -1
- package/lib/cjs/components/datatable/datatable.js +234 -740
- package/lib/cjs/components/datatable/datatable.js.map +1 -1
- package/lib/cjs/components/dropdown/dropdown.d.ts +2 -2
- package/lib/cjs/components/dropdown/dropdown.d.ts.map +1 -1
- package/lib/cjs/components/dropdown/dropdown.js +68 -31
- package/lib/cjs/components/dropdown/dropdown.js.map +1 -1
- package/lib/cjs/components/input-number/index.d.ts +7 -0
- package/lib/cjs/components/input-number/index.d.ts.map +1 -0
- package/lib/cjs/components/input-number/index.js +10 -0
- package/lib/cjs/components/input-number/index.js.map +1 -0
- package/lib/cjs/components/input-number/input-number.d.ts +40 -0
- package/lib/cjs/components/input-number/input-number.d.ts.map +1 -0
- package/lib/cjs/components/input-number/input-number.js +248 -0
- package/lib/cjs/components/input-number/input-number.js.map +1 -0
- package/lib/cjs/components/input-number/types.d.ts +30 -0
- package/lib/cjs/components/input-number/types.d.ts.map +1 -0
- package/lib/cjs/components/input-number/types.js +7 -0
- package/lib/cjs/components/input-number/types.js.map +1 -0
- package/lib/cjs/components/select/config.d.ts +1 -0
- package/lib/cjs/components/select/config.d.ts.map +1 -1
- package/lib/cjs/components/select/config.js +2 -1
- package/lib/cjs/components/select/config.js.map +1 -1
- package/lib/cjs/components/select/index.d.ts +1 -1
- package/lib/cjs/components/select/index.d.ts.map +1 -1
- package/lib/cjs/components/select/select.d.ts +8 -1
- package/lib/cjs/components/select/select.d.ts.map +1 -1
- package/lib/cjs/components/select/select.js +14 -1
- package/lib/cjs/components/select/select.js.map +1 -1
- package/lib/cjs/components/select/tags.d.ts.map +1 -1
- package/lib/cjs/components/select/tags.js +10 -0
- package/lib/cjs/components/select/tags.js.map +1 -1
- package/lib/cjs/index.d.ts +9 -1
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +11 -7
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/init-all.d.ts +6 -0
- package/lib/cjs/init-all.d.ts.map +1 -0
- package/lib/cjs/init-all.js +17 -0
- package/lib/cjs/init-all.js.map +1 -0
- package/lib/cjs/legacy.d.ts +8 -0
- package/lib/cjs/legacy.d.ts.map +1 -0
- package/lib/cjs/legacy.js +26 -0
- package/lib/cjs/legacy.js.map +1 -0
- package/lib/esm/components/context-menu/context-menu.d.ts +66 -0
- package/lib/esm/components/context-menu/context-menu.d.ts.map +1 -0
- package/lib/esm/components/context-menu/context-menu.js +420 -0
- package/lib/esm/components/context-menu/context-menu.js.map +1 -0
- package/lib/esm/components/context-menu/index.d.ts +7 -0
- package/lib/esm/components/context-menu/index.d.ts.map +1 -0
- package/lib/esm/components/context-menu/index.js +6 -0
- package/lib/esm/components/context-menu/index.js.map +1 -0
- package/lib/esm/components/context-menu/types.d.ts +30 -0
- package/lib/esm/components/context-menu/types.d.ts.map +1 -0
- package/lib/esm/components/context-menu/types.js +6 -0
- package/lib/esm/components/context-menu/types.js.map +1 -0
- package/lib/esm/components/datatable/datatable-checkbox.d.ts.map +1 -1
- package/lib/esm/components/datatable/datatable-checkbox.js +34 -15
- package/lib/esm/components/datatable/datatable-checkbox.js.map +1 -1
- package/lib/esm/components/datatable/datatable-contracts.d.ts +66 -0
- package/lib/esm/components/datatable/datatable-contracts.d.ts.map +1 -0
- package/lib/esm/components/datatable/datatable-contracts.js +6 -0
- package/lib/esm/components/datatable/datatable-contracts.js.map +1 -0
- package/lib/esm/components/datatable/datatable-event-adapter.d.ts +7 -0
- package/lib/esm/components/datatable/datatable-event-adapter.d.ts.map +1 -0
- package/lib/esm/components/datatable/datatable-event-adapter.js +13 -0
- package/lib/esm/components/datatable/datatable-event-adapter.js.map +1 -0
- package/lib/esm/components/datatable/datatable-local-provider.d.ts +25 -0
- package/lib/esm/components/datatable/datatable-local-provider.d.ts.map +1 -0
- package/lib/esm/components/datatable/datatable-local-provider.js +187 -0
- package/lib/esm/components/datatable/datatable-local-provider.js.map +1 -0
- package/lib/esm/components/datatable/datatable-pagination-renderer.d.ts +15 -0
- package/lib/esm/components/datatable/datatable-pagination-renderer.d.ts.map +1 -0
- package/lib/esm/components/datatable/datatable-pagination-renderer.js +141 -0
- package/lib/esm/components/datatable/datatable-pagination-renderer.js.map +1 -0
- package/lib/esm/components/datatable/datatable-remote-provider.d.ts +25 -0
- package/lib/esm/components/datatable/datatable-remote-provider.d.ts.map +1 -0
- package/lib/esm/components/datatable/datatable-remote-provider.js +188 -0
- package/lib/esm/components/datatable/datatable-remote-provider.js.map +1 -0
- package/lib/esm/components/datatable/datatable-state-store.d.ts +21 -0
- package/lib/esm/components/datatable/datatable-state-store.d.ts.map +1 -0
- package/lib/esm/components/datatable/datatable-state-store.js +78 -0
- package/lib/esm/components/datatable/datatable-state-store.js.map +1 -0
- package/lib/esm/components/datatable/datatable-table-renderer.d.ts +16 -0
- package/lib/esm/components/datatable/datatable-table-renderer.d.ts.map +1 -0
- package/lib/esm/components/datatable/datatable-table-renderer.js +138 -0
- package/lib/esm/components/datatable/datatable-table-renderer.js.map +1 -0
- package/lib/esm/components/datatable/datatable.d.ts +9 -87
- package/lib/esm/components/datatable/datatable.d.ts.map +1 -1
- package/lib/esm/components/datatable/datatable.js +234 -740
- package/lib/esm/components/datatable/datatable.js.map +1 -1
- package/lib/esm/components/dropdown/dropdown.d.ts +2 -2
- package/lib/esm/components/dropdown/dropdown.d.ts.map +1 -1
- package/lib/esm/components/dropdown/dropdown.js +68 -31
- package/lib/esm/components/dropdown/dropdown.js.map +1 -1
- package/lib/esm/components/input-number/index.d.ts +7 -0
- package/lib/esm/components/input-number/index.d.ts.map +1 -0
- package/lib/esm/components/input-number/index.js +6 -0
- package/lib/esm/components/input-number/index.js.map +1 -0
- package/lib/esm/components/input-number/input-number.d.ts +40 -0
- package/lib/esm/components/input-number/input-number.d.ts.map +1 -0
- package/lib/esm/components/input-number/input-number.js +245 -0
- package/lib/esm/components/input-number/input-number.js.map +1 -0
- package/lib/esm/components/input-number/types.d.ts +30 -0
- package/lib/esm/components/input-number/types.d.ts.map +1 -0
- package/lib/esm/components/input-number/types.js +6 -0
- package/lib/esm/components/input-number/types.js.map +1 -0
- package/lib/esm/components/select/config.d.ts +1 -0
- package/lib/esm/components/select/config.d.ts.map +1 -1
- package/lib/esm/components/select/config.js +2 -1
- package/lib/esm/components/select/config.js.map +1 -1
- package/lib/esm/components/select/index.d.ts +1 -1
- package/lib/esm/components/select/index.d.ts.map +1 -1
- package/lib/esm/components/select/select.d.ts +8 -1
- package/lib/esm/components/select/select.d.ts.map +1 -1
- package/lib/esm/components/select/select.js +14 -1
- package/lib/esm/components/select/select.js.map +1 -1
- package/lib/esm/components/select/tags.d.ts.map +1 -1
- package/lib/esm/components/select/tags.js +11 -1
- package/lib/esm/components/select/tags.js.map +1 -1
- package/lib/esm/index.d.ts +9 -1
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +7 -5
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/init-all.d.ts +6 -0
- package/lib/esm/init-all.d.ts.map +1 -0
- package/lib/esm/init-all.js +13 -0
- package/lib/esm/init-all.js.map +1 -0
- package/lib/esm/legacy.d.ts +8 -0
- package/lib/esm/legacy.d.ts.map +1 -0
- package/lib/esm/legacy.js +8 -0
- package/lib/esm/legacy.js.map +1 -0
- package/package.json +35 -11
- package/src/__tests__/entrypoints.test.ts +71 -0
- package/src/components/context-menu/__tests__/context-menu.test.ts +117 -0
- package/src/components/context-menu/context-menu.css +32 -0
- package/src/components/context-menu/context-menu.ts +529 -0
- package/src/components/context-menu/index.ts +10 -0
- package/src/components/context-menu/types.ts +32 -0
- package/src/components/datatable/__tests__/architecture-boundaries.test.ts +259 -0
- package/src/components/datatable/datatable-checkbox.ts +34 -23
- package/src/components/datatable/datatable-contracts.ts +96 -0
- package/src/components/datatable/datatable-event-adapter.ts +21 -0
- package/src/components/datatable/datatable-local-provider.ts +193 -0
- package/src/components/datatable/datatable-pagination-renderer.ts +225 -0
- package/src/components/datatable/datatable-remote-provider.ts +178 -0
- package/src/components/datatable/datatable-state-store.ts +94 -0
- package/src/components/datatable/datatable-table-renderer.ts +214 -0
- package/src/components/datatable/datatable.ts +250 -918
- package/src/components/dropdown/dropdown.ts +86 -58
- package/src/components/input/input-group.css +14 -1
- package/src/components/input-number/__tests__/input-number.test.ts +278 -0
- package/src/components/input-number/index.ts +11 -0
- package/src/components/input-number/input-number.ts +267 -0
- package/src/components/input-number/types.ts +32 -0
- package/src/components/select/__tests__/ux-behaviors.test.ts +72 -0
- package/src/components/select/config.ts +3 -1
- package/src/components/select/index.ts +1 -1
- package/src/components/select/select.css +23 -20
- package/src/components/select/select.ts +15 -1
- package/src/components/select/tags.ts +14 -1
- package/src/index.ts +18 -5
- package/src/init-all.ts +15 -0
- package/src/legacy.ts +9 -0
- package/styles.css +1 -0
|
@@ -64,32 +64,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
64
64
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
68
|
-
var t = {};
|
|
69
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
70
|
-
t[p] = s[p];
|
|
71
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
72
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
73
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
74
|
-
t[p[i]] = s[p[i]];
|
|
75
|
-
}
|
|
76
|
-
return t;
|
|
77
|
-
};
|
|
78
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
79
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
80
|
-
if (ar || !(i in from)) {
|
|
81
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
82
|
-
ar[i] = from[i];
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
86
|
-
};
|
|
87
67
|
import KTComponent from '../component';
|
|
88
|
-
import KTUtils from '../../helpers/utils';
|
|
89
68
|
import KTComponents from '../../index';
|
|
90
69
|
import KTData from '../../helpers/data';
|
|
91
70
|
import { createCheckboxHandler, } from './datatable-checkbox';
|
|
92
71
|
import { createSortHandler } from './datatable-sort';
|
|
72
|
+
import { createDataTableEventAdapter } from './datatable-event-adapter';
|
|
73
|
+
import { KTDataTableLocalDataProvider } from './datatable-local-provider';
|
|
74
|
+
import { KTDataTableRemoteDataProvider } from './datatable-remote-provider';
|
|
75
|
+
import { KTDataTableConfigStateStore } from './datatable-state-store';
|
|
76
|
+
import { KTDataTableDomPaginationRenderer } from './datatable-pagination-renderer';
|
|
77
|
+
import { KTDataTableDomTableRenderer } from './datatable-table-renderer';
|
|
93
78
|
/**
|
|
94
79
|
* Custom DataTable plugin class with server-side API, pagination, and sorting
|
|
95
80
|
* @classdesc A custom KTComponent class that integrates server-side API, pagination, and sorting functionality into a table.
|
|
@@ -109,18 +94,12 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
109
94
|
_this._originalTheadClass = ''; // Store original thead class
|
|
110
95
|
_this._originalTdClasses = []; // Store original td classes as a 2D array [row][col]
|
|
111
96
|
_this._originalThClasses = []; // Store original th classes
|
|
97
|
+
_this._infoElement = null;
|
|
98
|
+
_this._sizeElement = null;
|
|
99
|
+
_this._paginationElement = null;
|
|
100
|
+
_this._cleanupCallbacks = [];
|
|
112
101
|
_this._data = [];
|
|
113
102
|
_this._isFetching = false;
|
|
114
|
-
/**
|
|
115
|
-
* AbortController for cancelling previous fetch requests
|
|
116
|
-
* Used to prevent race conditions when multiple requests are triggered rapidly
|
|
117
|
-
*/
|
|
118
|
-
_this._abortController = null;
|
|
119
|
-
/**
|
|
120
|
-
* Request ID counter for tracking request sequence
|
|
121
|
-
* Used to detect and ignore stale responses from older requests
|
|
122
|
-
*/
|
|
123
|
-
_this._requestId = 0;
|
|
124
103
|
if (KTData.has(element, _this._name)) {
|
|
125
104
|
// Already initialized (e.g. by createInstances). Merge user config so columns/sortType etc. apply.
|
|
126
105
|
var existing = KTDataTable.getInstance(element);
|
|
@@ -131,22 +110,26 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
131
110
|
}
|
|
132
111
|
_this._defaultConfig = _this._initDefaultConfig(config);
|
|
133
112
|
_this._init(element);
|
|
113
|
+
if (!_this._element) {
|
|
114
|
+
return _this;
|
|
115
|
+
}
|
|
134
116
|
_this._buildConfig();
|
|
117
|
+
_this._stateStore = new KTDataTableConfigStateStore(_this._config);
|
|
118
|
+
_this._eventAdapter = createDataTableEventAdapter(_this._fireEvent.bind(_this), _this._dispatchEvent.bind(_this));
|
|
135
119
|
// Store the instance directly on the element
|
|
136
120
|
KTDataTable.asElementWithInstance(element).instance = _this;
|
|
137
121
|
_this._initElements();
|
|
122
|
+
_this._tableRenderer = new KTDataTableDomTableRenderer();
|
|
123
|
+
_this._paginationRenderer = new KTDataTableDomPaginationRenderer();
|
|
124
|
+
_this._initDataProviders();
|
|
138
125
|
// Initialize checkbox handler
|
|
139
|
-
_this._checkbox = createCheckboxHandler(_this._element, _this._config,
|
|
140
|
-
_this._fireEvent(eventName, eventData);
|
|
141
|
-
_this._dispatchEvent(eventName, eventData);
|
|
142
|
-
});
|
|
126
|
+
_this._checkbox = createCheckboxHandler(_this._element, _this._config, _this._emit.bind(_this));
|
|
143
127
|
// Initialize sort handler
|
|
144
128
|
_this._sortHandler = createSortHandler(_this._config, _this._theadElement, function () { return ({
|
|
145
129
|
sortField: _this.getState().sortField,
|
|
146
130
|
sortOrder: _this.getState().sortOrder,
|
|
147
131
|
}); }, function (field, order) {
|
|
148
|
-
_this.
|
|
149
|
-
_this._config._state.sortOrder = order;
|
|
132
|
+
_this._stateStore.setSort(field, order);
|
|
150
133
|
}, _this._fireEvent.bind(_this), _this._dispatchEvent.bind(_this), _this._updateData.bind(_this));
|
|
151
134
|
_this._sortHandler.initSort();
|
|
152
135
|
if (_this._config.stateSave === false) {
|
|
@@ -156,8 +139,7 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
156
139
|
_this._loadState();
|
|
157
140
|
}
|
|
158
141
|
_this._updateData();
|
|
159
|
-
_this.
|
|
160
|
-
_this._dispatchEvent('init');
|
|
142
|
+
_this._emit('init');
|
|
161
143
|
return _this;
|
|
162
144
|
}
|
|
163
145
|
KTDataTable.asElementWithInstance = function (element) {
|
|
@@ -166,6 +148,30 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
166
148
|
KTDataTable.asSearchElementWithDebounce = function (element) {
|
|
167
149
|
return element;
|
|
168
150
|
};
|
|
151
|
+
KTDataTable.prototype._emit = function (eventName, eventData) {
|
|
152
|
+
this._eventAdapter.emit(eventName, eventData);
|
|
153
|
+
};
|
|
154
|
+
KTDataTable.prototype._initDataProviders = function () {
|
|
155
|
+
var _this = this;
|
|
156
|
+
this._localProvider = new KTDataTableLocalDataProvider({
|
|
157
|
+
config: this._config,
|
|
158
|
+
elements: function () { return ({
|
|
159
|
+
tableElement: _this._tableElement,
|
|
160
|
+
tbodyElement: _this._tbodyElement,
|
|
161
|
+
theadElement: _this._theadElement,
|
|
162
|
+
}); },
|
|
163
|
+
getLogicalColumnCount: this._getLogicalColumnCount.bind(this),
|
|
164
|
+
storeOriginalClasses: this._storeOriginalClasses.bind(this),
|
|
165
|
+
stateStore: this._stateStore,
|
|
166
|
+
});
|
|
167
|
+
this._remoteProvider = new KTDataTableRemoteDataProvider({
|
|
168
|
+
config: this._config,
|
|
169
|
+
createUrl: this._createUrl.bind(this),
|
|
170
|
+
eventAdapter: this._eventAdapter,
|
|
171
|
+
noticeOnTable: this._noticeOnTable.bind(this),
|
|
172
|
+
stateStore: this._stateStore,
|
|
173
|
+
});
|
|
174
|
+
};
|
|
169
175
|
/**
|
|
170
176
|
* Initialize default configuration for the datatable
|
|
171
177
|
* @param config User-provided configuration options
|
|
@@ -372,33 +378,31 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
372
378
|
* @returns {void}
|
|
373
379
|
*/
|
|
374
380
|
KTDataTable.prototype._initElements = function () {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
381
|
+
var _a;
|
|
382
|
+
var root = this._element;
|
|
383
|
+
var attrs = this._config.attributes;
|
|
384
|
+
if (!root || !(attrs === null || attrs === void 0 ? void 0 : attrs.table)) {
|
|
385
|
+
throw new Error('KTDataTable: root element and table selector are required');
|
|
386
|
+
}
|
|
387
|
+
var tableEl = root.querySelector(attrs.table);
|
|
388
|
+
if (!tableEl) {
|
|
389
|
+
throw new Error("KTDataTable: table element not found (".concat(attrs.table, ")"));
|
|
390
|
+
}
|
|
391
|
+
this._tableElement = tableEl;
|
|
382
392
|
this._tbodyElement =
|
|
383
393
|
this._tableElement.tBodies[0] || this._tableElement.createTBody();
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
*/
|
|
387
|
-
this._theadElement = this._tableElement.tHead;
|
|
388
|
-
// Store original classes
|
|
394
|
+
this._theadElement =
|
|
395
|
+
(_a = this._tableElement.tHead) !== null && _a !== void 0 ? _a : this._tableElement.createTHead();
|
|
389
396
|
this._storeOriginalClasses();
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
this.
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
* Pagination element
|
|
400
|
-
*/
|
|
401
|
-
this._paginationElement = this._element.querySelector(this._config.attributes.pagination);
|
|
397
|
+
this._infoElement = attrs.info
|
|
398
|
+
? root.querySelector(attrs.info)
|
|
399
|
+
: null;
|
|
400
|
+
this._sizeElement = attrs.size
|
|
401
|
+
? root.querySelector(attrs.size)
|
|
402
|
+
: null;
|
|
403
|
+
this._paginationElement = attrs.pagination
|
|
404
|
+
? root.querySelector(attrs.pagination)
|
|
405
|
+
: null;
|
|
402
406
|
};
|
|
403
407
|
/**
|
|
404
408
|
* Store original classes from table elements
|
|
@@ -435,32 +439,39 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
435
439
|
*/
|
|
436
440
|
KTDataTable.prototype._updateData = function () {
|
|
437
441
|
return __awaiter(this, void 0, void 0, function () {
|
|
438
|
-
|
|
439
|
-
|
|
442
|
+
var result, _a;
|
|
443
|
+
return __generator(this, function (_b) {
|
|
444
|
+
switch (_b.label) {
|
|
440
445
|
case 0:
|
|
441
446
|
if (this._isFetching)
|
|
442
447
|
return [2 /*return*/]; // Prevent duplicate fetches
|
|
443
448
|
this._isFetching = true;
|
|
444
|
-
|
|
449
|
+
_b.label = 1;
|
|
445
450
|
case 1:
|
|
446
|
-
|
|
451
|
+
_b.trys.push([1, , 8, 9]);
|
|
447
452
|
this._showSpinner(); // Show spinner before fetching data
|
|
448
|
-
|
|
449
|
-
return [
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
+
this._emit('fetch');
|
|
454
|
+
if (!(typeof this._config.apiEndpoint === 'undefined')) return [3 /*break*/, 2];
|
|
455
|
+
_a = this._localProvider.fetchSync();
|
|
456
|
+
return [3 /*break*/, 4];
|
|
457
|
+
case 2: return [4 /*yield*/, this._remoteProvider.fetch()];
|
|
453
458
|
case 3:
|
|
454
|
-
_a.sent();
|
|
455
|
-
|
|
456
|
-
case 4:
|
|
459
|
+
_a = _b.sent();
|
|
460
|
+
_b.label = 4;
|
|
461
|
+
case 4:
|
|
462
|
+
result = _a;
|
|
463
|
+
if (!!result.skipped) return [3 /*break*/, 6];
|
|
464
|
+
this._data = result.data;
|
|
465
|
+
this._stateStore.patchState({ totalItems: result.totalItems });
|
|
466
|
+
return [4 /*yield*/, this._draw()];
|
|
457
467
|
case 5:
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
468
|
+
_b.sent();
|
|
469
|
+
this._emit('fetched');
|
|
470
|
+
_b.label = 6;
|
|
471
|
+
case 6: return [4 /*yield*/, this._finalize()];
|
|
472
|
+
case 7:
|
|
473
|
+
_b.sent();
|
|
474
|
+
return [3 /*break*/, 9];
|
|
464
475
|
case 8:
|
|
465
476
|
// Finally block now correctly executes after promises resolve, not immediately
|
|
466
477
|
this._isFetching = false;
|
|
@@ -475,7 +486,8 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
475
486
|
* @returns {void}
|
|
476
487
|
*/
|
|
477
488
|
KTDataTable.prototype._finalize = function () {
|
|
478
|
-
|
|
489
|
+
var _a;
|
|
490
|
+
(_a = this._element) === null || _a === void 0 ? void 0 : _a.classList.add('datatable-initialized');
|
|
479
491
|
// Initialize checkbox logic
|
|
480
492
|
this._checkbox.init();
|
|
481
493
|
// Re-initialize sort handler to restore click listeners after table redraw
|
|
@@ -497,6 +509,7 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
497
509
|
*/
|
|
498
510
|
KTDataTable.prototype._attachSearchEvent = function () {
|
|
499
511
|
var _this = this;
|
|
512
|
+
var _a, _b;
|
|
500
513
|
var tableId = this._tableId();
|
|
501
514
|
var searchElement = document.querySelector("[data-kt-datatable-search=\"#".concat(tableId, "\"]"));
|
|
502
515
|
// Get search state
|
|
@@ -520,159 +533,13 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
520
533
|
// Create a new debounced search function
|
|
521
534
|
var debouncedSearch = this._debounce(function () {
|
|
522
535
|
_this.search(searchElement.value);
|
|
523
|
-
}, this._config.search.delay);
|
|
536
|
+
}, (_b = (_a = this._config.search) === null || _a === void 0 ? void 0 : _a.delay) !== null && _b !== void 0 ? _b : 500);
|
|
524
537
|
// Store the new debounced function as a property of the element
|
|
525
538
|
searchWithDebounce._debouncedSearch = debouncedSearch;
|
|
526
539
|
// Add the new debounced event listener
|
|
527
540
|
searchElement.addEventListener('keyup', debouncedSearch);
|
|
528
541
|
}
|
|
529
542
|
};
|
|
530
|
-
/**
|
|
531
|
-
* Fetch data from the DOM
|
|
532
|
-
* Fetch data from the table element and save it to the `originalData` state property.
|
|
533
|
-
* This method is used when the data is not fetched from the server via an API endpoint.
|
|
534
|
-
*/
|
|
535
|
-
KTDataTable.prototype._fetchDataFromLocal = function () {
|
|
536
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
537
|
-
var _a, sortField, sortOrder, page, pageSize, search, originalData, _b, originalData_1, originalDataAttributes, _temp, searchTerm, startIndex, endIndex;
|
|
538
|
-
var _c;
|
|
539
|
-
return __generator(this, function (_d) {
|
|
540
|
-
switch (_d.label) {
|
|
541
|
-
case 0:
|
|
542
|
-
this._fireEvent('fetch');
|
|
543
|
-
this._dispatchEvent('fetch');
|
|
544
|
-
_a = this.getState(), sortField = _a.sortField, sortOrder = _a.sortOrder, page = _a.page, pageSize = _a.pageSize, search = _a.search;
|
|
545
|
-
originalData = this.getState().originalData;
|
|
546
|
-
// If the table element or the original data is not defined, bail
|
|
547
|
-
if (!this._tableElement ||
|
|
548
|
-
originalData === undefined ||
|
|
549
|
-
this._tableConfigInvalidate() ||
|
|
550
|
-
this._localTableHeaderInvalidate() ||
|
|
551
|
-
this._localTableContentInvalidate()) {
|
|
552
|
-
this._deleteState();
|
|
553
|
-
_b = this._localExtractTableContent(), originalData_1 = _b.originalData, originalDataAttributes = _b.originalDataAttributes;
|
|
554
|
-
this._config._state.originalData = originalData_1;
|
|
555
|
-
this._config._state.originalDataAttributes = originalDataAttributes;
|
|
556
|
-
}
|
|
557
|
-
// Update the original data variable
|
|
558
|
-
originalData = this.getState().originalData;
|
|
559
|
-
_temp = (this._data = __spreadArray([], originalData, true));
|
|
560
|
-
if (search) {
|
|
561
|
-
searchTerm = typeof search === 'string' ? search : '';
|
|
562
|
-
_temp = this._data = this._config.search.callback.call(this, this._data, searchTerm);
|
|
563
|
-
}
|
|
564
|
-
// If sorting is defined, sort the data
|
|
565
|
-
if (sortField !== undefined &&
|
|
566
|
-
sortOrder !== undefined &&
|
|
567
|
-
sortOrder !== '') {
|
|
568
|
-
if (typeof this._config.sort.callback === 'function') {
|
|
569
|
-
this._data = this._config.sort.callback.call(this, this._data, sortField, sortOrder);
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
// If there is data, slice it to the current page size
|
|
573
|
-
if (((_c = this._data) === null || _c === void 0 ? void 0 : _c.length) > 0) {
|
|
574
|
-
startIndex = (page - 1) * pageSize;
|
|
575
|
-
endIndex = startIndex + pageSize;
|
|
576
|
-
this._data = this._data.slice(startIndex, endIndex);
|
|
577
|
-
}
|
|
578
|
-
// Determine number of total rows
|
|
579
|
-
this._config._state.totalItems = _temp.length;
|
|
580
|
-
// Draw the data
|
|
581
|
-
return [4 /*yield*/, this._draw()];
|
|
582
|
-
case 1:
|
|
583
|
-
// Draw the data
|
|
584
|
-
_d.sent();
|
|
585
|
-
this._fireEvent('fetched');
|
|
586
|
-
this._dispatchEvent('fetched');
|
|
587
|
-
return [2 /*return*/];
|
|
588
|
-
}
|
|
589
|
-
});
|
|
590
|
-
});
|
|
591
|
-
};
|
|
592
|
-
/**
|
|
593
|
-
* Checks if the table content has been invalidated by comparing the current checksum of the table body
|
|
594
|
-
* with the stored checksum in the state. If the checksums are different, the state is updated with the
|
|
595
|
-
* new checksum and `true` is returned. Otherwise, `false` is returned.
|
|
596
|
-
*
|
|
597
|
-
* @returns {boolean} `true` if the table content has been invalidated, `false` otherwise.
|
|
598
|
-
*/
|
|
599
|
-
KTDataTable.prototype._localTableContentInvalidate = function () {
|
|
600
|
-
var checksum = KTUtils.checksum(JSON.stringify(this._tbodyElement.innerHTML));
|
|
601
|
-
if (this.getState()._contentChecksum !== checksum) {
|
|
602
|
-
this._config._state._contentChecksum = checksum;
|
|
603
|
-
return true;
|
|
604
|
-
}
|
|
605
|
-
return false;
|
|
606
|
-
};
|
|
607
|
-
KTDataTable.prototype._tableConfigInvalidate = function () {
|
|
608
|
-
// Remove _data and _state from config
|
|
609
|
-
var _a = this._config, _state = _a._state, restConfig = __rest(_a, ["_state"]);
|
|
610
|
-
var checksum = KTUtils.checksum(JSON.stringify(restConfig));
|
|
611
|
-
if (_state._configChecksum !== checksum) {
|
|
612
|
-
this._config._state._configChecksum = checksum;
|
|
613
|
-
return true;
|
|
614
|
-
}
|
|
615
|
-
return false;
|
|
616
|
-
};
|
|
617
|
-
/**
|
|
618
|
-
* Extract the table content and returns it as an object containing an array of original data and an array of original data attributes.
|
|
619
|
-
*
|
|
620
|
-
* @returns {{originalData: T[], originalDataAttributes: KTDataTableAttributeInterface[]}} - An object containing an array of original data and an array of original data attributes.
|
|
621
|
-
*/
|
|
622
|
-
KTDataTable.prototype._localExtractTableContent = function () {
|
|
623
|
-
var originalData = [];
|
|
624
|
-
var originalDataAttributes = [];
|
|
625
|
-
this._storeOriginalClasses();
|
|
626
|
-
var rows = this._tbodyElement.querySelectorAll('tr');
|
|
627
|
-
// Filter th elements to only include those with data-kt-datatable-column attribute
|
|
628
|
-
var allThs = this._theadElement
|
|
629
|
-
? this._theadElement.querySelectorAll('th')
|
|
630
|
-
: [];
|
|
631
|
-
var ths = Array.from(allThs).filter(function (th) {
|
|
632
|
-
return th.hasAttribute('data-kt-datatable-column');
|
|
633
|
-
});
|
|
634
|
-
rows.forEach(function (row) {
|
|
635
|
-
var dataRow = {};
|
|
636
|
-
var dataRowAttribute = {};
|
|
637
|
-
row.querySelectorAll('td').forEach(function (td, index) {
|
|
638
|
-
var _a, _b, _c;
|
|
639
|
-
var colName = (_a = ths[index]) === null || _a === void 0 ? void 0 : _a.getAttribute('data-kt-datatable-column');
|
|
640
|
-
if (colName) {
|
|
641
|
-
dataRow[colName] = (_b = td.innerHTML) === null || _b === void 0 ? void 0 : _b.trim();
|
|
642
|
-
}
|
|
643
|
-
else {
|
|
644
|
-
// Store the original HTML for fallback
|
|
645
|
-
dataRow[index] = (_c = td.innerHTML) === null || _c === void 0 ? void 0 : _c.trim();
|
|
646
|
-
}
|
|
647
|
-
});
|
|
648
|
-
if (Object.keys(dataRow).length > 0) {
|
|
649
|
-
originalData.push(dataRow);
|
|
650
|
-
originalDataAttributes.push(dataRowAttribute);
|
|
651
|
-
}
|
|
652
|
-
});
|
|
653
|
-
return { originalData: originalData, originalDataAttributes: originalDataAttributes };
|
|
654
|
-
};
|
|
655
|
-
/**
|
|
656
|
-
* Check if the table header is invalidated
|
|
657
|
-
* @returns {boolean} - Returns true if the table header is invalidated, false otherwise
|
|
658
|
-
*/
|
|
659
|
-
KTDataTable.prototype._localTableHeaderInvalidate = function () {
|
|
660
|
-
var originalData = this.getState().originalData;
|
|
661
|
-
var totalColumns = originalData.length
|
|
662
|
-
? Object.keys(originalData[0]).length
|
|
663
|
-
: 0;
|
|
664
|
-
// Count th elements with data-kt-datatable-column; when none (e.g. multi-row headers), use logical column count so we don't falsely invalidate
|
|
665
|
-
var allThs = this._theadElement
|
|
666
|
-
? this._theadElement.querySelectorAll('th')
|
|
667
|
-
: [];
|
|
668
|
-
var thsWithColumn = Array.from(allThs).filter(function (th) {
|
|
669
|
-
return th.hasAttribute('data-kt-datatable-column');
|
|
670
|
-
});
|
|
671
|
-
var currentTableHeaders = thsWithColumn.length > 0
|
|
672
|
-
? thsWithColumn.length
|
|
673
|
-
: this._getLogicalColumnCount();
|
|
674
|
-
return currentTableHeaders !== totalColumns;
|
|
675
|
-
};
|
|
676
543
|
/**
|
|
677
544
|
* Returns the logical data column count (number of data columns), used for multi-row headers
|
|
678
545
|
* where querySelectorAll('th') would overcount. Prefers state.originalData, then first tbody row td count.
|
|
@@ -691,162 +558,6 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
691
558
|
}
|
|
692
559
|
return 0;
|
|
693
560
|
};
|
|
694
|
-
/**
|
|
695
|
-
* Fetch data from the server
|
|
696
|
-
*/
|
|
697
|
-
KTDataTable.prototype._fetchDataFromServer = function () {
|
|
698
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
699
|
-
var currentRequestId, queryParams, response, error_1, responseData, error_2;
|
|
700
|
-
return __generator(this, function (_a) {
|
|
701
|
-
switch (_a.label) {
|
|
702
|
-
case 0:
|
|
703
|
-
currentRequestId = ++this._requestId;
|
|
704
|
-
this._fireEvent('fetch');
|
|
705
|
-
this._dispatchEvent('fetch');
|
|
706
|
-
queryParams = this._getQueryParamsForFetchRequest();
|
|
707
|
-
_a.label = 1;
|
|
708
|
-
case 1:
|
|
709
|
-
_a.trys.push([1, 3, , 4]);
|
|
710
|
-
return [4 /*yield*/, this._performFetchRequest(queryParams)];
|
|
711
|
-
case 2:
|
|
712
|
-
response = _a.sent();
|
|
713
|
-
return [3 /*break*/, 4];
|
|
714
|
-
case 3:
|
|
715
|
-
error_1 = _a.sent();
|
|
716
|
-
// Silently ignore AbortError - request was cancelled
|
|
717
|
-
if (error_1.name === 'AbortError') {
|
|
718
|
-
return [2 /*return*/];
|
|
719
|
-
}
|
|
720
|
-
throw error_1;
|
|
721
|
-
case 4:
|
|
722
|
-
// Check if this response is stale (a newer request has been initiated)
|
|
723
|
-
if (currentRequestId !== this._requestId) {
|
|
724
|
-
// Ignore stale response - a more recent request is in progress or has completed
|
|
725
|
-
return [2 /*return*/];
|
|
726
|
-
}
|
|
727
|
-
responseData = null;
|
|
728
|
-
_a.label = 5;
|
|
729
|
-
case 5:
|
|
730
|
-
_a.trys.push([5, 7, , 8]);
|
|
731
|
-
return [4 /*yield*/, response.json()];
|
|
732
|
-
case 6:
|
|
733
|
-
responseData = _a.sent();
|
|
734
|
-
return [3 /*break*/, 8];
|
|
735
|
-
case 7:
|
|
736
|
-
error_2 = _a.sent();
|
|
737
|
-
// Fire event with complete error context for application handling
|
|
738
|
-
this._fireEvent('parseError', {
|
|
739
|
-
response: response,
|
|
740
|
-
error: String(error_2),
|
|
741
|
-
status: response.status,
|
|
742
|
-
statusText: response.statusText,
|
|
743
|
-
});
|
|
744
|
-
this._dispatchEvent('parseError', {
|
|
745
|
-
response: response,
|
|
746
|
-
error: String(error_2),
|
|
747
|
-
status: response.status,
|
|
748
|
-
statusText: response.statusText,
|
|
749
|
-
});
|
|
750
|
-
return [2 /*return*/];
|
|
751
|
-
case 8:
|
|
752
|
-
// Double-check request ID after JSON parsing (additional safety)
|
|
753
|
-
if (currentRequestId !== this._requestId) {
|
|
754
|
-
return [2 /*return*/];
|
|
755
|
-
}
|
|
756
|
-
this._fireEvent('fetched', { response: responseData });
|
|
757
|
-
this._dispatchEvent('fetched', { response: responseData });
|
|
758
|
-
// Use the mapResponse function to transform the data if provided
|
|
759
|
-
if (typeof this._config.mapResponse === 'function') {
|
|
760
|
-
responseData = this._config.mapResponse.call(this, responseData);
|
|
761
|
-
}
|
|
762
|
-
this._data = responseData.data;
|
|
763
|
-
this._config._state.totalItems = responseData.totalCount;
|
|
764
|
-
return [4 /*yield*/, this._draw()];
|
|
765
|
-
case 9:
|
|
766
|
-
_a.sent();
|
|
767
|
-
this._fireEvent('fetched');
|
|
768
|
-
this._dispatchEvent('fetched');
|
|
769
|
-
return [2 /*return*/];
|
|
770
|
-
}
|
|
771
|
-
});
|
|
772
|
-
});
|
|
773
|
-
};
|
|
774
|
-
/**
|
|
775
|
-
* Get the query params for a fetch request
|
|
776
|
-
* @returns The query params for the fetch request
|
|
777
|
-
*/
|
|
778
|
-
KTDataTable.prototype._getQueryParamsForFetchRequest = function () {
|
|
779
|
-
// Get the current state of the datatable
|
|
780
|
-
var _a = this.getState(), page = _a.page, pageSize = _a.pageSize, sortField = _a.sortField, sortOrder = _a.sortOrder, filters = _a.filters, search = _a.search;
|
|
781
|
-
// Create a new URLSearchParams object to store the query params
|
|
782
|
-
var queryParams = new URLSearchParams();
|
|
783
|
-
// Add the current page number and page size to the query params
|
|
784
|
-
queryParams.set('page', String(page));
|
|
785
|
-
queryParams.set('size', String(pageSize));
|
|
786
|
-
// If there is a sort order and field set, add them to the query params
|
|
787
|
-
if (sortOrder !== undefined) {
|
|
788
|
-
queryParams.set('sortOrder', String(sortOrder));
|
|
789
|
-
}
|
|
790
|
-
if (sortField !== undefined) {
|
|
791
|
-
queryParams.set('sortField', String(sortField));
|
|
792
|
-
}
|
|
793
|
-
// If there are any filters set, add them to the query params
|
|
794
|
-
if (Array.isArray(filters) && filters.length) {
|
|
795
|
-
queryParams.set('filters', JSON.stringify(filters.map(function (filter) { return ({
|
|
796
|
-
// Map the filter object to a simpler object with just the necessary properties
|
|
797
|
-
column: filter.column,
|
|
798
|
-
type: filter.type,
|
|
799
|
-
value: filter.value,
|
|
800
|
-
}); })));
|
|
801
|
-
}
|
|
802
|
-
if (search) {
|
|
803
|
-
queryParams.set('search', typeof search === 'object' ? JSON.stringify(search) : search);
|
|
804
|
-
}
|
|
805
|
-
// If a mapRequest function is provided, call it with the query params object
|
|
806
|
-
if (typeof this._config.mapRequest === 'function') {
|
|
807
|
-
queryParams = this._config.mapRequest.call(this, queryParams);
|
|
808
|
-
}
|
|
809
|
-
// Return the query params object
|
|
810
|
-
return queryParams;
|
|
811
|
-
};
|
|
812
|
-
KTDataTable.prototype._performFetchRequest = function (queryParams) {
|
|
813
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
814
|
-
var requestMethod, requestBody, apiEndpointWithQueryParams;
|
|
815
|
-
var _this = this;
|
|
816
|
-
return __generator(this, function (_a) {
|
|
817
|
-
requestMethod = this._config.requestMethod;
|
|
818
|
-
requestBody = undefined;
|
|
819
|
-
// Cancel previous request to prevent race conditions
|
|
820
|
-
if (this._abortController) {
|
|
821
|
-
this._abortController.abort();
|
|
822
|
-
}
|
|
823
|
-
// Create new AbortController for this request
|
|
824
|
-
this._abortController = new AbortController();
|
|
825
|
-
// If the request method is POST, send the query params as the request body
|
|
826
|
-
if (requestMethod === 'POST') {
|
|
827
|
-
requestBody = queryParams;
|
|
828
|
-
}
|
|
829
|
-
else if (requestMethod === 'GET') {
|
|
830
|
-
apiEndpointWithQueryParams = this._createUrl(this._config.apiEndpoint);
|
|
831
|
-
apiEndpointWithQueryParams.search = queryParams.toString();
|
|
832
|
-
this._config.apiEndpoint = apiEndpointWithQueryParams.toString();
|
|
833
|
-
}
|
|
834
|
-
return [2 /*return*/, fetch(this._config.apiEndpoint, __assign(__assign({ method: requestMethod, body: requestBody, headers: this._config.requestHeaders }, (this._config.requestCredentials && {
|
|
835
|
-
credentials: this._config.requestCredentials,
|
|
836
|
-
})), (this._abortController && { signal: this._abortController.signal }))).catch(function (error) {
|
|
837
|
-
// Silently ignore AbortError - this is expected when requests are cancelled
|
|
838
|
-
if (error.name === 'AbortError') {
|
|
839
|
-
return Promise.reject(error);
|
|
840
|
-
}
|
|
841
|
-
// Trigger an error event for non-abort errors
|
|
842
|
-
_this._fireEvent('error', { error: error });
|
|
843
|
-
_this._dispatchEvent('error', { error: error });
|
|
844
|
-
_this._noticeOnTable('Error performing fetch request: ' + String(error));
|
|
845
|
-
throw error;
|
|
846
|
-
})];
|
|
847
|
-
});
|
|
848
|
-
});
|
|
849
|
-
};
|
|
850
561
|
/**
|
|
851
562
|
* Creates a complete URL from a relative path or a full URL.
|
|
852
563
|
*
|
|
@@ -862,7 +573,10 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
862
573
|
* @returns {URL} The resulting URL object.
|
|
863
574
|
*/
|
|
864
575
|
KTDataTable.prototype._createUrl = function (pathOrUrl, baseUrl) {
|
|
865
|
-
|
|
576
|
+
var _a;
|
|
577
|
+
if (baseUrl === void 0) { baseUrl = typeof window !== 'undefined'
|
|
578
|
+
? window.location.origin
|
|
579
|
+
: null; }
|
|
866
580
|
// Regular expression to check if the input is a full URL
|
|
867
581
|
var isFullUrl = /^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(pathOrUrl);
|
|
868
582
|
if (isFullUrl) {
|
|
@@ -872,7 +586,38 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
872
586
|
var normalizedPath = pathOrUrl.startsWith('/')
|
|
873
587
|
? pathOrUrl
|
|
874
588
|
: "/".concat(pathOrUrl);
|
|
875
|
-
|
|
589
|
+
// Opaque origins (e.g. srcdoc iframes) serialize as the string "null", which is not a valid URL base.
|
|
590
|
+
var bases = [];
|
|
591
|
+
if (baseUrl && baseUrl !== 'null') {
|
|
592
|
+
bases.push(baseUrl);
|
|
593
|
+
}
|
|
594
|
+
if (typeof window !== 'undefined') {
|
|
595
|
+
var href = window.location.href;
|
|
596
|
+
if (href && !bases.includes(href)) {
|
|
597
|
+
bases.push(href);
|
|
598
|
+
}
|
|
599
|
+
try {
|
|
600
|
+
if (window.parent !== window && ((_a = window.parent.location) === null || _a === void 0 ? void 0 : _a.href)) {
|
|
601
|
+
var parentHref = window.parent.location.href;
|
|
602
|
+
if (parentHref && !bases.includes(parentHref)) {
|
|
603
|
+
bases.push(parentHref);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
catch (_b) {
|
|
608
|
+
// parent is cross-origin
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
for (var _i = 0, bases_1 = bases; _i < bases_1.length; _i++) {
|
|
612
|
+
var base = bases_1[_i];
|
|
613
|
+
try {
|
|
614
|
+
return new URL(normalizedPath, base);
|
|
615
|
+
}
|
|
616
|
+
catch (_c) {
|
|
617
|
+
// try next base
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
throw new Error("KTDataTable: cannot resolve relative apiEndpoint \"".concat(pathOrUrl, "\" (no valid base URL; use an absolute apiEndpoint)."));
|
|
876
621
|
};
|
|
877
622
|
/**
|
|
878
623
|
* Update the table and pagination controls with new data
|
|
@@ -881,20 +626,19 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
881
626
|
KTDataTable.prototype._draw = function () {
|
|
882
627
|
return __awaiter(this, void 0, void 0, function () {
|
|
883
628
|
return __generator(this, function (_a) {
|
|
884
|
-
this.
|
|
885
|
-
Math.ceil(this.getState().totalItems / this.getState().pageSize) || 0
|
|
886
|
-
|
|
887
|
-
this.
|
|
629
|
+
this._stateStore.patchState({
|
|
630
|
+
totalPages: Math.ceil(this.getState().totalItems / this.getState().pageSize) || 0,
|
|
631
|
+
});
|
|
632
|
+
this._emit('draw');
|
|
888
633
|
this._dispose();
|
|
889
634
|
// Update the table and pagination controls
|
|
890
635
|
if (this._theadElement && this._tbodyElement) {
|
|
891
636
|
this._updateTable();
|
|
892
637
|
}
|
|
893
|
-
if (this._infoElement
|
|
638
|
+
if (this._infoElement || this._sizeElement || this._paginationElement) {
|
|
894
639
|
this._updatePagination();
|
|
895
640
|
}
|
|
896
|
-
this.
|
|
897
|
-
this._dispatchEvent('drew');
|
|
641
|
+
this._emit('drew');
|
|
898
642
|
// Spinner is hidden in _finalize() to ensure it stays visible until the entire request completes
|
|
899
643
|
// Removed duplicate _hideSpinner() call here to prevent premature hiding
|
|
900
644
|
if (this._config.stateSave) {
|
|
@@ -909,115 +653,18 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
909
653
|
* @returns {HTMLTableSectionElement} The new table body element
|
|
910
654
|
*/
|
|
911
655
|
KTDataTable.prototype._updateTable = function () {
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
this
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
return tbodyElement;
|
|
924
|
-
};
|
|
925
|
-
/**
|
|
926
|
-
* Update the table content
|
|
927
|
-
* @param tbodyElement The table body element
|
|
928
|
-
* @returns {HTMLTableSectionElement} The updated table body element
|
|
929
|
-
*/
|
|
930
|
-
KTDataTable.prototype._updateTableContent = function (tbodyElement) {
|
|
931
|
-
var _this = this;
|
|
932
|
-
var fragment = document.createDocumentFragment();
|
|
933
|
-
tbodyElement.textContent = ''; // Clear the tbody element
|
|
934
|
-
if (this._data.length === 0) {
|
|
935
|
-
this._noticeOnTable(this._config.infoEmpty || '');
|
|
936
|
-
return tbodyElement;
|
|
937
|
-
}
|
|
938
|
-
// Filter th elements to only include those with data-kt-datatable-column attribute
|
|
939
|
-
// This prevents creating blank td elements for merged header cells (colspan/rowspan)
|
|
940
|
-
var allThs = this._theadElement
|
|
941
|
-
? this._theadElement.querySelectorAll('th')
|
|
942
|
-
: [];
|
|
943
|
-
var ths = Array.from(allThs).filter(function (th) {
|
|
944
|
-
return th.hasAttribute('data-kt-datatable-column');
|
|
656
|
+
return this._tableRenderer.render({
|
|
657
|
+
config: this._config,
|
|
658
|
+
context: this,
|
|
659
|
+
data: this._data,
|
|
660
|
+
getLogicalColumnCount: this._getLogicalColumnCount.bind(this),
|
|
661
|
+
getState: this.getState.bind(this),
|
|
662
|
+
originalTbodyClass: this._originalTbodyClass,
|
|
663
|
+
originalTrClasses: this._originalTrClasses,
|
|
664
|
+
originalTdClasses: this._originalTdClasses,
|
|
665
|
+
tableElement: this._tableElement,
|
|
666
|
+
theadElement: this._theadElement,
|
|
945
667
|
});
|
|
946
|
-
// When no th has data-kt-datatable-column (e.g. multi-row headers), use logical column count from tbody so we don't overcount thead cells
|
|
947
|
-
var columnsToRender = ths.length > 0 ? ths : [];
|
|
948
|
-
var logicalColumnCount = ths.length > 0 ? ths.length : this._getLogicalColumnCount();
|
|
949
|
-
this._data.forEach(function (item, rowIndex) {
|
|
950
|
-
var row = document.createElement('tr');
|
|
951
|
-
// Apply original tr class if available
|
|
952
|
-
if (_this._originalTrClasses && _this._originalTrClasses[rowIndex]) {
|
|
953
|
-
row.className = _this._originalTrClasses[rowIndex];
|
|
954
|
-
}
|
|
955
|
-
if (!_this._config.columns) {
|
|
956
|
-
var dataRowAttributes = _this.getState().originalDataAttributes
|
|
957
|
-
? _this.getState().originalDataAttributes[rowIndex]
|
|
958
|
-
: null;
|
|
959
|
-
for (var colIndex = 0; colIndex < logicalColumnCount; colIndex++) {
|
|
960
|
-
var th = columnsToRender[colIndex];
|
|
961
|
-
var colName = th === null || th === void 0 ? void 0 : th.getAttribute('data-kt-datatable-column');
|
|
962
|
-
var td = document.createElement('td');
|
|
963
|
-
var value = void 0;
|
|
964
|
-
if (colName && Object.prototype.hasOwnProperty.call(item, colName)) {
|
|
965
|
-
value = item[colName];
|
|
966
|
-
}
|
|
967
|
-
else if (Object.prototype.hasOwnProperty.call(item, colIndex)) {
|
|
968
|
-
value = item[colIndex];
|
|
969
|
-
}
|
|
970
|
-
else {
|
|
971
|
-
value = '';
|
|
972
|
-
}
|
|
973
|
-
td.innerHTML = value;
|
|
974
|
-
// Apply original td class if available
|
|
975
|
-
if (_this._originalTdClasses &&
|
|
976
|
-
_this._originalTdClasses[rowIndex] &&
|
|
977
|
-
_this._originalTdClasses[rowIndex][colIndex]) {
|
|
978
|
-
td.className = _this._originalTdClasses[rowIndex][colIndex];
|
|
979
|
-
}
|
|
980
|
-
if (dataRowAttributes && dataRowAttributes[colIndex]) {
|
|
981
|
-
for (var attr in dataRowAttributes[colIndex]) {
|
|
982
|
-
td.setAttribute(attr, dataRowAttributes[colIndex][attr]);
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
row.appendChild(td);
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
else {
|
|
989
|
-
Object.keys(_this._config.columns).forEach(function (key, colIndex) {
|
|
990
|
-
var td = document.createElement('td');
|
|
991
|
-
var columnDef = _this._config.columns[key];
|
|
992
|
-
// Apply original td class if available
|
|
993
|
-
if (_this._originalTdClasses &&
|
|
994
|
-
_this._originalTdClasses[rowIndex] &&
|
|
995
|
-
_this._originalTdClasses[rowIndex][colIndex]) {
|
|
996
|
-
td.className = _this._originalTdClasses[rowIndex][colIndex];
|
|
997
|
-
}
|
|
998
|
-
if (typeof columnDef.render === 'function') {
|
|
999
|
-
var result = columnDef.render.call(_this, item[key], item, _this);
|
|
1000
|
-
if (result instanceof HTMLElement ||
|
|
1001
|
-
result instanceof DocumentFragment) {
|
|
1002
|
-
td.appendChild(result);
|
|
1003
|
-
}
|
|
1004
|
-
else if (typeof result === 'string') {
|
|
1005
|
-
td.innerHTML = result;
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
else {
|
|
1009
|
-
td.textContent = item[key];
|
|
1010
|
-
}
|
|
1011
|
-
if (typeof columnDef.createdCell === 'function') {
|
|
1012
|
-
columnDef.createdCell.call(_this, td, item[key], item, row);
|
|
1013
|
-
}
|
|
1014
|
-
row.appendChild(td);
|
|
1015
|
-
});
|
|
1016
|
-
}
|
|
1017
|
-
fragment.appendChild(row);
|
|
1018
|
-
});
|
|
1019
|
-
tbodyElement.appendChild(fragment);
|
|
1020
|
-
return tbodyElement;
|
|
1021
668
|
};
|
|
1022
669
|
/**
|
|
1023
670
|
* Show a notice on the table
|
|
@@ -1026,66 +673,22 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1026
673
|
*/
|
|
1027
674
|
KTDataTable.prototype._noticeOnTable = function (message) {
|
|
1028
675
|
if (message === void 0) { message = ''; }
|
|
1029
|
-
|
|
1030
|
-
var cell = row.insertCell();
|
|
1031
|
-
var logicalCount = this._getLogicalColumnCount();
|
|
1032
|
-
// Use logical column count so multi-row headers don't overcount; fallback to 1 when 0 so message still displays
|
|
1033
|
-
cell.colSpan = logicalCount > 0 ? logicalCount : 1;
|
|
1034
|
-
cell.innerHTML = message;
|
|
676
|
+
this._tableRenderer.notice(this._tableElement, this._getLogicalColumnCount.bind(this), message);
|
|
1035
677
|
};
|
|
1036
678
|
KTDataTable.prototype._updatePagination = function () {
|
|
1037
|
-
this.
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
if (
|
|
1048
|
-
|
|
1049
|
-
}
|
|
1050
|
-
// Loop through all child elements of the container and remove them one by one
|
|
1051
|
-
while (container.firstChild) {
|
|
1052
|
-
// Remove the first child element (which is the first element in the list of child elements)
|
|
1053
|
-
container.removeChild(container.firstChild);
|
|
1054
|
-
}
|
|
1055
|
-
};
|
|
1056
|
-
/**
|
|
1057
|
-
* Creates a container element for the items per page selector.
|
|
1058
|
-
* @param _sizeElement The element to create the page size controls in.
|
|
1059
|
-
* @returns The container element.
|
|
1060
|
-
*/
|
|
1061
|
-
KTDataTable.prototype._createPageSizeControls = function (_sizeElement) {
|
|
1062
|
-
var _this = this;
|
|
1063
|
-
// If no element is provided, return early
|
|
1064
|
-
if (!_sizeElement) {
|
|
1065
|
-
return _sizeElement;
|
|
679
|
+
var cleanup = this._paginationRenderer.render({
|
|
680
|
+
config: this._config,
|
|
681
|
+
dataLength: this._data.length,
|
|
682
|
+
infoElement: this._infoElement,
|
|
683
|
+
paginateData: this._paginateData.bind(this),
|
|
684
|
+
paginationElement: this._paginationElement,
|
|
685
|
+
reloadPageSize: this._reloadPageSize.bind(this),
|
|
686
|
+
sizeElement: this._sizeElement,
|
|
687
|
+
state: this.getState(),
|
|
688
|
+
});
|
|
689
|
+
if (typeof cleanup === 'function') {
|
|
690
|
+
this._cleanupCallbacks.push(cleanup);
|
|
1066
691
|
}
|
|
1067
|
-
// Wait for the element to be attached to the DOM
|
|
1068
|
-
setTimeout(function () {
|
|
1069
|
-
// Create <option> elements for each page size option
|
|
1070
|
-
var options = _this._config.pageSizes.map(function (size) {
|
|
1071
|
-
var option = document.createElement('option');
|
|
1072
|
-
option.value = String(size);
|
|
1073
|
-
option.text = String(size);
|
|
1074
|
-
option.selected = _this.getState().pageSize === size;
|
|
1075
|
-
return option;
|
|
1076
|
-
});
|
|
1077
|
-
// Add the <option> elements to the provided element
|
|
1078
|
-
_sizeElement.append.apply(_sizeElement, options);
|
|
1079
|
-
}, 100);
|
|
1080
|
-
// Create an event listener for the "change" event on the element
|
|
1081
|
-
var _pageSizeControlsEvent = function (event) {
|
|
1082
|
-
// When the element changes, reload the page with the new page size and page number 1
|
|
1083
|
-
_this._reloadPageSize(Number(event.target.value), 1);
|
|
1084
|
-
};
|
|
1085
|
-
// Bind the event listener to the component instance
|
|
1086
|
-
_sizeElement.onchange = _pageSizeControlsEvent.bind(this);
|
|
1087
|
-
// Return the element
|
|
1088
|
-
return _sizeElement;
|
|
1089
692
|
};
|
|
1090
693
|
/**
|
|
1091
694
|
* Reloads the data with the specified page size and optional page number.
|
|
@@ -1095,120 +698,10 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1095
698
|
KTDataTable.prototype._reloadPageSize = function (pageSize, page) {
|
|
1096
699
|
if (page === void 0) { page = 1; }
|
|
1097
700
|
// Update the page size and page number in the state
|
|
1098
|
-
this.
|
|
1099
|
-
this._config._state.page = page;
|
|
701
|
+
this._stateStore.setPageSize(pageSize, page);
|
|
1100
702
|
// Update the data with the new page size and page number
|
|
1101
703
|
this._updateData();
|
|
1102
704
|
};
|
|
1103
|
-
/**
|
|
1104
|
-
* Creates the pagination controls for the component.
|
|
1105
|
-
* @param _infoElement The element to set the info text in.
|
|
1106
|
-
* @param _paginationElement The element to create the pagination controls in.
|
|
1107
|
-
* @return {HTMLElement} The element containing the pagination controls.
|
|
1108
|
-
*/
|
|
1109
|
-
KTDataTable.prototype._createPaginationControls = function (_infoElement, _paginationElement) {
|
|
1110
|
-
if (!_infoElement || !_paginationElement || this._data.length === 0) {
|
|
1111
|
-
return null;
|
|
1112
|
-
}
|
|
1113
|
-
this._setPaginationInfoText(_infoElement);
|
|
1114
|
-
var paginationContainer = this._createPaginationContainer(_paginationElement);
|
|
1115
|
-
if (paginationContainer) {
|
|
1116
|
-
this._createPaginationButtons(paginationContainer);
|
|
1117
|
-
}
|
|
1118
|
-
return paginationContainer;
|
|
1119
|
-
};
|
|
1120
|
-
/**
|
|
1121
|
-
* Sets the info text for the pagination controls.
|
|
1122
|
-
* @param _infoElement The element to set the info text in.
|
|
1123
|
-
*/
|
|
1124
|
-
KTDataTable.prototype._setPaginationInfoText = function (_infoElement) {
|
|
1125
|
-
_infoElement.textContent = this._config.info
|
|
1126
|
-
.replace('{start}', (this.getState().page - 1) * this.getState().pageSize + 1 + '')
|
|
1127
|
-
.replace('{end}', Math.min(this.getState().page * this.getState().pageSize, this.getState().totalItems) + '')
|
|
1128
|
-
.replace('{total}', this.getState().totalItems + '');
|
|
1129
|
-
};
|
|
1130
|
-
/**
|
|
1131
|
-
* Creates the container element for the pagination controls.
|
|
1132
|
-
* @param _paginationElement The element to create the pagination controls in.
|
|
1133
|
-
* @return {HTMLElement} The container element.
|
|
1134
|
-
*/
|
|
1135
|
-
KTDataTable.prototype._createPaginationContainer = function (_paginationElement) {
|
|
1136
|
-
// No longer create a wrapping div. Just return the pagination element itself.
|
|
1137
|
-
return _paginationElement;
|
|
1138
|
-
};
|
|
1139
|
-
/**
|
|
1140
|
-
* Creates the pagination buttons for the component.
|
|
1141
|
-
* @param paginationContainer The container element for the pagination controls.
|
|
1142
|
-
*/
|
|
1143
|
-
KTDataTable.prototype._createPaginationButtons = function (paginationContainer) {
|
|
1144
|
-
var _this = this;
|
|
1145
|
-
var _a = this.getState(), currentPage = _a.page, totalPages = _a.totalPages;
|
|
1146
|
-
var _b = this._config.pagination, previous = _b.previous, next = _b.next, number = _b.number, more = _b.more;
|
|
1147
|
-
// Helper function to create a button
|
|
1148
|
-
var createButton = function (text, className, disabled, handleClick) {
|
|
1149
|
-
var button = document.createElement('button');
|
|
1150
|
-
button.className = className;
|
|
1151
|
-
button.innerHTML = text;
|
|
1152
|
-
button.disabled = disabled;
|
|
1153
|
-
button.onclick = handleClick;
|
|
1154
|
-
return button;
|
|
1155
|
-
};
|
|
1156
|
-
// Add Previous Button
|
|
1157
|
-
paginationContainer.appendChild(createButton(previous.text, "".concat(previous.class).concat(currentPage === 1 ? ' disabled' : ''), currentPage === 1, function () { return _this._paginateData(currentPage - 1); }));
|
|
1158
|
-
// Calculate range of pages
|
|
1159
|
-
var pageMoreEnabled = this._config.pageMore;
|
|
1160
|
-
if (pageMoreEnabled) {
|
|
1161
|
-
var maxButtons = this._config.pageMoreLimit;
|
|
1162
|
-
var range_1 = this._calculatePageRange(currentPage, totalPages, maxButtons);
|
|
1163
|
-
// Add start ellipsis
|
|
1164
|
-
if (range_1.start > 1) {
|
|
1165
|
-
paginationContainer.appendChild(createButton(more.text, more.class, false, function () {
|
|
1166
|
-
return _this._paginateData(Math.max(1, range_1.start - 1));
|
|
1167
|
-
}));
|
|
1168
|
-
}
|
|
1169
|
-
var _loop_1 = function (i) {
|
|
1170
|
-
paginationContainer.appendChild(createButton(number.text.replace('{page}', i.toString()), "".concat(number.class).concat(currentPage === i ? ' active disabled' : ''), currentPage === i, function () { return _this._paginateData(i); }));
|
|
1171
|
-
};
|
|
1172
|
-
// Add page buttons
|
|
1173
|
-
for (var i = range_1.start; i <= range_1.end; i++) {
|
|
1174
|
-
_loop_1(i);
|
|
1175
|
-
}
|
|
1176
|
-
// Add end ellipsis
|
|
1177
|
-
if (pageMoreEnabled && range_1.end < totalPages) {
|
|
1178
|
-
paginationContainer.appendChild(createButton(more.text, more.class, false, function () {
|
|
1179
|
-
return _this._paginateData(Math.min(totalPages, range_1.end + 1));
|
|
1180
|
-
}));
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1183
|
-
else {
|
|
1184
|
-
var _loop_2 = function (i) {
|
|
1185
|
-
paginationContainer.appendChild(createButton(number.text.replace('{page}', i.toString()), "".concat(number.class).concat(currentPage === i ? ' active disabled' : ''), currentPage === i, function () { return _this._paginateData(i); }));
|
|
1186
|
-
};
|
|
1187
|
-
// Add page buttons
|
|
1188
|
-
for (var i = 1; i <= totalPages; i++) {
|
|
1189
|
-
_loop_2(i);
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
// Add Next Button
|
|
1193
|
-
paginationContainer.appendChild(createButton(next.text, "".concat(next.class).concat(currentPage === totalPages ? ' disabled' : ''), currentPage === totalPages, function () { return _this._paginateData(currentPage + 1); }));
|
|
1194
|
-
};
|
|
1195
|
-
// New helper method to calculate page range
|
|
1196
|
-
KTDataTable.prototype._calculatePageRange = function (currentPage, totalPages, maxButtons) {
|
|
1197
|
-
var startPage, endPage;
|
|
1198
|
-
var halfMaxButtons = Math.floor(maxButtons / 2);
|
|
1199
|
-
if (totalPages <= maxButtons) {
|
|
1200
|
-
startPage = 1;
|
|
1201
|
-
endPage = totalPages;
|
|
1202
|
-
}
|
|
1203
|
-
else {
|
|
1204
|
-
startPage = Math.max(currentPage - halfMaxButtons, 1);
|
|
1205
|
-
endPage = Math.min(startPage + maxButtons - 1, totalPages);
|
|
1206
|
-
if (endPage - startPage < maxButtons - 1) {
|
|
1207
|
-
startPage = Math.max(endPage - maxButtons + 1, 1);
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
return { start: startPage, end: endPage };
|
|
1211
|
-
};
|
|
1212
705
|
/**
|
|
1213
706
|
* Method for handling pagination
|
|
1214
707
|
* @param page - The page number to navigate to
|
|
@@ -1217,39 +710,54 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1217
710
|
if (page < 1 || !Number.isInteger(page)) {
|
|
1218
711
|
return;
|
|
1219
712
|
}
|
|
1220
|
-
this.
|
|
1221
|
-
this._dispatchEvent('pagination', { page: page });
|
|
713
|
+
this._emit('pagination', { page: page });
|
|
1222
714
|
if (page >= 1 && page <= this.getState().totalPages) {
|
|
1223
|
-
this.
|
|
715
|
+
this._stateStore.setPage(page);
|
|
1224
716
|
this._updateData();
|
|
1225
717
|
}
|
|
1226
718
|
};
|
|
1227
719
|
// Method to show the loading spinner
|
|
1228
720
|
KTDataTable.prototype._showSpinner = function () {
|
|
1229
|
-
var
|
|
721
|
+
var _a, _b;
|
|
722
|
+
var root = this._element;
|
|
723
|
+
var spinnerSel = (_a = this._config.attributes) === null || _a === void 0 ? void 0 : _a.spinner;
|
|
724
|
+
var fromDom = root && spinnerSel
|
|
725
|
+
? root.querySelector(spinnerSel)
|
|
726
|
+
: null;
|
|
727
|
+
var spinner = fromDom !== null && fromDom !== void 0 ? fromDom : this._createSpinner();
|
|
1230
728
|
if (spinner) {
|
|
1231
729
|
spinner.style.display = 'block';
|
|
1232
730
|
}
|
|
1233
|
-
|
|
731
|
+
root === null || root === void 0 ? void 0 : root.classList.add((_b = this._config.loadingClass) !== null && _b !== void 0 ? _b : 'loading');
|
|
1234
732
|
};
|
|
1235
733
|
// Method to hide the loading spinner
|
|
1236
734
|
KTDataTable.prototype._hideSpinner = function () {
|
|
1237
|
-
var
|
|
735
|
+
var _a, _b;
|
|
736
|
+
var root = this._element;
|
|
737
|
+
var spinnerSel = (_a = this._config.attributes) === null || _a === void 0 ? void 0 : _a.spinner;
|
|
738
|
+
var spinner = root && spinnerSel
|
|
739
|
+
? root.querySelector(spinnerSel)
|
|
740
|
+
: null;
|
|
1238
741
|
if (spinner) {
|
|
1239
742
|
spinner.style.display = 'none';
|
|
1240
743
|
}
|
|
1241
|
-
|
|
744
|
+
root === null || root === void 0 ? void 0 : root.classList.remove((_b = this._config.loadingClass) !== null && _b !== void 0 ? _b : 'loading');
|
|
1242
745
|
};
|
|
1243
746
|
// Method to create a spinner element if it doesn't exist
|
|
1244
747
|
KTDataTable.prototype._createSpinner = function () {
|
|
1245
|
-
|
|
748
|
+
var loading = this._config.loading;
|
|
749
|
+
if (!loading) {
|
|
1246
750
|
return null;
|
|
1247
751
|
}
|
|
1248
752
|
var template = document.createElement('template');
|
|
1249
|
-
template.innerHTML =
|
|
753
|
+
template.innerHTML = loading.template
|
|
1250
754
|
.trim()
|
|
1251
|
-
.replace('{content}',
|
|
1252
|
-
var
|
|
755
|
+
.replace('{content}', loading.content);
|
|
756
|
+
var first = template.content.firstChild;
|
|
757
|
+
if (!first || !(first instanceof HTMLElement)) {
|
|
758
|
+
return null;
|
|
759
|
+
}
|
|
760
|
+
var spinner = first;
|
|
1253
761
|
spinner.setAttribute('data-kt-datatable-spinner', 'true');
|
|
1254
762
|
this._tableElement.appendChild(spinner);
|
|
1255
763
|
return spinner;
|
|
@@ -1259,8 +767,7 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1259
767
|
* @returns {void}
|
|
1260
768
|
*/
|
|
1261
769
|
KTDataTable.prototype._saveState = function () {
|
|
1262
|
-
this.
|
|
1263
|
-
this._dispatchEvent('stateSave');
|
|
770
|
+
this._emit('stateSave');
|
|
1264
771
|
var ns = this._tableNamespace();
|
|
1265
772
|
if (ns) {
|
|
1266
773
|
localStorage.setItem(ns, JSON.stringify(this.getState()));
|
|
@@ -1277,7 +784,7 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1277
784
|
try {
|
|
1278
785
|
var state = JSON.parse(stateString);
|
|
1279
786
|
if (state)
|
|
1280
|
-
this.
|
|
787
|
+
this._stateStore.replaceState(state);
|
|
1281
788
|
return state;
|
|
1282
789
|
}
|
|
1283
790
|
catch (_a) { }
|
|
@@ -1308,32 +815,37 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1308
815
|
};
|
|
1309
816
|
KTDataTable.prototype._tableId = function () {
|
|
1310
817
|
var _a, _b;
|
|
1311
|
-
var
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
id = this._tableElement.getAttribute('id');
|
|
818
|
+
var tableIdAttr = (_a = this._tableElement) === null || _a === void 0 ? void 0 : _a.getAttribute('id');
|
|
819
|
+
if (tableIdAttr) {
|
|
820
|
+
return tableIdAttr;
|
|
1315
821
|
}
|
|
1316
|
-
|
|
1317
|
-
if (
|
|
1318
|
-
|
|
822
|
+
var rootIdAttr = (_b = this._element) === null || _b === void 0 ? void 0 : _b.getAttribute('id');
|
|
823
|
+
if (rootIdAttr) {
|
|
824
|
+
return rootIdAttr;
|
|
1319
825
|
}
|
|
1320
|
-
return
|
|
826
|
+
return '';
|
|
1321
827
|
};
|
|
1322
828
|
/**
|
|
1323
829
|
* Clean up all event listeners, handlers, and DOM nodes created by this instance.
|
|
1324
830
|
* This method is called before re-rendering or when disposing the component.
|
|
1325
831
|
*/
|
|
1326
832
|
KTDataTable.prototype._dispose = function () {
|
|
833
|
+
var _a, _b, _c;
|
|
834
|
+
var root = this._element;
|
|
835
|
+
if (!root) {
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
this._cleanupCallbacks.forEach(function (cleanup) { return cleanup(); });
|
|
839
|
+
this._cleanupCallbacks = [];
|
|
1327
840
|
// --- 1. Remove search input event listener (debounced) ---
|
|
1328
841
|
var tableId = this._tableId();
|
|
1329
842
|
var searchElement = document.querySelector("[data-kt-datatable-search=\"#".concat(tableId, "\"]"));
|
|
1330
843
|
if (searchElement) {
|
|
1331
844
|
var searchWithDebounce = KTDataTable.asSearchElementWithDebounce(searchElement);
|
|
1332
|
-
if (
|
|
1333
|
-
|
|
845
|
+
if (searchWithDebounce._debouncedSearch) {
|
|
846
|
+
searchElement.removeEventListener('keyup', searchWithDebounce._debouncedSearch);
|
|
847
|
+
delete searchWithDebounce._debouncedSearch;
|
|
1334
848
|
}
|
|
1335
|
-
searchElement.removeEventListener('keyup', searchWithDebounce._debouncedSearch);
|
|
1336
|
-
delete searchWithDebounce._debouncedSearch;
|
|
1337
849
|
}
|
|
1338
850
|
// --- 2. Remove page size dropdown event listener ---
|
|
1339
851
|
if (this._sizeElement && this._sizeElement.onchange) {
|
|
@@ -1353,10 +865,12 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1353
865
|
checkboxWithDispose.dispose();
|
|
1354
866
|
}
|
|
1355
867
|
else {
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
868
|
+
var checkSel = (_a = this._config.attributes) === null || _a === void 0 ? void 0 : _a.check;
|
|
869
|
+
if (checkSel) {
|
|
870
|
+
var headerCheckElement = root.querySelector(checkSel);
|
|
871
|
+
if (headerCheckElement) {
|
|
872
|
+
headerCheckElement.replaceWith(headerCheckElement.cloneNode(true));
|
|
873
|
+
}
|
|
1360
874
|
}
|
|
1361
875
|
}
|
|
1362
876
|
// KTDataTableSortAPI does not have a dispose method, but we can remove th click listeners by replacing them
|
|
@@ -1367,16 +881,20 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1367
881
|
});
|
|
1368
882
|
}
|
|
1369
883
|
// --- 5. Remove spinner DOM node if it exists ---
|
|
1370
|
-
var
|
|
1371
|
-
if (
|
|
1372
|
-
spinner.
|
|
884
|
+
var spinnerSel = (_b = this._config.attributes) === null || _b === void 0 ? void 0 : _b.spinner;
|
|
885
|
+
if (spinnerSel) {
|
|
886
|
+
var spinner = root.querySelector(spinnerSel);
|
|
887
|
+
if (spinner === null || spinner === void 0 ? void 0 : spinner.parentNode) {
|
|
888
|
+
spinner.parentNode.removeChild(spinner);
|
|
889
|
+
}
|
|
1373
890
|
}
|
|
1374
|
-
|
|
891
|
+
root.classList.remove((_c = this._config.loadingClass) !== null && _c !== void 0 ? _c : 'loading');
|
|
1375
892
|
// --- 6. Remove instance reference from the DOM element ---
|
|
1376
|
-
var elementWithInstance = KTDataTable.asElementWithInstance(
|
|
893
|
+
var elementWithInstance = KTDataTable.asElementWithInstance(root);
|
|
1377
894
|
if (elementWithInstance.instance) {
|
|
1378
895
|
delete elementWithInstance.instance;
|
|
1379
896
|
}
|
|
897
|
+
KTData.remove(root, this._name);
|
|
1380
898
|
// --- 7. (Optional) Clear localStorage state ---
|
|
1381
899
|
// Uncomment the following line if you want to clear state on dispose:
|
|
1382
900
|
// this._deleteState();
|
|
@@ -1401,23 +919,7 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1401
919
|
* @returns {KTDataTableStateInterface} The current state of the table.
|
|
1402
920
|
*/
|
|
1403
921
|
KTDataTable.prototype.getState = function () {
|
|
1404
|
-
return
|
|
1405
|
-
/**
|
|
1406
|
-
* The current page number.
|
|
1407
|
-
*/
|
|
1408
|
-
page: 1,
|
|
1409
|
-
/**
|
|
1410
|
-
* The field that the data is sorted by.
|
|
1411
|
-
*/
|
|
1412
|
-
sortField: null,
|
|
1413
|
-
/**
|
|
1414
|
-
* The sort order (ascending or descending).
|
|
1415
|
-
*/
|
|
1416
|
-
sortOrder: '',
|
|
1417
|
-
/**
|
|
1418
|
-
* The number of rows to display per page.
|
|
1419
|
-
*/
|
|
1420
|
-
pageSize: this._config.pageSize, filters: [] }, this._config._state);
|
|
922
|
+
return this._stateStore.getState();
|
|
1421
923
|
};
|
|
1422
924
|
/**
|
|
1423
925
|
* Sorts the data in the table by the specified field.
|
|
@@ -1428,10 +930,8 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1428
930
|
var state = this.getState();
|
|
1429
931
|
var sortOrder = this._sortHandler.toggleSortOrder(state.sortField, state.sortOrder, field);
|
|
1430
932
|
this._sortHandler.setSortIcon(field, sortOrder);
|
|
1431
|
-
this.
|
|
1432
|
-
this.
|
|
1433
|
-
this._fireEvent('sort', { field: field, order: sortOrder });
|
|
1434
|
-
this._dispatchEvent('sort', { field: field, order: sortOrder });
|
|
933
|
+
this._stateStore.setSort(field, sortOrder);
|
|
934
|
+
this._emit('sort', { field: field, order: sortOrder });
|
|
1435
935
|
this._updateData();
|
|
1436
936
|
};
|
|
1437
937
|
/**
|
|
@@ -1464,15 +964,13 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1464
964
|
* Triggers the 'reload' event and the 'kt.datatable.reload' custom event.
|
|
1465
965
|
*/
|
|
1466
966
|
KTDataTable.prototype.reload = function () {
|
|
1467
|
-
this.
|
|
1468
|
-
this._dispatchEvent('reload');
|
|
967
|
+
this._emit('reload');
|
|
1469
968
|
// Fetch the data from the server using the current sort and filter settings
|
|
1470
969
|
this._updateData();
|
|
1471
970
|
};
|
|
1472
971
|
KTDataTable.prototype.redraw = function (page) {
|
|
1473
972
|
if (page === void 0) { page = 1; }
|
|
1474
|
-
this.
|
|
1475
|
-
this._dispatchEvent('redraw');
|
|
973
|
+
this._emit('redraw');
|
|
1476
974
|
this._paginateData(page);
|
|
1477
975
|
};
|
|
1478
976
|
/**
|
|
@@ -1501,18 +999,16 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1501
999
|
* @throws Error if the filter object is null or undefined.
|
|
1502
1000
|
*/
|
|
1503
1001
|
KTDataTable.prototype.setFilter = function (filter) {
|
|
1504
|
-
this.
|
|
1505
|
-
filter,
|
|
1506
|
-
], false);
|
|
1507
|
-
this._config._state.page = 1;
|
|
1002
|
+
this._stateStore.setFilter(filter);
|
|
1508
1003
|
return this;
|
|
1509
1004
|
};
|
|
1510
1005
|
KTDataTable.prototype.dispose = function () {
|
|
1006
|
+
var _a;
|
|
1007
|
+
(_a = this._remoteProvider) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
1511
1008
|
this._dispose();
|
|
1512
1009
|
};
|
|
1513
1010
|
KTDataTable.prototype.search = function (query) {
|
|
1514
|
-
this.
|
|
1515
|
-
this._config._state.page = 1;
|
|
1011
|
+
this._stateStore.setSearch(query);
|
|
1516
1012
|
this.reload();
|
|
1517
1013
|
};
|
|
1518
1014
|
/**
|
|
@@ -1605,8 +1101,7 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1605
1101
|
*/
|
|
1606
1102
|
KTDataTable.prototype.check = function () {
|
|
1607
1103
|
this._checkbox.check();
|
|
1608
|
-
this.
|
|
1609
|
-
this._dispatchEvent('checked');
|
|
1104
|
+
this._emit('checked');
|
|
1610
1105
|
};
|
|
1611
1106
|
/**
|
|
1612
1107
|
* Uncheck all visible row checkboxes
|
|
@@ -1614,8 +1109,7 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1614
1109
|
*/
|
|
1615
1110
|
KTDataTable.prototype.uncheck = function () {
|
|
1616
1111
|
this._checkbox.uncheck();
|
|
1617
|
-
this.
|
|
1618
|
-
this._dispatchEvent('unchecked');
|
|
1112
|
+
this._emit('unchecked');
|
|
1619
1113
|
};
|
|
1620
1114
|
/**
|
|
1621
1115
|
* Get all checked row IDs (across all pages if preserveSelection is true)
|