@slickgrid-universal/vanilla-bundle 3.7.1 → 4.0.0-alpha.0
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/{commonjs → cjs}/components/slick-vanilla-grid-bundle.js +141 -203
- package/dist/cjs/components/slick-vanilla-grid-bundle.js.map +1 -0
- package/dist/{commonjs → cjs}/services/universalContainer.service.js +1 -1
- package/dist/cjs/services/universalContainer.service.js.map +1 -0
- package/dist/esm/components/slick-vanilla-grid-bundle.js +142 -204
- package/dist/esm/components/slick-vanilla-grid-bundle.js.map +1 -1
- package/dist/esm/services/universalContainer.service.js +1 -1
- package/dist/esm/services/universalContainer.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/components/slick-vanilla-grid-bundle.d.ts +18 -143
- package/dist/types/components/slick-vanilla-grid-bundle.d.ts.map +1 -1
- package/dist/types/index.d.ts +6 -17
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/interfaces/slickerGridInstance.interface.d.ts +2 -2
- package/dist/types/interfaces/slickerGridInstance.interface.d.ts.map +1 -1
- package/package.json +12 -13
- package/dist/commonjs/components/slick-vanilla-grid-bundle.js.map +0 -1
- package/dist/commonjs/services/universalContainer.service.js.map +0 -1
- /package/dist/{commonjs → cjs}/index.js +0 -0
- /package/dist/{commonjs → cjs}/index.js.map +0 -0
- /package/dist/{commonjs → cjs}/interfaces/index.js +0 -0
- /package/dist/{commonjs → cjs}/interfaces/index.js.map +0 -0
- /package/dist/{commonjs → cjs}/interfaces/slickerGridInstance.interface.js +0 -0
- /package/dist/{commonjs → cjs}/interfaces/slickerGridInstance.interface.js.map +0 -0
- /package/dist/{commonjs → cjs}/services/index.js +0 -0
- /package/dist/{commonjs → cjs}/services/index.js.map +0 -0
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.SlickVanillaGridBundle = void 0;
|
|
5
4
|
const lite_1 = require("dequal/lite");
|
|
6
5
|
require("flatpickr/dist/l10n/fr");
|
|
7
|
-
require("slickgrid/slick.core");
|
|
8
|
-
require("slickgrid/slick.interactions");
|
|
9
|
-
require("slickgrid/slick.grid");
|
|
10
|
-
require("slickgrid/slick.dataview");
|
|
11
|
-
const Sortable_ = require("sortablejs");
|
|
12
|
-
const Sortable = ((_a = Sortable_ === null || Sortable_ === void 0 ? void 0 : Sortable_['default']) !== null && _a !== void 0 ? _a : Sortable_); // patch for rollup
|
|
13
6
|
const common_1 = require("@slickgrid-universal/common");
|
|
14
7
|
const event_pub_sub_1 = require("@slickgrid-universal/event-pub-sub");
|
|
15
8
|
const empty_warning_component_1 = require("@slickgrid-universal/empty-warning-component");
|
|
16
9
|
const custom_footer_component_1 = require("@slickgrid-universal/custom-footer-component");
|
|
17
10
|
const pagination_component_1 = require("@slickgrid-universal/pagination-component");
|
|
18
11
|
const universalContainer_service_1 = require("../services/universalContainer.service");
|
|
19
|
-
// add Sortable to the window object so that SlickGrid lib can use globally
|
|
20
|
-
window.Sortable = Sortable;
|
|
21
12
|
class SlickVanillaGridBundle {
|
|
22
13
|
get eventHandler() {
|
|
23
14
|
return this._eventHandler;
|
|
@@ -35,17 +26,15 @@ class SlickVanillaGridBundle {
|
|
|
35
26
|
}
|
|
36
27
|
}
|
|
37
28
|
get dataset() {
|
|
38
|
-
|
|
39
|
-
return ((_a = this.dataView) === null || _a === void 0 ? void 0 : _a.getItems()) || [];
|
|
29
|
+
return this.dataView?.getItems() || [];
|
|
40
30
|
}
|
|
41
31
|
set dataset(newDataset) {
|
|
42
|
-
var _a, _b;
|
|
43
32
|
const prevDatasetLn = this._currentDatasetLength;
|
|
44
33
|
const isDatasetEqual = (0, lite_1.dequal)(newDataset, this.dataset || []);
|
|
45
|
-
const isDeepCopyDataOnPageLoadEnabled = !!(
|
|
34
|
+
const isDeepCopyDataOnPageLoadEnabled = !!(this._gridOptions?.enableDeepCopyDatasetOnPageLoad);
|
|
46
35
|
let data = isDeepCopyDataOnPageLoadEnabled ? (0, common_1.deepCopy)(newDataset || []) : newDataset;
|
|
47
36
|
// when Tree Data is enabled and we don't yet have the hierarchical dataset filled, we can force a convert+sort of the array
|
|
48
|
-
if (this.slickGrid &&
|
|
37
|
+
if (this.slickGrid && this.gridOptions?.enableTreeData && Array.isArray(newDataset) && (newDataset.length > 0 || newDataset.length !== prevDatasetLn || !isDatasetEqual)) {
|
|
49
38
|
this._isDatasetHierarchicalInitialized = false;
|
|
50
39
|
data = this.sortTreeDataset(newDataset, !isDatasetEqual); // if dataset changed, then force a refresh anyway
|
|
51
40
|
}
|
|
@@ -61,21 +50,19 @@ class SlickVanillaGridBundle {
|
|
|
61
50
|
return this.sharedService.hierarchicalDataset;
|
|
62
51
|
}
|
|
63
52
|
set datasetHierarchical(newHierarchicalDataset) {
|
|
64
|
-
var _a, _b;
|
|
65
53
|
const isDatasetEqual = (0, lite_1.dequal)(newHierarchicalDataset, this.sharedService.hierarchicalDataset || []);
|
|
66
54
|
const prevFlatDatasetLn = this._currentDatasetLength;
|
|
67
55
|
this.sharedService.hierarchicalDataset = newHierarchicalDataset;
|
|
68
|
-
if (newHierarchicalDataset && this.columnDefinitions &&
|
|
56
|
+
if (newHierarchicalDataset && this.columnDefinitions && this.filterService?.clearFilters) {
|
|
69
57
|
this.filterService.clearFilters();
|
|
70
58
|
}
|
|
71
59
|
// when a hierarchical dataset is set afterward, we can reset the flat dataset and call a tree data sort that will overwrite the flat dataset
|
|
72
|
-
if (this.dataView && newHierarchicalDataset && this.slickGrid &&
|
|
60
|
+
if (this.dataView && newHierarchicalDataset && this.slickGrid && this.sortService?.processTreeDataInitialSort) {
|
|
73
61
|
this.sortService.processTreeDataInitialSort();
|
|
74
62
|
// we also need to reset/refresh the Tree Data filters because if we inserted new item(s) then it might not show up without doing this refresh
|
|
75
63
|
// however we need 1 cpu cycle before having the DataView refreshed, so we need to wrap this check in a setTimeout
|
|
76
64
|
setTimeout(() => {
|
|
77
|
-
|
|
78
|
-
const flatDatasetLn = (_b = (_a = this.dataView) === null || _a === void 0 ? void 0 : _a.getItemCount()) !== null && _b !== void 0 ? _b : 0;
|
|
65
|
+
const flatDatasetLn = this.dataView?.getItemCount() ?? 0;
|
|
79
66
|
if (flatDatasetLn > 0 && (flatDatasetLn !== prevFlatDatasetLn || !isDatasetEqual)) {
|
|
80
67
|
this.filterService.refreshTreeDataFilters();
|
|
81
68
|
}
|
|
@@ -90,17 +77,16 @@ class SlickVanillaGridBundle {
|
|
|
90
77
|
return this._gridOptions || {};
|
|
91
78
|
}
|
|
92
79
|
set gridOptions(options) {
|
|
93
|
-
var _a, _b, _c;
|
|
94
80
|
let mergedOptions;
|
|
95
81
|
// if we already have grid options, when grid was already initialized, we'll merge with those options
|
|
96
82
|
// else we'll merge with global grid options
|
|
97
|
-
if (
|
|
98
|
-
mergedOptions =
|
|
83
|
+
if (this.slickGrid?.getOptions) {
|
|
84
|
+
mergedOptions = (common_1.Utils.extend(true, {}, this.slickGrid.getOptions(), options));
|
|
99
85
|
}
|
|
100
86
|
else {
|
|
101
87
|
mergedOptions = this.mergeGridOptions(options);
|
|
102
88
|
}
|
|
103
|
-
if (
|
|
89
|
+
if (this.sharedService?.gridOptions && this.slickGrid?.setOptions) {
|
|
104
90
|
this.sharedService.gridOptions = mergedOptions;
|
|
105
91
|
this.slickGrid.setOptions(mergedOptions, false, true); // make sure to supressColumnCheck (3rd arg) to avoid problem with changeColumnsArrangement() and custom grid view
|
|
106
92
|
this.slickGrid.reRenderColumns(true); // then call a re-render since we did supressColumnCheck on previous setOptions
|
|
@@ -111,7 +97,6 @@ class SlickVanillaGridBundle {
|
|
|
111
97
|
return this._paginationOptions;
|
|
112
98
|
}
|
|
113
99
|
set paginationOptions(newPaginationOptions) {
|
|
114
|
-
var _a;
|
|
115
100
|
if (newPaginationOptions && this._paginationOptions) {
|
|
116
101
|
this._paginationOptions = { ...this._paginationOptions, ...newPaginationOptions };
|
|
117
102
|
}
|
|
@@ -119,7 +104,7 @@ class SlickVanillaGridBundle {
|
|
|
119
104
|
this._paginationOptions = newPaginationOptions;
|
|
120
105
|
}
|
|
121
106
|
this.gridOptions.pagination = this._paginationOptions;
|
|
122
|
-
this.paginationService.updateTotalItems(
|
|
107
|
+
this.paginationService.updateTotalItems(newPaginationOptions?.totalItems ?? 0, true);
|
|
123
108
|
}
|
|
124
109
|
get isDatasetInitialized() {
|
|
125
110
|
return this._isDatasetInitialized;
|
|
@@ -149,7 +134,6 @@ class SlickVanillaGridBundle {
|
|
|
149
134
|
* @param {Object} services - Typically only used for Unit Testing when we want to pass Mocked/Stub Services
|
|
150
135
|
*/
|
|
151
136
|
constructor(gridParentContainerElm, columnDefs, options, dataset, hierarchicalDataset, services) {
|
|
152
|
-
var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
153
137
|
this._currentDatasetLength = 0;
|
|
154
138
|
this._hideHeaderRowAfterPageLoad = false;
|
|
155
139
|
this._isDatasetInitialized = false;
|
|
@@ -175,46 +159,42 @@ class SlickVanillaGridBundle {
|
|
|
175
159
|
gridParentContainerElm.appendChild(this._gridContainerElm);
|
|
176
160
|
// check if the user wants to hide the header row from the start
|
|
177
161
|
// we only want to do this check once in the constructor
|
|
178
|
-
this._hideHeaderRowAfterPageLoad = (
|
|
162
|
+
this._hideHeaderRowAfterPageLoad = (options?.showHeaderRow === false);
|
|
179
163
|
this._columnDefinitions = columnDefs || [];
|
|
180
164
|
if (this._columnDefinitions.length > 0) {
|
|
181
165
|
this.copyColumnWidthsReference(this._columnDefinitions);
|
|
182
166
|
}
|
|
183
167
|
// save resource refs to register before the grid options are merged and possibly deep copied
|
|
184
168
|
// since a deep copy of grid options would lose original resource refs but we want to keep them as singleton
|
|
185
|
-
this._registeredResources =
|
|
186
|
-
/* istanbul ignore if */
|
|
187
|
-
if (options === null || options === void 0 ? void 0 : options.registerExternalResources) {
|
|
188
|
-
console.warn('[Slickgrid-Universal] Please note that the grid option `registerExternalResources` was deprecated, please use `externalResources` instead.');
|
|
189
|
-
}
|
|
169
|
+
this._registeredResources = options?.externalResources || [];
|
|
190
170
|
this._gridOptions = this.mergeGridOptions(options || {});
|
|
191
|
-
const isDeepCopyDataOnPageLoadEnabled = !!(
|
|
192
|
-
this.universalContainerService =
|
|
171
|
+
const isDeepCopyDataOnPageLoadEnabled = !!(this._gridOptions?.enableDeepCopyDatasetOnPageLoad);
|
|
172
|
+
this.universalContainerService = services?.universalContainerService ?? new universalContainer_service_1.UniversalContainerService();
|
|
193
173
|
// if user is providing a Translate Service, it has to be passed under the "translater" grid option
|
|
194
|
-
this.translaterService =
|
|
174
|
+
this.translaterService = services?.translaterService ?? this._gridOptions?.translater;
|
|
195
175
|
// initialize and assign all Service Dependencies
|
|
196
|
-
this._eventPubSubService =
|
|
197
|
-
this._eventPubSubService.eventNamingStyle =
|
|
176
|
+
this._eventPubSubService = services?.eventPubSubService ?? new event_pub_sub_1.EventPubSubService(gridParentContainerElm);
|
|
177
|
+
this._eventPubSubService.eventNamingStyle = this._gridOptions?.eventNamingStyle ?? event_pub_sub_1.EventNamingStyle.camelCase;
|
|
198
178
|
const slickgridConfig = new common_1.SlickgridConfig();
|
|
199
|
-
this.backendUtilityService =
|
|
200
|
-
this.gridEventService =
|
|
201
|
-
this.sharedService =
|
|
202
|
-
this.collectionService =
|
|
203
|
-
this.extensionUtility =
|
|
179
|
+
this.backendUtilityService = services?.backendUtilityService ?? new common_1.BackendUtilityService();
|
|
180
|
+
this.gridEventService = services?.gridEventService ?? new common_1.GridEventService();
|
|
181
|
+
this.sharedService = services?.sharedService ?? new common_1.SharedService();
|
|
182
|
+
this.collectionService = services?.collectionService ?? new common_1.CollectionService(this.translaterService);
|
|
183
|
+
this.extensionUtility = services?.extensionUtility ?? new common_1.ExtensionUtility(this.sharedService, this.backendUtilityService, this.translaterService);
|
|
204
184
|
this.filterFactory = new common_1.FilterFactory(slickgridConfig, this.translaterService, this.collectionService);
|
|
205
|
-
this.filterService =
|
|
206
|
-
this.resizerService =
|
|
207
|
-
this.sortService =
|
|
208
|
-
this.treeDataService =
|
|
209
|
-
this.paginationService =
|
|
210
|
-
this.extensionService =
|
|
211
|
-
this.gridStateService =
|
|
212
|
-
this.gridService =
|
|
213
|
-
this.groupingService =
|
|
185
|
+
this.filterService = services?.filterService ?? new common_1.FilterService(this.filterFactory, this._eventPubSubService, this.sharedService, this.backendUtilityService);
|
|
186
|
+
this.resizerService = services?.resizerService ?? new common_1.ResizerService(this._eventPubSubService);
|
|
187
|
+
this.sortService = services?.sortService ?? new common_1.SortService(this.sharedService, this._eventPubSubService, this.backendUtilityService);
|
|
188
|
+
this.treeDataService = services?.treeDataService ?? new common_1.TreeDataService(this._eventPubSubService, this.sharedService, this.sortService);
|
|
189
|
+
this.paginationService = services?.paginationService ?? new common_1.PaginationService(this._eventPubSubService, this.sharedService, this.backendUtilityService);
|
|
190
|
+
this.extensionService = services?.extensionService ?? new common_1.ExtensionService(this.extensionUtility, this.filterService, this._eventPubSubService, this.sharedService, this.sortService, this.treeDataService, this.translaterService);
|
|
191
|
+
this.gridStateService = services?.gridStateService ?? new common_1.GridStateService(this.extensionService, this.filterService, this._eventPubSubService, this.sharedService, this.sortService, this.treeDataService);
|
|
192
|
+
this.gridService = services?.gridService ?? new common_1.GridService(this.gridStateService, this.filterService, this._eventPubSubService, this.paginationService, this.sharedService, this.sortService, this.treeDataService);
|
|
193
|
+
this.groupingService = services?.groupingAndColspanService ?? new common_1.GroupingAndColspanService(this.extensionUtility, this._eventPubSubService);
|
|
214
194
|
if (hierarchicalDataset) {
|
|
215
195
|
this.sharedService.hierarchicalDataset = (isDeepCopyDataOnPageLoadEnabled ? (0, common_1.deepCopy)(hierarchicalDataset || []) : hierarchicalDataset) || [];
|
|
216
196
|
}
|
|
217
|
-
const eventHandler = new
|
|
197
|
+
const eventHandler = new common_1.SlickEventHandler();
|
|
218
198
|
// register all service instances in the container
|
|
219
199
|
this.universalContainerService.registerInstance('PubSubService', this._eventPubSubService); // external resources require this one registration (ExcelExport, TextExport)
|
|
220
200
|
this.universalContainerService.registerInstance('EventPubSubService', this._eventPubSubService);
|
|
@@ -239,47 +219,45 @@ class SlickVanillaGridBundle {
|
|
|
239
219
|
}
|
|
240
220
|
}
|
|
241
221
|
emptyGridContainerElm() {
|
|
242
|
-
|
|
243
|
-
const gridContainerId = (_b = (_a = this.gridOptions) === null || _a === void 0 ? void 0 : _a.gridContainerId) !== null && _b !== void 0 ? _b : 'grid1';
|
|
222
|
+
const gridContainerId = this.gridOptions?.gridContainerId ?? 'grid1';
|
|
244
223
|
const gridContainerElm = document.querySelector(`#${gridContainerId}`);
|
|
245
224
|
(0, common_1.emptyElement)(gridContainerElm);
|
|
246
225
|
}
|
|
247
226
|
/** Dispose of the Component */
|
|
248
227
|
dispose(shouldEmptyDomElementContainer = false) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
(_c = this._eventPubSubService) === null || _c === void 0 ? void 0 : _c.publish('onAfterGridDestroyed', true);
|
|
228
|
+
this._eventPubSubService?.publish('onBeforeGridDestroy', this.slickGrid);
|
|
229
|
+
this._eventHandler?.unsubscribeAll();
|
|
230
|
+
this._eventPubSubService?.publish('onAfterGridDestroyed', true);
|
|
253
231
|
// dispose the Services
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
232
|
+
this.extensionService?.dispose();
|
|
233
|
+
this.filterService?.dispose();
|
|
234
|
+
this.gridEventService?.dispose();
|
|
235
|
+
this.gridService?.dispose();
|
|
236
|
+
this.gridStateService?.dispose();
|
|
237
|
+
this.groupingService?.dispose();
|
|
238
|
+
this.paginationService?.dispose();
|
|
239
|
+
this.resizerService?.dispose();
|
|
240
|
+
this.sortService?.dispose();
|
|
241
|
+
this.treeDataService?.dispose();
|
|
242
|
+
this.universalContainerService?.dispose();
|
|
265
243
|
// dispose all registered external resources
|
|
266
244
|
this.disposeExternalResources();
|
|
267
245
|
// dispose the Components
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
246
|
+
this.slickFooter?.dispose();
|
|
247
|
+
this.slickEmptyWarning?.dispose();
|
|
248
|
+
this.slickPagination?.dispose();
|
|
271
249
|
(0, common_1.unsubscribeAll)(this.subscriptions);
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
if (typeof
|
|
275
|
-
|
|
250
|
+
this._eventPubSubService?.unsubscribeAll();
|
|
251
|
+
this.dataView?.setItems([]);
|
|
252
|
+
if (typeof this.dataView?.destroy === 'function') {
|
|
253
|
+
this.dataView?.destroy();
|
|
276
254
|
}
|
|
277
|
-
|
|
255
|
+
this.slickGrid?.destroy(true);
|
|
278
256
|
this.slickGrid = null;
|
|
279
257
|
(0, common_1.emptyElement)(this._gridContainerElm);
|
|
280
258
|
(0, common_1.emptyElement)(this._gridParentContainerElm);
|
|
281
|
-
|
|
282
|
-
|
|
259
|
+
this._gridContainerElm?.remove();
|
|
260
|
+
this._gridParentContainerElm?.remove();
|
|
283
261
|
if (this.backendServiceApi) {
|
|
284
262
|
for (const prop of Object.keys(this.backendServiceApi)) {
|
|
285
263
|
this.backendServiceApi[prop] = null;
|
|
@@ -298,14 +276,14 @@ class SlickVanillaGridBundle {
|
|
|
298
276
|
if (shouldEmptyDomElementContainer) {
|
|
299
277
|
this.emptyGridContainerElm();
|
|
300
278
|
}
|
|
301
|
-
|
|
279
|
+
this._eventPubSubService?.dispose();
|
|
302
280
|
this._slickerGridInstances = null;
|
|
303
281
|
}
|
|
304
282
|
disposeExternalResources() {
|
|
305
283
|
if (Array.isArray(this._registeredResources)) {
|
|
306
284
|
while (this._registeredResources.length > 0) {
|
|
307
285
|
const res = this._registeredResources.pop();
|
|
308
|
-
if (res
|
|
286
|
+
if (res?.dispose) {
|
|
309
287
|
res.dispose();
|
|
310
288
|
}
|
|
311
289
|
}
|
|
@@ -313,7 +291,6 @@ class SlickVanillaGridBundle {
|
|
|
313
291
|
this._registeredResources = [];
|
|
314
292
|
}
|
|
315
293
|
initialization(gridContainerElm, eventHandler) {
|
|
316
|
-
var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
|
|
317
294
|
// when detecting a frozen grid, we'll automatically enable the mousewheel scroll handler so that we can scroll from both left/right frozen containers
|
|
318
295
|
if (this.gridOptions && ((this.gridOptions.frozenRow !== undefined && this.gridOptions.frozenRow >= 0) || this.gridOptions.frozenColumn !== undefined && this.gridOptions.frozenColumn >= 0) && this.gridOptions.enableMouseWheelScrollHandler === undefined) {
|
|
319
296
|
this.gridOptions.enableMouseWheelScrollHandler = true;
|
|
@@ -323,20 +300,20 @@ class SlickVanillaGridBundle {
|
|
|
323
300
|
this._eventPubSubService.publish('onBeforeGridCreate', true);
|
|
324
301
|
this._eventHandler = eventHandler;
|
|
325
302
|
this._gridOptions = this.mergeGridOptions(this._gridOptions || {});
|
|
326
|
-
this.backendServiceApi =
|
|
303
|
+
this.backendServiceApi = this._gridOptions?.backendServiceApi;
|
|
327
304
|
this._isLocalGrid = !this.backendServiceApi; // considered a local grid if it doesn't have a backend service set
|
|
328
|
-
this._eventPubSubService.eventNamingStyle =
|
|
329
|
-
this._paginationOptions =
|
|
305
|
+
this._eventPubSubService.eventNamingStyle = this._gridOptions?.eventNamingStyle ?? event_pub_sub_1.EventNamingStyle.camelCase;
|
|
306
|
+
this._paginationOptions = this.gridOptions?.pagination;
|
|
330
307
|
this.createBackendApiInternalPostProcessCallback(this._gridOptions);
|
|
331
308
|
if (!this.customDataView) {
|
|
332
|
-
const dataviewInlineFilters =
|
|
333
|
-
let dataViewOptions = { inlineFilters: dataviewInlineFilters };
|
|
309
|
+
const dataviewInlineFilters = this._gridOptions?.dataView?.inlineFilters ?? false;
|
|
310
|
+
let dataViewOptions = { ...this._gridOptions.dataView, inlineFilters: dataviewInlineFilters };
|
|
334
311
|
if (this.gridOptions.draggableGrouping || this.gridOptions.enableGrouping) {
|
|
335
312
|
this.groupItemMetadataProvider = new common_1.SlickGroupItemMetadataProvider();
|
|
336
313
|
this.sharedService.groupItemMetadataProvider = this.groupItemMetadataProvider;
|
|
337
314
|
dataViewOptions = { ...dataViewOptions, groupItemMetadataProvider: this.groupItemMetadataProvider };
|
|
338
315
|
}
|
|
339
|
-
this.dataView = new
|
|
316
|
+
this.dataView = new common_1.SlickDataView(dataViewOptions, this._eventPubSubService);
|
|
340
317
|
this._eventPubSubService.publish('onDataviewCreated', this.dataView);
|
|
341
318
|
}
|
|
342
319
|
// get any possible Services that user want to register which don't require SlickGrid to be instantiated
|
|
@@ -348,7 +325,7 @@ class SlickVanillaGridBundle {
|
|
|
348
325
|
// then take back "editor.model" and make it the new "editor" so that SlickGrid Editor Factory still works
|
|
349
326
|
this._columnDefinitions = this.swapInternalEditorToSlickGridFactoryEditor(this._columnDefinitions || []);
|
|
350
327
|
// if the user wants to automatically add a Custom Editor Formatter, we need to call the auto add function again
|
|
351
|
-
if (this._gridOptions
|
|
328
|
+
if (this._gridOptions?.autoAddCustomEditorFormatter) {
|
|
352
329
|
(0, common_1.autoAddEditorFormatterToColumnsWithEditor)(this._columnDefinitions, this._gridOptions.autoAddCustomEditorFormatter);
|
|
353
330
|
}
|
|
354
331
|
// save reference for all columns before they optionally become hidden/visible
|
|
@@ -366,20 +343,23 @@ class SlickVanillaGridBundle {
|
|
|
366
343
|
// when we did find some to create (RowMove, RowDetail, RowSelections), it will automatically modify column definitions (by previous subscribe)
|
|
367
344
|
this.extensionService.createExtensionsBeforeGridCreation(this._columnDefinitions, this._gridOptions);
|
|
368
345
|
// if user entered some Pinning/Frozen "presets", we need to apply them in the grid options
|
|
369
|
-
if (
|
|
346
|
+
if (this.gridOptions.presets?.pinning) {
|
|
370
347
|
this.gridOptions = { ...this.gridOptions, ...this.gridOptions.presets.pinning };
|
|
371
348
|
}
|
|
372
|
-
this.slickGrid = new
|
|
349
|
+
this.slickGrid = new common_1.SlickGrid(gridContainerElm, this.dataView, this._columnDefinitions, this._gridOptions, this._eventPubSubService);
|
|
373
350
|
this.sharedService.dataView = this.dataView;
|
|
374
351
|
this.sharedService.slickGrid = this.slickGrid;
|
|
375
352
|
this.sharedService.gridContainerElement = this._gridContainerElm;
|
|
353
|
+
if (this.groupItemMetadataProvider) {
|
|
354
|
+
this.slickGrid.registerPlugin(this.groupItemMetadataProvider); // register GroupItemMetadataProvider when Grouping is enabled
|
|
355
|
+
}
|
|
376
356
|
this.extensionService.bindDifferentExtensions();
|
|
377
357
|
this.bindDifferentHooks(this.slickGrid, this._gridOptions, this.dataView);
|
|
378
358
|
this._slickgridInitialized = true;
|
|
379
359
|
// when it's a frozen grid, we need to keep the frozen column id for reference if we ever show/hide column from ColumnPicker/GridMenu afterward
|
|
380
|
-
const frozenColumnIndex =
|
|
360
|
+
const frozenColumnIndex = this._gridOptions?.frozenColumn ?? -1;
|
|
381
361
|
if (frozenColumnIndex >= 0 && frozenColumnIndex <= this._columnDefinitions.length && this._columnDefinitions.length > 0) {
|
|
382
|
-
this.sharedService.frozenVisibleColumnId =
|
|
362
|
+
this.sharedService.frozenVisibleColumnId = this._columnDefinitions[frozenColumnIndex]?.id ?? '';
|
|
383
363
|
}
|
|
384
364
|
// get any possible Services that user want to register
|
|
385
365
|
this.registerResources();
|
|
@@ -395,13 +375,13 @@ class SlickVanillaGridBundle {
|
|
|
395
375
|
}
|
|
396
376
|
// load the data in the DataView (unless it's a hierarchical dataset, if so it will be loaded after the initial tree sort)
|
|
397
377
|
if (Array.isArray(this.dataset)) {
|
|
398
|
-
const initialDataset =
|
|
399
|
-
|
|
378
|
+
const initialDataset = this.gridOptions?.enableTreeData ? this.sortTreeDataset(this.dataset) : this.dataset;
|
|
379
|
+
this.dataView?.setItems(initialDataset, this._gridOptions.datasetIdPropertyName);
|
|
400
380
|
}
|
|
401
381
|
// if you don't want the items that are not visible (due to being filtered out or being on a different page)
|
|
402
382
|
// to stay selected, pass 'false' to the second arg
|
|
403
|
-
const selectionModel =
|
|
404
|
-
if (selectionModel &&
|
|
383
|
+
const selectionModel = this.slickGrid?.getSelectionModel();
|
|
384
|
+
if (selectionModel && this._gridOptions?.dataView && this._gridOptions.dataView.hasOwnProperty('syncGridSelection')) {
|
|
405
385
|
// if we are using a Backend Service, we will do an extra flag check, the reason is because it might have some unintended behaviors
|
|
406
386
|
// with the BackendServiceApi because technically the data in the page changes the DataView on every page change.
|
|
407
387
|
let preservedRowSelectionWithBackend = false;
|
|
@@ -415,14 +395,14 @@ class SlickVanillaGridBundle {
|
|
|
415
395
|
// when using BackendServiceApi, we'll be using the "syncGridSelectionWithBackendService" flag BUT "syncGridSelection" must also be set to True
|
|
416
396
|
preservedRowSelection = syncGridSelection && preservedRowSelectionWithBackend;
|
|
417
397
|
}
|
|
418
|
-
|
|
398
|
+
this.dataView?.syncGridSelection(this.slickGrid, preservedRowSelection);
|
|
419
399
|
}
|
|
420
400
|
else if (typeof syncGridSelection === 'object') {
|
|
421
|
-
|
|
401
|
+
this.dataView?.syncGridSelection(this.slickGrid, syncGridSelection.preserveHidden, syncGridSelection.preserveHiddenOnSelectionChange);
|
|
422
402
|
}
|
|
423
403
|
}
|
|
424
404
|
this.slickGrid.invalidate();
|
|
425
|
-
if ((
|
|
405
|
+
if ((this.dataView?.getLength() ?? 0) > 0) {
|
|
426
406
|
if (!this._isDatasetInitialized && (this._gridOptions.enableCheckboxSelector || this._gridOptions.enableRowSelection)) {
|
|
427
407
|
this.loadRowSelectionPresetWhenExists();
|
|
428
408
|
}
|
|
@@ -441,7 +421,7 @@ class SlickVanillaGridBundle {
|
|
|
441
421
|
this.gridEventService.bindOnClick(this.slickGrid);
|
|
442
422
|
// bind the Backend Service API callback functions only after the grid is initialized
|
|
443
423
|
// because the preProcess() and onInit() might get triggered
|
|
444
|
-
if (
|
|
424
|
+
if (this.gridOptions?.backendServiceApi) {
|
|
445
425
|
this.bindBackendCallbackFunctions(this.gridOptions);
|
|
446
426
|
}
|
|
447
427
|
// publish & dispatch certain events
|
|
@@ -460,7 +440,7 @@ class SlickVanillaGridBundle {
|
|
|
460
440
|
// public methods
|
|
461
441
|
dispose: this.dispose.bind(this),
|
|
462
442
|
// return all available Services (non-singleton)
|
|
463
|
-
backendService:
|
|
443
|
+
backendService: this.gridOptions?.backendServiceApi?.service,
|
|
464
444
|
eventPubSubService: this._eventPubSubService,
|
|
465
445
|
filterService: this.filterService,
|
|
466
446
|
gridEventService: this.gridEventService,
|
|
@@ -475,13 +455,13 @@ class SlickVanillaGridBundle {
|
|
|
475
455
|
treeDataService: this.treeDataService,
|
|
476
456
|
};
|
|
477
457
|
// addons (SlickGrid extra plugins/controls)
|
|
478
|
-
this._extensions =
|
|
458
|
+
this._extensions = this.extensionService?.extensionList;
|
|
479
459
|
// all instances (SlickGrid, DataView & all Services)
|
|
480
460
|
this._eventPubSubService.publish('onSlickerGridCreated', this.instances);
|
|
481
461
|
this._isGridInitialized = true;
|
|
482
462
|
}
|
|
483
463
|
mergeGridOptions(gridOptions) {
|
|
484
|
-
const options =
|
|
464
|
+
const options = common_1.Utils.extend(true, {}, common_1.GlobalGridOptions, gridOptions);
|
|
485
465
|
// also make sure to show the header row if user have enabled filtering
|
|
486
466
|
if (options.enableFiltering && !options.showHeaderRow) {
|
|
487
467
|
options.showHeaderRow = options.enableFiltering;
|
|
@@ -489,7 +469,7 @@ class SlickVanillaGridBundle {
|
|
|
489
469
|
// using copy extend to do a deep clone has an unwanted side on objects and pageSizes but ES6 spread has other worst side effects
|
|
490
470
|
// so we will just overwrite the pageSizes when needed, this is the only one causing issues so far.
|
|
491
471
|
// On a deep extend, Object and Array are extended, but object wrappers on primitive types such as String, Boolean, and Number are not.
|
|
492
|
-
if (
|
|
472
|
+
if (options?.pagination && (gridOptions.enablePagination || gridOptions.backendServiceApi) && gridOptions.pagination && Array.isArray(gridOptions.pagination.pageSizes)) {
|
|
493
473
|
options.pagination.pageSizes = gridOptions.pagination.pageSizes;
|
|
494
474
|
}
|
|
495
475
|
// when we use Pagination on Local Grid, it doesn't seem to work without enableFiltering
|
|
@@ -508,8 +488,8 @@ class SlickVanillaGridBundle {
|
|
|
508
488
|
* refresh the Dataset & Pagination without having the user to create his own PostProcess every time
|
|
509
489
|
*/
|
|
510
490
|
createBackendApiInternalPostProcessCallback(gridOptions) {
|
|
511
|
-
const backendApi = gridOptions
|
|
512
|
-
if (backendApi
|
|
491
|
+
const backendApi = gridOptions?.backendServiceApi;
|
|
492
|
+
if (backendApi?.service) {
|
|
513
493
|
const backendApiService = backendApi.service;
|
|
514
494
|
// internalPostProcess only works (for now) with a GraphQL Service, so make sure it is of that type
|
|
515
495
|
if ( /* backendApiService instanceof GraphqlService || */typeof backendApiService.getDatasetName === 'function') {
|
|
@@ -525,10 +505,9 @@ class SlickVanillaGridBundle {
|
|
|
525
505
|
}
|
|
526
506
|
}
|
|
527
507
|
bindDifferentHooks(grid, gridOptions, dataView) {
|
|
528
|
-
var _a, _b;
|
|
529
508
|
// if user is providing a Translate Service, we need to add our PubSub Service (but only after creating all dependencies)
|
|
530
509
|
// so that we can later subscribe to the "onLanguageChange" event and translate any texts whenever that get triggered
|
|
531
|
-
if (gridOptions.enableTranslate &&
|
|
510
|
+
if (gridOptions.enableTranslate && this.translaterService?.addPubSubMessaging) {
|
|
532
511
|
this.translaterService.addPubSubMessaging(this._eventPubSubService);
|
|
533
512
|
}
|
|
534
513
|
// translate them all on first load, then on each language change
|
|
@@ -551,31 +530,11 @@ class SlickVanillaGridBundle {
|
|
|
551
530
|
// if user set an onInit Backend, we'll run it right away (and if so, we also need to run preProcess, internalPostProcess & postProcess)
|
|
552
531
|
if (gridOptions.backendServiceApi) {
|
|
553
532
|
const backendApi = gridOptions.backendServiceApi;
|
|
554
|
-
if (
|
|
533
|
+
if (backendApi?.service?.init) {
|
|
555
534
|
backendApi.service.init(backendApi.options, gridOptions.pagination, this.slickGrid, this.sharedService);
|
|
556
535
|
}
|
|
557
536
|
}
|
|
558
537
|
if (dataView && grid) {
|
|
559
|
-
// expose all Slick Grid Events through dispatch
|
|
560
|
-
for (const prop in grid) {
|
|
561
|
-
if (grid.hasOwnProperty(prop) && prop.startsWith('on')) {
|
|
562
|
-
this._eventHandler.subscribe(grid[prop], (event, args) => {
|
|
563
|
-
var _a, _b;
|
|
564
|
-
const gridEventName = this._eventPubSubService.getEventNameByNamingConvention(prop, (_b = (_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.defaultSlickgridEventPrefix) !== null && _b !== void 0 ? _b : '');
|
|
565
|
-
return this._eventPubSubService.dispatchCustomEvent(gridEventName, { eventData: event, args });
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
// expose all Slick DataView Events through dispatch
|
|
570
|
-
for (const prop in dataView) {
|
|
571
|
-
if (dataView.hasOwnProperty(prop) && prop.startsWith('on')) {
|
|
572
|
-
this._eventHandler.subscribe(dataView[prop], (event, args) => {
|
|
573
|
-
var _a, _b;
|
|
574
|
-
const dataViewEventName = this._eventPubSubService.getEventNameByNamingConvention(prop, (_b = (_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.defaultSlickgridEventPrefix) !== null && _b !== void 0 ? _b : '');
|
|
575
|
-
return this._eventPubSubService.dispatchCustomEvent(dataViewEventName, { eventData: event, args });
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
538
|
// after all events are exposed
|
|
580
539
|
// we can bind external filter (backend) when available or default onFilter (dataView)
|
|
581
540
|
if (gridOptions.enableFiltering) {
|
|
@@ -600,23 +559,21 @@ class SlickVanillaGridBundle {
|
|
|
600
559
|
}
|
|
601
560
|
// When data changes in the DataView, we need to refresh the metrics and/or display a warning if the dataset is empty
|
|
602
561
|
this._eventHandler.subscribe(dataView.onRowCountChanged, () => {
|
|
603
|
-
var _a, _b, _c;
|
|
604
562
|
grid.invalidate();
|
|
605
|
-
this.handleOnItemCountChanged(
|
|
563
|
+
this.handleOnItemCountChanged(this.dataView?.getFilteredItemCount() || 0, this.dataView?.getItemCount() ?? 0);
|
|
606
564
|
});
|
|
607
565
|
this._eventHandler.subscribe(dataView.onSetItemsCalled, (_e, args) => {
|
|
608
|
-
|
|
609
|
-
this.handleOnItemCountChanged(((_a = this.dataView) === null || _a === void 0 ? void 0 : _a.getFilteredItemCount()) || 0, args.itemCount);
|
|
566
|
+
this.handleOnItemCountChanged(this.dataView?.getFilteredItemCount() || 0, args.itemCount);
|
|
610
567
|
// when user has resize by content enabled, we'll force a full width calculation since we change our entire dataset
|
|
611
568
|
if (args.itemCount > 0 && (this.gridOptions.autosizeColumnsByCellContentOnFirstLoad || this.gridOptions.enableAutoResizeColumnsByCellContent)) {
|
|
612
|
-
this.resizerService.resizeColumnsByCellContent(!
|
|
569
|
+
this.resizerService.resizeColumnsByCellContent(!this.gridOptions?.resizeByContentOnlyOnFirstLoad);
|
|
613
570
|
}
|
|
614
571
|
});
|
|
615
572
|
// when filtering data with local dataset, we need to update each row else it will not always show correctly in the UI
|
|
616
573
|
// also don't use "invalidateRows" since it destroys the entire row and as bad user experience when updating a row
|
|
617
574
|
if (gridOptions && gridOptions.enableFiltering && !gridOptions.enableRowDetailView) {
|
|
618
575
|
this._eventHandler.subscribe(dataView.onRowsChanged, (_e, args) => {
|
|
619
|
-
if (
|
|
576
|
+
if (args?.rows && Array.isArray(args.rows)) {
|
|
620
577
|
args.rows.forEach((row) => grid.updateRow(row));
|
|
621
578
|
grid.render();
|
|
622
579
|
}
|
|
@@ -632,7 +589,7 @@ class SlickVanillaGridBundle {
|
|
|
632
589
|
this.loadFilterPresetsWhenDatasetInitialized();
|
|
633
590
|
}
|
|
634
591
|
// did the user add a colspan callback? If so, hook it into the DataView getItemMetadata
|
|
635
|
-
if (
|
|
592
|
+
if (gridOptions?.colspanCallback && dataView?.getItem && dataView?.getItemMetadata) {
|
|
636
593
|
dataView.getItemMetadata = (rowNumber) => {
|
|
637
594
|
let callbackResult = null;
|
|
638
595
|
if (gridOptions.colspanCallback) {
|
|
@@ -643,15 +600,14 @@ class SlickVanillaGridBundle {
|
|
|
643
600
|
}
|
|
644
601
|
}
|
|
645
602
|
bindBackendCallbackFunctions(gridOptions) {
|
|
646
|
-
var _a, _b, _c, _d, _f, _g;
|
|
647
603
|
const backendApi = gridOptions.backendServiceApi;
|
|
648
|
-
const backendApiService = backendApi
|
|
649
|
-
const serviceOptions =
|
|
650
|
-
const isExecuteCommandOnInit = (!serviceOptions) ? false : ((serviceOptions
|
|
604
|
+
const backendApiService = backendApi?.service;
|
|
605
|
+
const serviceOptions = backendApiService?.options ?? {};
|
|
606
|
+
const isExecuteCommandOnInit = (!serviceOptions) ? false : ((serviceOptions?.hasOwnProperty('executeProcessCommandOnInit')) ? serviceOptions['executeProcessCommandOnInit'] : true);
|
|
651
607
|
if (backendApiService) {
|
|
652
608
|
// update backend filters (if need be) BEFORE the query runs (via the onInit command a few lines below)
|
|
653
609
|
// if user entered some any "presets", we need to reflect them all in the grid
|
|
654
|
-
if (gridOptions
|
|
610
|
+
if (gridOptions?.presets) {
|
|
655
611
|
// Filters "presets"
|
|
656
612
|
if (backendApiService.updateFilters && Array.isArray(gridOptions.presets.filters) && gridOptions.presets.filters.length > 0) {
|
|
657
613
|
backendApiService.updateFilters(gridOptions.presets.filters, true);
|
|
@@ -659,7 +615,7 @@ class SlickVanillaGridBundle {
|
|
|
659
615
|
// Sorters "presets"
|
|
660
616
|
if (backendApiService.updateSorters && Array.isArray(gridOptions.presets.sorters) && gridOptions.presets.sorters.length > 0) {
|
|
661
617
|
// when using multi-column sort, we can have multiple but on single sort then only grab the first sort provided
|
|
662
|
-
const sortColumns =
|
|
618
|
+
const sortColumns = this._gridOptions?.multiColumnSort ? gridOptions.presets.sorters : gridOptions.presets.sorters.slice(0, 1);
|
|
663
619
|
backendApiService.updateSorters(undefined, sortColumns);
|
|
664
620
|
}
|
|
665
621
|
// Pagination "presets"
|
|
@@ -677,10 +633,9 @@ class SlickVanillaGridBundle {
|
|
|
677
633
|
// execute onInit command when necessary
|
|
678
634
|
if (backendApi && backendApiService && (backendApi.onInit || isExecuteCommandOnInit)) {
|
|
679
635
|
const query = (typeof backendApiService.buildQuery === 'function') ? backendApiService.buildQuery() : '';
|
|
680
|
-
const process = isExecuteCommandOnInit ? (
|
|
636
|
+
const process = isExecuteCommandOnInit ? (backendApi.process?.(query) ?? null) : (backendApi.onInit?.(query) ?? null);
|
|
681
637
|
// wrap this inside a setTimeout to avoid timing issue since the gridOptions needs to be ready before running this onInit
|
|
682
638
|
setTimeout(() => {
|
|
683
|
-
var _a, _b, _c, _d;
|
|
684
639
|
const backendUtilityService = this.backendUtilityService;
|
|
685
640
|
// keep start time & end timestamps & return it after process execution
|
|
686
641
|
const startTime = new Date();
|
|
@@ -689,13 +644,13 @@ class SlickVanillaGridBundle {
|
|
|
689
644
|
backendApi.preProcess();
|
|
690
645
|
}
|
|
691
646
|
// the processes can be a Promise (like Http)
|
|
692
|
-
const totalItems =
|
|
647
|
+
const totalItems = this.gridOptions?.pagination?.totalItems ?? 0;
|
|
693
648
|
if (process instanceof Promise) {
|
|
694
649
|
process
|
|
695
650
|
.then((processResult) => backendUtilityService.executeBackendProcessesCallback(startTime, processResult, backendApi, totalItems))
|
|
696
651
|
.catch((error) => backendUtilityService.onBackendError(error, backendApi));
|
|
697
652
|
}
|
|
698
|
-
else if (process &&
|
|
653
|
+
else if (process && this.rxjs?.isObservable(process)) {
|
|
699
654
|
this.subscriptions.push(process.subscribe((processResult) => backendUtilityService.executeBackendProcessesCallback(startTime, processResult, backendApi, totalItems), (error) => backendUtilityService.onBackendError(error, backendApi)));
|
|
700
655
|
}
|
|
701
656
|
});
|
|
@@ -717,19 +672,18 @@ class SlickVanillaGridBundle {
|
|
|
717
672
|
else {
|
|
718
673
|
this.resizerService.resizeGrid();
|
|
719
674
|
}
|
|
720
|
-
if (grid &&
|
|
675
|
+
if (grid && options?.enableAutoResize) {
|
|
721
676
|
if (options.autoFitColumnsOnFirstLoad && options.enableAutoSizeColumns && typeof grid.autosizeColumns === 'function') {
|
|
722
677
|
grid.autosizeColumns();
|
|
723
678
|
}
|
|
724
679
|
}
|
|
725
680
|
}
|
|
726
681
|
executeAfterDataviewCreated(gridOptions) {
|
|
727
|
-
var _a;
|
|
728
682
|
// if user entered some Sort "presets", we need to reflect them all in the DOM
|
|
729
683
|
if (gridOptions.enableSorting) {
|
|
730
684
|
if (gridOptions.presets && Array.isArray(gridOptions.presets.sorters)) {
|
|
731
685
|
// when using multi-column sort, we can have multiple but on single sort then only grab the first sort provided
|
|
732
|
-
const sortColumns =
|
|
686
|
+
const sortColumns = this._gridOptions?.multiColumnSort ? gridOptions.presets.sorters : gridOptions.presets.sorters.slice(0, 1);
|
|
733
687
|
this.sortService.loadGridSorters(sortColumns);
|
|
734
688
|
}
|
|
735
689
|
}
|
|
@@ -739,9 +693,8 @@ class SlickVanillaGridBundle {
|
|
|
739
693
|
* Also if we use Row Selection or the Checkbox Selector with a Backend Service (Odata, GraphQL), we need to reset any selection
|
|
740
694
|
*/
|
|
741
695
|
paginationChanged(pagination) {
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
if (this.slickGrid && !isSyncGridSelectionEnabled && ((_c = this._gridOptions) === null || _c === void 0 ? void 0 : _c.backendServiceApi) && (this.gridOptions.enableRowSelection || this.gridOptions.enableCheckboxSelector)) {
|
|
696
|
+
const isSyncGridSelectionEnabled = this.gridStateService?.needToPreserveRowSelection() ?? false;
|
|
697
|
+
if (this.slickGrid && !isSyncGridSelectionEnabled && this._gridOptions?.backendServiceApi && (this.gridOptions.enableRowSelection || this.gridOptions.enableCheckboxSelector)) {
|
|
745
698
|
this.slickGrid.setSelectedRows([]);
|
|
746
699
|
}
|
|
747
700
|
const { pageNumber, pageSize } = pagination;
|
|
@@ -760,7 +713,6 @@ class SlickVanillaGridBundle {
|
|
|
760
713
|
* @param dataset
|
|
761
714
|
*/
|
|
762
715
|
refreshGridData(dataset, totalCount) {
|
|
763
|
-
var _a, _b, _c, _d, _f;
|
|
764
716
|
// local grid, check if we need to show the Pagination
|
|
765
717
|
// if so then also check if there's any presets and finally initialize the PaginationService
|
|
766
718
|
// a local grid with Pagination presets will potentially have a different total of items, we'll need to get it from the DataView and update our total
|
|
@@ -773,7 +725,7 @@ class SlickVanillaGridBundle {
|
|
|
773
725
|
const finalTotalCount = totalCount || dataset.length;
|
|
774
726
|
this.displayEmptyDataWarning(finalTotalCount < 1);
|
|
775
727
|
}
|
|
776
|
-
if (Array.isArray(dataset) && this.slickGrid &&
|
|
728
|
+
if (Array.isArray(dataset) && this.slickGrid && this.dataView?.setItems) {
|
|
777
729
|
this.dataView.setItems(dataset, this._gridOptions.datasetIdPropertyName);
|
|
778
730
|
if (!this._gridOptions.backendServiceApi && !this._gridOptions.enableTreeData) {
|
|
779
731
|
this.dataView.reSort();
|
|
@@ -792,11 +744,11 @@ class SlickVanillaGridBundle {
|
|
|
792
744
|
}
|
|
793
745
|
// display the Pagination component only after calling this refresh data first, we call it here so that if we preset pagination page number it will be shown correctly
|
|
794
746
|
this.showPagination = (this._gridOptions && (this._gridOptions.enablePagination || (this._gridOptions.backendServiceApi && this._gridOptions.enablePagination === undefined))) ? true : false;
|
|
795
|
-
if (this._paginationOptions &&
|
|
747
|
+
if (this._paginationOptions && this._gridOptions?.pagination && this._gridOptions?.backendServiceApi) {
|
|
796
748
|
const paginationOptions = this.setPaginationOptionsWhenPresetDefined(this._gridOptions, this._paginationOptions);
|
|
797
749
|
// when we have a totalCount use it, else we'll take it from the pagination object
|
|
798
750
|
// only update the total items if it's different to avoid refreshing the UI
|
|
799
|
-
const totalRecords = (totalCount !== undefined) ? totalCount : (
|
|
751
|
+
const totalRecords = (totalCount !== undefined) ? totalCount : (this._gridOptions?.pagination?.totalItems);
|
|
800
752
|
if (totalRecords !== undefined && totalRecords !== this.totalItems) {
|
|
801
753
|
this.totalItems = +totalRecords;
|
|
802
754
|
}
|
|
@@ -823,7 +775,6 @@ class SlickVanillaGridBundle {
|
|
|
823
775
|
* If using translater, we also need to trigger a re-translate of the column headers
|
|
824
776
|
*/
|
|
825
777
|
updateColumnDefinitionsList(newColumnDefinitions) {
|
|
826
|
-
var _a, _b, _c;
|
|
827
778
|
if (this.slickGrid && this._gridOptions && Array.isArray(newColumnDefinitions)) {
|
|
828
779
|
// map/swap the internal library Editor to the SlickGrid Editor factory
|
|
829
780
|
newColumnDefinitions = this.swapInternalEditorToSlickGridFactoryEditor(newColumnDefinitions);
|
|
@@ -837,10 +788,10 @@ class SlickVanillaGridBundle {
|
|
|
837
788
|
else {
|
|
838
789
|
this.extensionService.renderColumnHeaders(newColumnDefinitions, true);
|
|
839
790
|
}
|
|
840
|
-
if (this.slickGrid &&
|
|
791
|
+
if (this.slickGrid && this._gridOptions?.enableAutoSizeColumns) {
|
|
841
792
|
this.slickGrid.autosizeColumns();
|
|
842
793
|
}
|
|
843
|
-
else if (
|
|
794
|
+
else if (this._gridOptions?.enableAutoResizeColumnsByCellContent && this.resizerService?.resizeColumnsByCellContent) {
|
|
844
795
|
this.resizerService.resizeColumnsByCellContent();
|
|
845
796
|
}
|
|
846
797
|
}
|
|
@@ -850,8 +801,7 @@ class SlickVanillaGridBundle {
|
|
|
850
801
|
* @param showing
|
|
851
802
|
*/
|
|
852
803
|
showHeaderRow(showing = true) {
|
|
853
|
-
|
|
854
|
-
(_a = this.slickGrid) === null || _a === void 0 ? void 0 : _a.setHeaderRowVisibility(showing, false);
|
|
804
|
+
this.slickGrid?.setHeaderRowVisibility(showing);
|
|
855
805
|
if (this.slickGrid && showing === true && this._isGridInitialized) {
|
|
856
806
|
this.slickGrid.setColumns(this.columnDefinitions);
|
|
857
807
|
}
|
|
@@ -862,8 +812,7 @@ class SlickVanillaGridBundle {
|
|
|
862
812
|
* if there are then load them in the paginationOptions object
|
|
863
813
|
*/
|
|
864
814
|
setPaginationOptionsWhenPresetDefined(gridOptions, paginationOptions) {
|
|
865
|
-
|
|
866
|
-
if (((_a = gridOptions.presets) === null || _a === void 0 ? void 0 : _a.pagination) && paginationOptions && !this._isPaginationInitialized) {
|
|
815
|
+
if (gridOptions.presets?.pagination && paginationOptions && !this._isPaginationInitialized) {
|
|
867
816
|
paginationOptions.pageSize = gridOptions.presets.pagination.pageSize;
|
|
868
817
|
paginationOptions.pageNumber = gridOptions.presets.pagination.pageNumber;
|
|
869
818
|
}
|
|
@@ -880,12 +829,10 @@ class SlickVanillaGridBundle {
|
|
|
880
829
|
columnDefinitions.forEach(col => col.originalWidth = col.width);
|
|
881
830
|
}
|
|
882
831
|
displayEmptyDataWarning(showWarning = true) {
|
|
883
|
-
|
|
884
|
-
(_a = this.slickEmptyWarning) === null || _a === void 0 ? void 0 : _a.showEmptyDataMessage(showWarning);
|
|
832
|
+
this.slickEmptyWarning?.showEmptyDataMessage(showWarning);
|
|
885
833
|
}
|
|
886
834
|
/** When data changes in the DataView, we'll refresh the metrics and/or display a warning if the dataset is empty */
|
|
887
835
|
handleOnItemCountChanged(currentPageRowItemCount, totalItemCount) {
|
|
888
|
-
var _a;
|
|
889
836
|
this._currentDatasetLength = totalItemCount;
|
|
890
837
|
this.metrics = {
|
|
891
838
|
startTime: new Date(),
|
|
@@ -898,7 +845,7 @@ class SlickVanillaGridBundle {
|
|
|
898
845
|
this.slickFooter.metrics = this.metrics;
|
|
899
846
|
}
|
|
900
847
|
// when using local (in-memory) dataset, we'll display a warning message when filtered data is empty
|
|
901
|
-
if (this._isLocalGrid &&
|
|
848
|
+
if (this._isLocalGrid && this._gridOptions?.enableEmptyDataWarningMessage) {
|
|
902
849
|
this.displayEmptyDataWarning(currentPageRowItemCount === 0);
|
|
903
850
|
}
|
|
904
851
|
}
|
|
@@ -912,10 +859,9 @@ class SlickVanillaGridBundle {
|
|
|
912
859
|
this.paginationService.totalItems = this.totalItems;
|
|
913
860
|
this.paginationService.init(this.slickGrid, paginationOptions, this.backendServiceApi);
|
|
914
861
|
this.subscriptions.push(this._eventPubSubService.subscribe('onPaginationChanged', paginationChanges => this.paginationChanged(paginationChanges)), this._eventPubSubService.subscribe('onPaginationVisibilityChanged', visibility => {
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
(_c = this.backendUtilityService) === null || _c === void 0 ? void 0 : _c.refreshBackendDataset(this.gridOptions);
|
|
862
|
+
this.showPagination = visibility?.visible ?? false;
|
|
863
|
+
if (this.gridOptions?.backendServiceApi) {
|
|
864
|
+
this.backendUtilityService?.refreshBackendDataset(this.gridOptions);
|
|
919
865
|
}
|
|
920
866
|
this.renderPagination(this.showPagination);
|
|
921
867
|
}));
|
|
@@ -931,8 +877,7 @@ class SlickVanillaGridBundle {
|
|
|
931
877
|
* @param {Boolean} shouldDisposePaginationService - when disposing the Pagination, do we also want to dispose of the Pagination Service? (defaults to True)
|
|
932
878
|
*/
|
|
933
879
|
renderPagination(showPagination = true) {
|
|
934
|
-
|
|
935
|
-
if (((_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.enablePagination) && !this._isPaginationInitialized && showPagination) {
|
|
880
|
+
if (this._gridOptions?.enablePagination && !this._isPaginationInitialized && showPagination) {
|
|
936
881
|
this.slickPagination = new pagination_component_1.SlickPaginationComponent(this.paginationService, this._eventPubSubService, this.sharedService, this.translaterService);
|
|
937
882
|
this.slickPagination.renderPagination(this._gridParentContainerElm);
|
|
938
883
|
this._isPaginationInitialized = true;
|
|
@@ -946,9 +891,8 @@ class SlickVanillaGridBundle {
|
|
|
946
891
|
}
|
|
947
892
|
/** Load the Editor Collection asynchronously and replace the "collection" property when Promise resolves */
|
|
948
893
|
loadEditorCollectionAsync(column) {
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
(column === null || column === void 0 ? void 0 : column.editor).disabled = true; // disable the Editor DOM element, we'll re-enable it after receiving the collection with "updateEditorCollection()"
|
|
894
|
+
const collectionAsync = (column?.editor).collectionAsync;
|
|
895
|
+
(column?.editor).disabled = true; // disable the Editor DOM element, we'll re-enable it after receiving the collection with "updateEditorCollection()"
|
|
952
896
|
if (collectionAsync instanceof Promise) {
|
|
953
897
|
// wait for the "collectionAsync", once resolved we will save it into the "collection"
|
|
954
898
|
// the collectionAsync can be of 3 types HttpClient, HttpFetch or a Promise
|
|
@@ -956,7 +900,7 @@ class SlickVanillaGridBundle {
|
|
|
956
900
|
if (Array.isArray(response)) {
|
|
957
901
|
this.updateEditorCollection(column, response); // from Promise
|
|
958
902
|
}
|
|
959
|
-
else if (
|
|
903
|
+
else if (response?.status >= 200 && response.status < 300 && typeof response.json === 'function') {
|
|
960
904
|
if (response.bodyUsed) {
|
|
961
905
|
console.warn(`[SlickGrid-Universal] The response body passed to collectionAsync was already read.`
|
|
962
906
|
+ `Either pass the dataset from the Response or clone the response first using response.clone()`);
|
|
@@ -966,12 +910,12 @@ class SlickVanillaGridBundle {
|
|
|
966
910
|
response.json().then(data => this.updateEditorCollection(column, data));
|
|
967
911
|
}
|
|
968
912
|
}
|
|
969
|
-
else if (response
|
|
913
|
+
else if (response?.content) {
|
|
970
914
|
this.updateEditorCollection(column, response['content']); // from http-client
|
|
971
915
|
}
|
|
972
916
|
});
|
|
973
917
|
}
|
|
974
|
-
else if (
|
|
918
|
+
else if (this.rxjs?.isObservable(collectionAsync)) {
|
|
975
919
|
// wrap this inside a setTimeout to avoid timing issue since updateEditorCollection requires to call SlickGrid getColumns() method
|
|
976
920
|
setTimeout(() => {
|
|
977
921
|
this.subscriptions.push(collectionAsync.subscribe((resolvedCollection) => this.updateEditorCollection(column, resolvedCollection)));
|
|
@@ -983,7 +927,7 @@ class SlickVanillaGridBundle {
|
|
|
983
927
|
const columnPosition = this._columnDefinitions.findIndex(c => c.id === columnId);
|
|
984
928
|
if (columnPosition >= 0) {
|
|
985
929
|
const dynColumn = this._columnDefinitions[columnPosition];
|
|
986
|
-
if (
|
|
930
|
+
if (dynColumn?.id === columnId && !gridPresetColumns.some(c => c.id === columnId)) {
|
|
987
931
|
columnPosition > 0
|
|
988
932
|
? gridPresetColumns.splice(columnPosition, 0, dynColumn)
|
|
989
933
|
: gridPresetColumns.unshift(dynColumn);
|
|
@@ -993,22 +937,21 @@ class SlickVanillaGridBundle {
|
|
|
993
937
|
}
|
|
994
938
|
/** Load any possible Columns Grid Presets */
|
|
995
939
|
loadColumnPresetsWhenDatasetInitialized() {
|
|
996
|
-
var _a, _b, _c, _d, _f, _g, _h, _j, _k;
|
|
997
940
|
// if user entered some Columns "presets", we need to reflect them all in the grid
|
|
998
941
|
if (this.slickGrid && this.gridOptions.presets && Array.isArray(this.gridOptions.presets.columns) && this.gridOptions.presets.columns.length > 0) {
|
|
999
942
|
const gridPresetColumns = this.gridStateService.getAssociatedGridColumns(this.slickGrid, this.gridOptions.presets.columns);
|
|
1000
943
|
if (gridPresetColumns && Array.isArray(gridPresetColumns) && gridPresetColumns.length > 0 && Array.isArray(this._columnDefinitions)) {
|
|
1001
944
|
// make sure that the dynamic columns are included in presets (1.Row Move, 2. Row Selection, 3. Row Detail)
|
|
1002
945
|
if (this.gridOptions.enableRowMoveManager) {
|
|
1003
|
-
const rmmColId =
|
|
946
|
+
const rmmColId = this.gridOptions?.rowMoveManager?.columnId ?? '_move';
|
|
1004
947
|
this.insertDynamicPresetColumns(rmmColId, gridPresetColumns);
|
|
1005
948
|
}
|
|
1006
949
|
if (this.gridOptions.enableCheckboxSelector) {
|
|
1007
|
-
const chkColId =
|
|
950
|
+
const chkColId = this.gridOptions?.checkboxSelector?.columnId ?? '_checkbox_selector';
|
|
1008
951
|
this.insertDynamicPresetColumns(chkColId, gridPresetColumns);
|
|
1009
952
|
}
|
|
1010
953
|
if (this.gridOptions.enableRowDetailView) {
|
|
1011
|
-
const rdvColId =
|
|
954
|
+
const rdvColId = this.gridOptions?.rowDetailView?.columnId ?? '_detail_selector';
|
|
1012
955
|
this.insertDynamicPresetColumns(rdvColId, gridPresetColumns);
|
|
1013
956
|
}
|
|
1014
957
|
// keep copy the original optional `width` properties optionally provided by the user.
|
|
@@ -1022,13 +965,12 @@ class SlickVanillaGridBundle {
|
|
|
1022
965
|
}
|
|
1023
966
|
/** Load any possible Filters Grid Presets */
|
|
1024
967
|
loadFilterPresetsWhenDatasetInitialized() {
|
|
1025
|
-
var _a, _b, _c;
|
|
1026
968
|
if (this.gridOptions && !this.customDataView) {
|
|
1027
969
|
// if user entered some Filter "presets", we need to reflect them all in the DOM
|
|
1028
970
|
// also note that a presets of Tree Data Toggling will also call this method because Tree Data toggling does work with data filtering
|
|
1029
971
|
// (collapsing a parent will basically use Filter for hidding (aka collapsing) away the child underneat it)
|
|
1030
|
-
if (this.gridOptions.presets && (Array.isArray(this.gridOptions.presets.filters) || Array.isArray(
|
|
1031
|
-
this.filterService.populateColumnFilterSearchTermPresets(
|
|
972
|
+
if (this.gridOptions.presets && (Array.isArray(this.gridOptions.presets.filters) || Array.isArray(this.gridOptions.presets?.treeData?.toggledItems))) {
|
|
973
|
+
this.filterService.populateColumnFilterSearchTermPresets(this.gridOptions.presets?.filters || []);
|
|
1032
974
|
}
|
|
1033
975
|
}
|
|
1034
976
|
}
|
|
@@ -1038,13 +980,12 @@ class SlickVanillaGridBundle {
|
|
|
1038
980
|
* a local grid with Pagination presets will potentially have a different total of items, we'll need to get it from the DataView and update our total
|
|
1039
981
|
*/
|
|
1040
982
|
loadLocalGridPagination(dataset) {
|
|
1041
|
-
var _a;
|
|
1042
983
|
if (this.gridOptions && this._paginationOptions) {
|
|
1043
984
|
this.totalItems = Array.isArray(dataset) ? dataset.length : 0;
|
|
1044
|
-
if (this._paginationOptions &&
|
|
985
|
+
if (this._paginationOptions && this.dataView?.getPagingInfo) {
|
|
1045
986
|
const slickPagingInfo = this.dataView.getPagingInfo();
|
|
1046
|
-
if (
|
|
1047
|
-
this.totalItems =
|
|
987
|
+
if (slickPagingInfo?.hasOwnProperty('totalRows') && this._paginationOptions.totalItems !== slickPagingInfo.totalRows) {
|
|
988
|
+
this.totalItems = slickPagingInfo?.totalRows || 0;
|
|
1048
989
|
}
|
|
1049
990
|
}
|
|
1050
991
|
this._paginationOptions.totalItems = this.totalItems;
|
|
@@ -1054,12 +995,11 @@ class SlickVanillaGridBundle {
|
|
|
1054
995
|
}
|
|
1055
996
|
/** Load any Row Selections into the DataView that were presets by the user */
|
|
1056
997
|
loadRowSelectionPresetWhenExists() {
|
|
1057
|
-
var _a, _b, _c;
|
|
1058
998
|
// if user entered some Row Selections "presets"
|
|
1059
|
-
const presets =
|
|
1060
|
-
const selectionModel =
|
|
999
|
+
const presets = this.gridOptions?.presets;
|
|
1000
|
+
const selectionModel = this.slickGrid?.getSelectionModel();
|
|
1061
1001
|
const enableRowSelection = this.gridOptions && (this.gridOptions.enableCheckboxSelector || this.gridOptions.enableRowSelection);
|
|
1062
|
-
if (this.slickGrid && this.dataView && enableRowSelection && selectionModel &&
|
|
1002
|
+
if (this.slickGrid && this.dataView && enableRowSelection && selectionModel && presets?.rowSelection && (Array.isArray(presets.rowSelection.gridRowIndexes) || Array.isArray(presets.rowSelection.dataContextIds))) {
|
|
1063
1003
|
let dataContextIds = presets.rowSelection.dataContextIds;
|
|
1064
1004
|
let gridRowIndexes = presets.rowSelection.gridRowIndexes;
|
|
1065
1005
|
// maps the IDs to the Grid Rows and vice versa, the "dataContextIds" has precedence over the other
|
|
@@ -1097,7 +1037,7 @@ class SlickVanillaGridBundle {
|
|
|
1097
1037
|
// register all services by executing their init method and providing them with the Grid object
|
|
1098
1038
|
if (Array.isArray(this._registeredResources)) {
|
|
1099
1039
|
for (const resource of this._registeredResources) {
|
|
1100
|
-
if (
|
|
1040
|
+
if (resource?.className === 'RxJsResource') {
|
|
1101
1041
|
this.registerRxJsResource(resource);
|
|
1102
1042
|
}
|
|
1103
1043
|
}
|
|
@@ -1154,7 +1094,6 @@ class SlickVanillaGridBundle {
|
|
|
1154
1094
|
* @returns {Array<Object>} sort flat parent/child dataset
|
|
1155
1095
|
*/
|
|
1156
1096
|
sortTreeDataset(flatDatasetInput, forceGridRefresh = false) {
|
|
1157
|
-
var _a, _b;
|
|
1158
1097
|
const prevDatasetLn = this._currentDatasetLength;
|
|
1159
1098
|
let sortedDatasetResult;
|
|
1160
1099
|
let flatDatasetOutput = [];
|
|
@@ -1164,7 +1103,7 @@ class SlickVanillaGridBundle {
|
|
|
1164
1103
|
flatDatasetOutput = sortedDatasetResult.flat;
|
|
1165
1104
|
}
|
|
1166
1105
|
else if (Array.isArray(flatDatasetInput) && flatDatasetInput.length > 0) {
|
|
1167
|
-
if (
|
|
1106
|
+
if (this.gridOptions?.treeDataOptions?.initialSort) {
|
|
1168
1107
|
// else we need to first convert the flat dataset to a hierarchical dataset and then sort
|
|
1169
1108
|
sortedDatasetResult = this.treeDataService.convertFlatParentChildToTreeDatasetAndSort(flatDatasetInput, this._columnDefinitions || [], this.gridOptions);
|
|
1170
1109
|
this.sharedService.hierarchicalDataset = sortedDatasetResult.hierarchical;
|
|
@@ -1195,14 +1134,13 @@ class SlickVanillaGridBundle {
|
|
|
1195
1134
|
console.error('[Slickgrid-Universal] Make sure that none of your Column Definition "id" property includes a dot in its name because that will cause some problems with the Editors. For example if your column definition "field" property is "user.firstName" then use "firstName" as the column "id".');
|
|
1196
1135
|
}
|
|
1197
1136
|
return columns.map((column) => {
|
|
1198
|
-
var _a;
|
|
1199
1137
|
// on every Editor that have a "collectionAsync", resolve the data and assign it to the "collection" property
|
|
1200
|
-
if (
|
|
1138
|
+
if (column.editor?.collectionAsync) {
|
|
1201
1139
|
this.loadEditorCollectionAsync(column);
|
|
1202
1140
|
}
|
|
1203
1141
|
// if there's already an internalColumnEditor we'll use it, else it would be inside the editor
|
|
1204
1142
|
const columnEditor = column.internalColumnEditor || column.editor;
|
|
1205
|
-
return { ...column, editor: columnEditor
|
|
1143
|
+
return { ...column, editor: columnEditor?.model, internalColumnEditor: { ...columnEditor } };
|
|
1206
1144
|
});
|
|
1207
1145
|
}
|
|
1208
1146
|
/** translate all columns (including hidden columns) */
|
|
@@ -1231,7 +1169,7 @@ class SlickVanillaGridBundle {
|
|
|
1231
1169
|
}
|
|
1232
1170
|
// get current Editor, remove it from the DOm then re-enable it and re-render it with the new collection.
|
|
1233
1171
|
const currentEditor = this.slickGrid.getCellEditor();
|
|
1234
|
-
if (
|
|
1172
|
+
if (currentEditor?.disable && currentEditor?.renderDomElement) {
|
|
1235
1173
|
if (typeof currentEditor.destroy === 'function') {
|
|
1236
1174
|
currentEditor.destroy();
|
|
1237
1175
|
}
|