@keenthemes/ktui 1.2.6 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -5
- package/dist/ktui.js +3775 -2298
- package/dist/ktui.min.js +1 -1
- package/dist/ktui.min.js.map +1 -1
- package/dist/styles.css +25 -5
- package/lib/cjs/components/datatable/datatable-checkbox.d.ts +37 -1
- package/lib/cjs/components/datatable/datatable-checkbox.d.ts.map +1 -1
- package/lib/cjs/components/datatable/datatable-checkbox.js +143 -156
- package/lib/cjs/components/datatable/datatable-checkbox.js.map +1 -1
- package/lib/cjs/components/datatable/datatable-column-utils.d.ts +30 -0
- package/lib/cjs/components/datatable/datatable-column-utils.d.ts.map +1 -0
- package/lib/cjs/components/datatable/datatable-column-utils.js +42 -0
- package/lib/cjs/components/datatable/datatable-column-utils.js.map +1 -0
- package/lib/cjs/components/datatable/datatable-contracts.d.ts +2 -4
- package/lib/cjs/components/datatable/datatable-contracts.d.ts.map +1 -1
- package/lib/cjs/components/datatable/datatable-defaults.d.ts +20 -0
- package/lib/cjs/components/datatable/datatable-defaults.d.ts.map +1 -0
- package/lib/cjs/components/datatable/datatable-defaults.js +193 -0
- package/lib/cjs/components/datatable/datatable-defaults.js.map +1 -0
- package/lib/cjs/components/datatable/datatable-layout-plugin.d.ts.map +1 -1
- package/lib/cjs/components/datatable/datatable-layout-plugin.js +11 -1
- package/lib/cjs/components/datatable/datatable-layout-plugin.js.map +1 -1
- package/lib/cjs/components/datatable/datatable-local-provider.d.ts.map +1 -1
- package/lib/cjs/components/datatable/datatable-local-provider.js +80 -24
- package/lib/cjs/components/datatable/datatable-local-provider.js.map +1 -1
- package/lib/cjs/components/datatable/datatable-pagination-renderer.d.ts.map +1 -1
- package/lib/cjs/components/datatable/datatable-pagination-renderer.js +3 -2
- package/lib/cjs/components/datatable/datatable-pagination-renderer.js.map +1 -1
- package/lib/cjs/components/datatable/datatable-registry.d.ts +18 -0
- package/lib/cjs/components/datatable/datatable-registry.d.ts.map +1 -0
- package/lib/cjs/components/datatable/datatable-registry.js +66 -0
- package/lib/cjs/components/datatable/datatable-registry.js.map +1 -0
- package/lib/cjs/components/datatable/datatable-remote-provider.d.ts.map +1 -1
- package/lib/cjs/components/datatable/datatable-remote-provider.js +1 -2
- package/lib/cjs/components/datatable/datatable-remote-provider.js.map +1 -1
- package/lib/cjs/components/datatable/datatable-search-handler.d.ts +10 -0
- package/lib/cjs/components/datatable/datatable-search-handler.d.ts.map +1 -0
- package/lib/cjs/components/datatable/datatable-search-handler.js +65 -0
- package/lib/cjs/components/datatable/datatable-search-handler.js.map +1 -0
- package/lib/cjs/components/datatable/datatable-sort.d.ts +31 -4
- package/lib/cjs/components/datatable/datatable-sort.d.ts.map +1 -1
- package/lib/cjs/components/datatable/datatable-sort.js +86 -58
- package/lib/cjs/components/datatable/datatable-sort.js.map +1 -1
- package/lib/cjs/components/datatable/datatable-spinner.d.ts +30 -0
- package/lib/cjs/components/datatable/datatable-spinner.d.ts.map +1 -0
- package/lib/cjs/components/datatable/datatable-spinner.js +54 -0
- package/lib/cjs/components/datatable/datatable-spinner.js.map +1 -0
- package/lib/cjs/components/datatable/datatable-state-persistence.d.ts +19 -0
- package/lib/cjs/components/datatable/datatable-state-persistence.d.ts.map +1 -0
- package/lib/cjs/components/datatable/datatable-state-persistence.js +59 -0
- package/lib/cjs/components/datatable/datatable-state-persistence.js.map +1 -0
- package/lib/cjs/components/datatable/datatable-table-renderer.d.ts +2 -0
- package/lib/cjs/components/datatable/datatable-table-renderer.d.ts.map +1 -1
- package/lib/cjs/components/datatable/datatable-table-renderer.js +75 -16
- package/lib/cjs/components/datatable/datatable-table-renderer.js.map +1 -1
- package/lib/cjs/components/datatable/datatable-utils.d.ts +10 -0
- package/lib/cjs/components/datatable/datatable-utils.d.ts.map +1 -0
- package/lib/cjs/components/datatable/datatable-utils.js +15 -0
- package/lib/cjs/components/datatable/datatable-utils.js.map +1 -0
- package/lib/cjs/components/datatable/datatable.d.ts +26 -34
- package/lib/cjs/components/datatable/datatable.d.ts.map +1 -1
- package/lib/cjs/components/datatable/datatable.js +155 -492
- package/lib/cjs/components/datatable/datatable.js.map +1 -1
- package/lib/cjs/components/datatable/index.d.ts +1 -1
- package/lib/cjs/components/datatable/index.d.ts.map +1 -1
- package/lib/cjs/components/datatable/types.d.ts +100 -11
- package/lib/cjs/components/datatable/types.d.ts.map +1 -1
- package/lib/cjs/index.d.ts +1 -1
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +6 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/components/datatable/datatable-checkbox.d.ts +37 -1
- package/lib/esm/components/datatable/datatable-checkbox.d.ts.map +1 -1
- package/lib/esm/components/datatable/datatable-checkbox.js +142 -155
- package/lib/esm/components/datatable/datatable-checkbox.js.map +1 -1
- package/lib/esm/components/datatable/datatable-column-utils.d.ts +30 -0
- package/lib/esm/components/datatable/datatable-column-utils.d.ts.map +1 -0
- package/lib/esm/components/datatable/datatable-column-utils.js +38 -0
- package/lib/esm/components/datatable/datatable-column-utils.js.map +1 -0
- package/lib/esm/components/datatable/datatable-contracts.d.ts +2 -4
- package/lib/esm/components/datatable/datatable-contracts.d.ts.map +1 -1
- package/lib/esm/components/datatable/datatable-defaults.d.ts +20 -0
- package/lib/esm/components/datatable/datatable-defaults.d.ts.map +1 -0
- package/lib/esm/components/datatable/datatable-defaults.js +190 -0
- package/lib/esm/components/datatable/datatable-defaults.js.map +1 -0
- package/lib/esm/components/datatable/datatable-layout-plugin.d.ts.map +1 -1
- package/lib/esm/components/datatable/datatable-layout-plugin.js +11 -1
- package/lib/esm/components/datatable/datatable-layout-plugin.js.map +1 -1
- package/lib/esm/components/datatable/datatable-local-provider.d.ts.map +1 -1
- package/lib/esm/components/datatable/datatable-local-provider.js +80 -24
- package/lib/esm/components/datatable/datatable-local-provider.js.map +1 -1
- package/lib/esm/components/datatable/datatable-pagination-renderer.d.ts.map +1 -1
- package/lib/esm/components/datatable/datatable-pagination-renderer.js +3 -2
- package/lib/esm/components/datatable/datatable-pagination-renderer.js.map +1 -1
- package/lib/esm/components/datatable/datatable-registry.d.ts +18 -0
- package/lib/esm/components/datatable/datatable-registry.d.ts.map +1 -0
- package/lib/esm/components/datatable/datatable-registry.js +63 -0
- package/lib/esm/components/datatable/datatable-registry.js.map +1 -0
- package/lib/esm/components/datatable/datatable-remote-provider.d.ts.map +1 -1
- package/lib/esm/components/datatable/datatable-remote-provider.js +1 -2
- package/lib/esm/components/datatable/datatable-remote-provider.js.map +1 -1
- package/lib/esm/components/datatable/datatable-search-handler.d.ts +10 -0
- package/lib/esm/components/datatable/datatable-search-handler.d.ts.map +1 -0
- package/lib/esm/components/datatable/datatable-search-handler.js +62 -0
- package/lib/esm/components/datatable/datatable-search-handler.js.map +1 -0
- package/lib/esm/components/datatable/datatable-sort.d.ts +31 -4
- package/lib/esm/components/datatable/datatable-sort.d.ts.map +1 -1
- package/lib/esm/components/datatable/datatable-sort.js +85 -57
- package/lib/esm/components/datatable/datatable-sort.js.map +1 -1
- package/lib/esm/components/datatable/datatable-spinner.d.ts +30 -0
- package/lib/esm/components/datatable/datatable-spinner.d.ts.map +1 -0
- package/lib/esm/components/datatable/datatable-spinner.js +51 -0
- package/lib/esm/components/datatable/datatable-spinner.js.map +1 -0
- package/lib/esm/components/datatable/datatable-state-persistence.d.ts +19 -0
- package/lib/esm/components/datatable/datatable-state-persistence.d.ts.map +1 -0
- package/lib/esm/components/datatable/datatable-state-persistence.js +55 -0
- package/lib/esm/components/datatable/datatable-state-persistence.js.map +1 -0
- package/lib/esm/components/datatable/datatable-table-renderer.d.ts +2 -0
- package/lib/esm/components/datatable/datatable-table-renderer.d.ts.map +1 -1
- package/lib/esm/components/datatable/datatable-table-renderer.js +75 -16
- package/lib/esm/components/datatable/datatable-table-renderer.js.map +1 -1
- package/lib/esm/components/datatable/datatable-utils.d.ts +10 -0
- package/lib/esm/components/datatable/datatable-utils.d.ts.map +1 -0
- package/lib/esm/components/datatable/datatable-utils.js +12 -0
- package/lib/esm/components/datatable/datatable-utils.js.map +1 -0
- package/lib/esm/components/datatable/datatable.d.ts +26 -34
- package/lib/esm/components/datatable/datatable.d.ts.map +1 -1
- package/lib/esm/components/datatable/datatable.js +157 -494
- package/lib/esm/components/datatable/datatable.js.map +1 -1
- package/lib/esm/components/datatable/index.d.ts +1 -1
- package/lib/esm/components/datatable/index.d.ts.map +1 -1
- package/lib/esm/components/datatable/types.d.ts +100 -11
- package/lib/esm/components/datatable/types.d.ts.map +1 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +6 -0
- package/lib/esm/index.js.map +1 -1
- package/package.json +5 -1
- package/skills/ktui/SKILL.md +711 -0
- package/skills/ktui-datatable/SKILL.md +302 -0
- package/skills/ktui-install/SKILL.md +150 -0
- package/skills/ktui-select/SKILL.md +271 -0
- package/src/components/__tests__/component.test.ts +347 -0
- package/src/components/collapse/collapse.css +2 -2
- package/src/components/datatable/__tests__/architecture-boundaries.test.ts +56 -8
- package/src/components/datatable/__tests__/currency-sort.test.ts +25 -28
- package/src/components/datatable/__tests__/datatable-checkbox.test.ts +527 -0
- package/src/components/datatable/__tests__/datatable-column-utils.test.ts +117 -0
- package/src/components/datatable/__tests__/datatable-defaults.test.ts +57 -0
- package/src/components/datatable/__tests__/datatable-finalize-extended.test.ts +361 -0
- package/src/components/datatable/__tests__/datatable-fixed-layout.test.ts +427 -0
- package/src/components/datatable/__tests__/datatable-improvements.test.ts +484 -0
- package/src/components/datatable/__tests__/datatable-pagination-extended.test.ts +508 -0
- package/src/components/datatable/__tests__/datatable-public-api.test.ts +269 -0
- package/src/components/datatable/__tests__/datatable-registry.test.ts +172 -0
- package/src/components/datatable/__tests__/datatable-remote-provider.test.ts +468 -0
- package/src/components/datatable/__tests__/datatable-search-handler.test.ts +124 -0
- package/src/components/datatable/__tests__/datatable-sort-extended.test.ts +417 -0
- package/src/components/datatable/__tests__/datatable-spinner.test.ts +95 -0
- package/src/components/datatable/__tests__/datatable-table-renderer-extended.test.ts +425 -0
- package/src/components/datatable/__tests__/datatable-types.test.ts +117 -0
- package/src/components/datatable/__tests__/datatable-utils.test.ts +52 -0
- package/src/components/datatable/__tests__/multi-row-headers.test.ts +7 -7
- package/src/components/datatable/__tests__/pagination-reset.test.ts +129 -6
- package/src/components/datatable/__tests__/race-conditions.test.ts +11 -11
- package/src/components/datatable/__tests__/setup.ts +12 -4
- package/src/components/datatable/datatable-checkbox.ts +144 -145
- package/src/components/datatable/datatable-column-utils.ts +63 -0
- package/src/components/datatable/datatable-contracts.ts +2 -3
- package/src/components/datatable/datatable-defaults.ts +204 -0
- package/src/components/datatable/datatable-layout-plugin.ts +11 -1
- package/src/components/datatable/datatable-local-provider.ts +91 -28
- package/src/components/datatable/datatable-pagination-renderer.ts +3 -2
- package/src/components/datatable/datatable-registry.ts +89 -0
- package/src/components/datatable/datatable-remote-provider.ts +1 -3
- package/src/components/datatable/datatable-search-handler.ts +97 -0
- package/src/components/datatable/datatable-sort.ts +111 -66
- package/src/components/datatable/datatable-spinner.ts +103 -0
- package/src/components/datatable/datatable-state-persistence.ts +67 -0
- package/src/components/datatable/datatable-table-renderer.ts +81 -18
- package/src/components/datatable/datatable-utils.ts +12 -0
- package/src/components/datatable/datatable.ts +191 -580
- package/src/components/datatable/index.ts +3 -0
- package/src/components/datatable/types.ts +124 -23
- package/src/helpers/__tests__/dom.test.ts +776 -0
- package/src/helpers/__tests__/utils.test.ts +332 -0
- package/src/index.ts +10 -0
- package/skills/ktui-components/SKILL.md +0 -41
- package/skills/ktui-theming/SKILL.md +0 -50
- package/src/components/datatable/datatable-event-adapter.ts +0 -21
|
@@ -65,22 +65,36 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
65
65
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
69
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
70
|
+
if (ar || !(i in from)) {
|
|
71
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
72
|
+
ar[i] = from[i];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
76
|
+
};
|
|
68
77
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
69
78
|
exports.KTDataTable = void 0;
|
|
70
79
|
exports.initAllDataTables = initAllDataTables;
|
|
71
80
|
var component_1 = require("../component");
|
|
72
|
-
var index_1 = require("../../index");
|
|
73
81
|
var data_1 = require("../../helpers/data");
|
|
74
82
|
var datatable_checkbox_1 = require("./datatable-checkbox");
|
|
75
83
|
var datatable_sort_1 = require("./datatable-sort");
|
|
76
84
|
var datatable_layout_plugin_1 = require("./datatable-layout-plugin");
|
|
77
|
-
var
|
|
85
|
+
var datatable_defaults_1 = require("./datatable-defaults");
|
|
86
|
+
var datatable_column_utils_1 = require("./datatable-column-utils");
|
|
78
87
|
var datatable_local_provider_1 = require("./datatable-local-provider");
|
|
79
88
|
var datatable_remote_provider_1 = require("./datatable-remote-provider");
|
|
80
89
|
var datatable_state_store_1 = require("./datatable-state-store");
|
|
81
90
|
var datatable_pagination_renderer_1 = require("./datatable-pagination-renderer");
|
|
82
91
|
var datatable_table_renderer_1 = require("./datatable-table-renderer");
|
|
83
92
|
var utils_1 = require("../../helpers/utils");
|
|
93
|
+
var datatable_search_handler_1 = require("./datatable-search-handler");
|
|
94
|
+
var datatable_state_persistence_1 = require("./datatable-state-persistence");
|
|
95
|
+
var datatable_spinner_1 = require("./datatable-spinner");
|
|
96
|
+
var datatable_registry_1 = require("./datatable-registry");
|
|
97
|
+
var datatable_utils_1 = require("./datatable-utils");
|
|
84
98
|
/**
|
|
85
99
|
* Custom DataTable plugin class with server-side API, pagination, and sorting
|
|
86
100
|
* @classdesc A custom KTComponent class that integrates server-side API, pagination, and sorting functionality into a table.
|
|
@@ -90,21 +104,27 @@ var utils_1 = require("../../helpers/utils");
|
|
|
90
104
|
* @param {HTMLElement} element The table element
|
|
91
105
|
* @param {KTDataTableConfigInterface} [config] Additional configuration options
|
|
92
106
|
*/
|
|
107
|
+
var datatableRegistry = (0, datatable_registry_1.createDataTableRegistry)();
|
|
93
108
|
var KTDataTable = /** @class */ (function (_super) {
|
|
94
109
|
__extends(KTDataTable, _super);
|
|
95
110
|
function KTDataTable(element, config) {
|
|
96
111
|
var _this = _super.call(this) || this;
|
|
97
112
|
_this._name = 'datatable';
|
|
98
|
-
_this.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
113
|
+
_this._originalClasses = {
|
|
114
|
+
tbody: '',
|
|
115
|
+
thead: '',
|
|
116
|
+
tr: [],
|
|
117
|
+
td: [],
|
|
118
|
+
th: [],
|
|
119
|
+
};
|
|
103
120
|
_this._infoElement = null;
|
|
104
121
|
_this._sizeElement = null;
|
|
105
122
|
_this._paginationElement = null;
|
|
106
123
|
_this._layoutPlugin = null;
|
|
107
124
|
_this._cleanupCallbacks = [];
|
|
125
|
+
_this._searchHandler = (0, datatable_search_handler_1.createSearchHandler)();
|
|
126
|
+
_this._statePersistence = (0, datatable_state_persistence_1.createStatePersistence)();
|
|
127
|
+
_this._spinner = (0, datatable_spinner_1.createSpinner)();
|
|
108
128
|
_this._data = [];
|
|
109
129
|
_this._isFetching = false;
|
|
110
130
|
if (data_1.default.has(element, _this._name)) {
|
|
@@ -126,23 +146,39 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
126
146
|
_this._buildConfig();
|
|
127
147
|
_this._normalizePageSizeConfig();
|
|
128
148
|
_this._stateStore = new datatable_state_store_1.KTDataTableConfigStateStore(_this._config);
|
|
129
|
-
_this._eventAdapter =
|
|
149
|
+
_this._eventAdapter = {
|
|
150
|
+
emit: function (eventName, eventData) {
|
|
151
|
+
_this._emit(eventName, eventData);
|
|
152
|
+
},
|
|
153
|
+
};
|
|
130
154
|
// Store the instance directly on the element
|
|
131
|
-
|
|
155
|
+
datatableRegistry.register(element, _this);
|
|
132
156
|
_this._initElements();
|
|
133
157
|
_this._layoutPlugin = _this._createLayoutPlugin();
|
|
134
158
|
_this._tableRenderer = new datatable_table_renderer_1.KTDataTableDomTableRenderer();
|
|
135
159
|
_this._paginationRenderer = new datatable_pagination_renderer_1.KTDataTableDomPaginationRenderer();
|
|
136
160
|
_this._initDataProviders();
|
|
137
161
|
// Initialize checkbox handler
|
|
138
|
-
_this._checkbox =
|
|
162
|
+
_this._checkbox = new datatable_checkbox_1.KTDataTableCheckboxHandler(_this._element, _this._config, _this._emit.bind(_this), {
|
|
163
|
+
getState: function () { return _this._stateStore.getState(); },
|
|
164
|
+
setSelectedRows: function (rows) {
|
|
165
|
+
_this._stateStore.patchState({ selectedRows: rows });
|
|
166
|
+
},
|
|
167
|
+
});
|
|
139
168
|
// Initialize sort handler
|
|
140
|
-
_this._sortHandler =
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
169
|
+
_this._sortHandler = new datatable_sort_1.KTDataTableSortHandler({
|
|
170
|
+
config: _this._config,
|
|
171
|
+
theadElement: _this._theadElement,
|
|
172
|
+
getState: function () { return ({
|
|
173
|
+
sortField: _this.getState().sortField,
|
|
174
|
+
sortOrder: _this.getState().sortOrder,
|
|
175
|
+
}); },
|
|
176
|
+
setState: function (field, order) {
|
|
177
|
+
_this._stateStore.setSort(field, order);
|
|
178
|
+
},
|
|
179
|
+
emit: _this._emit.bind(_this),
|
|
180
|
+
updateData: _this._updateData.bind(_this),
|
|
181
|
+
});
|
|
146
182
|
_this._sortHandler.initSort();
|
|
147
183
|
if (_this._config.stateSave === false) {
|
|
148
184
|
_this._deleteState();
|
|
@@ -152,17 +188,11 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
152
188
|
_this._normalizePageState();
|
|
153
189
|
}
|
|
154
190
|
_this._updateData();
|
|
155
|
-
_this._emit('init');
|
|
156
191
|
return _this;
|
|
157
192
|
}
|
|
158
|
-
KTDataTable.asElementWithInstance = function (element) {
|
|
159
|
-
return element;
|
|
160
|
-
};
|
|
161
|
-
KTDataTable.asSearchElementWithDebounce = function (element) {
|
|
162
|
-
return element;
|
|
163
|
-
};
|
|
164
193
|
KTDataTable.prototype._emit = function (eventName, eventData) {
|
|
165
|
-
this.
|
|
194
|
+
this._fireEvent(eventName, eventData);
|
|
195
|
+
this._dispatchEvent("kt.datatable.".concat(eventName), eventData);
|
|
166
196
|
};
|
|
167
197
|
KTDataTable.prototype._initDataProviders = function () {
|
|
168
198
|
var _this = this;
|
|
@@ -211,7 +241,7 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
211
241
|
.map(function (size) { return Number(size); })
|
|
212
242
|
.filter(function (size) { return Number.isFinite(size) && size > 0; })
|
|
213
243
|
.map(function (size) { return Math.floor(size); });
|
|
214
|
-
var fallbackPageSizes = [
|
|
244
|
+
var fallbackPageSizes = __spreadArray([], datatable_defaults_1.DEFAULT_PAGE_SIZES, true);
|
|
215
245
|
this._config.pageSizes =
|
|
216
246
|
pageSizes.length > 0 ? Array.from(new Set(pageSizes)) : fallbackPageSizes;
|
|
217
247
|
var configuredPageSize = Number(this._config.pageSize);
|
|
@@ -244,201 +274,37 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
244
274
|
* @param config User-provided configuration options
|
|
245
275
|
* @returns Default configuration merged with user-provided options
|
|
246
276
|
*/
|
|
277
|
+
KTDataTable.prototype._createDefaultSearchCallback = function () {
|
|
278
|
+
return (function (data, search) {
|
|
279
|
+
if (!data || !search) {
|
|
280
|
+
return [];
|
|
281
|
+
}
|
|
282
|
+
var searchLower = search.toLowerCase();
|
|
283
|
+
return data.filter(function (item) {
|
|
284
|
+
if (!item) {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
return Object.values(item).some(function (value) {
|
|
288
|
+
if (typeof value !== 'string' &&
|
|
289
|
+
typeof value !== 'number' &&
|
|
290
|
+
typeof value !== 'boolean') {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
var valueText = (0, datatable_utils_1.stripHtml)(value).toLowerCase();
|
|
294
|
+
return valueText.includes(searchLower);
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
};
|
|
247
299
|
KTDataTable.prototype._initDefaultConfig = function (config) {
|
|
248
300
|
var _this = this;
|
|
249
|
-
return __assign({
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
*/
|
|
253
|
-
requestMethod: 'GET',
|
|
254
|
-
/**
|
|
255
|
-
* Custom HTTP headers for the API request
|
|
256
|
-
*/
|
|
257
|
-
requestHeaders: {
|
|
258
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
259
|
-
},
|
|
260
|
-
/**
|
|
261
|
-
* Pagination info template
|
|
262
|
-
*/
|
|
263
|
-
info: '{start}-{end} of {total}',
|
|
264
|
-
/**
|
|
265
|
-
* Info text when there is no data
|
|
266
|
-
*/
|
|
267
|
-
infoEmpty: 'No records found',
|
|
268
|
-
/**
|
|
269
|
-
* Available page sizes
|
|
270
|
-
*/
|
|
271
|
-
pageSizes: [5, 10, 20, 30, 50],
|
|
272
|
-
/**
|
|
273
|
-
* Default page size
|
|
274
|
-
*/
|
|
275
|
-
pageSize: 10,
|
|
276
|
-
/**
|
|
277
|
-
* Enable or disable pagination more button
|
|
278
|
-
*/
|
|
279
|
-
pageMore: true,
|
|
280
|
-
/**
|
|
281
|
-
* Maximum number of pages before enabling pagination more button
|
|
282
|
-
*/
|
|
283
|
-
pageMoreLimit: 3,
|
|
284
|
-
/**
|
|
285
|
-
* Pagination button templates
|
|
286
|
-
*/
|
|
287
|
-
pagination: {
|
|
288
|
-
number: {
|
|
289
|
-
/**
|
|
290
|
-
* CSS classes to be added to the pagination button
|
|
291
|
-
*/
|
|
292
|
-
class: 'kt-datatable-pagination-button',
|
|
293
|
-
/**
|
|
294
|
-
* Text to be displayed in the pagination button
|
|
295
|
-
*/
|
|
296
|
-
text: '{page}',
|
|
297
|
-
},
|
|
298
|
-
previous: {
|
|
299
|
-
/**
|
|
300
|
-
* CSS classes to be added to the previous pagination button
|
|
301
|
-
*/
|
|
302
|
-
class: 'kt-datatable-pagination-button kt-datatable-pagination-prev',
|
|
303
|
-
/**
|
|
304
|
-
* Text to be displayed in the previous pagination button
|
|
305
|
-
*/
|
|
306
|
-
text: "\n\t\t\t\t\t\t<svg class=\"rtl:transform rtl:rotate-180 size-3.5 shrink-0\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n\t\t\t\t\t\t\t<path d=\"M8.86501 16.7882V12.8481H21.1459C21.3724 12.8481 21.5897 12.7581 21.7498 12.5979C21.91 12.4378 22 12.2205 22 11.994C22 11.7675 21.91 11.5503 21.7498 11.3901C21.5897 11.2299 21.3724 11.1399 21.1459 11.1399H8.86501V7.2112C8.86628 7.10375 8.83517 6.9984 8.77573 6.90887C8.7163 6.81934 8.63129 6.74978 8.53177 6.70923C8.43225 6.66869 8.32283 6.65904 8.21775 6.68155C8.11267 6.70405 8.0168 6.75766 7.94262 6.83541L2.15981 11.6182C2.1092 11.668 2.06901 11.7274 2.04157 11.7929C2.01413 11.8584 2 11.9287 2 11.9997C2 12.0707 2.01413 12.141 2.04157 12.2065C2.06901 12.272 2.1092 12.3314 2.15981 12.3812L7.94262 17.164C8.0168 17.2417 8.11267 17.2953 8.21775 17.3178C8.32283 17.3403 8.43225 17.3307 8.53177 17.2902C8.63129 17.2496 8.7163 17.18 8.77573 17.0905C8.83517 17.001 8.86628 16.8956 8.86501 16.7882Z\" fill=\"currentColor\"/>\n\t\t\t\t\t\t</svg>\n\t\t\t\t\t",
|
|
307
|
-
},
|
|
308
|
-
next: {
|
|
309
|
-
/**
|
|
310
|
-
* CSS classes to be added to the next pagination button
|
|
311
|
-
*/
|
|
312
|
-
class: 'kt-datatable-pagination-button kt-datatable-pagination-next',
|
|
313
|
-
/**
|
|
314
|
-
* Text to be displayed in the next pagination button
|
|
315
|
-
*/
|
|
316
|
-
text: "\n\t\t\t\t\t\t<svg class=\"rtl:transform rtl:rotate-180 size-3.5 shrink-0\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n\t\t\t\t\t\t\t<path d=\"M15.135 7.21144V11.1516H2.85407C2.62756 11.1516 2.41032 11.2415 2.25015 11.4017C2.08998 11.5619 2 11.7791 2 12.0056C2 12.2321 2.08998 12.4494 2.25015 12.6096C2.41032 12.7697 2.62756 12.8597 2.85407 12.8597H15.135V16.7884C15.1337 16.8959 15.1648 17.0012 15.2243 17.0908C15.2837 17.1803 15.3687 17.2499 15.4682 17.2904C15.5677 17.3309 15.6772 17.3406 15.7822 17.3181C15.8873 17.2956 15.9832 17.242 16.0574 17.1642L21.8402 12.3814C21.8908 12.3316 21.931 12.2722 21.9584 12.2067C21.9859 12.1412 22 12.0709 22 11.9999C22 11.9289 21.9859 11.8586 21.9584 11.7931C21.931 11.7276 21.8908 11.6683 21.8402 11.6185L16.0574 6.83565C15.9832 6.75791 15.8873 6.70429 15.7822 6.68179C15.6772 6.65929 15.5677 6.66893 15.4682 6.70948C15.3687 6.75002 15.2837 6.81959 15.2243 6.90911C15.1648 6.99864 15.1337 7.10399 15.135 7.21144Z\" fill=\"currentColor\"/>\n\t\t\t\t\t\t</svg>\n\t\t\t\t\t",
|
|
317
|
-
},
|
|
318
|
-
more: {
|
|
319
|
-
/**
|
|
320
|
-
* CSS classes to be added to the pagination more button
|
|
321
|
-
*/
|
|
322
|
-
class: 'kt-datatable-pagination-button kt-datatable-pagination-more',
|
|
323
|
-
/**
|
|
324
|
-
* Text to be displayed in the pagination more button
|
|
325
|
-
*/
|
|
326
|
-
text: '...',
|
|
327
|
-
},
|
|
328
|
-
},
|
|
329
|
-
/**
|
|
330
|
-
* Sorting options
|
|
331
|
-
*/
|
|
332
|
-
sort: {
|
|
333
|
-
/**
|
|
334
|
-
* CSS classes to be added to the sortable headers
|
|
335
|
-
*/
|
|
336
|
-
classes: {
|
|
337
|
-
base: 'kt-table-col',
|
|
338
|
-
asc: 'asc',
|
|
339
|
-
desc: 'desc',
|
|
340
|
-
},
|
|
341
|
-
/**
|
|
342
|
-
* Local sorting callback function
|
|
343
|
-
* Sorts the data array based on the sort field and order
|
|
344
|
-
* @param data Data array to be sorted
|
|
345
|
-
* @param sortField Property name of the data object to be sorted by
|
|
346
|
-
* @param sortOrder Sorting order (ascending or descending)
|
|
347
|
-
* @returns Sorted data array
|
|
348
|
-
*/
|
|
349
|
-
callback: function (data, sortField, sortOrder) {
|
|
301
|
+
return __assign(__assign(__assign({}, datatable_defaults_1.DATATABLE_DEFAULTS), {
|
|
302
|
+
// Per-instance state; DATATABLE_DEFAULTS._state is a shared singleton.
|
|
303
|
+
_state: {}, sort: __assign(__assign({}, datatable_defaults_1.DATATABLE_DEFAULTS.sort), { callback: function (data, sortField, sortOrder) {
|
|
350
304
|
return _this._sortHandler
|
|
351
305
|
? _this._sortHandler.sortData(data, sortField, sortOrder)
|
|
352
306
|
: data;
|
|
353
|
-
},
|
|
354
|
-
}, search: {
|
|
355
|
-
/**
|
|
356
|
-
* Delay in milliseconds before the search function is applied to the data array
|
|
357
|
-
* @default 500
|
|
358
|
-
*/
|
|
359
|
-
delay: 500, // ms
|
|
360
|
-
/**
|
|
361
|
-
* Local search callback function
|
|
362
|
-
* Filters the data array based on the search string
|
|
363
|
-
* @param data Data array to be filtered
|
|
364
|
-
* @param search Search string used to filter the data array
|
|
365
|
-
* @returns Filtered data array
|
|
366
|
-
*/
|
|
367
|
-
callback: function (data, search) {
|
|
368
|
-
if (!data || !search) {
|
|
369
|
-
return [];
|
|
370
|
-
}
|
|
371
|
-
return data.filter(function (item) {
|
|
372
|
-
if (!item) {
|
|
373
|
-
return false;
|
|
374
|
-
}
|
|
375
|
-
return Object.values(item).some(function (value) {
|
|
376
|
-
if (typeof value !== 'string' &&
|
|
377
|
-
typeof value !== 'number' &&
|
|
378
|
-
typeof value !== 'boolean') {
|
|
379
|
-
return false;
|
|
380
|
-
}
|
|
381
|
-
var valueText = String(value)
|
|
382
|
-
.replace(/<|>| /g, '')
|
|
383
|
-
.toLowerCase();
|
|
384
|
-
return valueText.includes(search.toLowerCase());
|
|
385
|
-
});
|
|
386
|
-
});
|
|
387
|
-
},
|
|
388
|
-
},
|
|
389
|
-
/**
|
|
390
|
-
* Loading spinner options
|
|
391
|
-
*/
|
|
392
|
-
loading: {
|
|
393
|
-
/**
|
|
394
|
-
* Template to be displayed during data fetching process
|
|
395
|
-
*/
|
|
396
|
-
template: "\n\t\t\t\t\t<div class=\"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2\">\n\t\t\t\t\t\t<div class=\"kt-datatable-loading\">\n\t\t\t\t\t\t\t<svg class=\"animate-spin -ml-1 h-5 w-5 text-gray-600\" xmlns=\"http://www.w3.org/2000/svg\" fill=\"none\" viewBox=\"0 0 24 24\">\n\t\t\t\t\t\t\t\t<circle class=\"opacity-25\" cx=\"12\" cy=\"12\" r=\"10\" stroke=\"currentColor\" stroke-width=\"3\"></circle>\n\t\t\t\t\t\t\t\t<path class=\"opacity-75\" fill=\"currentColor\" d=\"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z\"></path>\n\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t\t{content}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t",
|
|
397
|
-
/**
|
|
398
|
-
* Loading text to be displayed in the template
|
|
399
|
-
*/
|
|
400
|
-
content: 'Loading...',
|
|
401
|
-
},
|
|
402
|
-
/**
|
|
403
|
-
* Selectors of the elements to be targeted
|
|
404
|
-
*/
|
|
405
|
-
attributes: {
|
|
406
|
-
/**
|
|
407
|
-
* Data table element
|
|
408
|
-
*/
|
|
409
|
-
table: 'table[data-kt-datatable-table="true"]',
|
|
410
|
-
/**
|
|
411
|
-
* Pagination info element
|
|
412
|
-
*/
|
|
413
|
-
info: '[data-kt-datatable-info="true"]',
|
|
414
|
-
/**
|
|
415
|
-
* Page size dropdown element
|
|
416
|
-
*/
|
|
417
|
-
size: '[data-kt-datatable-size="true"]',
|
|
418
|
-
/**
|
|
419
|
-
* Pagination element
|
|
420
|
-
*/
|
|
421
|
-
pagination: '[data-kt-datatable-pagination="true"]',
|
|
422
|
-
/**
|
|
423
|
-
* Spinner element
|
|
424
|
-
*/
|
|
425
|
-
spinner: '[data-kt-datatable-spinner="true"]',
|
|
426
|
-
/**
|
|
427
|
-
* Checkbox element
|
|
428
|
-
*/
|
|
429
|
-
check: '[data-kt-datatable-check="true"]',
|
|
430
|
-
checkbox: '[data-kt-datatable-row-check="true"]',
|
|
431
|
-
},
|
|
432
|
-
/**
|
|
433
|
-
* Enable or disable state saving
|
|
434
|
-
*/
|
|
435
|
-
stateSave: true, checkbox: {
|
|
436
|
-
checkedClass: 'checked',
|
|
437
|
-
},
|
|
438
|
-
/**
|
|
439
|
-
* Private properties
|
|
440
|
-
*/
|
|
441
|
-
_state: {}, loadingClass: 'loading' }, config);
|
|
307
|
+
} }), search: __assign(__assign({}, datatable_defaults_1.DATATABLE_DEFAULTS.search), { callback: this._createDefaultSearchCallback() }) }), config);
|
|
442
308
|
};
|
|
443
309
|
/**
|
|
444
310
|
* Initialize table, tbody, thead, info, size, and pagination elements
|
|
@@ -479,24 +345,24 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
479
345
|
var _this = this;
|
|
480
346
|
// Store tbody class
|
|
481
347
|
if (this._tbodyElement) {
|
|
482
|
-
this.
|
|
348
|
+
this._originalClasses.tbody = this._tbodyElement.className || '';
|
|
483
349
|
}
|
|
484
350
|
// Store thead class and th classes
|
|
485
351
|
if (this._theadElement) {
|
|
486
|
-
this.
|
|
352
|
+
this._originalClasses.thead = this._theadElement.className || '';
|
|
487
353
|
// Store th classes
|
|
488
354
|
var thElements = this._theadElement.querySelectorAll('th');
|
|
489
|
-
this.
|
|
355
|
+
this._originalClasses.th = Array.from(thElements).map(function (th) { return th.className || ''; });
|
|
490
356
|
}
|
|
491
357
|
// Store tr and td classes
|
|
492
358
|
if (this._tbodyElement) {
|
|
493
359
|
var originalRows = this._tbodyElement.querySelectorAll('tr');
|
|
494
|
-
this.
|
|
360
|
+
this._originalClasses.tr = Array.from(originalRows).map(function (row) { return row.className || ''; });
|
|
495
361
|
// Store td classes as a 2D array
|
|
496
|
-
this.
|
|
362
|
+
this._originalClasses.td = [];
|
|
497
363
|
Array.from(originalRows).forEach(function (row, rowIndex) {
|
|
498
364
|
var tdElements = row.querySelectorAll('td');
|
|
499
|
-
_this.
|
|
365
|
+
_this._originalClasses.td[rowIndex] = Array.from(tdElements).map(function (td) { return td.className || ''; });
|
|
500
366
|
});
|
|
501
367
|
}
|
|
502
368
|
};
|
|
@@ -516,8 +382,7 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
516
382
|
_b.label = 1;
|
|
517
383
|
case 1:
|
|
518
384
|
_b.trys.push([1, , 8, 9]);
|
|
519
|
-
this.
|
|
520
|
-
this._emit('fetch');
|
|
385
|
+
this._spinner.show(this._element, this._config, this._tableElement); // Show spinner before fetching data
|
|
521
386
|
if (!(typeof this._config.apiEndpoint === 'undefined')) return [3 /*break*/, 2];
|
|
522
387
|
_a = this._localProvider.fetchSync();
|
|
523
388
|
return [3 /*break*/, 4];
|
|
@@ -533,11 +398,11 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
533
398
|
return [4 /*yield*/, this._draw()];
|
|
534
399
|
case 5:
|
|
535
400
|
_b.sent();
|
|
536
|
-
this._emit('fetched');
|
|
537
401
|
_b.label = 6;
|
|
538
402
|
case 6: return [4 /*yield*/, this._finalize()];
|
|
539
403
|
case 7:
|
|
540
404
|
_b.sent();
|
|
405
|
+
this._emit('update');
|
|
541
406
|
return [3 /*break*/, 9];
|
|
542
407
|
case 8:
|
|
543
408
|
// Finally block now correctly executes after promises resolve, not immediately
|
|
@@ -553,7 +418,8 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
553
418
|
* @returns {void}
|
|
554
419
|
*/
|
|
555
420
|
KTDataTable.prototype._finalize = function () {
|
|
556
|
-
var
|
|
421
|
+
var _this = this;
|
|
422
|
+
var _a, _b, _c;
|
|
557
423
|
(_a = this._element) === null || _a === void 0 ? void 0 : _a.classList.add('datatable-initialized');
|
|
558
424
|
// Initialize checkbox logic
|
|
559
425
|
this._checkbox.init();
|
|
@@ -561,50 +427,20 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
561
427
|
if (this._sortHandler) {
|
|
562
428
|
this._sortHandler.initSort();
|
|
563
429
|
}
|
|
564
|
-
this.
|
|
565
|
-
if (typeof index_1.default !== 'undefined') {
|
|
566
|
-
index_1.default.init();
|
|
567
|
-
}
|
|
430
|
+
this._searchHandler.attach(this._tableId(), this.getState().search, (_c = (_b = this._config.search) === null || _b === void 0 ? void 0 : _b.delay) !== null && _c !== void 0 ? _c : datatable_defaults_1.DEFAULT_SEARCH_DELAY, function (query) { return _this.search(query); });
|
|
568
431
|
/**
|
|
569
432
|
* Hide spinner
|
|
570
433
|
*/
|
|
571
|
-
this.
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
var searchElement = document.querySelector("[data-kt-datatable-search=\"#".concat(tableId, "\"]"));
|
|
582
|
-
// Get search state
|
|
583
|
-
var search = this.getState().search;
|
|
584
|
-
// Set search value
|
|
585
|
-
if (searchElement) {
|
|
586
|
-
searchElement.value =
|
|
587
|
-
search === undefined || search === null
|
|
588
|
-
? ''
|
|
589
|
-
: typeof search === 'string'
|
|
590
|
-
? search
|
|
591
|
-
: String(search);
|
|
592
|
-
}
|
|
593
|
-
if (searchElement) {
|
|
594
|
-
// Check if a debounced search function already exists
|
|
595
|
-
var searchWithDebounce = KTDataTable.asSearchElementWithDebounce(searchElement);
|
|
596
|
-
if (searchWithDebounce._debouncedSearch) {
|
|
597
|
-
// Remove the existing debounced event listener
|
|
598
|
-
searchElement.removeEventListener('keyup', searchWithDebounce._debouncedSearch);
|
|
599
|
-
}
|
|
600
|
-
// Create a new debounced search function
|
|
601
|
-
var debouncedSearch = this._debounce(function () {
|
|
602
|
-
_this.search(searchElement.value);
|
|
603
|
-
}, (_b = (_a = this._config.search) === null || _a === void 0 ? void 0 : _a.delay) !== null && _b !== void 0 ? _b : 500);
|
|
604
|
-
// Store the new debounced function as a property of the element
|
|
605
|
-
searchWithDebounce._debouncedSearch = debouncedSearch;
|
|
606
|
-
// Add the new debounced event listener
|
|
607
|
-
searchElement.addEventListener('keyup', debouncedSearch);
|
|
434
|
+
this._spinner.hide(this._element, this._config);
|
|
435
|
+
// Update content checksum AFTER all DOM modifications (checkbox init
|
|
436
|
+
// adds checked-class to <tr> elements which changes tbody innerHTML).
|
|
437
|
+
// If we save the checksum earlier (in _draw), the next fetchSync()
|
|
438
|
+
// sees a mismatch, re-extracts from the DOM, and loses rows that
|
|
439
|
+
// were on other pages — making pagination show empty.
|
|
440
|
+
if (!this._config.apiEndpoint) {
|
|
441
|
+
this._stateStore.patchState({
|
|
442
|
+
_contentChecksum: utils_1.default.checksum(JSON.stringify(this._tbodyElement.innerHTML)),
|
|
443
|
+
});
|
|
608
444
|
}
|
|
609
445
|
};
|
|
610
446
|
/**
|
|
@@ -613,17 +449,7 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
613
449
|
* @returns {number} Number of data columns, or 0 if unknown
|
|
614
450
|
*/
|
|
615
451
|
KTDataTable.prototype._getLogicalColumnCount = function () {
|
|
616
|
-
|
|
617
|
-
if (originalData && originalData.length > 0) {
|
|
618
|
-
return Object.keys(originalData[0]).length;
|
|
619
|
-
}
|
|
620
|
-
if (this._tbodyElement) {
|
|
621
|
-
var firstRow = this._tbodyElement.querySelector('tr');
|
|
622
|
-
if (firstRow) {
|
|
623
|
-
return firstRow.querySelectorAll('td').length;
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
return 0;
|
|
452
|
+
return (0, datatable_column_utils_1.getLogicalColumnCount)(this._theadElement, this._tbodyElement, this.getState().originalData);
|
|
627
453
|
};
|
|
628
454
|
/**
|
|
629
455
|
* Creates a complete URL from a relative path or a full URL.
|
|
@@ -702,8 +528,7 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
702
528
|
: 1;
|
|
703
529
|
this._stateStore.patchState({ totalPages: totalPages, page: page });
|
|
704
530
|
(_b = (_a = this._layoutPlugin) === null || _a === void 0 ? void 0 : _a.beforeDraw) === null || _b === void 0 ? void 0 : _b.call(_a, this._getLayoutPluginContext());
|
|
705
|
-
this.
|
|
706
|
-
this._dispose();
|
|
531
|
+
this._cleanupForRedraw();
|
|
707
532
|
// Update the table and pagination controls
|
|
708
533
|
if (this._theadElement && this._tbodyElement) {
|
|
709
534
|
this._updateTable();
|
|
@@ -712,12 +537,6 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
712
537
|
this._updatePagination();
|
|
713
538
|
}
|
|
714
539
|
(_d = (_c = this._layoutPlugin) === null || _c === void 0 ? void 0 : _c.afterDraw) === null || _d === void 0 ? void 0 : _d.call(_c, this._getLayoutPluginContext());
|
|
715
|
-
if (!this._config.apiEndpoint) {
|
|
716
|
-
this._stateStore.patchState({
|
|
717
|
-
_contentChecksum: utils_1.default.checksum(JSON.stringify(this._tbodyElement.innerHTML)),
|
|
718
|
-
});
|
|
719
|
-
}
|
|
720
|
-
this._emit('drew');
|
|
721
540
|
// Spinner is hidden in _finalize() to ensure it stays visible until the entire request completes
|
|
722
541
|
// Removed duplicate _hideSpinner() call here to prevent premature hiding
|
|
723
542
|
if (this._config.stateSave) {
|
|
@@ -738,9 +557,7 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
738
557
|
data: this._data,
|
|
739
558
|
getLogicalColumnCount: this._getLogicalColumnCount.bind(this),
|
|
740
559
|
getState: this.getState.bind(this),
|
|
741
|
-
|
|
742
|
-
originalTrClasses: this._originalTrClasses,
|
|
743
|
-
originalTdClasses: this._originalTdClasses,
|
|
560
|
+
originalClasses: this._originalClasses,
|
|
744
561
|
tableElement: this._tableElement,
|
|
745
562
|
theadElement: this._theadElement,
|
|
746
563
|
});
|
|
@@ -790,87 +607,31 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
790
607
|
if (page < 1 || !Number.isInteger(page)) {
|
|
791
608
|
return;
|
|
792
609
|
}
|
|
793
|
-
this._emit('pagination', { page: page });
|
|
794
610
|
if (page >= 1 && page <= this.getState().totalPages) {
|
|
795
611
|
this._stateStore.setPage(page);
|
|
796
612
|
this._updateData();
|
|
797
613
|
}
|
|
798
614
|
};
|
|
799
|
-
// Method to show the loading spinner
|
|
800
|
-
KTDataTable.prototype._showSpinner = function () {
|
|
801
|
-
var _a, _b;
|
|
802
|
-
var root = this._element;
|
|
803
|
-
var spinnerSel = (_a = this._config.attributes) === null || _a === void 0 ? void 0 : _a.spinner;
|
|
804
|
-
var fromDom = root && spinnerSel ? root.querySelector(spinnerSel) : null;
|
|
805
|
-
var spinner = fromDom !== null && fromDom !== void 0 ? fromDom : this._createSpinner();
|
|
806
|
-
if (spinner) {
|
|
807
|
-
spinner.style.display = 'block';
|
|
808
|
-
}
|
|
809
|
-
root === null || root === void 0 ? void 0 : root.classList.add((_b = this._config.loadingClass) !== null && _b !== void 0 ? _b : 'loading');
|
|
810
|
-
};
|
|
811
|
-
// Method to hide the loading spinner
|
|
812
|
-
KTDataTable.prototype._hideSpinner = function () {
|
|
813
|
-
var _a, _b;
|
|
814
|
-
var root = this._element;
|
|
815
|
-
var spinnerSel = (_a = this._config.attributes) === null || _a === void 0 ? void 0 : _a.spinner;
|
|
816
|
-
var spinner = root && spinnerSel ? root.querySelector(spinnerSel) : null;
|
|
817
|
-
if (spinner) {
|
|
818
|
-
spinner.style.display = 'none';
|
|
819
|
-
}
|
|
820
|
-
root === null || root === void 0 ? void 0 : root.classList.remove((_b = this._config.loadingClass) !== null && _b !== void 0 ? _b : 'loading');
|
|
821
|
-
};
|
|
822
|
-
// Method to create a spinner element if it doesn't exist
|
|
823
|
-
KTDataTable.prototype._createSpinner = function () {
|
|
824
|
-
var loading = this._config.loading;
|
|
825
|
-
if (!loading) {
|
|
826
|
-
return null;
|
|
827
|
-
}
|
|
828
|
-
var template = document.createElement('template');
|
|
829
|
-
template.innerHTML = loading.template
|
|
830
|
-
.trim()
|
|
831
|
-
.replace('{content}', loading.content);
|
|
832
|
-
var first = template.content.firstChild;
|
|
833
|
-
if (!first || !(first instanceof HTMLElement)) {
|
|
834
|
-
return null;
|
|
835
|
-
}
|
|
836
|
-
var spinner = first;
|
|
837
|
-
spinner.setAttribute('data-kt-datatable-spinner', 'true');
|
|
838
|
-
this._tableElement.appendChild(spinner);
|
|
839
|
-
return spinner;
|
|
840
|
-
};
|
|
841
615
|
/**
|
|
842
616
|
* Saves the current state of the table to local storage.
|
|
843
617
|
* @returns {void}
|
|
844
618
|
*/
|
|
845
619
|
KTDataTable.prototype._saveState = function () {
|
|
846
|
-
this.
|
|
847
|
-
var ns = this._tableNamespace();
|
|
848
|
-
if (ns) {
|
|
849
|
-
localStorage.setItem(ns, JSON.stringify(this.getState()));
|
|
850
|
-
}
|
|
620
|
+
this._statePersistence.save(this._tableNamespace(), this.getState());
|
|
851
621
|
};
|
|
852
622
|
/**
|
|
853
623
|
* Loads the saved state of the table from local storage, if it exists.
|
|
854
624
|
* @returns {Object} The saved state of the table, or null if no saved state exists.
|
|
855
625
|
*/
|
|
856
626
|
KTDataTable.prototype._loadState = function () {
|
|
857
|
-
var
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
if (state)
|
|
863
|
-
this._stateStore.replaceState(state);
|
|
864
|
-
return state;
|
|
865
|
-
}
|
|
866
|
-
catch (_a) { }
|
|
867
|
-
return null;
|
|
627
|
+
var ns = this._tableNamespace();
|
|
628
|
+
var saved = this._statePersistence.load(ns);
|
|
629
|
+
if (saved)
|
|
630
|
+
this._stateStore.replaceState(saved);
|
|
631
|
+
return saved;
|
|
868
632
|
};
|
|
869
633
|
KTDataTable.prototype._deleteState = function () {
|
|
870
|
-
|
|
871
|
-
if (ns) {
|
|
872
|
-
localStorage.removeItem(ns);
|
|
873
|
-
}
|
|
634
|
+
this._statePersistence.remove(this._tableNamespace());
|
|
874
635
|
};
|
|
875
636
|
/**
|
|
876
637
|
* Gets the namespace for the table's state.
|
|
@@ -881,13 +642,7 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
881
642
|
* @returns {string} The namespace for the table's state.
|
|
882
643
|
*/
|
|
883
644
|
KTDataTable.prototype._tableNamespace = function () {
|
|
884
|
-
|
|
885
|
-
// Use the specified namespace, if one is given
|
|
886
|
-
if (this._config.stateNamespace) {
|
|
887
|
-
return this._config.stateNamespace;
|
|
888
|
-
}
|
|
889
|
-
// Fallback to the component's UID
|
|
890
|
-
return (_a = this._tableId()) !== null && _a !== void 0 ? _a : this._name;
|
|
645
|
+
return (0, datatable_state_persistence_1.resolveTableNamespace)(this._config, this._tableElement, this._element, this._name);
|
|
891
646
|
};
|
|
892
647
|
KTDataTable.prototype._tableId = function () {
|
|
893
648
|
var _a, _b;
|
|
@@ -905,91 +660,43 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
905
660
|
* Clean up all event listeners, handlers, and DOM nodes created by this instance.
|
|
906
661
|
* This method is called before re-rendering or when disposing the component.
|
|
907
662
|
*/
|
|
908
|
-
|
|
909
|
-
|
|
663
|
+
/**
|
|
664
|
+
* Clean up event listeners and DOM artifacts for a redraw cycle.
|
|
665
|
+
* Does NOT remove the instance from the registry — the datatable
|
|
666
|
+
* remains accessible via getInstance() during the redraw window.
|
|
667
|
+
*/
|
|
668
|
+
KTDataTable.prototype._cleanupForRedraw = function () {
|
|
669
|
+
var _a, _b;
|
|
910
670
|
(_b = (_a = this._layoutPlugin) === null || _a === void 0 ? void 0 : _a.dispose) === null || _b === void 0 ? void 0 : _b.call(_a, this._getLayoutPluginContext());
|
|
911
|
-
|
|
912
|
-
if (!root) {
|
|
671
|
+
if (!this._element) {
|
|
913
672
|
return;
|
|
914
673
|
}
|
|
915
674
|
this._cleanupCallbacks.forEach(function (cleanup) { return cleanup(); });
|
|
916
675
|
this._cleanupCallbacks = [];
|
|
917
|
-
|
|
918
|
-
var tableId = this._tableId();
|
|
919
|
-
var searchElement = document.querySelector("[data-kt-datatable-search=\"#".concat(tableId, "\"]"));
|
|
920
|
-
if (searchElement) {
|
|
921
|
-
var searchWithDebounce = KTDataTable.asSearchElementWithDebounce(searchElement);
|
|
922
|
-
if (searchWithDebounce._debouncedSearch) {
|
|
923
|
-
searchElement.removeEventListener('keyup', searchWithDebounce._debouncedSearch);
|
|
924
|
-
delete searchWithDebounce._debouncedSearch;
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
// --- 2. Remove page size dropdown event listener ---
|
|
676
|
+
this._searchHandler.detach(this._tableId());
|
|
928
677
|
if (this._sizeElement && this._sizeElement.onchange) {
|
|
929
678
|
this._sizeElement.onchange = null;
|
|
930
679
|
}
|
|
931
|
-
// --- 3. Remove all pagination button event listeners ---
|
|
932
680
|
if (this._paginationElement) {
|
|
933
|
-
// Remove all child nodes (buttons) to ensure no lingering listeners
|
|
934
681
|
while (this._paginationElement.firstChild) {
|
|
935
682
|
this._paginationElement.removeChild(this._paginationElement.firstChild);
|
|
936
683
|
}
|
|
937
684
|
}
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
if (this._checkbox && typeof checkboxWithDispose.dispose === 'function') {
|
|
942
|
-
checkboxWithDispose.dispose();
|
|
943
|
-
}
|
|
944
|
-
else {
|
|
945
|
-
var checkSel = (_c = this._config.attributes) === null || _c === void 0 ? void 0 : _c.check;
|
|
946
|
-
if (checkSel) {
|
|
947
|
-
var headerCheckElement = root.querySelector(checkSel);
|
|
948
|
-
if (headerCheckElement) {
|
|
949
|
-
headerCheckElement.replaceWith(headerCheckElement.cloneNode(true));
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
// KTDataTableSortAPI does not have a dispose method, but we can remove th click listeners by replacing them
|
|
954
|
-
if (this._theadElement) {
|
|
955
|
-
var ths = this._theadElement.querySelectorAll('th');
|
|
956
|
-
ths.forEach(function (th) {
|
|
957
|
-
th.replaceWith(th.cloneNode(true));
|
|
958
|
-
});
|
|
959
|
-
}
|
|
960
|
-
// --- 5. Remove spinner DOM node if it exists ---
|
|
961
|
-
var spinnerSel = (_d = this._config.attributes) === null || _d === void 0 ? void 0 : _d.spinner;
|
|
962
|
-
if (spinnerSel) {
|
|
963
|
-
var spinner = root.querySelector(spinnerSel);
|
|
964
|
-
if (spinner === null || spinner === void 0 ? void 0 : spinner.parentNode) {
|
|
965
|
-
spinner.parentNode.removeChild(spinner);
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
root.classList.remove((_e = this._config.loadingClass) !== null && _e !== void 0 ? _e : 'loading');
|
|
969
|
-
// --- 6. Remove instance reference from the DOM element ---
|
|
970
|
-
var elementWithInstance = KTDataTable.asElementWithInstance(root);
|
|
971
|
-
if (elementWithInstance.instance) {
|
|
972
|
-
delete elementWithInstance.instance;
|
|
973
|
-
}
|
|
974
|
-
data_1.default.remove(root, this._name);
|
|
975
|
-
// --- 7. (Optional) Clear localStorage state ---
|
|
976
|
-
// Uncomment the following line if you want to clear state on dispose:
|
|
977
|
-
// this._deleteState();
|
|
685
|
+
this._checkbox.dispose();
|
|
686
|
+
this._sortHandler.dispose();
|
|
687
|
+
this._spinner.remove(this._element, this._config);
|
|
978
688
|
};
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
clearTimeout(timeout);
|
|
991
|
-
timeout = window.setTimeout(later, wait);
|
|
992
|
-
};
|
|
689
|
+
/**
|
|
690
|
+
* Full disposal — cleans up listeners AND removes the instance from
|
|
691
|
+
* the registry. Only called when the component is being destroyed.
|
|
692
|
+
*/
|
|
693
|
+
KTDataTable.prototype._dispose = function () {
|
|
694
|
+
this._cleanupForRedraw();
|
|
695
|
+
var root = this._element;
|
|
696
|
+
if (root) {
|
|
697
|
+
datatableRegistry.remove(root);
|
|
698
|
+
data_1.default.remove(root, this._name);
|
|
699
|
+
}
|
|
993
700
|
};
|
|
994
701
|
/**
|
|
995
702
|
* Gets the current state of the table.
|
|
@@ -1000,12 +707,14 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1000
707
|
};
|
|
1001
708
|
/**
|
|
1002
709
|
* Sorts the data in the table by the specified field.
|
|
710
|
+
* When `order` is provided, applies that sort direction instead of toggling.
|
|
1003
711
|
* @param field The field to sort by.
|
|
712
|
+
* @param order Optional sort direction (`asc`, `desc`, or `''` to clear).
|
|
1004
713
|
*/
|
|
1005
|
-
KTDataTable.prototype.sort = function (field) {
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
714
|
+
KTDataTable.prototype.sort = function (field, order) {
|
|
715
|
+
var sortOrder = order !== undefined
|
|
716
|
+
? order
|
|
717
|
+
: this._sortHandler.toggleSortOrder(this.getState().sortField, this.getState().sortOrder, field);
|
|
1009
718
|
this._sortHandler.setSortIcon(field, sortOrder);
|
|
1010
719
|
this._stateStore.setSort(field, sortOrder);
|
|
1011
720
|
this._emit('sort', { field: field, order: sortOrder });
|
|
@@ -1037,36 +746,28 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1037
746
|
this._reloadPageSize(pageSize);
|
|
1038
747
|
};
|
|
1039
748
|
/**
|
|
1040
|
-
* Reloads the data from the
|
|
1041
|
-
*
|
|
749
|
+
* Reloads the data from the source (API or DOM) and redraws the table.
|
|
750
|
+
* @returns {Promise<void>}
|
|
1042
751
|
*/
|
|
1043
752
|
KTDataTable.prototype.reload = function () {
|
|
1044
|
-
this._emit('reload');
|
|
1045
753
|
// Fetch the data from the server using the current sort and filter settings
|
|
1046
754
|
this._updateData();
|
|
1047
755
|
};
|
|
1048
756
|
KTDataTable.prototype.redraw = function (page) {
|
|
1049
757
|
if (page === void 0) { page = 1; }
|
|
1050
|
-
this._emit('redraw');
|
|
1051
758
|
this._paginateData(page);
|
|
1052
759
|
};
|
|
1053
760
|
/**
|
|
1054
761
|
* Show the loading spinner of the data table.
|
|
1055
762
|
*/
|
|
1056
763
|
KTDataTable.prototype.showSpinner = function () {
|
|
1057
|
-
|
|
1058
|
-
* Show the loading spinner of the data table.
|
|
1059
|
-
*/
|
|
1060
|
-
this._showSpinner();
|
|
764
|
+
this._spinner.show(this._element, this._config, this._tableElement);
|
|
1061
765
|
};
|
|
1062
766
|
/**
|
|
1063
767
|
* Hide the loading spinner of the data table.
|
|
1064
768
|
*/
|
|
1065
769
|
KTDataTable.prototype.hideSpinner = function () {
|
|
1066
|
-
|
|
1067
|
-
* Hide the loading spinner of the data table.
|
|
1068
|
-
*/
|
|
1069
|
-
this._hideSpinner();
|
|
770
|
+
this._spinner.hide(this._element, this._config);
|
|
1070
771
|
};
|
|
1071
772
|
/**
|
|
1072
773
|
* Filter data using the specified filter object.
|
|
@@ -1093,21 +794,7 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1093
794
|
* This function is now browser-guarded and must be called explicitly.
|
|
1094
795
|
*/
|
|
1095
796
|
KTDataTable.createInstances = function () {
|
|
1096
|
-
|
|
1097
|
-
if (typeof document === 'undefined')
|
|
1098
|
-
return;
|
|
1099
|
-
var elements = document.querySelectorAll('[data-kt-datatable="true"]');
|
|
1100
|
-
elements.forEach(function (element) {
|
|
1101
|
-
if (element.hasAttribute('data-kt-datatable') &&
|
|
1102
|
-
!element.classList.contains('datatable-initialized')) {
|
|
1103
|
-
/**
|
|
1104
|
-
* Create an instance of KTDataTable for the given element
|
|
1105
|
-
* @param element The element to create an instance for
|
|
1106
|
-
*/
|
|
1107
|
-
var instance = new KTDataTable(element);
|
|
1108
|
-
_this._instances.set(element, instance);
|
|
1109
|
-
}
|
|
1110
|
-
});
|
|
797
|
+
datatableRegistry.createAll(function (el) { return new KTDataTable(el); });
|
|
1111
798
|
};
|
|
1112
799
|
/**
|
|
1113
800
|
* Get the KTDataTable instance for a given element.
|
|
@@ -1116,21 +803,13 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1116
803
|
* @returns The KTDataTable instance or undefined if not found
|
|
1117
804
|
*/
|
|
1118
805
|
KTDataTable.getInstance = function (element) {
|
|
1119
|
-
|
|
1120
|
-
var instanceFromMap = this._instances.get(element);
|
|
1121
|
-
if (instanceFromMap) {
|
|
1122
|
-
return instanceFromMap;
|
|
1123
|
-
}
|
|
1124
|
-
// Fallback to element's instance property (for manually created instances)
|
|
1125
|
-
return KTDataTable.asElementWithInstance(element).instance;
|
|
806
|
+
return datatableRegistry.get(element);
|
|
1126
807
|
};
|
|
1127
808
|
/**
|
|
1128
809
|
* Initializes all KTDataTable instances on the page.
|
|
1129
810
|
* This function is now browser-guarded and must be called explicitly.
|
|
1130
811
|
*/
|
|
1131
812
|
KTDataTable.init = function () {
|
|
1132
|
-
if (typeof document === 'undefined')
|
|
1133
|
-
return;
|
|
1134
813
|
KTDataTable.createInstances();
|
|
1135
814
|
};
|
|
1136
815
|
/**
|
|
@@ -1138,25 +817,7 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1138
817
|
* Useful for Livewire wire:navigate where the DOM is replaced and new tables need to be initialized.
|
|
1139
818
|
*/
|
|
1140
819
|
KTDataTable.reinit = function () {
|
|
1141
|
-
|
|
1142
|
-
return;
|
|
1143
|
-
var elements = document.querySelectorAll('[data-kt-datatable="true"]');
|
|
1144
|
-
elements.forEach(function (element) {
|
|
1145
|
-
try {
|
|
1146
|
-
var instance = KTDataTable.getInstance(element);
|
|
1147
|
-
if (instance && typeof instance.dispose === 'function') {
|
|
1148
|
-
instance.dispose();
|
|
1149
|
-
}
|
|
1150
|
-
data_1.default.remove(element, 'datatable');
|
|
1151
|
-
element.removeAttribute('data-kt-datatable-initialized');
|
|
1152
|
-
element.classList.remove('datatable-initialized');
|
|
1153
|
-
}
|
|
1154
|
-
catch (_a) {
|
|
1155
|
-
// ignore per-element errors
|
|
1156
|
-
}
|
|
1157
|
-
});
|
|
1158
|
-
KTDataTable._instances.clear();
|
|
1159
|
-
KTDataTable.createInstances();
|
|
820
|
+
datatableRegistry.reinit(function (el) { return new KTDataTable(el); });
|
|
1160
821
|
};
|
|
1161
822
|
/**
|
|
1162
823
|
* Check if all visible rows are checked (header checkbox state)
|
|
@@ -1196,16 +857,18 @@ var KTDataTable = /** @class */ (function (_super) {
|
|
|
1196
857
|
return this._checkbox.getChecked();
|
|
1197
858
|
};
|
|
1198
859
|
/**
|
|
1199
|
-
*
|
|
860
|
+
* Re-apply checkbox checked states to visible rows after a redraw or pagination change.
|
|
1200
861
|
* @returns {void}
|
|
1201
862
|
*/
|
|
1202
|
-
KTDataTable.prototype.
|
|
863
|
+
KTDataTable.prototype.refreshCheckboxes = function () {
|
|
1203
864
|
this._checkbox.updateState();
|
|
1204
865
|
};
|
|
1205
866
|
/**
|
|
1206
|
-
*
|
|
867
|
+
* @deprecated Use {@link refreshCheckboxes} instead.
|
|
1207
868
|
*/
|
|
1208
|
-
KTDataTable.
|
|
869
|
+
KTDataTable.prototype.update = function () {
|
|
870
|
+
this.refreshCheckboxes();
|
|
871
|
+
};
|
|
1209
872
|
return KTDataTable;
|
|
1210
873
|
}(component_1.default));
|
|
1211
874
|
exports.KTDataTable = KTDataTable;
|