@slickgrid-universal/vanilla-bundle 2.5.0 → 2.6.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.
Files changed (32) hide show
  1. package/dist/commonjs/components/slick-vanilla-grid-bundle.js +1201 -1201
  2. package/dist/commonjs/index.js +55 -55
  3. package/dist/commonjs/interfaces/index.js +17 -17
  4. package/dist/commonjs/interfaces/slickerGridInstance.interface.js +2 -2
  5. package/dist/commonjs/services/index.js +17 -17
  6. package/dist/commonjs/services/universalContainer.service.js +25 -25
  7. package/dist/esm/components/slick-vanilla-grid-bundle.js +1201 -1201
  8. package/dist/esm/index.js +28 -28
  9. package/dist/esm/interfaces/index.js +1 -1
  10. package/dist/esm/interfaces/slickerGridInstance.interface.js +1 -1
  11. package/dist/esm/services/index.js +1 -1
  12. package/dist/esm/services/universalContainer.service.js +21 -21
  13. package/dist/tsconfig.tsbuildinfo +1 -0
  14. package/dist/{commonjs → types}/components/slick-vanilla-grid-bundle.d.ts +328 -327
  15. package/dist/types/components/slick-vanilla-grid-bundle.d.ts.map +1 -0
  16. package/dist/{commonjs → types}/index.d.ts +249 -248
  17. package/dist/types/index.d.ts.map +1 -0
  18. package/dist/{esm → types}/interfaces/index.d.ts +2 -1
  19. package/dist/types/interfaces/index.d.ts.map +1 -0
  20. package/dist/{esm → types}/interfaces/slickerGridInstance.interface.d.ts +37 -36
  21. package/dist/types/interfaces/slickerGridInstance.interface.d.ts.map +1 -0
  22. package/dist/{commonjs → types}/services/index.d.ts +2 -1
  23. package/dist/types/services/index.d.ts.map +1 -0
  24. package/dist/{commonjs → types}/services/universalContainer.service.d.ts +8 -7
  25. package/dist/types/services/universalContainer.service.d.ts.map +1 -0
  26. package/package.json +13 -13
  27. package/dist/commonjs/interfaces/index.d.ts +0 -1
  28. package/dist/commonjs/interfaces/slickerGridInstance.interface.d.ts +0 -36
  29. package/dist/esm/components/slick-vanilla-grid-bundle.d.ts +0 -327
  30. package/dist/esm/index.d.ts +0 -248
  31. package/dist/esm/services/index.d.ts +0 -1
  32. package/dist/esm/services/universalContainer.service.d.ts +0 -7
@@ -1,1202 +1,1202 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.SlickVanillaGridBundle = void 0;
5
- const lite_1 = require("dequal/lite");
6
- require("jquery");
7
- require("flatpickr/dist/l10n/fr");
8
- require("slickgrid/slick.core");
9
- require("slickgrid/slick.interactions");
10
- require("slickgrid/slick.grid");
11
- require("slickgrid/slick.dataview");
12
- const Sortable_ = require("sortablejs");
13
- const Sortable = ((_a = Sortable_ === null || Sortable_ === void 0 ? void 0 : Sortable_['default']) !== null && _a !== void 0 ? _a : Sortable_); // patch for rollup
14
- const common_1 = require("@slickgrid-universal/common");
15
- const event_pub_sub_1 = require("@slickgrid-universal/event-pub-sub");
16
- const empty_warning_component_1 = require("@slickgrid-universal/empty-warning-component");
17
- const custom_footer_component_1 = require("@slickgrid-universal/custom-footer-component");
18
- const pagination_component_1 = require("@slickgrid-universal/pagination-component");
19
- const universalContainer_service_1 = require("../services/universalContainer.service");
20
- // add Sortable to the window object so that SlickGrid lib can use globally
21
- window.Sortable = Sortable;
22
- class SlickVanillaGridBundle {
23
- get eventHandler() {
24
- return this._eventHandler;
25
- }
26
- get columnDefinitions() {
27
- return this._columnDefinitions || [];
28
- }
29
- set columnDefinitions(columnDefinitions) {
30
- this._columnDefinitions = columnDefinitions;
31
- if (this._slickgridInitialized) {
32
- this.updateColumnDefinitionsList(this._columnDefinitions);
33
- }
34
- if (columnDefinitions.length > 0) {
35
- this.copyColumnWidthsReference(columnDefinitions);
36
- }
37
- }
38
- get dataset() {
39
- var _a;
40
- return ((_a = this.dataView) === null || _a === void 0 ? void 0 : _a.getItems()) || [];
41
- }
42
- set dataset(newDataset) {
43
- var _a, _b;
44
- const prevDatasetLn = this._currentDatasetLength;
45
- const isDatasetEqual = (0, lite_1.dequal)(newDataset, this.dataset || []);
46
- const isDeepCopyDataOnPageLoadEnabled = !!((_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.enableDeepCopyDatasetOnPageLoad);
47
- let data = isDeepCopyDataOnPageLoadEnabled ? $.extend(true, [], newDataset) : newDataset;
48
- // when Tree Data is enabled and we don't yet have the hierarchical dataset filled, we can force a convert+sort of the array
49
- if (this.slickGrid && ((_b = this.gridOptions) === null || _b === void 0 ? void 0 : _b.enableTreeData) && Array.isArray(newDataset) && (newDataset.length > 0 || newDataset.length !== prevDatasetLn || !isDatasetEqual)) {
50
- this._isDatasetHierarchicalInitialized = false;
51
- data = this.sortTreeDataset(newDataset, !isDatasetEqual); // if dataset changed, then force a refresh anyway
52
- }
53
- this.refreshGridData(data || []);
54
- this._currentDatasetLength = (newDataset || []).length;
55
- // expand/autofit columns on first page load
56
- // we can assume that if the prevDataset was empty then we are on first load
57
- if (this.slickGrid && this.gridOptions.autoFitColumnsOnFirstLoad && prevDatasetLn === 0) {
58
- this.slickGrid.autosizeColumns();
59
- }
60
- }
61
- get datasetHierarchical() {
62
- return this.sharedService.hierarchicalDataset;
63
- }
64
- set datasetHierarchical(newHierarchicalDataset) {
65
- var _a, _b, _c, _d;
66
- const isDatasetEqual = (0, lite_1.dequal)(newHierarchicalDataset, this.sharedService.hierarchicalDataset || []);
67
- const prevFlatDatasetLn = this._currentDatasetLength;
68
- this.sharedService.hierarchicalDataset = newHierarchicalDataset;
69
- if (newHierarchicalDataset && this.columnDefinitions && ((_a = this.filterService) === null || _a === void 0 ? void 0 : _a.clearFilters)) {
70
- this.filterService.clearFilters();
71
- }
72
- // 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
73
- if (this.dataView && newHierarchicalDataset && this.slickGrid && ((_b = this.sortService) === null || _b === void 0 ? void 0 : _b.processTreeDataInitialSort)) {
74
- this.dataView.setItems([], (_d = (_c = this._gridOptions) === null || _c === void 0 ? void 0 : _c.datasetIdPropertyName) !== null && _d !== void 0 ? _d : 'id');
75
- this.sortService.processTreeDataInitialSort();
76
- // 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
77
- // however we need 1 cpu cycle before having the DataView refreshed, so we need to wrap this check in a setTimeout
78
- setTimeout(() => {
79
- var _a, _b;
80
- const flatDatasetLn = (_b = (_a = this.dataView) === null || _a === void 0 ? void 0 : _a.getItemCount()) !== null && _b !== void 0 ? _b : 0;
81
- if (flatDatasetLn > 0 && (flatDatasetLn !== prevFlatDatasetLn || !isDatasetEqual)) {
82
- this.filterService.refreshTreeDataFilters();
83
- }
84
- });
85
- }
86
- this._isDatasetHierarchicalInitialized = true;
87
- }
88
- set eventPubSubService(pubSub) {
89
- this._eventPubSubService = pubSub;
90
- }
91
- get gridOptions() {
92
- return this._gridOptions || {};
93
- }
94
- set gridOptions(options) {
95
- var _a, _b, _c;
96
- let mergedOptions;
97
- // if we already have grid options, when grid was already initialized, we'll merge with those options
98
- // else we'll merge with global grid options
99
- if ((_a = this.slickGrid) === null || _a === void 0 ? void 0 : _a.getOptions) {
100
- mergedOptions = $.extend(true, {}, this.slickGrid.getOptions(), options);
101
- }
102
- else {
103
- mergedOptions = this.mergeGridOptions(options);
104
- }
105
- if (((_b = this.sharedService) === null || _b === void 0 ? void 0 : _b.gridOptions) && ((_c = this.slickGrid) === null || _c === void 0 ? void 0 : _c.setOptions)) {
106
- this.sharedService.gridOptions = mergedOptions;
107
- this.slickGrid.setOptions(mergedOptions, false, true); // make sure to supressColumnCheck (3rd arg) to avoid problem with changeColumnsArrangement() and custom grid view
108
- this.slickGrid.reRenderColumns(true); // then call a re-render since we did supressColumnCheck on previous setOptions
109
- }
110
- this._gridOptions = mergedOptions;
111
- }
112
- get paginationOptions() {
113
- return this._paginationOptions;
114
- }
115
- set paginationOptions(newPaginationOptions) {
116
- var _a;
117
- if (newPaginationOptions && this._paginationOptions) {
118
- this._paginationOptions = { ...this._paginationOptions, ...newPaginationOptions };
119
- }
120
- else {
121
- this._paginationOptions = newPaginationOptions;
122
- }
123
- this.gridOptions.pagination = this._paginationOptions;
124
- this.paginationService.updateTotalItems((_a = newPaginationOptions === null || newPaginationOptions === void 0 ? void 0 : newPaginationOptions.totalItems) !== null && _a !== void 0 ? _a : 0, true);
125
- }
126
- get isDatasetInitialized() {
127
- return this._isDatasetInitialized;
128
- }
129
- set isDatasetInitialized(isInitialized) {
130
- this._isDatasetInitialized = isInitialized;
131
- }
132
- get isGridInitialized() {
133
- return this._isGridInitialized;
134
- }
135
- get instances() {
136
- return this._slickerGridInstances;
137
- }
138
- get extensions() {
139
- return this._extensions;
140
- }
141
- get registeredResources() {
142
- return this._registeredResources;
143
- }
144
- /**
145
- * Slicker Grid Bundle constructor
146
- * @param {Object} gridParentContainerElm - div HTML DOM element container
147
- * @param {Array<Column>} columnDefs - Column Definitions
148
- * @param {Object} options - Grid Options
149
- * @param {Array<Object>} dataset - Dataset
150
- * @param {Array<Object>} hierarchicalDataset - Hierarchical Dataset
151
- * @param {Object} services - Typically only used for Unit Testing when we want to pass Mocked/Stub Services
152
- */
153
- constructor(gridParentContainerElm, columnDefs, options, dataset, hierarchicalDataset, services) {
154
- var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
155
- this._currentDatasetLength = 0;
156
- this._hideHeaderRowAfterPageLoad = false;
157
- this._isDatasetInitialized = false;
158
- this._isDatasetHierarchicalInitialized = false;
159
- this._isGridInitialized = false;
160
- this._isLocalGrid = true;
161
- this._isPaginationInitialized = false;
162
- this._registeredResources = [];
163
- this._slickgridInitialized = false;
164
- this.customDataView = false;
165
- this.totalItems = 0;
166
- this.subscriptions = [];
167
- this.showPagination = false;
168
- // make sure that the grid container doesn't already have the "slickgrid-container" css class
169
- // if it does then we won't create yet another grid, just stop there
170
- if (gridParentContainerElm.querySelectorAll('.slickgrid-container').length !== 0) {
171
- return;
172
- }
173
- gridParentContainerElm.classList.add('grid-pane');
174
- this._gridParentContainerElm = gridParentContainerElm;
175
- this._gridContainerElm = document.createElement('div');
176
- this._gridContainerElm.classList.add('slickgrid-container');
177
- gridParentContainerElm.appendChild(this._gridContainerElm);
178
- // check if the user wants to hide the header row from the start
179
- // we only want to do this check once in the constructor
180
- this._hideHeaderRowAfterPageLoad = ((options === null || options === void 0 ? void 0 : options.showHeaderRow) === false);
181
- this._columnDefinitions = columnDefs || [];
182
- if (this._columnDefinitions.length > 0) {
183
- this.copyColumnWidthsReference(this._columnDefinitions);
184
- }
185
- this._gridOptions = this.mergeGridOptions(options || {});
186
- const isDeepCopyDataOnPageLoadEnabled = !!((_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.enableDeepCopyDatasetOnPageLoad);
187
- this.universalContainerService = (_b = services === null || services === void 0 ? void 0 : services.universalContainerService) !== null && _b !== void 0 ? _b : new universalContainer_service_1.UniversalContainerService();
188
- // if user is providing a Translate Service, it has to be passed under the "translater" grid option
189
- this.translaterService = (_c = services === null || services === void 0 ? void 0 : services.translaterService) !== null && _c !== void 0 ? _c : this._gridOptions.translater;
190
- // initialize and assign all Service Dependencies
191
- this._eventPubSubService = (_d = services === null || services === void 0 ? void 0 : services.eventPubSubService) !== null && _d !== void 0 ? _d : new event_pub_sub_1.EventPubSubService(gridParentContainerElm);
192
- this._eventPubSubService.eventNamingStyle = (_g = (_f = this._gridOptions) === null || _f === void 0 ? void 0 : _f.eventNamingStyle) !== null && _g !== void 0 ? _g : event_pub_sub_1.EventNamingStyle.camelCase;
193
- const slickgridConfig = new common_1.SlickgridConfig();
194
- this.backendUtilityService = (_h = services === null || services === void 0 ? void 0 : services.backendUtilityService) !== null && _h !== void 0 ? _h : new common_1.BackendUtilityService();
195
- this.gridEventService = (_j = services === null || services === void 0 ? void 0 : services.gridEventService) !== null && _j !== void 0 ? _j : new common_1.GridEventService();
196
- this.sharedService = (_k = services === null || services === void 0 ? void 0 : services.sharedService) !== null && _k !== void 0 ? _k : new common_1.SharedService();
197
- this.collectionService = (_l = services === null || services === void 0 ? void 0 : services.collectionService) !== null && _l !== void 0 ? _l : new common_1.CollectionService(this.translaterService);
198
- this.extensionUtility = (_m = services === null || services === void 0 ? void 0 : services.extensionUtility) !== null && _m !== void 0 ? _m : new common_1.ExtensionUtility(this.sharedService, this.backendUtilityService, this.translaterService);
199
- this.filterFactory = new common_1.FilterFactory(slickgridConfig, this.translaterService, this.collectionService);
200
- this.filterService = (_o = services === null || services === void 0 ? void 0 : services.filterService) !== null && _o !== void 0 ? _o : new common_1.FilterService(this.filterFactory, this._eventPubSubService, this.sharedService, this.backendUtilityService);
201
- this.resizerService = (_p = services === null || services === void 0 ? void 0 : services.resizerService) !== null && _p !== void 0 ? _p : new common_1.ResizerService(this._eventPubSubService);
202
- this.sortService = (_q = services === null || services === void 0 ? void 0 : services.sortService) !== null && _q !== void 0 ? _q : new common_1.SortService(this.sharedService, this._eventPubSubService, this.backendUtilityService);
203
- this.treeDataService = (_r = services === null || services === void 0 ? void 0 : services.treeDataService) !== null && _r !== void 0 ? _r : new common_1.TreeDataService(this._eventPubSubService, this.sharedService, this.sortService);
204
- this.paginationService = (_s = services === null || services === void 0 ? void 0 : services.paginationService) !== null && _s !== void 0 ? _s : new common_1.PaginationService(this._eventPubSubService, this.sharedService, this.backendUtilityService);
205
- this.extensionService = (_t = services === null || services === void 0 ? void 0 : services.extensionService) !== null && _t !== void 0 ? _t : new common_1.ExtensionService(this.extensionUtility, this.filterService, this._eventPubSubService, this.sharedService, this.sortService, this.treeDataService, this.translaterService);
206
- this.gridStateService = (_u = services === null || services === void 0 ? void 0 : services.gridStateService) !== null && _u !== void 0 ? _u : new common_1.GridStateService(this.extensionService, this.filterService, this._eventPubSubService, this.sharedService, this.sortService, this.treeDataService);
207
- this.gridService = (_v = services === null || services === void 0 ? void 0 : services.gridService) !== null && _v !== void 0 ? _v : new common_1.GridService(this.gridStateService, this.filterService, this._eventPubSubService, this.paginationService, this.sharedService, this.sortService, this.treeDataService);
208
- this.groupingService = (_w = services === null || services === void 0 ? void 0 : services.groupingAndColspanService) !== null && _w !== void 0 ? _w : new common_1.GroupingAndColspanService(this.extensionUtility, this._eventPubSubService);
209
- if (hierarchicalDataset) {
210
- this.sharedService.hierarchicalDataset = (isDeepCopyDataOnPageLoadEnabled ? $.extend(true, [], hierarchicalDataset) : hierarchicalDataset) || [];
211
- }
212
- const eventHandler = new Slick.EventHandler();
213
- // register all service instances in the container
214
- this.universalContainerService.registerInstance('PubSubService', this._eventPubSubService); // external resources require this one registration (ExcelExport, TextExport)
215
- this.universalContainerService.registerInstance('EventPubSubService', this._eventPubSubService);
216
- this.universalContainerService.registerInstance('ExtensionUtility', this.extensionUtility);
217
- this.universalContainerService.registerInstance('FilterService', this.filterService);
218
- this.universalContainerService.registerInstance('CollectionService', this.collectionService);
219
- this.universalContainerService.registerInstance('ExtensionService', this.extensionService);
220
- this.universalContainerService.registerInstance('GridEventService', this.gridEventService);
221
- this.universalContainerService.registerInstance('GridService', this.gridService);
222
- this.universalContainerService.registerInstance('GridStateService', this.gridStateService);
223
- this.universalContainerService.registerInstance('GroupingAndColspanService', this.groupingService);
224
- this.universalContainerService.registerInstance('PaginationService', this.paginationService);
225
- this.universalContainerService.registerInstance('ResizerService', this.resizerService);
226
- this.universalContainerService.registerInstance('SharedService', this.sharedService);
227
- this.universalContainerService.registerInstance('SortService', this.sortService);
228
- this.universalContainerService.registerInstance('TranslaterService', this.translaterService);
229
- this.universalContainerService.registerInstance('TreeDataService', this.treeDataService);
230
- this.initialization(this._gridContainerElm, eventHandler);
231
- if (!hierarchicalDataset && !this.gridOptions.backendServiceApi) {
232
- this.dataset = dataset || [];
233
- this._currentDatasetLength = this.dataset.length;
234
- }
235
- }
236
- emptyGridContainerElm() {
237
- var _a, _b;
238
- const gridContainerId = (_b = (_a = this.gridOptions) === null || _a === void 0 ? void 0 : _a.gridContainerId) !== null && _b !== void 0 ? _b : 'grid1';
239
- const gridContainerElm = document.querySelector(`#${gridContainerId}`);
240
- (0, common_1.emptyElement)(gridContainerElm);
241
- }
242
- /** Dispose of the Component */
243
- dispose(shouldEmptyDomElementContainer = false) {
244
- 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;
245
- (_a = this._eventPubSubService) === null || _a === void 0 ? void 0 : _a.publish('onBeforeGridDestroy', this.slickGrid);
246
- (_b = this._eventHandler) === null || _b === void 0 ? void 0 : _b.unsubscribeAll();
247
- (_c = this._eventPubSubService) === null || _c === void 0 ? void 0 : _c.publish('onAfterGridDestroyed', true);
248
- // dispose the Services
249
- (_d = this.extensionService) === null || _d === void 0 ? void 0 : _d.dispose();
250
- (_f = this.filterService) === null || _f === void 0 ? void 0 : _f.dispose();
251
- (_g = this.gridEventService) === null || _g === void 0 ? void 0 : _g.dispose();
252
- (_h = this.gridService) === null || _h === void 0 ? void 0 : _h.dispose();
253
- (_j = this.gridStateService) === null || _j === void 0 ? void 0 : _j.dispose();
254
- (_k = this.groupingService) === null || _k === void 0 ? void 0 : _k.dispose();
255
- (_l = this.paginationService) === null || _l === void 0 ? void 0 : _l.dispose();
256
- (_m = this.resizerService) === null || _m === void 0 ? void 0 : _m.dispose();
257
- (_o = this.sortService) === null || _o === void 0 ? void 0 : _o.dispose();
258
- (_p = this.treeDataService) === null || _p === void 0 ? void 0 : _p.dispose();
259
- (_q = this.universalContainerService) === null || _q === void 0 ? void 0 : _q.dispose();
260
- // dispose all registered external resources
261
- if (Array.isArray(this._registeredResources)) {
262
- while (this._registeredResources.length > 0) {
263
- const resource = this._registeredResources.pop();
264
- if (resource === null || resource === void 0 ? void 0 : resource.dispose) {
265
- resource.dispose();
266
- }
267
- }
268
- this._registeredResources = [];
269
- }
270
- // dispose the Components
271
- (_r = this.slickFooter) === null || _r === void 0 ? void 0 : _r.dispose();
272
- (_s = this.slickEmptyWarning) === null || _s === void 0 ? void 0 : _s.dispose();
273
- (_t = this.slickPagination) === null || _t === void 0 ? void 0 : _t.dispose();
274
- (0, common_1.unsubscribeAll)(this.subscriptions);
275
- (_u = this._eventPubSubService) === null || _u === void 0 ? void 0 : _u.unsubscribeAll();
276
- (_v = this.dataView) === null || _v === void 0 ? void 0 : _v.setItems([]);
277
- if ((_w = this.dataView) === null || _w === void 0 ? void 0 : _w.destroy) {
278
- (_x = this.dataView) === null || _x === void 0 ? void 0 : _x.destroy();
279
- }
280
- (_y = this.slickGrid) === null || _y === void 0 ? void 0 : _y.destroy(true);
281
- this.slickGrid = null;
282
- (0, common_1.emptyElement)(this._gridContainerElm);
283
- (0, common_1.emptyElement)(this._gridParentContainerElm);
284
- (_z = this._gridContainerElm) === null || _z === void 0 ? void 0 : _z.remove();
285
- (_0 = this._gridParentContainerElm) === null || _0 === void 0 ? void 0 : _0.remove();
286
- if (this.backendServiceApi) {
287
- for (const prop of Object.keys(this.backendServiceApi)) {
288
- this.backendServiceApi[prop] = null;
289
- }
290
- this.backendServiceApi = undefined;
291
- }
292
- for (const prop of Object.keys(this.columnDefinitions)) {
293
- this.columnDefinitions[prop] = null;
294
- }
295
- for (const prop of Object.keys(this.sharedService)) {
296
- this.sharedService[prop] = null;
297
- }
298
- this.datasetHierarchical = undefined;
299
- this._columnDefinitions = [];
300
- // we could optionally also empty the content of the grid container DOM element
301
- if (shouldEmptyDomElementContainer) {
302
- this.emptyGridContainerElm();
303
- }
304
- (_1 = this._eventPubSubService) === null || _1 === void 0 ? void 0 : _1.dispose();
305
- this._slickerGridInstances = null;
306
- }
307
- initialization(gridContainerElm, eventHandler) {
308
- 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;
309
- // when detecting a frozen grid, we'll automatically enable the mousewheel scroll handler so that we can scroll from both left/right frozen containers
310
- if (this.gridOptions && ((this.gridOptions.frozenRow !== undefined && this.gridOptions.frozenRow >= 0) || this.gridOptions.frozenColumn !== undefined && this.gridOptions.frozenColumn >= 0) && this.gridOptions.enableMouseWheelScrollHandler === undefined) {
311
- this.gridOptions.enableMouseWheelScrollHandler = true;
312
- }
313
- // create the slickgrid container and add it to the user's grid container
314
- this._gridContainerElm = gridContainerElm;
315
- this._eventPubSubService.publish('onBeforeGridCreate', true);
316
- this._eventHandler = eventHandler;
317
- this._gridOptions = this.mergeGridOptions(this._gridOptions || {});
318
- this.backendServiceApi = (_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.backendServiceApi;
319
- this._isLocalGrid = !this.backendServiceApi; // considered a local grid if it doesn't have a backend service set
320
- this._eventPubSubService.eventNamingStyle = (_c = (_b = this._gridOptions) === null || _b === void 0 ? void 0 : _b.eventNamingStyle) !== null && _c !== void 0 ? _c : event_pub_sub_1.EventNamingStyle.camelCase;
321
- this._paginationOptions = (_d = this.gridOptions) === null || _d === void 0 ? void 0 : _d.pagination;
322
- this.createBackendApiInternalPostProcessCallback(this._gridOptions);
323
- if (!this.customDataView) {
324
- const dataviewInlineFilters = (_h = (_g = (_f = this._gridOptions) === null || _f === void 0 ? void 0 : _f.dataView) === null || _g === void 0 ? void 0 : _g.inlineFilters) !== null && _h !== void 0 ? _h : false;
325
- let dataViewOptions = { inlineFilters: dataviewInlineFilters };
326
- if (this.gridOptions.draggableGrouping || this.gridOptions.enableGrouping) {
327
- this.groupItemMetadataProvider = new common_1.SlickGroupItemMetadataProvider();
328
- this.sharedService.groupItemMetadataProvider = this.groupItemMetadataProvider;
329
- dataViewOptions = { ...dataViewOptions, groupItemMetadataProvider: this.groupItemMetadataProvider };
330
- }
331
- this.dataView = new Slick.Data.DataView(dataViewOptions);
332
- this._eventPubSubService.publish('onDataviewCreated', this.dataView);
333
- }
334
- // get any possible Services that user want to register which don't require SlickGrid to be instantiated
335
- // RxJS Resource is in this lot because it has to be registered before anything else and doesn't require SlickGrid to be initialized
336
- this.preRegisterResources();
337
- // for convenience to the user, we provide the property "editor" as an Slickgrid-Universal editor complex object
338
- // however "editor" is used internally by SlickGrid for it's own Editor Factory
339
- // so in our lib we will swap "editor" and copy it into a new property called "internalColumnEditor"
340
- // then take back "editor.model" and make it the new "editor" so that SlickGrid Editor Factory still works
341
- this._columnDefinitions = this.swapInternalEditorToSlickGridFactoryEditor(this._columnDefinitions || []);
342
- // if the user wants to automatically add a Custom Editor Formatter, we need to call the auto add function again
343
- if (this._gridOptions.autoAddCustomEditorFormatter) {
344
- (0, common_1.autoAddEditorFormatterToColumnsWithEditor)(this._columnDefinitions, this._gridOptions.autoAddCustomEditorFormatter);
345
- }
346
- // save reference for all columns before they optionally become hidden/visible
347
- this.sharedService.allColumns = this._columnDefinitions;
348
- this.sharedService.visibleColumns = this._columnDefinitions;
349
- // TODO: revisit later, this is conflicting with Grid State & Presets
350
- // before certain extentions/plugins potentially adds extra columns not created by the user itself (RowMove, RowDetail, RowSelections)
351
- // we'll subscribe to the event and push back the change to the user so they always use full column defs array including extra cols
352
- // this.subscriptions.push(
353
- // this._eventPubSubService.subscribe<{ columns: Column[]; pluginName: string }>('onPluginColumnsChanged', data => {
354
- // this._columnDefinitions = this.columnDefinitions = data.columns;
355
- // })
356
- // );
357
- // after subscribing to potential columns changed, we are ready to create these optional extensions
358
- // when we did find some to create (RowMove, RowDetail, RowSelections), it will automatically modify column definitions (by previous subscribe)
359
- this.extensionService.createExtensionsBeforeGridCreation(this._columnDefinitions, this._gridOptions);
360
- // if user entered some Pinning/Frozen "presets", we need to apply them in the grid options
361
- if ((_j = this.gridOptions.presets) === null || _j === void 0 ? void 0 : _j.pinning) {
362
- this.gridOptions = { ...this.gridOptions, ...this.gridOptions.presets.pinning };
363
- }
364
- this.slickGrid = new Slick.Grid(gridContainerElm, this.dataView, this._columnDefinitions, this._gridOptions);
365
- this.sharedService.dataView = this.dataView;
366
- this.sharedService.slickGrid = this.slickGrid;
367
- this.sharedService.gridContainerElement = this._gridContainerElm;
368
- this.extensionService.bindDifferentExtensions();
369
- this.bindDifferentHooks(this.slickGrid, this._gridOptions, this.dataView);
370
- this._slickgridInitialized = true;
371
- // 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
372
- const frozenColumnIndex = (_l = (_k = this._gridOptions) === null || _k === void 0 ? void 0 : _k.frozenColumn) !== null && _l !== void 0 ? _l : -1;
373
- if (frozenColumnIndex >= 0 && frozenColumnIndex <= this._columnDefinitions.length && this._columnDefinitions.length > 0) {
374
- this.sharedService.frozenVisibleColumnId = (_o = (_m = this._columnDefinitions[frozenColumnIndex]) === null || _m === void 0 ? void 0 : _m.id) !== null && _o !== void 0 ? _o : '';
375
- }
376
- // get any possible Services that user want to register
377
- this.registerResources();
378
- // initialize the SlickGrid grid
379
- this.slickGrid.init();
380
- // initialized the resizer service only after SlickGrid is initialized
381
- // if we don't we end up binding our resize to a grid element that doesn't yet exist in the DOM and the resizer service will fail silently (because it has a try/catch that unbinds the resize without throwing back)
382
- this.resizerService.init(this.slickGrid, this._gridParentContainerElm);
383
- // user could show a custom footer with the data metrics (dataset length and last updated timestamp)
384
- if (!this.gridOptions.enablePagination && this.gridOptions.showCustomFooter && this.gridOptions.customFooterOptions) {
385
- this.slickFooter = new custom_footer_component_1.SlickFooterComponent(this.slickGrid, this.gridOptions.customFooterOptions, this._eventPubSubService, this.translaterService);
386
- this.slickFooter.renderFooter(this._gridParentContainerElm);
387
- }
388
- // load the data in the DataView (unless it's a hierarchical dataset, if so it will be loaded after the initial tree sort)
389
- if (Array.isArray(this.dataset)) {
390
- const initialDataset = ((_p = this.gridOptions) === null || _p === void 0 ? void 0 : _p.enableTreeData) ? this.sortTreeDataset(this.dataset) : this.dataset;
391
- (_q = this.dataView) === null || _q === void 0 ? void 0 : _q.setItems(initialDataset, this._gridOptions.datasetIdPropertyName);
392
- }
393
- // if you don't want the items that are not visible (due to being filtered out or being on a different page)
394
- // to stay selected, pass 'false' to the second arg
395
- const selectionModel = (_s = (_r = this.slickGrid) === null || _r === void 0 ? void 0 : _r.getSelectionModel) === null || _s === void 0 ? void 0 : _s.call(_r);
396
- if (selectionModel && ((_t = this._gridOptions) === null || _t === void 0 ? void 0 : _t.dataView) && this._gridOptions.dataView.hasOwnProperty('syncGridSelection')) {
397
- // if we are using a Backend Service, we will do an extra flag check, the reason is because it might have some unintended behaviors
398
- // with the BackendServiceApi because technically the data in the page changes the DataView on every page change.
399
- let preservedRowSelectionWithBackend = false;
400
- if (this._gridOptions.backendServiceApi && this._gridOptions.dataView.hasOwnProperty('syncGridSelectionWithBackendService')) {
401
- preservedRowSelectionWithBackend = this._gridOptions.dataView.syncGridSelectionWithBackendService;
402
- }
403
- const syncGridSelection = this._gridOptions.dataView.syncGridSelection;
404
- if (typeof syncGridSelection === 'boolean') {
405
- let preservedRowSelection = syncGridSelection;
406
- if (!this._isLocalGrid) {
407
- // when using BackendServiceApi, we'll be using the "syncGridSelectionWithBackendService" flag BUT "syncGridSelection" must also be set to True
408
- preservedRowSelection = syncGridSelection && preservedRowSelectionWithBackend;
409
- }
410
- (_u = this.dataView) === null || _u === void 0 ? void 0 : _u.syncGridSelection(this.slickGrid, preservedRowSelection);
411
- }
412
- else if (typeof syncGridSelection === 'object') {
413
- (_v = this.dataView) === null || _v === void 0 ? void 0 : _v.syncGridSelection(this.slickGrid, syncGridSelection.preserveHidden, syncGridSelection.preserveHiddenOnSelectionChange);
414
- }
415
- }
416
- this.slickGrid.invalidate();
417
- if (((_x = (_w = this.dataView) === null || _w === void 0 ? void 0 : _w.getLength()) !== null && _x !== void 0 ? _x : 0) > 0) {
418
- if (!this._isDatasetInitialized && (this._gridOptions.enableCheckboxSelector || this._gridOptions.enableRowSelection)) {
419
- this.loadRowSelectionPresetWhenExists();
420
- }
421
- this.loadFilterPresetsWhenDatasetInitialized();
422
- this._isDatasetInitialized = true;
423
- }
424
- // user might want to hide the header row on page load but still have `enableFiltering: true`
425
- // if that is the case, we need to hide the headerRow ONLY AFTER all filters got created & dataView exist
426
- if (this._hideHeaderRowAfterPageLoad) {
427
- this.showHeaderRow(false);
428
- this.sharedService.hideHeaderRowAfterPageLoad = this._hideHeaderRowAfterPageLoad;
429
- }
430
- // on cell click, mainly used with the columnDef.action callback
431
- this.gridEventService.bindOnBeforeEditCell(this.slickGrid);
432
- this.gridEventService.bindOnCellChange(this.slickGrid);
433
- this.gridEventService.bindOnClick(this.slickGrid);
434
- // bind the Backend Service API callback functions only after the grid is initialized
435
- // because the preProcess() and onInit() might get triggered
436
- if ((_y = this.gridOptions) === null || _y === void 0 ? void 0 : _y.backendServiceApi) {
437
- this.bindBackendCallbackFunctions(this.gridOptions);
438
- }
439
- // publish & dispatch certain events
440
- this._eventPubSubService.publish('onGridCreated', this.slickGrid);
441
- // after the DataView is created & updated execute some processes & dispatch some events
442
- if (!this.customDataView) {
443
- this.executeAfterDataviewCreated(this.gridOptions);
444
- }
445
- // bind resize ONLY after the dataView is ready
446
- this.bindResizeHook(this.slickGrid, this.gridOptions);
447
- // once the grid is created, we'll return its instance (we do this to return Transient Services from DI)
448
- this._slickerGridInstances = {
449
- // Slick Grid & DataView objects
450
- dataView: this.dataView,
451
- slickGrid: this.slickGrid,
452
- // public methods
453
- dispose: this.dispose.bind(this),
454
- // return all available Services (non-singleton)
455
- backendService: (_0 = (_z = this.gridOptions) === null || _z === void 0 ? void 0 : _z.backendServiceApi) === null || _0 === void 0 ? void 0 : _0.service,
456
- eventPubSubService: this._eventPubSubService,
457
- filterService: this.filterService,
458
- gridEventService: this.gridEventService,
459
- gridStateService: this.gridStateService,
460
- gridService: this.gridService,
461
- groupingService: this.groupingService,
462
- extensionService: this.extensionService,
463
- extensionUtility: this.extensionUtility,
464
- paginationService: this.paginationService,
465
- resizerService: this.resizerService,
466
- sortService: this.sortService,
467
- treeDataService: this.treeDataService,
468
- };
469
- // addons (SlickGrid extra plugins/controls)
470
- this._extensions = (_1 = this.extensionService) === null || _1 === void 0 ? void 0 : _1.extensionList;
471
- // all instances (SlickGrid, DataView & all Services)
472
- this._eventPubSubService.publish('onSlickerGridCreated', this.instances);
473
- this._isGridInitialized = true;
474
- }
475
- mergeGridOptions(gridOptions) {
476
- const options = $.extend(true, {}, common_1.GlobalGridOptions, gridOptions);
477
- // also make sure to show the header row if user have enabled filtering
478
- if (options.enableFiltering && !options.showHeaderRow) {
479
- options.showHeaderRow = options.enableFiltering;
480
- }
481
- // using jQuery extend to do a deep clone has an unwanted side on objects and pageSizes but ES6 spread has other worst side effects
482
- // so we will just overwrite the pageSizes when needed, this is the only one causing issues so far.
483
- // jQuery wrote this on their docs:: On a deep extend, Object and Array are extended, but object wrappers on primitive types such as String, Boolean, and Number are not.
484
- if ((options === null || options === void 0 ? void 0 : options.pagination) && (gridOptions.enablePagination || gridOptions.backendServiceApi) && gridOptions.pagination && Array.isArray(gridOptions.pagination.pageSizes)) {
485
- options.pagination.pageSizes = gridOptions.pagination.pageSizes;
486
- }
487
- // when we use Pagination on Local Grid, it doesn't seem to work without enableFiltering
488
- // so we'll enable the filtering but we'll keep the header row hidden
489
- if (this.sharedService && !options.enableFiltering && options.enablePagination && this._isLocalGrid) {
490
- options.enableFiltering = true;
491
- options.showHeaderRow = false;
492
- this._hideHeaderRowAfterPageLoad = true;
493
- this.sharedService.hideHeaderRowAfterPageLoad = true;
494
- }
495
- return options;
496
- }
497
- /**
498
- * Define our internal Post Process callback, it will execute internally after we get back result from the Process backend call
499
- * For now, this is GraphQL Service ONLY feature and it will basically
500
- * refresh the Dataset & Pagination without having the user to create his own PostProcess every time
501
- */
502
- createBackendApiInternalPostProcessCallback(gridOptions) {
503
- const backendApi = gridOptions === null || gridOptions === void 0 ? void 0 : gridOptions.backendServiceApi;
504
- if (backendApi === null || backendApi === void 0 ? void 0 : backendApi.service) {
505
- const backendApiService = backendApi.service;
506
- // internalPostProcess only works (for now) with a GraphQL Service, so make sure it is of that type
507
- if ( /* backendApiService instanceof GraphqlService || */typeof backendApiService.getDatasetName === 'function') {
508
- backendApi.internalPostProcess = (processResult) => {
509
- const datasetName = (backendApi && backendApiService && typeof backendApiService.getDatasetName === 'function') ? backendApiService.getDatasetName() : '';
510
- if (processResult && processResult.data && processResult.data[datasetName]) {
511
- const data = processResult.data[datasetName].hasOwnProperty('nodes') ? processResult.data[datasetName].nodes : processResult.data[datasetName];
512
- const totalCount = processResult.data[datasetName].hasOwnProperty('totalCount') ? processResult.data[datasetName].totalCount : processResult.data[datasetName].length;
513
- this.refreshGridData(data, totalCount || 0);
514
- }
515
- };
516
- }
517
- }
518
- }
519
- bindDifferentHooks(grid, gridOptions, dataView) {
520
- var _a, _b;
521
- // if user is providing a Translate Service, we need to add our PubSub Service (but only after creating all dependencies)
522
- // so that we can later subscribe to the "onLanguageChange" event and translate any texts whenever that get triggered
523
- if (gridOptions.enableTranslate && ((_a = this.translaterService) === null || _a === void 0 ? void 0 : _a.addPubSubMessaging)) {
524
- this.translaterService.addPubSubMessaging(this._eventPubSubService);
525
- }
526
- // translate them all on first load, then on each language change
527
- if (gridOptions.enableTranslate) {
528
- this.extensionService.translateAllExtensions();
529
- this.translateColumnHeaderTitleKeys();
530
- this.translateColumnGroupKeys();
531
- }
532
- // on locale change, we have to manually translate the Headers, GridMenu
533
- this.subscriptions.push(this._eventPubSubService.subscribe('onLanguageChange', () => {
534
- if (gridOptions.enableTranslate) {
535
- this.extensionService.translateAllExtensions();
536
- this.translateColumnHeaderTitleKeys();
537
- this.translateColumnGroupKeys();
538
- if (gridOptions.createPreHeaderPanel && !gridOptions.enableDraggableGrouping) {
539
- this.groupingService.translateGroupingAndColSpan();
540
- }
541
- }
542
- }));
543
- // if user set an onInit Backend, we'll run it right away (and if so, we also need to run preProcess, internalPostProcess & postProcess)
544
- if (gridOptions.backendServiceApi) {
545
- const backendApi = gridOptions.backendServiceApi;
546
- if ((_b = backendApi === null || backendApi === void 0 ? void 0 : backendApi.service) === null || _b === void 0 ? void 0 : _b.init) {
547
- backendApi.service.init(backendApi.options, gridOptions.pagination, this.slickGrid, this.sharedService);
548
- }
549
- }
550
- if (dataView && grid) {
551
- // expose all Slick Grid Events through dispatch
552
- for (const prop in grid) {
553
- if (grid.hasOwnProperty(prop) && prop.startsWith('on')) {
554
- this._eventHandler.subscribe(grid[prop], (event, args) => {
555
- var _a, _b;
556
- const gridEventName = this._eventPubSubService.getEventNameByNamingConvention(prop, (_b = (_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.defaultSlickgridEventPrefix) !== null && _b !== void 0 ? _b : '');
557
- return this._eventPubSubService.dispatchCustomEvent(gridEventName, { eventData: event, args });
558
- });
559
- }
560
- }
561
- // expose all Slick DataView Events through dispatch
562
- for (const prop in dataView) {
563
- if (dataView.hasOwnProperty(prop) && prop.startsWith('on')) {
564
- this._eventHandler.subscribe(dataView[prop], (event, args) => {
565
- var _a, _b;
566
- const dataViewEventName = this._eventPubSubService.getEventNameByNamingConvention(prop, (_b = (_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.defaultSlickgridEventPrefix) !== null && _b !== void 0 ? _b : '');
567
- return this._eventPubSubService.dispatchCustomEvent(dataViewEventName, { eventData: event, args });
568
- });
569
- }
570
- }
571
- // after all events are exposed
572
- // we can bind external filter (backend) when available or default onFilter (dataView)
573
- if (gridOptions.enableFiltering) {
574
- this.filterService.init(grid);
575
- // bind external filter (backend) unless specified to use the local one
576
- if (gridOptions.backendServiceApi && !gridOptions.backendServiceApi.useLocalFiltering) {
577
- this.filterService.bindBackendOnFilter(grid);
578
- }
579
- else {
580
- this.filterService.bindLocalOnFilter(grid);
581
- }
582
- }
583
- // bind external sorting (backend) when available or default onSort (dataView)
584
- if (gridOptions.enableSorting) {
585
- // bind external sorting (backend) unless specified to use the local one
586
- if (gridOptions.backendServiceApi && !gridOptions.backendServiceApi.useLocalSorting) {
587
- this.sortService.bindBackendOnSort(grid);
588
- }
589
- else {
590
- this.sortService.bindLocalOnSort(grid);
591
- }
592
- }
593
- // When data changes in the DataView, we need to refresh the metrics and/or display a warning if the dataset is empty
594
- this._eventHandler.subscribe(dataView.onRowCountChanged, () => {
595
- var _a, _b, _c;
596
- grid.invalidate();
597
- this.handleOnItemCountChanged(((_a = this.dataView) === null || _a === void 0 ? void 0 : _a.getFilteredItemCount()) || 0, (_c = (_b = this.dataView) === null || _b === void 0 ? void 0 : _b.getItemCount()) !== null && _c !== void 0 ? _c : 0);
598
- });
599
- this._eventHandler.subscribe(dataView.onSetItemsCalled, (_e, args) => {
600
- var _a, _b;
601
- this.handleOnItemCountChanged(((_a = this.dataView) === null || _a === void 0 ? void 0 : _a.getFilteredItemCount()) || 0, args.itemCount);
602
- // when user has resize by content enabled, we'll force a full width calculation since we change our entire dataset
603
- if (args.itemCount > 0 && (this.gridOptions.autosizeColumnsByCellContentOnFirstLoad || this.gridOptions.enableAutoResizeColumnsByCellContent)) {
604
- this.resizerService.resizeColumnsByCellContent(!((_b = this.gridOptions) === null || _b === void 0 ? void 0 : _b.resizeByContentOnlyOnFirstLoad));
605
- }
606
- });
607
- // when filtering data with local dataset, we need to update each row else it will not always show correctly in the UI
608
- // also don't use "invalidateRows" since it destroys the entire row and as bad user experience when updating a row
609
- if (gridOptions && gridOptions.enableFiltering && !gridOptions.enableRowDetailView) {
610
- this._eventHandler.subscribe(dataView.onRowsChanged, (_e, args) => {
611
- if ((args === null || args === void 0 ? void 0 : args.rows) && Array.isArray(args.rows)) {
612
- args.rows.forEach((row) => grid.updateRow(row));
613
- grid.render();
614
- }
615
- });
616
- }
617
- // when column are reordered, we need to update the visibleColumn array
618
- this._eventHandler.subscribe(grid.onColumnsReordered, (_e, args) => {
619
- this.sharedService.hasColumnsReordered = true;
620
- this.sharedService.visibleColumns = args.impactedColumns;
621
- });
622
- // load any presets if any (after dataset is initialized)
623
- this.loadColumnPresetsWhenDatasetInitialized();
624
- this.loadFilterPresetsWhenDatasetInitialized();
625
- }
626
- // did the user add a colspan callback? If so, hook it into the DataView getItemMetadata
627
- if ((gridOptions === null || gridOptions === void 0 ? void 0 : gridOptions.colspanCallback) && (dataView === null || dataView === void 0 ? void 0 : dataView.getItem) && (dataView === null || dataView === void 0 ? void 0 : dataView.getItemMetadata)) {
628
- dataView.getItemMetadata = (rowNumber) => {
629
- let callbackResult = null;
630
- if (gridOptions.colspanCallback) {
631
- callbackResult = gridOptions.colspanCallback(dataView.getItem(rowNumber));
632
- }
633
- return callbackResult;
634
- };
635
- }
636
- }
637
- bindBackendCallbackFunctions(gridOptions) {
638
- var _a, _b, _c, _d, _f, _g;
639
- const backendApi = gridOptions.backendServiceApi;
640
- const backendApiService = backendApi === null || backendApi === void 0 ? void 0 : backendApi.service;
641
- const serviceOptions = (_a = backendApiService === null || backendApiService === void 0 ? void 0 : backendApiService.options) !== null && _a !== void 0 ? _a : {};
642
- const isExecuteCommandOnInit = (!serviceOptions) ? false : ((serviceOptions === null || serviceOptions === void 0 ? void 0 : serviceOptions.hasOwnProperty('executeProcessCommandOnInit')) ? serviceOptions['executeProcessCommandOnInit'] : true);
643
- if (backendApiService) {
644
- // update backend filters (if need be) BEFORE the query runs (via the onInit command a few lines below)
645
- // if user entered some any "presets", we need to reflect them all in the grid
646
- if (gridOptions === null || gridOptions === void 0 ? void 0 : gridOptions.presets) {
647
- // Filters "presets"
648
- if (backendApiService.updateFilters && Array.isArray(gridOptions.presets.filters) && gridOptions.presets.filters.length > 0) {
649
- backendApiService.updateFilters(gridOptions.presets.filters, true);
650
- }
651
- // Sorters "presets"
652
- if (backendApiService.updateSorters && Array.isArray(gridOptions.presets.sorters) && gridOptions.presets.sorters.length > 0) {
653
- // when using multi-column sort, we can have multiple but on single sort then only grab the first sort provided
654
- const sortColumns = ((_b = this._gridOptions) === null || _b === void 0 ? void 0 : _b.multiColumnSort) ? gridOptions.presets.sorters : gridOptions.presets.sorters.slice(0, 1);
655
- backendApiService.updateSorters(undefined, sortColumns);
656
- }
657
- // Pagination "presets"
658
- if (backendApiService.updatePagination && gridOptions.presets.pagination) {
659
- const { pageNumber, pageSize } = gridOptions.presets.pagination;
660
- backendApiService.updatePagination(pageNumber, pageSize);
661
- }
662
- }
663
- else {
664
- const columnFilters = this.filterService.getColumnFilters();
665
- if (columnFilters && backendApiService.updateFilters) {
666
- backendApiService.updateFilters(columnFilters, false);
667
- }
668
- }
669
- // execute onInit command when necessary
670
- if (backendApi && backendApiService && (backendApi.onInit || isExecuteCommandOnInit)) {
671
- const query = (typeof backendApiService.buildQuery === 'function') ? backendApiService.buildQuery() : '';
672
- const process = isExecuteCommandOnInit ? ((_d = (_c = backendApi.process) === null || _c === void 0 ? void 0 : _c.call(backendApi, query)) !== null && _d !== void 0 ? _d : null) : ((_g = (_f = backendApi.onInit) === null || _f === void 0 ? void 0 : _f.call(backendApi, query)) !== null && _g !== void 0 ? _g : null);
673
- // wrap this inside a setTimeout to avoid timing issue since the gridOptions needs to be ready before running this onInit
674
- setTimeout(() => {
675
- var _a, _b, _c, _d;
676
- const backendUtilityService = this.backendUtilityService;
677
- // keep start time & end timestamps & return it after process execution
678
- const startTime = new Date();
679
- // run any pre-process, if defined, for example a spinner
680
- if (backendApi.preProcess) {
681
- backendApi.preProcess();
682
- }
683
- // the processes can be a Promise (like Http)
684
- const totalItems = (_c = (_b = (_a = this.gridOptions) === null || _a === void 0 ? void 0 : _a.pagination) === null || _b === void 0 ? void 0 : _b.totalItems) !== null && _c !== void 0 ? _c : 0;
685
- if (process instanceof Promise) {
686
- process
687
- .then((processResult) => backendUtilityService.executeBackendProcessesCallback(startTime, processResult, backendApi, totalItems))
688
- .catch((error) => backendUtilityService.onBackendError(error, backendApi));
689
- }
690
- else if (process && ((_d = this.rxjs) === null || _d === void 0 ? void 0 : _d.isObservable(process))) {
691
- this.subscriptions.push(process.subscribe((processResult) => backendUtilityService.executeBackendProcessesCallback(startTime, processResult, backendApi, totalItems), (error) => backendUtilityService.onBackendError(error, backendApi)));
692
- }
693
- });
694
- }
695
- }
696
- }
697
- bindResizeHook(grid, options) {
698
- if ((options.autoFitColumnsOnFirstLoad && options.autosizeColumnsByCellContentOnFirstLoad) || (options.enableAutoSizeColumns && options.enableAutoResizeColumnsByCellContent)) {
699
- throw new Error(`[Slickgrid-Universal] You cannot enable both autosize/fit viewport & resize by content, you must choose which resize technique to use. You can enable these 2 options ("autoFitColumnsOnFirstLoad" and "enableAutoSizeColumns") OR these other 2 options ("autosizeColumnsByCellContentOnFirstLoad" and "enableAutoResizeColumnsByCellContent").`);
700
- }
701
- if (grid && options.autoFitColumnsOnFirstLoad && options.enableAutoSizeColumns && typeof grid.autosizeColumns === 'function') {
702
- // expand/autofit columns on first page load
703
- grid.autosizeColumns();
704
- }
705
- // auto-resize grid on browser resize (optionally provide grid height or width)
706
- if (options.gridHeight || options.gridWidth) {
707
- this.resizerService.resizeGrid(0, { height: options.gridHeight, width: options.gridWidth });
708
- }
709
- else {
710
- this.resizerService.resizeGrid();
711
- }
712
- if (grid && (options === null || options === void 0 ? void 0 : options.enableAutoResize)) {
713
- if (options.autoFitColumnsOnFirstLoad && options.enableAutoSizeColumns && typeof grid.autosizeColumns === 'function') {
714
- grid.autosizeColumns();
715
- }
716
- }
717
- }
718
- executeAfterDataviewCreated(gridOptions) {
719
- var _a;
720
- // if user entered some Sort "presets", we need to reflect them all in the DOM
721
- if (gridOptions.enableSorting) {
722
- if (gridOptions.presets && Array.isArray(gridOptions.presets.sorters)) {
723
- // when using multi-column sort, we can have multiple but on single sort then only grab the first sort provided
724
- const sortColumns = ((_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.multiColumnSort) ? gridOptions.presets.sorters : gridOptions.presets.sorters.slice(0, 1);
725
- this.sortService.loadGridSorters(sortColumns);
726
- }
727
- }
728
- }
729
- /**
730
- * On a Pagination changed, we will trigger a Grid State changed with the new pagination info
731
- * Also if we use Row Selection or the Checkbox Selector with a Backend Service (Odata, GraphQL), we need to reset any selection
732
- */
733
- paginationChanged(pagination) {
734
- var _a, _b, _c;
735
- const isSyncGridSelectionEnabled = (_b = (_a = this.gridStateService) === null || _a === void 0 ? void 0 : _a.needToPreserveRowSelection()) !== null && _b !== void 0 ? _b : false;
736
- if (this.slickGrid && !isSyncGridSelectionEnabled && ((_c = this._gridOptions) === null || _c === void 0 ? void 0 : _c.backendServiceApi) && (this.gridOptions.enableRowSelection || this.gridOptions.enableCheckboxSelector)) {
737
- this.slickGrid.setSelectedRows([]);
738
- }
739
- const { pageNumber, pageSize } = pagination;
740
- if (this.sharedService) {
741
- if (pageSize !== undefined && pageNumber !== undefined) {
742
- this.sharedService.currentPagination = { pageNumber, pageSize };
743
- }
744
- }
745
- this._eventPubSubService.publish('onGridStateChanged', {
746
- change: { newValues: { pageNumber, pageSize }, type: common_1.GridStateType.pagination },
747
- gridState: this.gridStateService.getCurrentGridState()
748
- });
749
- }
750
- /**
751
- * When dataset changes, we need to refresh the entire grid UI & possibly resize it as well
752
- * @param dataset
753
- */
754
- refreshGridData(dataset, totalCount) {
755
- var _a, _b, _c, _d, _f;
756
- // local grid, check if we need to show the Pagination
757
- // if so then also check if there's any presets and finally initialize the PaginationService
758
- // 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
759
- if (this.slickGrid && this._gridOptions) {
760
- if (this._gridOptions.enablePagination && this._isLocalGrid) {
761
- this.showPagination = true;
762
- this.loadLocalGridPagination(dataset);
763
- }
764
- if (this._gridOptions.enableEmptyDataWarningMessage && Array.isArray(dataset)) {
765
- const finalTotalCount = totalCount || dataset.length;
766
- this.displayEmptyDataWarning(finalTotalCount < 1);
767
- }
768
- if (Array.isArray(dataset) && this.slickGrid && ((_a = this.dataView) === null || _a === void 0 ? void 0 : _a.setItems)) {
769
- this.dataView.setItems(dataset, this._gridOptions.datasetIdPropertyName);
770
- if (!this._gridOptions.backendServiceApi && !this._gridOptions.enableTreeData) {
771
- this.dataView.reSort();
772
- }
773
- if (dataset.length > 0) {
774
- if (!this._isDatasetInitialized) {
775
- this.loadFilterPresetsWhenDatasetInitialized();
776
- if (this._gridOptions.enableCheckboxSelector) {
777
- this.loadRowSelectionPresetWhenExists();
778
- }
779
- }
780
- this._isDatasetInitialized = true;
781
- }
782
- if (dataset) {
783
- this.slickGrid.invalidate();
784
- }
785
- // 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
786
- this.showPagination = (this._gridOptions && (this._gridOptions.enablePagination || (this._gridOptions.backendServiceApi && this._gridOptions.enablePagination === undefined))) ? true : false;
787
- if (this._paginationOptions && ((_b = this._gridOptions) === null || _b === void 0 ? void 0 : _b.pagination) && ((_c = this._gridOptions) === null || _c === void 0 ? void 0 : _c.backendServiceApi)) {
788
- const paginationOptions = this.setPaginationOptionsWhenPresetDefined(this._gridOptions, this._paginationOptions);
789
- // when we have a totalCount use it, else we'll take it from the pagination object
790
- // only update the total items if it's different to avoid refreshing the UI
791
- const totalRecords = (totalCount !== undefined) ? totalCount : ((_f = (_d = this._gridOptions) === null || _d === void 0 ? void 0 : _d.pagination) === null || _f === void 0 ? void 0 : _f.totalItems);
792
- if (totalRecords !== undefined && totalRecords !== this.totalItems) {
793
- this.totalItems = +totalRecords;
794
- }
795
- // initialize the Pagination Service with new pagination options (which might have presets)
796
- if (!this._isPaginationInitialized) {
797
- this.initializePaginationService(paginationOptions);
798
- }
799
- else {
800
- // update the pagination service with the new total
801
- this.paginationService.updateTotalItems(this.totalItems);
802
- }
803
- }
804
- // resize the grid inside a slight timeout, in case other DOM element changed prior to the resize (like a filter/pagination changed)
805
- if (this.slickGrid && this._gridOptions.enableAutoResize) {
806
- const delay = this._gridOptions.autoResize && this._gridOptions.autoResize.delay;
807
- this.resizerService.resizeGrid(delay || 10);
808
- }
809
- }
810
- }
811
- }
812
- /**
813
- * Dynamically change or update the column definitions list.
814
- * We will re-render the grid so that the new header and data shows up correctly.
815
- * If using translater, we also need to trigger a re-translate of the column headers
816
- */
817
- updateColumnDefinitionsList(newColumnDefinitions) {
818
- var _a, _b, _c;
819
- if (this.slickGrid && this._gridOptions && Array.isArray(newColumnDefinitions)) {
820
- // map/swap the internal library Editor to the SlickGrid Editor factory
821
- newColumnDefinitions = this.swapInternalEditorToSlickGridFactoryEditor(newColumnDefinitions);
822
- // if the user wants to automatically add a Custom Editor Formatter, we need to call the auto add function again
823
- if (this._gridOptions.autoAddCustomEditorFormatter) {
824
- (0, common_1.autoAddEditorFormatterToColumnsWithEditor)(newColumnDefinitions, this._gridOptions.autoAddCustomEditorFormatter);
825
- }
826
- if (this._gridOptions.enableTranslate) {
827
- this.extensionService.translateColumnHeaders(false, newColumnDefinitions);
828
- }
829
- else {
830
- this.extensionService.renderColumnHeaders(newColumnDefinitions, true);
831
- }
832
- if (this.slickGrid && ((_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.enableAutoSizeColumns)) {
833
- this.slickGrid.autosizeColumns();
834
- }
835
- else if (((_b = this._gridOptions) === null || _b === void 0 ? void 0 : _b.enableAutoResizeColumnsByCellContent) && ((_c = this.resizerService) === null || _c === void 0 ? void 0 : _c.resizeColumnsByCellContent)) {
836
- this.resizerService.resizeColumnsByCellContent();
837
- }
838
- }
839
- }
840
- /**
841
- * Show the filter row displayed on first row, we can optionally pass false to hide it.
842
- * @param showing
843
- */
844
- showHeaderRow(showing = true) {
845
- var _a;
846
- (_a = this.slickGrid) === null || _a === void 0 ? void 0 : _a.setHeaderRowVisibility(showing, false);
847
- if (this.slickGrid && showing === true && this._isGridInitialized) {
848
- this.slickGrid.setColumns(this.columnDefinitions);
849
- }
850
- return showing;
851
- }
852
- /**
853
- * Check if there's any Pagination Presets defined in the Grid Options,
854
- * if there are then load them in the paginationOptions object
855
- */
856
- setPaginationOptionsWhenPresetDefined(gridOptions, paginationOptions) {
857
- var _a;
858
- if (((_a = gridOptions.presets) === null || _a === void 0 ? void 0 : _a.pagination) && paginationOptions && !this._isPaginationInitialized) {
859
- paginationOptions.pageSize = gridOptions.presets.pagination.pageSize;
860
- paginationOptions.pageNumber = gridOptions.presets.pagination.pageNumber;
861
- }
862
- return paginationOptions;
863
- }
864
- // --
865
- // protected functions
866
- // ------------------
867
- /**
868
- * Loop through all column definitions and copy the original optional `width` properties optionally provided by the user.
869
- * We will use this when doing a resize by cell content, if user provided a `width` it won't override it.
870
- */
871
- copyColumnWidthsReference(columnDefinitions) {
872
- columnDefinitions.forEach(col => col.originalWidth = col.width);
873
- }
874
- displayEmptyDataWarning(showWarning = true) {
875
- var _a;
876
- (_a = this.slickEmptyWarning) === null || _a === void 0 ? void 0 : _a.showEmptyDataMessage(showWarning);
877
- }
878
- /** When data changes in the DataView, we'll refresh the metrics and/or display a warning if the dataset is empty */
879
- handleOnItemCountChanged(currentPageRowItemCount, totalItemCount) {
880
- var _a;
881
- this._currentDatasetLength = totalItemCount;
882
- this.metrics = {
883
- startTime: new Date(),
884
- endTime: new Date(),
885
- itemCount: currentPageRowItemCount,
886
- totalItemCount
887
- };
888
- // if custom footer is enabled, then we'll update its metrics
889
- if (this.slickFooter) {
890
- this.slickFooter.metrics = this.metrics;
891
- }
892
- // when using local (in-memory) dataset, we'll display a warning message when filtered data is empty
893
- if (this._isLocalGrid && ((_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.enableEmptyDataWarningMessage)) {
894
- this.displayEmptyDataWarning(currentPageRowItemCount === 0);
895
- }
896
- }
897
- /** Initialize the Pagination Service once */
898
- initializePaginationService(paginationOptions) {
899
- if (this.slickGrid && this.gridOptions) {
900
- this.paginationData = {
901
- gridOptions: this.gridOptions,
902
- paginationService: this.paginationService,
903
- };
904
- this.paginationService.totalItems = this.totalItems;
905
- this.paginationService.init(this.slickGrid, paginationOptions, this.backendServiceApi);
906
- this.subscriptions.push(this._eventPubSubService.subscribe('onPaginationChanged', paginationChanges => this.paginationChanged(paginationChanges)), this._eventPubSubService.subscribe('onPaginationVisibilityChanged', visibility => {
907
- var _a, _b, _c;
908
- this.showPagination = (_a = visibility === null || visibility === void 0 ? void 0 : visibility.visible) !== null && _a !== void 0 ? _a : false;
909
- if ((_b = this.gridOptions) === null || _b === void 0 ? void 0 : _b.backendServiceApi) {
910
- (_c = this.backendUtilityService) === null || _c === void 0 ? void 0 : _c.refreshBackendDataset(this.gridOptions);
911
- }
912
- this.renderPagination(this.showPagination);
913
- }));
914
- // also initialize (render) the pagination component
915
- this.renderPagination();
916
- this._isPaginationInitialized = true;
917
- }
918
- }
919
- /**
920
- * Render (or dispose) the Pagination Component, user can optionally provide False (to not show it) which will in term dispose of the Pagination,
921
- * also while disposing we can choose to omit the disposable of the Pagination Service (if we are simply toggling the Pagination, we want to keep the Service alive)
922
- * @param {Boolean} showPagination - show (new render) or not (dispose) the Pagination
923
- * @param {Boolean} shouldDisposePaginationService - when disposing the Pagination, do we also want to dispose of the Pagination Service? (defaults to True)
924
- */
925
- renderPagination(showPagination = true) {
926
- var _a;
927
- if (((_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.enablePagination) && !this._isPaginationInitialized && showPagination) {
928
- this.slickPagination = new pagination_component_1.SlickPaginationComponent(this.paginationService, this._eventPubSubService, this.sharedService, this.translaterService);
929
- this.slickPagination.renderPagination(this._gridParentContainerElm);
930
- this._isPaginationInitialized = true;
931
- }
932
- else if (!showPagination) {
933
- if (this.slickPagination) {
934
- this.slickPagination.dispose();
935
- }
936
- this._isPaginationInitialized = false;
937
- }
938
- }
939
- /** Load the Editor Collection asynchronously and replace the "collection" property when Promise resolves */
940
- loadEditorCollectionAsync(column) {
941
- var _a;
942
- const collectionAsync = (column === null || column === void 0 ? void 0 : column.editor).collectionAsync;
943
- (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()"
944
- if (collectionAsync instanceof Promise) {
945
- // wait for the "collectionAsync", once resolved we will save it into the "collection"
946
- // the collectionAsync can be of 3 types HttpClient, HttpFetch or a Promise
947
- collectionAsync.then((response) => {
948
- if (Array.isArray(response)) {
949
- this.updateEditorCollection(column, response); // from Promise
950
- }
951
- else if ((response === null || response === void 0 ? void 0 : response.status) >= 200 && response.status < 300 && typeof response.json === 'function') {
952
- if (response.bodyUsed) {
953
- console.warn(`[SlickGrid-Universal] The response body passed to collectionAsync was already read.`
954
- + `Either pass the dataset from the Response or clone the response first using response.clone()`);
955
- }
956
- else {
957
- // from Fetch
958
- response.json().then(data => this.updateEditorCollection(column, data));
959
- }
960
- }
961
- else if (response === null || response === void 0 ? void 0 : response.content) {
962
- this.updateEditorCollection(column, response['content']); // from http-client
963
- }
964
- });
965
- }
966
- else if ((_a = this.rxjs) === null || _a === void 0 ? void 0 : _a.isObservable(collectionAsync)) {
967
- // wrap this inside a setTimeout to avoid timing issue since updateEditorCollection requires to call SlickGrid getColumns() method
968
- setTimeout(() => {
969
- this.subscriptions.push(collectionAsync.subscribe((resolvedCollection) => this.updateEditorCollection(column, resolvedCollection)));
970
- });
971
- }
972
- }
973
- /** Load any possible Columns Grid Presets */
974
- loadColumnPresetsWhenDatasetInitialized() {
975
- // if user entered some Columns "presets", we need to reflect them all in the grid
976
- if (this.slickGrid && this.gridOptions.presets && Array.isArray(this.gridOptions.presets.columns) && this.gridOptions.presets.columns.length > 0) {
977
- const gridColumns = this.gridStateService.getAssociatedGridColumns(this.slickGrid, this.gridOptions.presets.columns);
978
- if (gridColumns && Array.isArray(gridColumns) && gridColumns.length > 0) {
979
- // make sure that the checkbox selector is also visible if it is enabled
980
- if (this.gridOptions.enableCheckboxSelector) {
981
- const checkboxColumn = (Array.isArray(this._columnDefinitions) && this._columnDefinitions.length > 0) ? this._columnDefinitions[0] : null;
982
- if (checkboxColumn && checkboxColumn.id === '_checkbox_selector' && gridColumns[0].id !== '_checkbox_selector') {
983
- gridColumns.unshift(checkboxColumn);
984
- }
985
- }
986
- // keep copy the original optional `width` properties optionally provided by the user.
987
- // We will use this when doing a resize by cell content, if user provided a `width` it won't override it.
988
- gridColumns.forEach(col => col.originalWidth = col.width);
989
- // finally set the new presets columns (including checkbox selector if need be)
990
- this.slickGrid.setColumns(gridColumns);
991
- this.sharedService.visibleColumns = gridColumns;
992
- }
993
- }
994
- }
995
- /** Load any possible Filters Grid Presets */
996
- loadFilterPresetsWhenDatasetInitialized() {
997
- var _a, _b, _c;
998
- if (this.gridOptions && !this.customDataView) {
999
- // if user entered some Filter "presets", we need to reflect them all in the DOM
1000
- // also note that a presets of Tree Data Toggling will also call this method because Tree Data toggling does work with data filtering
1001
- // (collapsing a parent will basically use Filter for hidding (aka collapsing) away the child underneat it)
1002
- if (this.gridOptions.presets && (Array.isArray(this.gridOptions.presets.filters) || Array.isArray((_b = (_a = this.gridOptions.presets) === null || _a === void 0 ? void 0 : _a.treeData) === null || _b === void 0 ? void 0 : _b.toggledItems))) {
1003
- this.filterService.populateColumnFilterSearchTermPresets(((_c = this.gridOptions.presets) === null || _c === void 0 ? void 0 : _c.filters) || []);
1004
- }
1005
- }
1006
- }
1007
- /**
1008
- * local grid, check if we need to show the Pagination
1009
- * if so then also check if there's any presets and finally initialize the PaginationService
1010
- * 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
1011
- */
1012
- loadLocalGridPagination(dataset) {
1013
- var _a;
1014
- if (this.gridOptions && this._paginationOptions) {
1015
- this.totalItems = Array.isArray(dataset) ? dataset.length : 0;
1016
- if (this._paginationOptions && ((_a = this.dataView) === null || _a === void 0 ? void 0 : _a.getPagingInfo)) {
1017
- const slickPagingInfo = this.dataView.getPagingInfo();
1018
- if ((slickPagingInfo === null || slickPagingInfo === void 0 ? void 0 : slickPagingInfo.hasOwnProperty('totalRows')) && this._paginationOptions.totalItems !== slickPagingInfo.totalRows) {
1019
- this.totalItems = (slickPagingInfo === null || slickPagingInfo === void 0 ? void 0 : slickPagingInfo.totalRows) || 0;
1020
- }
1021
- }
1022
- this._paginationOptions.totalItems = this.totalItems;
1023
- const paginationOptions = this.setPaginationOptionsWhenPresetDefined(this.gridOptions, this._paginationOptions);
1024
- this.initializePaginationService(paginationOptions);
1025
- }
1026
- }
1027
- /** Load any Row Selections into the DataView that were presets by the user */
1028
- loadRowSelectionPresetWhenExists() {
1029
- var _a, _b, _c;
1030
- // if user entered some Row Selections "presets"
1031
- const presets = (_a = this.gridOptions) === null || _a === void 0 ? void 0 : _a.presets;
1032
- const selectionModel = (_c = (_b = this.slickGrid) === null || _b === void 0 ? void 0 : _b.getSelectionModel) === null || _c === void 0 ? void 0 : _c.call(_b);
1033
- const enableRowSelection = this.gridOptions && (this.gridOptions.enableCheckboxSelector || this.gridOptions.enableRowSelection);
1034
- if (this.slickGrid && this.dataView && enableRowSelection && selectionModel && (presets === null || presets === void 0 ? void 0 : presets.rowSelection) && (Array.isArray(presets.rowSelection.gridRowIndexes) || Array.isArray(presets.rowSelection.dataContextIds))) {
1035
- let dataContextIds = presets.rowSelection.dataContextIds;
1036
- let gridRowIndexes = presets.rowSelection.gridRowIndexes;
1037
- // maps the IDs to the Grid Rows and vice versa, the "dataContextIds" has precedence over the other
1038
- if (Array.isArray(dataContextIds) && dataContextIds.length > 0) {
1039
- gridRowIndexes = this.dataView.mapIdsToRows(dataContextIds) || [];
1040
- }
1041
- else if (Array.isArray(gridRowIndexes) && gridRowIndexes.length > 0) {
1042
- dataContextIds = this.dataView.mapRowsToIds(gridRowIndexes) || [];
1043
- }
1044
- // apply row selection when defined as grid presets
1045
- if (this.slickGrid && Array.isArray(gridRowIndexes)) {
1046
- this.slickGrid.setSelectedRows(gridRowIndexes);
1047
- this.dataView.setSelectedIds(dataContextIds || [], {
1048
- isRowBeingAdded: true,
1049
- shouldTriggerEvent: false,
1050
- applyRowSelectionToGrid: true
1051
- });
1052
- }
1053
- }
1054
- }
1055
- /** Pre-Register any Resource that don't require SlickGrid to be instantiated (for example RxJS Resource) */
1056
- preRegisterResources() {
1057
- this._registeredResources = this.gridOptions.registerExternalResources || [];
1058
- // bind & initialize all Components/Services that were tagged as enabled
1059
- // register all services by executing their init method and providing them with the Grid object
1060
- if (Array.isArray(this._registeredResources)) {
1061
- for (const resource of this._registeredResources) {
1062
- if ((resource === null || resource === void 0 ? void 0 : resource.className) === 'RxJsResource') {
1063
- this.registerRxJsResource(resource);
1064
- }
1065
- }
1066
- }
1067
- }
1068
- registerResources() {
1069
- // at this point, we consider all the registered services as external services, anything else registered afterward aren't external
1070
- if (Array.isArray(this._registeredResources)) {
1071
- this.sharedService.externalRegisteredResources = this._registeredResources;
1072
- }
1073
- // push all other Services that we want to be registered
1074
- this._registeredResources.push(this.gridService, this.gridStateService);
1075
- // when using Grouping/DraggableGrouping/Colspan register its Service
1076
- if (this.gridOptions.createPreHeaderPanel && !this.gridOptions.enableDraggableGrouping) {
1077
- this._registeredResources.push(this.groupingService);
1078
- }
1079
- // when using Tree Data View, register its Service
1080
- if (this.gridOptions.enableTreeData) {
1081
- this._registeredResources.push(this.treeDataService);
1082
- }
1083
- // when user enables translation, we need to translate Headers on first pass & subsequently in the bindDifferentHooks
1084
- if (this.gridOptions.enableTranslate) {
1085
- this.extensionService.translateColumnHeaders();
1086
- }
1087
- // also initialize (render) the empty warning component
1088
- this.slickEmptyWarning = new empty_warning_component_1.SlickEmptyWarningComponent();
1089
- this._registeredResources.push(this.slickEmptyWarning);
1090
- // bind & initialize all Components/Services that were tagged as enabled
1091
- // register all services by executing their init method and providing them with the Grid object
1092
- if (Array.isArray(this._registeredResources)) {
1093
- for (const resource of this._registeredResources) {
1094
- if (this.slickGrid && typeof resource.init === 'function') {
1095
- resource.init(this.slickGrid, this.universalContainerService);
1096
- }
1097
- }
1098
- }
1099
- }
1100
- /** Register the RxJS Resource in all necessary services which uses */
1101
- registerRxJsResource(resource) {
1102
- this.rxjs = resource;
1103
- this.backendUtilityService.addRxJsResource(this.rxjs);
1104
- this.filterFactory.addRxJsResource(this.rxjs);
1105
- this.filterService.addRxJsResource(this.rxjs);
1106
- this.sortService.addRxJsResource(this.rxjs);
1107
- this.paginationService.addRxJsResource(this.rxjs);
1108
- this.universalContainerService.registerInstance('RxJsFacade', this.rxjs);
1109
- this.universalContainerService.registerInstance('RxJsResource', this.rxjs);
1110
- }
1111
- /**
1112
- * Takes a flat dataset with parent/child relationship, sort it (via its tree structure) and return the sorted flat array
1113
- * @returns {Array<Object>} sort flat parent/child dataset
1114
- */
1115
- sortTreeDataset(flatDatasetInput, forceGridRefresh = false) {
1116
- var _a, _b;
1117
- const prevDatasetLn = this._currentDatasetLength;
1118
- let sortedDatasetResult;
1119
- let flatDatasetOutput = [];
1120
- // if the hierarchical dataset was already initialized then no need to re-convert it, we can use it directly from the shared service ref
1121
- if (this._isDatasetHierarchicalInitialized && this.datasetHierarchical) {
1122
- sortedDatasetResult = this.treeDataService.sortHierarchicalDataset(this.datasetHierarchical);
1123
- flatDatasetOutput = sortedDatasetResult.flat;
1124
- }
1125
- else if (Array.isArray(flatDatasetInput) && flatDatasetInput.length > 0) {
1126
- if ((_b = (_a = this.gridOptions) === null || _a === void 0 ? void 0 : _a.treeDataOptions) === null || _b === void 0 ? void 0 : _b.initialSort) {
1127
- // else we need to first convert the flat dataset to a hierarchical dataset and then sort
1128
- sortedDatasetResult = this.treeDataService.convertFlatParentChildToTreeDatasetAndSort(flatDatasetInput, this._columnDefinitions || [], this.gridOptions);
1129
- this.sharedService.hierarchicalDataset = sortedDatasetResult.hierarchical;
1130
- flatDatasetOutput = sortedDatasetResult.flat;
1131
- }
1132
- else {
1133
- // else we assume that the user provided an array that is already sorted (user's responsability)
1134
- // and so we can simply convert the array to a tree structure and we're done, no need to sort
1135
- this.sharedService.hierarchicalDataset = this.treeDataService.convertFlatParentChildToTreeDataset(flatDatasetInput, this.gridOptions);
1136
- flatDatasetOutput = flatDatasetInput || [];
1137
- }
1138
- }
1139
- // if we add/remove item(s) from the dataset, we need to also refresh our tree data filters
1140
- if (flatDatasetInput.length > 0 && (forceGridRefresh || flatDatasetInput.length !== prevDatasetLn)) {
1141
- this.filterService.refreshTreeDataFilters(flatDatasetOutput);
1142
- }
1143
- return flatDatasetOutput;
1144
- }
1145
- /**
1146
- * For convenience to the user, we provide the property "editor" as an Slickgrid-Universal editor complex object
1147
- * however "editor" is used internally by SlickGrid for it's own Editor Factory
1148
- * so in our lib we will swap "editor" and copy it into a new property called "internalColumnEditor"
1149
- * then take back "editor.model" and make it the new "editor" so that SlickGrid Editor Factory still works
1150
- */
1151
- swapInternalEditorToSlickGridFactoryEditor(columnDefinitions) {
1152
- const columns = Array.isArray(columnDefinitions) ? columnDefinitions : [];
1153
- if (columns.some(col => `${col.id}`.includes('.'))) {
1154
- 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".');
1155
- }
1156
- return columns.map((column) => {
1157
- var _a;
1158
- // on every Editor that have a "collectionAsync", resolve the data and assign it to the "collection" property
1159
- if ((_a = column.editor) === null || _a === void 0 ? void 0 : _a.collectionAsync) {
1160
- this.loadEditorCollectionAsync(column);
1161
- }
1162
- // if there's already an internalColumnEditor we'll use it, else it would be inside the editor
1163
- const columnEditor = column.internalColumnEditor || column.editor;
1164
- return { ...column, editor: columnEditor === null || columnEditor === void 0 ? void 0 : columnEditor.model, internalColumnEditor: { ...columnEditor } };
1165
- });
1166
- }
1167
- /** translate all columns (including hidden columns) */
1168
- translateColumnHeaderTitleKeys() {
1169
- this.extensionUtility.translateItems(this.sharedService.allColumns, 'nameKey', 'name');
1170
- }
1171
- /** translate all column groups (including hidden columns) */
1172
- translateColumnGroupKeys() {
1173
- this.extensionUtility.translateItems(this.sharedService.allColumns, 'columnGroupKey', 'columnGroup');
1174
- }
1175
- /**
1176
- * Update the "internalColumnEditor.collection" property.
1177
- * Since this is called after the async call resolves, the pointer will not be the same as the "column" argument passed.
1178
- * Once we found the new pointer, we will reassign the "editor" and "collection" to the "internalColumnEditor" so it has newest collection
1179
- */
1180
- updateEditorCollection(column, newCollection) {
1181
- column.editor.collection = newCollection;
1182
- column.editor.disabled = false;
1183
- if (this.slickGrid) {
1184
- // find the new column reference pointer & re-assign the new editor to the internalColumnEditor
1185
- if (Array.isArray(this.columnDefinitions)) {
1186
- const columnRef = this.columnDefinitions.find((col) => col.id === column.id);
1187
- if (columnRef) {
1188
- columnRef.internalColumnEditor = column.editor;
1189
- }
1190
- }
1191
- // get current Editor, remove it from the DOm then re-enable it and re-render it with the new collection.
1192
- const currentEditor = this.slickGrid.getCellEditor();
1193
- if ((currentEditor === null || currentEditor === void 0 ? void 0 : currentEditor.disable) && (currentEditor === null || currentEditor === void 0 ? void 0 : currentEditor.renderDomElement)) {
1194
- currentEditor.destroy();
1195
- currentEditor.disable(false);
1196
- currentEditor.renderDomElement(newCollection);
1197
- }
1198
- }
1199
- }
1200
- }
1201
- exports.SlickVanillaGridBundle = SlickVanillaGridBundle;
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.SlickVanillaGridBundle = void 0;
5
+ const lite_1 = require("dequal/lite");
6
+ require("jquery");
7
+ require("flatpickr/dist/l10n/fr");
8
+ require("slickgrid/slick.core");
9
+ require("slickgrid/slick.interactions");
10
+ require("slickgrid/slick.grid");
11
+ require("slickgrid/slick.dataview");
12
+ const Sortable_ = require("sortablejs");
13
+ const Sortable = ((_a = Sortable_ === null || Sortable_ === void 0 ? void 0 : Sortable_['default']) !== null && _a !== void 0 ? _a : Sortable_); // patch for rollup
14
+ const common_1 = require("@slickgrid-universal/common");
15
+ const event_pub_sub_1 = require("@slickgrid-universal/event-pub-sub");
16
+ const empty_warning_component_1 = require("@slickgrid-universal/empty-warning-component");
17
+ const custom_footer_component_1 = require("@slickgrid-universal/custom-footer-component");
18
+ const pagination_component_1 = require("@slickgrid-universal/pagination-component");
19
+ const universalContainer_service_1 = require("../services/universalContainer.service");
20
+ // add Sortable to the window object so that SlickGrid lib can use globally
21
+ window.Sortable = Sortable;
22
+ class SlickVanillaGridBundle {
23
+ get eventHandler() {
24
+ return this._eventHandler;
25
+ }
26
+ get columnDefinitions() {
27
+ return this._columnDefinitions || [];
28
+ }
29
+ set columnDefinitions(columnDefinitions) {
30
+ this._columnDefinitions = columnDefinitions;
31
+ if (this._slickgridInitialized) {
32
+ this.updateColumnDefinitionsList(this._columnDefinitions);
33
+ }
34
+ if (columnDefinitions.length > 0) {
35
+ this.copyColumnWidthsReference(columnDefinitions);
36
+ }
37
+ }
38
+ get dataset() {
39
+ var _a;
40
+ return ((_a = this.dataView) === null || _a === void 0 ? void 0 : _a.getItems()) || [];
41
+ }
42
+ set dataset(newDataset) {
43
+ var _a, _b;
44
+ const prevDatasetLn = this._currentDatasetLength;
45
+ const isDatasetEqual = (0, lite_1.dequal)(newDataset, this.dataset || []);
46
+ const isDeepCopyDataOnPageLoadEnabled = !!((_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.enableDeepCopyDatasetOnPageLoad);
47
+ let data = isDeepCopyDataOnPageLoadEnabled ? $.extend(true, [], newDataset) : newDataset;
48
+ // when Tree Data is enabled and we don't yet have the hierarchical dataset filled, we can force a convert+sort of the array
49
+ if (this.slickGrid && ((_b = this.gridOptions) === null || _b === void 0 ? void 0 : _b.enableTreeData) && Array.isArray(newDataset) && (newDataset.length > 0 || newDataset.length !== prevDatasetLn || !isDatasetEqual)) {
50
+ this._isDatasetHierarchicalInitialized = false;
51
+ data = this.sortTreeDataset(newDataset, !isDatasetEqual); // if dataset changed, then force a refresh anyway
52
+ }
53
+ this.refreshGridData(data || []);
54
+ this._currentDatasetLength = (newDataset || []).length;
55
+ // expand/autofit columns on first page load
56
+ // we can assume that if the prevDataset was empty then we are on first load
57
+ if (this.slickGrid && this.gridOptions.autoFitColumnsOnFirstLoad && prevDatasetLn === 0) {
58
+ this.slickGrid.autosizeColumns();
59
+ }
60
+ }
61
+ get datasetHierarchical() {
62
+ return this.sharedService.hierarchicalDataset;
63
+ }
64
+ set datasetHierarchical(newHierarchicalDataset) {
65
+ var _a, _b, _c, _d;
66
+ const isDatasetEqual = (0, lite_1.dequal)(newHierarchicalDataset, this.sharedService.hierarchicalDataset || []);
67
+ const prevFlatDatasetLn = this._currentDatasetLength;
68
+ this.sharedService.hierarchicalDataset = newHierarchicalDataset;
69
+ if (newHierarchicalDataset && this.columnDefinitions && ((_a = this.filterService) === null || _a === void 0 ? void 0 : _a.clearFilters)) {
70
+ this.filterService.clearFilters();
71
+ }
72
+ // 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
73
+ if (this.dataView && newHierarchicalDataset && this.slickGrid && ((_b = this.sortService) === null || _b === void 0 ? void 0 : _b.processTreeDataInitialSort)) {
74
+ this.dataView.setItems([], (_d = (_c = this._gridOptions) === null || _c === void 0 ? void 0 : _c.datasetIdPropertyName) !== null && _d !== void 0 ? _d : 'id');
75
+ this.sortService.processTreeDataInitialSort();
76
+ // 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
77
+ // however we need 1 cpu cycle before having the DataView refreshed, so we need to wrap this check in a setTimeout
78
+ setTimeout(() => {
79
+ var _a, _b;
80
+ const flatDatasetLn = (_b = (_a = this.dataView) === null || _a === void 0 ? void 0 : _a.getItemCount()) !== null && _b !== void 0 ? _b : 0;
81
+ if (flatDatasetLn > 0 && (flatDatasetLn !== prevFlatDatasetLn || !isDatasetEqual)) {
82
+ this.filterService.refreshTreeDataFilters();
83
+ }
84
+ });
85
+ }
86
+ this._isDatasetHierarchicalInitialized = true;
87
+ }
88
+ set eventPubSubService(pubSub) {
89
+ this._eventPubSubService = pubSub;
90
+ }
91
+ get gridOptions() {
92
+ return this._gridOptions || {};
93
+ }
94
+ set gridOptions(options) {
95
+ var _a, _b, _c;
96
+ let mergedOptions;
97
+ // if we already have grid options, when grid was already initialized, we'll merge with those options
98
+ // else we'll merge with global grid options
99
+ if ((_a = this.slickGrid) === null || _a === void 0 ? void 0 : _a.getOptions) {
100
+ mergedOptions = $.extend(true, {}, this.slickGrid.getOptions(), options);
101
+ }
102
+ else {
103
+ mergedOptions = this.mergeGridOptions(options);
104
+ }
105
+ if (((_b = this.sharedService) === null || _b === void 0 ? void 0 : _b.gridOptions) && ((_c = this.slickGrid) === null || _c === void 0 ? void 0 : _c.setOptions)) {
106
+ this.sharedService.gridOptions = mergedOptions;
107
+ this.slickGrid.setOptions(mergedOptions, false, true); // make sure to supressColumnCheck (3rd arg) to avoid problem with changeColumnsArrangement() and custom grid view
108
+ this.slickGrid.reRenderColumns(true); // then call a re-render since we did supressColumnCheck on previous setOptions
109
+ }
110
+ this._gridOptions = mergedOptions;
111
+ }
112
+ get paginationOptions() {
113
+ return this._paginationOptions;
114
+ }
115
+ set paginationOptions(newPaginationOptions) {
116
+ var _a;
117
+ if (newPaginationOptions && this._paginationOptions) {
118
+ this._paginationOptions = { ...this._paginationOptions, ...newPaginationOptions };
119
+ }
120
+ else {
121
+ this._paginationOptions = newPaginationOptions;
122
+ }
123
+ this.gridOptions.pagination = this._paginationOptions;
124
+ this.paginationService.updateTotalItems((_a = newPaginationOptions === null || newPaginationOptions === void 0 ? void 0 : newPaginationOptions.totalItems) !== null && _a !== void 0 ? _a : 0, true);
125
+ }
126
+ get isDatasetInitialized() {
127
+ return this._isDatasetInitialized;
128
+ }
129
+ set isDatasetInitialized(isInitialized) {
130
+ this._isDatasetInitialized = isInitialized;
131
+ }
132
+ get isGridInitialized() {
133
+ return this._isGridInitialized;
134
+ }
135
+ get instances() {
136
+ return this._slickerGridInstances;
137
+ }
138
+ get extensions() {
139
+ return this._extensions;
140
+ }
141
+ get registeredResources() {
142
+ return this._registeredResources;
143
+ }
144
+ /**
145
+ * Slicker Grid Bundle constructor
146
+ * @param {Object} gridParentContainerElm - div HTML DOM element container
147
+ * @param {Array<Column>} columnDefs - Column Definitions
148
+ * @param {Object} options - Grid Options
149
+ * @param {Array<Object>} dataset - Dataset
150
+ * @param {Array<Object>} hierarchicalDataset - Hierarchical Dataset
151
+ * @param {Object} services - Typically only used for Unit Testing when we want to pass Mocked/Stub Services
152
+ */
153
+ constructor(gridParentContainerElm, columnDefs, options, dataset, hierarchicalDataset, services) {
154
+ var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
155
+ this._currentDatasetLength = 0;
156
+ this._hideHeaderRowAfterPageLoad = false;
157
+ this._isDatasetInitialized = false;
158
+ this._isDatasetHierarchicalInitialized = false;
159
+ this._isGridInitialized = false;
160
+ this._isLocalGrid = true;
161
+ this._isPaginationInitialized = false;
162
+ this._registeredResources = [];
163
+ this._slickgridInitialized = false;
164
+ this.customDataView = false;
165
+ this.totalItems = 0;
166
+ this.subscriptions = [];
167
+ this.showPagination = false;
168
+ // make sure that the grid container doesn't already have the "slickgrid-container" css class
169
+ // if it does then we won't create yet another grid, just stop there
170
+ if (gridParentContainerElm.querySelectorAll('.slickgrid-container').length !== 0) {
171
+ return;
172
+ }
173
+ gridParentContainerElm.classList.add('grid-pane');
174
+ this._gridParentContainerElm = gridParentContainerElm;
175
+ this._gridContainerElm = document.createElement('div');
176
+ this._gridContainerElm.classList.add('slickgrid-container');
177
+ gridParentContainerElm.appendChild(this._gridContainerElm);
178
+ // check if the user wants to hide the header row from the start
179
+ // we only want to do this check once in the constructor
180
+ this._hideHeaderRowAfterPageLoad = ((options === null || options === void 0 ? void 0 : options.showHeaderRow) === false);
181
+ this._columnDefinitions = columnDefs || [];
182
+ if (this._columnDefinitions.length > 0) {
183
+ this.copyColumnWidthsReference(this._columnDefinitions);
184
+ }
185
+ this._gridOptions = this.mergeGridOptions(options || {});
186
+ const isDeepCopyDataOnPageLoadEnabled = !!((_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.enableDeepCopyDatasetOnPageLoad);
187
+ this.universalContainerService = (_b = services === null || services === void 0 ? void 0 : services.universalContainerService) !== null && _b !== void 0 ? _b : new universalContainer_service_1.UniversalContainerService();
188
+ // if user is providing a Translate Service, it has to be passed under the "translater" grid option
189
+ this.translaterService = (_c = services === null || services === void 0 ? void 0 : services.translaterService) !== null && _c !== void 0 ? _c : this._gridOptions.translater;
190
+ // initialize and assign all Service Dependencies
191
+ this._eventPubSubService = (_d = services === null || services === void 0 ? void 0 : services.eventPubSubService) !== null && _d !== void 0 ? _d : new event_pub_sub_1.EventPubSubService(gridParentContainerElm);
192
+ this._eventPubSubService.eventNamingStyle = (_g = (_f = this._gridOptions) === null || _f === void 0 ? void 0 : _f.eventNamingStyle) !== null && _g !== void 0 ? _g : event_pub_sub_1.EventNamingStyle.camelCase;
193
+ const slickgridConfig = new common_1.SlickgridConfig();
194
+ this.backendUtilityService = (_h = services === null || services === void 0 ? void 0 : services.backendUtilityService) !== null && _h !== void 0 ? _h : new common_1.BackendUtilityService();
195
+ this.gridEventService = (_j = services === null || services === void 0 ? void 0 : services.gridEventService) !== null && _j !== void 0 ? _j : new common_1.GridEventService();
196
+ this.sharedService = (_k = services === null || services === void 0 ? void 0 : services.sharedService) !== null && _k !== void 0 ? _k : new common_1.SharedService();
197
+ this.collectionService = (_l = services === null || services === void 0 ? void 0 : services.collectionService) !== null && _l !== void 0 ? _l : new common_1.CollectionService(this.translaterService);
198
+ this.extensionUtility = (_m = services === null || services === void 0 ? void 0 : services.extensionUtility) !== null && _m !== void 0 ? _m : new common_1.ExtensionUtility(this.sharedService, this.backendUtilityService, this.translaterService);
199
+ this.filterFactory = new common_1.FilterFactory(slickgridConfig, this.translaterService, this.collectionService);
200
+ this.filterService = (_o = services === null || services === void 0 ? void 0 : services.filterService) !== null && _o !== void 0 ? _o : new common_1.FilterService(this.filterFactory, this._eventPubSubService, this.sharedService, this.backendUtilityService);
201
+ this.resizerService = (_p = services === null || services === void 0 ? void 0 : services.resizerService) !== null && _p !== void 0 ? _p : new common_1.ResizerService(this._eventPubSubService);
202
+ this.sortService = (_q = services === null || services === void 0 ? void 0 : services.sortService) !== null && _q !== void 0 ? _q : new common_1.SortService(this.sharedService, this._eventPubSubService, this.backendUtilityService);
203
+ this.treeDataService = (_r = services === null || services === void 0 ? void 0 : services.treeDataService) !== null && _r !== void 0 ? _r : new common_1.TreeDataService(this._eventPubSubService, this.sharedService, this.sortService);
204
+ this.paginationService = (_s = services === null || services === void 0 ? void 0 : services.paginationService) !== null && _s !== void 0 ? _s : new common_1.PaginationService(this._eventPubSubService, this.sharedService, this.backendUtilityService);
205
+ this.extensionService = (_t = services === null || services === void 0 ? void 0 : services.extensionService) !== null && _t !== void 0 ? _t : new common_1.ExtensionService(this.extensionUtility, this.filterService, this._eventPubSubService, this.sharedService, this.sortService, this.treeDataService, this.translaterService);
206
+ this.gridStateService = (_u = services === null || services === void 0 ? void 0 : services.gridStateService) !== null && _u !== void 0 ? _u : new common_1.GridStateService(this.extensionService, this.filterService, this._eventPubSubService, this.sharedService, this.sortService, this.treeDataService);
207
+ this.gridService = (_v = services === null || services === void 0 ? void 0 : services.gridService) !== null && _v !== void 0 ? _v : new common_1.GridService(this.gridStateService, this.filterService, this._eventPubSubService, this.paginationService, this.sharedService, this.sortService, this.treeDataService);
208
+ this.groupingService = (_w = services === null || services === void 0 ? void 0 : services.groupingAndColspanService) !== null && _w !== void 0 ? _w : new common_1.GroupingAndColspanService(this.extensionUtility, this._eventPubSubService);
209
+ if (hierarchicalDataset) {
210
+ this.sharedService.hierarchicalDataset = (isDeepCopyDataOnPageLoadEnabled ? $.extend(true, [], hierarchicalDataset) : hierarchicalDataset) || [];
211
+ }
212
+ const eventHandler = new Slick.EventHandler();
213
+ // register all service instances in the container
214
+ this.universalContainerService.registerInstance('PubSubService', this._eventPubSubService); // external resources require this one registration (ExcelExport, TextExport)
215
+ this.universalContainerService.registerInstance('EventPubSubService', this._eventPubSubService);
216
+ this.universalContainerService.registerInstance('ExtensionUtility', this.extensionUtility);
217
+ this.universalContainerService.registerInstance('FilterService', this.filterService);
218
+ this.universalContainerService.registerInstance('CollectionService', this.collectionService);
219
+ this.universalContainerService.registerInstance('ExtensionService', this.extensionService);
220
+ this.universalContainerService.registerInstance('GridEventService', this.gridEventService);
221
+ this.universalContainerService.registerInstance('GridService', this.gridService);
222
+ this.universalContainerService.registerInstance('GridStateService', this.gridStateService);
223
+ this.universalContainerService.registerInstance('GroupingAndColspanService', this.groupingService);
224
+ this.universalContainerService.registerInstance('PaginationService', this.paginationService);
225
+ this.universalContainerService.registerInstance('ResizerService', this.resizerService);
226
+ this.universalContainerService.registerInstance('SharedService', this.sharedService);
227
+ this.universalContainerService.registerInstance('SortService', this.sortService);
228
+ this.universalContainerService.registerInstance('TranslaterService', this.translaterService);
229
+ this.universalContainerService.registerInstance('TreeDataService', this.treeDataService);
230
+ this.initialization(this._gridContainerElm, eventHandler);
231
+ if (!hierarchicalDataset && !this.gridOptions.backendServiceApi) {
232
+ this.dataset = dataset || [];
233
+ this._currentDatasetLength = this.dataset.length;
234
+ }
235
+ }
236
+ emptyGridContainerElm() {
237
+ var _a, _b;
238
+ const gridContainerId = (_b = (_a = this.gridOptions) === null || _a === void 0 ? void 0 : _a.gridContainerId) !== null && _b !== void 0 ? _b : 'grid1';
239
+ const gridContainerElm = document.querySelector(`#${gridContainerId}`);
240
+ (0, common_1.emptyElement)(gridContainerElm);
241
+ }
242
+ /** Dispose of the Component */
243
+ dispose(shouldEmptyDomElementContainer = false) {
244
+ 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;
245
+ (_a = this._eventPubSubService) === null || _a === void 0 ? void 0 : _a.publish('onBeforeGridDestroy', this.slickGrid);
246
+ (_b = this._eventHandler) === null || _b === void 0 ? void 0 : _b.unsubscribeAll();
247
+ (_c = this._eventPubSubService) === null || _c === void 0 ? void 0 : _c.publish('onAfterGridDestroyed', true);
248
+ // dispose the Services
249
+ (_d = this.extensionService) === null || _d === void 0 ? void 0 : _d.dispose();
250
+ (_f = this.filterService) === null || _f === void 0 ? void 0 : _f.dispose();
251
+ (_g = this.gridEventService) === null || _g === void 0 ? void 0 : _g.dispose();
252
+ (_h = this.gridService) === null || _h === void 0 ? void 0 : _h.dispose();
253
+ (_j = this.gridStateService) === null || _j === void 0 ? void 0 : _j.dispose();
254
+ (_k = this.groupingService) === null || _k === void 0 ? void 0 : _k.dispose();
255
+ (_l = this.paginationService) === null || _l === void 0 ? void 0 : _l.dispose();
256
+ (_m = this.resizerService) === null || _m === void 0 ? void 0 : _m.dispose();
257
+ (_o = this.sortService) === null || _o === void 0 ? void 0 : _o.dispose();
258
+ (_p = this.treeDataService) === null || _p === void 0 ? void 0 : _p.dispose();
259
+ (_q = this.universalContainerService) === null || _q === void 0 ? void 0 : _q.dispose();
260
+ // dispose all registered external resources
261
+ if (Array.isArray(this._registeredResources)) {
262
+ while (this._registeredResources.length > 0) {
263
+ const resource = this._registeredResources.pop();
264
+ if (resource === null || resource === void 0 ? void 0 : resource.dispose) {
265
+ resource.dispose();
266
+ }
267
+ }
268
+ this._registeredResources = [];
269
+ }
270
+ // dispose the Components
271
+ (_r = this.slickFooter) === null || _r === void 0 ? void 0 : _r.dispose();
272
+ (_s = this.slickEmptyWarning) === null || _s === void 0 ? void 0 : _s.dispose();
273
+ (_t = this.slickPagination) === null || _t === void 0 ? void 0 : _t.dispose();
274
+ (0, common_1.unsubscribeAll)(this.subscriptions);
275
+ (_u = this._eventPubSubService) === null || _u === void 0 ? void 0 : _u.unsubscribeAll();
276
+ (_v = this.dataView) === null || _v === void 0 ? void 0 : _v.setItems([]);
277
+ if ((_w = this.dataView) === null || _w === void 0 ? void 0 : _w.destroy) {
278
+ (_x = this.dataView) === null || _x === void 0 ? void 0 : _x.destroy();
279
+ }
280
+ (_y = this.slickGrid) === null || _y === void 0 ? void 0 : _y.destroy(true);
281
+ this.slickGrid = null;
282
+ (0, common_1.emptyElement)(this._gridContainerElm);
283
+ (0, common_1.emptyElement)(this._gridParentContainerElm);
284
+ (_z = this._gridContainerElm) === null || _z === void 0 ? void 0 : _z.remove();
285
+ (_0 = this._gridParentContainerElm) === null || _0 === void 0 ? void 0 : _0.remove();
286
+ if (this.backendServiceApi) {
287
+ for (const prop of Object.keys(this.backendServiceApi)) {
288
+ this.backendServiceApi[prop] = null;
289
+ }
290
+ this.backendServiceApi = undefined;
291
+ }
292
+ for (const prop of Object.keys(this.columnDefinitions)) {
293
+ this.columnDefinitions[prop] = null;
294
+ }
295
+ for (const prop of Object.keys(this.sharedService)) {
296
+ this.sharedService[prop] = null;
297
+ }
298
+ this.datasetHierarchical = undefined;
299
+ this._columnDefinitions = [];
300
+ // we could optionally also empty the content of the grid container DOM element
301
+ if (shouldEmptyDomElementContainer) {
302
+ this.emptyGridContainerElm();
303
+ }
304
+ (_1 = this._eventPubSubService) === null || _1 === void 0 ? void 0 : _1.dispose();
305
+ this._slickerGridInstances = null;
306
+ }
307
+ initialization(gridContainerElm, eventHandler) {
308
+ 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;
309
+ // when detecting a frozen grid, we'll automatically enable the mousewheel scroll handler so that we can scroll from both left/right frozen containers
310
+ if (this.gridOptions && ((this.gridOptions.frozenRow !== undefined && this.gridOptions.frozenRow >= 0) || this.gridOptions.frozenColumn !== undefined && this.gridOptions.frozenColumn >= 0) && this.gridOptions.enableMouseWheelScrollHandler === undefined) {
311
+ this.gridOptions.enableMouseWheelScrollHandler = true;
312
+ }
313
+ // create the slickgrid container and add it to the user's grid container
314
+ this._gridContainerElm = gridContainerElm;
315
+ this._eventPubSubService.publish('onBeforeGridCreate', true);
316
+ this._eventHandler = eventHandler;
317
+ this._gridOptions = this.mergeGridOptions(this._gridOptions || {});
318
+ this.backendServiceApi = (_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.backendServiceApi;
319
+ this._isLocalGrid = !this.backendServiceApi; // considered a local grid if it doesn't have a backend service set
320
+ this._eventPubSubService.eventNamingStyle = (_c = (_b = this._gridOptions) === null || _b === void 0 ? void 0 : _b.eventNamingStyle) !== null && _c !== void 0 ? _c : event_pub_sub_1.EventNamingStyle.camelCase;
321
+ this._paginationOptions = (_d = this.gridOptions) === null || _d === void 0 ? void 0 : _d.pagination;
322
+ this.createBackendApiInternalPostProcessCallback(this._gridOptions);
323
+ if (!this.customDataView) {
324
+ const dataviewInlineFilters = (_h = (_g = (_f = this._gridOptions) === null || _f === void 0 ? void 0 : _f.dataView) === null || _g === void 0 ? void 0 : _g.inlineFilters) !== null && _h !== void 0 ? _h : false;
325
+ let dataViewOptions = { inlineFilters: dataviewInlineFilters };
326
+ if (this.gridOptions.draggableGrouping || this.gridOptions.enableGrouping) {
327
+ this.groupItemMetadataProvider = new common_1.SlickGroupItemMetadataProvider();
328
+ this.sharedService.groupItemMetadataProvider = this.groupItemMetadataProvider;
329
+ dataViewOptions = { ...dataViewOptions, groupItemMetadataProvider: this.groupItemMetadataProvider };
330
+ }
331
+ this.dataView = new Slick.Data.DataView(dataViewOptions);
332
+ this._eventPubSubService.publish('onDataviewCreated', this.dataView);
333
+ }
334
+ // get any possible Services that user want to register which don't require SlickGrid to be instantiated
335
+ // RxJS Resource is in this lot because it has to be registered before anything else and doesn't require SlickGrid to be initialized
336
+ this.preRegisterResources();
337
+ // for convenience to the user, we provide the property "editor" as an Slickgrid-Universal editor complex object
338
+ // however "editor" is used internally by SlickGrid for it's own Editor Factory
339
+ // so in our lib we will swap "editor" and copy it into a new property called "internalColumnEditor"
340
+ // then take back "editor.model" and make it the new "editor" so that SlickGrid Editor Factory still works
341
+ this._columnDefinitions = this.swapInternalEditorToSlickGridFactoryEditor(this._columnDefinitions || []);
342
+ // if the user wants to automatically add a Custom Editor Formatter, we need to call the auto add function again
343
+ if (this._gridOptions.autoAddCustomEditorFormatter) {
344
+ (0, common_1.autoAddEditorFormatterToColumnsWithEditor)(this._columnDefinitions, this._gridOptions.autoAddCustomEditorFormatter);
345
+ }
346
+ // save reference for all columns before they optionally become hidden/visible
347
+ this.sharedService.allColumns = this._columnDefinitions;
348
+ this.sharedService.visibleColumns = this._columnDefinitions;
349
+ // TODO: revisit later, this is conflicting with Grid State & Presets
350
+ // before certain extentions/plugins potentially adds extra columns not created by the user itself (RowMove, RowDetail, RowSelections)
351
+ // we'll subscribe to the event and push back the change to the user so they always use full column defs array including extra cols
352
+ // this.subscriptions.push(
353
+ // this._eventPubSubService.subscribe<{ columns: Column[]; pluginName: string }>('onPluginColumnsChanged', data => {
354
+ // this._columnDefinitions = this.columnDefinitions = data.columns;
355
+ // })
356
+ // );
357
+ // after subscribing to potential columns changed, we are ready to create these optional extensions
358
+ // when we did find some to create (RowMove, RowDetail, RowSelections), it will automatically modify column definitions (by previous subscribe)
359
+ this.extensionService.createExtensionsBeforeGridCreation(this._columnDefinitions, this._gridOptions);
360
+ // if user entered some Pinning/Frozen "presets", we need to apply them in the grid options
361
+ if ((_j = this.gridOptions.presets) === null || _j === void 0 ? void 0 : _j.pinning) {
362
+ this.gridOptions = { ...this.gridOptions, ...this.gridOptions.presets.pinning };
363
+ }
364
+ this.slickGrid = new Slick.Grid(gridContainerElm, this.dataView, this._columnDefinitions, this._gridOptions);
365
+ this.sharedService.dataView = this.dataView;
366
+ this.sharedService.slickGrid = this.slickGrid;
367
+ this.sharedService.gridContainerElement = this._gridContainerElm;
368
+ this.extensionService.bindDifferentExtensions();
369
+ this.bindDifferentHooks(this.slickGrid, this._gridOptions, this.dataView);
370
+ this._slickgridInitialized = true;
371
+ // 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
372
+ const frozenColumnIndex = (_l = (_k = this._gridOptions) === null || _k === void 0 ? void 0 : _k.frozenColumn) !== null && _l !== void 0 ? _l : -1;
373
+ if (frozenColumnIndex >= 0 && frozenColumnIndex <= this._columnDefinitions.length && this._columnDefinitions.length > 0) {
374
+ this.sharedService.frozenVisibleColumnId = (_o = (_m = this._columnDefinitions[frozenColumnIndex]) === null || _m === void 0 ? void 0 : _m.id) !== null && _o !== void 0 ? _o : '';
375
+ }
376
+ // get any possible Services that user want to register
377
+ this.registerResources();
378
+ // initialize the SlickGrid grid
379
+ this.slickGrid.init();
380
+ // initialized the resizer service only after SlickGrid is initialized
381
+ // if we don't we end up binding our resize to a grid element that doesn't yet exist in the DOM and the resizer service will fail silently (because it has a try/catch that unbinds the resize without throwing back)
382
+ this.resizerService.init(this.slickGrid, this._gridParentContainerElm);
383
+ // user could show a custom footer with the data metrics (dataset length and last updated timestamp)
384
+ if (!this.gridOptions.enablePagination && this.gridOptions.showCustomFooter && this.gridOptions.customFooterOptions) {
385
+ this.slickFooter = new custom_footer_component_1.SlickFooterComponent(this.slickGrid, this.gridOptions.customFooterOptions, this._eventPubSubService, this.translaterService);
386
+ this.slickFooter.renderFooter(this._gridParentContainerElm);
387
+ }
388
+ // load the data in the DataView (unless it's a hierarchical dataset, if so it will be loaded after the initial tree sort)
389
+ if (Array.isArray(this.dataset)) {
390
+ const initialDataset = ((_p = this.gridOptions) === null || _p === void 0 ? void 0 : _p.enableTreeData) ? this.sortTreeDataset(this.dataset) : this.dataset;
391
+ (_q = this.dataView) === null || _q === void 0 ? void 0 : _q.setItems(initialDataset, this._gridOptions.datasetIdPropertyName);
392
+ }
393
+ // if you don't want the items that are not visible (due to being filtered out or being on a different page)
394
+ // to stay selected, pass 'false' to the second arg
395
+ const selectionModel = (_s = (_r = this.slickGrid) === null || _r === void 0 ? void 0 : _r.getSelectionModel) === null || _s === void 0 ? void 0 : _s.call(_r);
396
+ if (selectionModel && ((_t = this._gridOptions) === null || _t === void 0 ? void 0 : _t.dataView) && this._gridOptions.dataView.hasOwnProperty('syncGridSelection')) {
397
+ // if we are using a Backend Service, we will do an extra flag check, the reason is because it might have some unintended behaviors
398
+ // with the BackendServiceApi because technically the data in the page changes the DataView on every page change.
399
+ let preservedRowSelectionWithBackend = false;
400
+ if (this._gridOptions.backendServiceApi && this._gridOptions.dataView.hasOwnProperty('syncGridSelectionWithBackendService')) {
401
+ preservedRowSelectionWithBackend = this._gridOptions.dataView.syncGridSelectionWithBackendService;
402
+ }
403
+ const syncGridSelection = this._gridOptions.dataView.syncGridSelection;
404
+ if (typeof syncGridSelection === 'boolean') {
405
+ let preservedRowSelection = syncGridSelection;
406
+ if (!this._isLocalGrid) {
407
+ // when using BackendServiceApi, we'll be using the "syncGridSelectionWithBackendService" flag BUT "syncGridSelection" must also be set to True
408
+ preservedRowSelection = syncGridSelection && preservedRowSelectionWithBackend;
409
+ }
410
+ (_u = this.dataView) === null || _u === void 0 ? void 0 : _u.syncGridSelection(this.slickGrid, preservedRowSelection);
411
+ }
412
+ else if (typeof syncGridSelection === 'object') {
413
+ (_v = this.dataView) === null || _v === void 0 ? void 0 : _v.syncGridSelection(this.slickGrid, syncGridSelection.preserveHidden, syncGridSelection.preserveHiddenOnSelectionChange);
414
+ }
415
+ }
416
+ this.slickGrid.invalidate();
417
+ if (((_x = (_w = this.dataView) === null || _w === void 0 ? void 0 : _w.getLength()) !== null && _x !== void 0 ? _x : 0) > 0) {
418
+ if (!this._isDatasetInitialized && (this._gridOptions.enableCheckboxSelector || this._gridOptions.enableRowSelection)) {
419
+ this.loadRowSelectionPresetWhenExists();
420
+ }
421
+ this.loadFilterPresetsWhenDatasetInitialized();
422
+ this._isDatasetInitialized = true;
423
+ }
424
+ // user might want to hide the header row on page load but still have `enableFiltering: true`
425
+ // if that is the case, we need to hide the headerRow ONLY AFTER all filters got created & dataView exist
426
+ if (this._hideHeaderRowAfterPageLoad) {
427
+ this.showHeaderRow(false);
428
+ this.sharedService.hideHeaderRowAfterPageLoad = this._hideHeaderRowAfterPageLoad;
429
+ }
430
+ // on cell click, mainly used with the columnDef.action callback
431
+ this.gridEventService.bindOnBeforeEditCell(this.slickGrid);
432
+ this.gridEventService.bindOnCellChange(this.slickGrid);
433
+ this.gridEventService.bindOnClick(this.slickGrid);
434
+ // bind the Backend Service API callback functions only after the grid is initialized
435
+ // because the preProcess() and onInit() might get triggered
436
+ if ((_y = this.gridOptions) === null || _y === void 0 ? void 0 : _y.backendServiceApi) {
437
+ this.bindBackendCallbackFunctions(this.gridOptions);
438
+ }
439
+ // publish & dispatch certain events
440
+ this._eventPubSubService.publish('onGridCreated', this.slickGrid);
441
+ // after the DataView is created & updated execute some processes & dispatch some events
442
+ if (!this.customDataView) {
443
+ this.executeAfterDataviewCreated(this.gridOptions);
444
+ }
445
+ // bind resize ONLY after the dataView is ready
446
+ this.bindResizeHook(this.slickGrid, this.gridOptions);
447
+ // once the grid is created, we'll return its instance (we do this to return Transient Services from DI)
448
+ this._slickerGridInstances = {
449
+ // Slick Grid & DataView objects
450
+ dataView: this.dataView,
451
+ slickGrid: this.slickGrid,
452
+ // public methods
453
+ dispose: this.dispose.bind(this),
454
+ // return all available Services (non-singleton)
455
+ backendService: (_0 = (_z = this.gridOptions) === null || _z === void 0 ? void 0 : _z.backendServiceApi) === null || _0 === void 0 ? void 0 : _0.service,
456
+ eventPubSubService: this._eventPubSubService,
457
+ filterService: this.filterService,
458
+ gridEventService: this.gridEventService,
459
+ gridStateService: this.gridStateService,
460
+ gridService: this.gridService,
461
+ groupingService: this.groupingService,
462
+ extensionService: this.extensionService,
463
+ extensionUtility: this.extensionUtility,
464
+ paginationService: this.paginationService,
465
+ resizerService: this.resizerService,
466
+ sortService: this.sortService,
467
+ treeDataService: this.treeDataService,
468
+ };
469
+ // addons (SlickGrid extra plugins/controls)
470
+ this._extensions = (_1 = this.extensionService) === null || _1 === void 0 ? void 0 : _1.extensionList;
471
+ // all instances (SlickGrid, DataView & all Services)
472
+ this._eventPubSubService.publish('onSlickerGridCreated', this.instances);
473
+ this._isGridInitialized = true;
474
+ }
475
+ mergeGridOptions(gridOptions) {
476
+ const options = $.extend(true, {}, common_1.GlobalGridOptions, gridOptions);
477
+ // also make sure to show the header row if user have enabled filtering
478
+ if (options.enableFiltering && !options.showHeaderRow) {
479
+ options.showHeaderRow = options.enableFiltering;
480
+ }
481
+ // using jQuery extend to do a deep clone has an unwanted side on objects and pageSizes but ES6 spread has other worst side effects
482
+ // so we will just overwrite the pageSizes when needed, this is the only one causing issues so far.
483
+ // jQuery wrote this on their docs:: On a deep extend, Object and Array are extended, but object wrappers on primitive types such as String, Boolean, and Number are not.
484
+ if ((options === null || options === void 0 ? void 0 : options.pagination) && (gridOptions.enablePagination || gridOptions.backendServiceApi) && gridOptions.pagination && Array.isArray(gridOptions.pagination.pageSizes)) {
485
+ options.pagination.pageSizes = gridOptions.pagination.pageSizes;
486
+ }
487
+ // when we use Pagination on Local Grid, it doesn't seem to work without enableFiltering
488
+ // so we'll enable the filtering but we'll keep the header row hidden
489
+ if (this.sharedService && !options.enableFiltering && options.enablePagination && this._isLocalGrid) {
490
+ options.enableFiltering = true;
491
+ options.showHeaderRow = false;
492
+ this._hideHeaderRowAfterPageLoad = true;
493
+ this.sharedService.hideHeaderRowAfterPageLoad = true;
494
+ }
495
+ return options;
496
+ }
497
+ /**
498
+ * Define our internal Post Process callback, it will execute internally after we get back result from the Process backend call
499
+ * For now, this is GraphQL Service ONLY feature and it will basically
500
+ * refresh the Dataset & Pagination without having the user to create his own PostProcess every time
501
+ */
502
+ createBackendApiInternalPostProcessCallback(gridOptions) {
503
+ const backendApi = gridOptions === null || gridOptions === void 0 ? void 0 : gridOptions.backendServiceApi;
504
+ if (backendApi === null || backendApi === void 0 ? void 0 : backendApi.service) {
505
+ const backendApiService = backendApi.service;
506
+ // internalPostProcess only works (for now) with a GraphQL Service, so make sure it is of that type
507
+ if ( /* backendApiService instanceof GraphqlService || */typeof backendApiService.getDatasetName === 'function') {
508
+ backendApi.internalPostProcess = (processResult) => {
509
+ const datasetName = (backendApi && backendApiService && typeof backendApiService.getDatasetName === 'function') ? backendApiService.getDatasetName() : '';
510
+ if (processResult && processResult.data && processResult.data[datasetName]) {
511
+ const data = processResult.data[datasetName].hasOwnProperty('nodes') ? processResult.data[datasetName].nodes : processResult.data[datasetName];
512
+ const totalCount = processResult.data[datasetName].hasOwnProperty('totalCount') ? processResult.data[datasetName].totalCount : processResult.data[datasetName].length;
513
+ this.refreshGridData(data, totalCount || 0);
514
+ }
515
+ };
516
+ }
517
+ }
518
+ }
519
+ bindDifferentHooks(grid, gridOptions, dataView) {
520
+ var _a, _b;
521
+ // if user is providing a Translate Service, we need to add our PubSub Service (but only after creating all dependencies)
522
+ // so that we can later subscribe to the "onLanguageChange" event and translate any texts whenever that get triggered
523
+ if (gridOptions.enableTranslate && ((_a = this.translaterService) === null || _a === void 0 ? void 0 : _a.addPubSubMessaging)) {
524
+ this.translaterService.addPubSubMessaging(this._eventPubSubService);
525
+ }
526
+ // translate them all on first load, then on each language change
527
+ if (gridOptions.enableTranslate) {
528
+ this.extensionService.translateAllExtensions();
529
+ this.translateColumnHeaderTitleKeys();
530
+ this.translateColumnGroupKeys();
531
+ }
532
+ // on locale change, we have to manually translate the Headers, GridMenu
533
+ this.subscriptions.push(this._eventPubSubService.subscribe('onLanguageChange', () => {
534
+ if (gridOptions.enableTranslate) {
535
+ this.extensionService.translateAllExtensions();
536
+ this.translateColumnHeaderTitleKeys();
537
+ this.translateColumnGroupKeys();
538
+ if (gridOptions.createPreHeaderPanel && !gridOptions.enableDraggableGrouping) {
539
+ this.groupingService.translateGroupingAndColSpan();
540
+ }
541
+ }
542
+ }));
543
+ // if user set an onInit Backend, we'll run it right away (and if so, we also need to run preProcess, internalPostProcess & postProcess)
544
+ if (gridOptions.backendServiceApi) {
545
+ const backendApi = gridOptions.backendServiceApi;
546
+ if ((_b = backendApi === null || backendApi === void 0 ? void 0 : backendApi.service) === null || _b === void 0 ? void 0 : _b.init) {
547
+ backendApi.service.init(backendApi.options, gridOptions.pagination, this.slickGrid, this.sharedService);
548
+ }
549
+ }
550
+ if (dataView && grid) {
551
+ // expose all Slick Grid Events through dispatch
552
+ for (const prop in grid) {
553
+ if (grid.hasOwnProperty(prop) && prop.startsWith('on')) {
554
+ this._eventHandler.subscribe(grid[prop], (event, args) => {
555
+ var _a, _b;
556
+ const gridEventName = this._eventPubSubService.getEventNameByNamingConvention(prop, (_b = (_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.defaultSlickgridEventPrefix) !== null && _b !== void 0 ? _b : '');
557
+ return this._eventPubSubService.dispatchCustomEvent(gridEventName, { eventData: event, args });
558
+ });
559
+ }
560
+ }
561
+ // expose all Slick DataView Events through dispatch
562
+ for (const prop in dataView) {
563
+ if (dataView.hasOwnProperty(prop) && prop.startsWith('on')) {
564
+ this._eventHandler.subscribe(dataView[prop], (event, args) => {
565
+ var _a, _b;
566
+ const dataViewEventName = this._eventPubSubService.getEventNameByNamingConvention(prop, (_b = (_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.defaultSlickgridEventPrefix) !== null && _b !== void 0 ? _b : '');
567
+ return this._eventPubSubService.dispatchCustomEvent(dataViewEventName, { eventData: event, args });
568
+ });
569
+ }
570
+ }
571
+ // after all events are exposed
572
+ // we can bind external filter (backend) when available or default onFilter (dataView)
573
+ if (gridOptions.enableFiltering) {
574
+ this.filterService.init(grid);
575
+ // bind external filter (backend) unless specified to use the local one
576
+ if (gridOptions.backendServiceApi && !gridOptions.backendServiceApi.useLocalFiltering) {
577
+ this.filterService.bindBackendOnFilter(grid);
578
+ }
579
+ else {
580
+ this.filterService.bindLocalOnFilter(grid);
581
+ }
582
+ }
583
+ // bind external sorting (backend) when available or default onSort (dataView)
584
+ if (gridOptions.enableSorting) {
585
+ // bind external sorting (backend) unless specified to use the local one
586
+ if (gridOptions.backendServiceApi && !gridOptions.backendServiceApi.useLocalSorting) {
587
+ this.sortService.bindBackendOnSort(grid);
588
+ }
589
+ else {
590
+ this.sortService.bindLocalOnSort(grid);
591
+ }
592
+ }
593
+ // When data changes in the DataView, we need to refresh the metrics and/or display a warning if the dataset is empty
594
+ this._eventHandler.subscribe(dataView.onRowCountChanged, () => {
595
+ var _a, _b, _c;
596
+ grid.invalidate();
597
+ this.handleOnItemCountChanged(((_a = this.dataView) === null || _a === void 0 ? void 0 : _a.getFilteredItemCount()) || 0, (_c = (_b = this.dataView) === null || _b === void 0 ? void 0 : _b.getItemCount()) !== null && _c !== void 0 ? _c : 0);
598
+ });
599
+ this._eventHandler.subscribe(dataView.onSetItemsCalled, (_e, args) => {
600
+ var _a, _b;
601
+ this.handleOnItemCountChanged(((_a = this.dataView) === null || _a === void 0 ? void 0 : _a.getFilteredItemCount()) || 0, args.itemCount);
602
+ // when user has resize by content enabled, we'll force a full width calculation since we change our entire dataset
603
+ if (args.itemCount > 0 && (this.gridOptions.autosizeColumnsByCellContentOnFirstLoad || this.gridOptions.enableAutoResizeColumnsByCellContent)) {
604
+ this.resizerService.resizeColumnsByCellContent(!((_b = this.gridOptions) === null || _b === void 0 ? void 0 : _b.resizeByContentOnlyOnFirstLoad));
605
+ }
606
+ });
607
+ // when filtering data with local dataset, we need to update each row else it will not always show correctly in the UI
608
+ // also don't use "invalidateRows" since it destroys the entire row and as bad user experience when updating a row
609
+ if (gridOptions && gridOptions.enableFiltering && !gridOptions.enableRowDetailView) {
610
+ this._eventHandler.subscribe(dataView.onRowsChanged, (_e, args) => {
611
+ if ((args === null || args === void 0 ? void 0 : args.rows) && Array.isArray(args.rows)) {
612
+ args.rows.forEach((row) => grid.updateRow(row));
613
+ grid.render();
614
+ }
615
+ });
616
+ }
617
+ // when column are reordered, we need to update the visibleColumn array
618
+ this._eventHandler.subscribe(grid.onColumnsReordered, (_e, args) => {
619
+ this.sharedService.hasColumnsReordered = true;
620
+ this.sharedService.visibleColumns = args.impactedColumns;
621
+ });
622
+ // load any presets if any (after dataset is initialized)
623
+ this.loadColumnPresetsWhenDatasetInitialized();
624
+ this.loadFilterPresetsWhenDatasetInitialized();
625
+ }
626
+ // did the user add a colspan callback? If so, hook it into the DataView getItemMetadata
627
+ if ((gridOptions === null || gridOptions === void 0 ? void 0 : gridOptions.colspanCallback) && (dataView === null || dataView === void 0 ? void 0 : dataView.getItem) && (dataView === null || dataView === void 0 ? void 0 : dataView.getItemMetadata)) {
628
+ dataView.getItemMetadata = (rowNumber) => {
629
+ let callbackResult = null;
630
+ if (gridOptions.colspanCallback) {
631
+ callbackResult = gridOptions.colspanCallback(dataView.getItem(rowNumber));
632
+ }
633
+ return callbackResult;
634
+ };
635
+ }
636
+ }
637
+ bindBackendCallbackFunctions(gridOptions) {
638
+ var _a, _b, _c, _d, _f, _g;
639
+ const backendApi = gridOptions.backendServiceApi;
640
+ const backendApiService = backendApi === null || backendApi === void 0 ? void 0 : backendApi.service;
641
+ const serviceOptions = (_a = backendApiService === null || backendApiService === void 0 ? void 0 : backendApiService.options) !== null && _a !== void 0 ? _a : {};
642
+ const isExecuteCommandOnInit = (!serviceOptions) ? false : ((serviceOptions === null || serviceOptions === void 0 ? void 0 : serviceOptions.hasOwnProperty('executeProcessCommandOnInit')) ? serviceOptions['executeProcessCommandOnInit'] : true);
643
+ if (backendApiService) {
644
+ // update backend filters (if need be) BEFORE the query runs (via the onInit command a few lines below)
645
+ // if user entered some any "presets", we need to reflect them all in the grid
646
+ if (gridOptions === null || gridOptions === void 0 ? void 0 : gridOptions.presets) {
647
+ // Filters "presets"
648
+ if (backendApiService.updateFilters && Array.isArray(gridOptions.presets.filters) && gridOptions.presets.filters.length > 0) {
649
+ backendApiService.updateFilters(gridOptions.presets.filters, true);
650
+ }
651
+ // Sorters "presets"
652
+ if (backendApiService.updateSorters && Array.isArray(gridOptions.presets.sorters) && gridOptions.presets.sorters.length > 0) {
653
+ // when using multi-column sort, we can have multiple but on single sort then only grab the first sort provided
654
+ const sortColumns = ((_b = this._gridOptions) === null || _b === void 0 ? void 0 : _b.multiColumnSort) ? gridOptions.presets.sorters : gridOptions.presets.sorters.slice(0, 1);
655
+ backendApiService.updateSorters(undefined, sortColumns);
656
+ }
657
+ // Pagination "presets"
658
+ if (backendApiService.updatePagination && gridOptions.presets.pagination) {
659
+ const { pageNumber, pageSize } = gridOptions.presets.pagination;
660
+ backendApiService.updatePagination(pageNumber, pageSize);
661
+ }
662
+ }
663
+ else {
664
+ const columnFilters = this.filterService.getColumnFilters();
665
+ if (columnFilters && backendApiService.updateFilters) {
666
+ backendApiService.updateFilters(columnFilters, false);
667
+ }
668
+ }
669
+ // execute onInit command when necessary
670
+ if (backendApi && backendApiService && (backendApi.onInit || isExecuteCommandOnInit)) {
671
+ const query = (typeof backendApiService.buildQuery === 'function') ? backendApiService.buildQuery() : '';
672
+ const process = isExecuteCommandOnInit ? ((_d = (_c = backendApi.process) === null || _c === void 0 ? void 0 : _c.call(backendApi, query)) !== null && _d !== void 0 ? _d : null) : ((_g = (_f = backendApi.onInit) === null || _f === void 0 ? void 0 : _f.call(backendApi, query)) !== null && _g !== void 0 ? _g : null);
673
+ // wrap this inside a setTimeout to avoid timing issue since the gridOptions needs to be ready before running this onInit
674
+ setTimeout(() => {
675
+ var _a, _b, _c, _d;
676
+ const backendUtilityService = this.backendUtilityService;
677
+ // keep start time & end timestamps & return it after process execution
678
+ const startTime = new Date();
679
+ // run any pre-process, if defined, for example a spinner
680
+ if (backendApi.preProcess) {
681
+ backendApi.preProcess();
682
+ }
683
+ // the processes can be a Promise (like Http)
684
+ const totalItems = (_c = (_b = (_a = this.gridOptions) === null || _a === void 0 ? void 0 : _a.pagination) === null || _b === void 0 ? void 0 : _b.totalItems) !== null && _c !== void 0 ? _c : 0;
685
+ if (process instanceof Promise) {
686
+ process
687
+ .then((processResult) => backendUtilityService.executeBackendProcessesCallback(startTime, processResult, backendApi, totalItems))
688
+ .catch((error) => backendUtilityService.onBackendError(error, backendApi));
689
+ }
690
+ else if (process && ((_d = this.rxjs) === null || _d === void 0 ? void 0 : _d.isObservable(process))) {
691
+ this.subscriptions.push(process.subscribe((processResult) => backendUtilityService.executeBackendProcessesCallback(startTime, processResult, backendApi, totalItems), (error) => backendUtilityService.onBackendError(error, backendApi)));
692
+ }
693
+ });
694
+ }
695
+ }
696
+ }
697
+ bindResizeHook(grid, options) {
698
+ if ((options.autoFitColumnsOnFirstLoad && options.autosizeColumnsByCellContentOnFirstLoad) || (options.enableAutoSizeColumns && options.enableAutoResizeColumnsByCellContent)) {
699
+ throw new Error(`[Slickgrid-Universal] You cannot enable both autosize/fit viewport & resize by content, you must choose which resize technique to use. You can enable these 2 options ("autoFitColumnsOnFirstLoad" and "enableAutoSizeColumns") OR these other 2 options ("autosizeColumnsByCellContentOnFirstLoad" and "enableAutoResizeColumnsByCellContent").`);
700
+ }
701
+ if (grid && options.autoFitColumnsOnFirstLoad && options.enableAutoSizeColumns && typeof grid.autosizeColumns === 'function') {
702
+ // expand/autofit columns on first page load
703
+ grid.autosizeColumns();
704
+ }
705
+ // auto-resize grid on browser resize (optionally provide grid height or width)
706
+ if (options.gridHeight || options.gridWidth) {
707
+ this.resizerService.resizeGrid(0, { height: options.gridHeight, width: options.gridWidth });
708
+ }
709
+ else {
710
+ this.resizerService.resizeGrid();
711
+ }
712
+ if (grid && (options === null || options === void 0 ? void 0 : options.enableAutoResize)) {
713
+ if (options.autoFitColumnsOnFirstLoad && options.enableAutoSizeColumns && typeof grid.autosizeColumns === 'function') {
714
+ grid.autosizeColumns();
715
+ }
716
+ }
717
+ }
718
+ executeAfterDataviewCreated(gridOptions) {
719
+ var _a;
720
+ // if user entered some Sort "presets", we need to reflect them all in the DOM
721
+ if (gridOptions.enableSorting) {
722
+ if (gridOptions.presets && Array.isArray(gridOptions.presets.sorters)) {
723
+ // when using multi-column sort, we can have multiple but on single sort then only grab the first sort provided
724
+ const sortColumns = ((_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.multiColumnSort) ? gridOptions.presets.sorters : gridOptions.presets.sorters.slice(0, 1);
725
+ this.sortService.loadGridSorters(sortColumns);
726
+ }
727
+ }
728
+ }
729
+ /**
730
+ * On a Pagination changed, we will trigger a Grid State changed with the new pagination info
731
+ * Also if we use Row Selection or the Checkbox Selector with a Backend Service (Odata, GraphQL), we need to reset any selection
732
+ */
733
+ paginationChanged(pagination) {
734
+ var _a, _b, _c;
735
+ const isSyncGridSelectionEnabled = (_b = (_a = this.gridStateService) === null || _a === void 0 ? void 0 : _a.needToPreserveRowSelection()) !== null && _b !== void 0 ? _b : false;
736
+ if (this.slickGrid && !isSyncGridSelectionEnabled && ((_c = this._gridOptions) === null || _c === void 0 ? void 0 : _c.backendServiceApi) && (this.gridOptions.enableRowSelection || this.gridOptions.enableCheckboxSelector)) {
737
+ this.slickGrid.setSelectedRows([]);
738
+ }
739
+ const { pageNumber, pageSize } = pagination;
740
+ if (this.sharedService) {
741
+ if (pageSize !== undefined && pageNumber !== undefined) {
742
+ this.sharedService.currentPagination = { pageNumber, pageSize };
743
+ }
744
+ }
745
+ this._eventPubSubService.publish('onGridStateChanged', {
746
+ change: { newValues: { pageNumber, pageSize }, type: common_1.GridStateType.pagination },
747
+ gridState: this.gridStateService.getCurrentGridState()
748
+ });
749
+ }
750
+ /**
751
+ * When dataset changes, we need to refresh the entire grid UI & possibly resize it as well
752
+ * @param dataset
753
+ */
754
+ refreshGridData(dataset, totalCount) {
755
+ var _a, _b, _c, _d, _f;
756
+ // local grid, check if we need to show the Pagination
757
+ // if so then also check if there's any presets and finally initialize the PaginationService
758
+ // 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
759
+ if (this.slickGrid && this._gridOptions) {
760
+ if (this._gridOptions.enablePagination && this._isLocalGrid) {
761
+ this.showPagination = true;
762
+ this.loadLocalGridPagination(dataset);
763
+ }
764
+ if (this._gridOptions.enableEmptyDataWarningMessage && Array.isArray(dataset)) {
765
+ const finalTotalCount = totalCount || dataset.length;
766
+ this.displayEmptyDataWarning(finalTotalCount < 1);
767
+ }
768
+ if (Array.isArray(dataset) && this.slickGrid && ((_a = this.dataView) === null || _a === void 0 ? void 0 : _a.setItems)) {
769
+ this.dataView.setItems(dataset, this._gridOptions.datasetIdPropertyName);
770
+ if (!this._gridOptions.backendServiceApi && !this._gridOptions.enableTreeData) {
771
+ this.dataView.reSort();
772
+ }
773
+ if (dataset.length > 0) {
774
+ if (!this._isDatasetInitialized) {
775
+ this.loadFilterPresetsWhenDatasetInitialized();
776
+ if (this._gridOptions.enableCheckboxSelector) {
777
+ this.loadRowSelectionPresetWhenExists();
778
+ }
779
+ }
780
+ this._isDatasetInitialized = true;
781
+ }
782
+ if (dataset) {
783
+ this.slickGrid.invalidate();
784
+ }
785
+ // 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
786
+ this.showPagination = (this._gridOptions && (this._gridOptions.enablePagination || (this._gridOptions.backendServiceApi && this._gridOptions.enablePagination === undefined))) ? true : false;
787
+ if (this._paginationOptions && ((_b = this._gridOptions) === null || _b === void 0 ? void 0 : _b.pagination) && ((_c = this._gridOptions) === null || _c === void 0 ? void 0 : _c.backendServiceApi)) {
788
+ const paginationOptions = this.setPaginationOptionsWhenPresetDefined(this._gridOptions, this._paginationOptions);
789
+ // when we have a totalCount use it, else we'll take it from the pagination object
790
+ // only update the total items if it's different to avoid refreshing the UI
791
+ const totalRecords = (totalCount !== undefined) ? totalCount : ((_f = (_d = this._gridOptions) === null || _d === void 0 ? void 0 : _d.pagination) === null || _f === void 0 ? void 0 : _f.totalItems);
792
+ if (totalRecords !== undefined && totalRecords !== this.totalItems) {
793
+ this.totalItems = +totalRecords;
794
+ }
795
+ // initialize the Pagination Service with new pagination options (which might have presets)
796
+ if (!this._isPaginationInitialized) {
797
+ this.initializePaginationService(paginationOptions);
798
+ }
799
+ else {
800
+ // update the pagination service with the new total
801
+ this.paginationService.updateTotalItems(this.totalItems);
802
+ }
803
+ }
804
+ // resize the grid inside a slight timeout, in case other DOM element changed prior to the resize (like a filter/pagination changed)
805
+ if (this.slickGrid && this._gridOptions.enableAutoResize) {
806
+ const delay = this._gridOptions.autoResize && this._gridOptions.autoResize.delay;
807
+ this.resizerService.resizeGrid(delay || 10);
808
+ }
809
+ }
810
+ }
811
+ }
812
+ /**
813
+ * Dynamically change or update the column definitions list.
814
+ * We will re-render the grid so that the new header and data shows up correctly.
815
+ * If using translater, we also need to trigger a re-translate of the column headers
816
+ */
817
+ updateColumnDefinitionsList(newColumnDefinitions) {
818
+ var _a, _b, _c;
819
+ if (this.slickGrid && this._gridOptions && Array.isArray(newColumnDefinitions)) {
820
+ // map/swap the internal library Editor to the SlickGrid Editor factory
821
+ newColumnDefinitions = this.swapInternalEditorToSlickGridFactoryEditor(newColumnDefinitions);
822
+ // if the user wants to automatically add a Custom Editor Formatter, we need to call the auto add function again
823
+ if (this._gridOptions.autoAddCustomEditorFormatter) {
824
+ (0, common_1.autoAddEditorFormatterToColumnsWithEditor)(newColumnDefinitions, this._gridOptions.autoAddCustomEditorFormatter);
825
+ }
826
+ if (this._gridOptions.enableTranslate) {
827
+ this.extensionService.translateColumnHeaders(false, newColumnDefinitions);
828
+ }
829
+ else {
830
+ this.extensionService.renderColumnHeaders(newColumnDefinitions, true);
831
+ }
832
+ if (this.slickGrid && ((_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.enableAutoSizeColumns)) {
833
+ this.slickGrid.autosizeColumns();
834
+ }
835
+ else if (((_b = this._gridOptions) === null || _b === void 0 ? void 0 : _b.enableAutoResizeColumnsByCellContent) && ((_c = this.resizerService) === null || _c === void 0 ? void 0 : _c.resizeColumnsByCellContent)) {
836
+ this.resizerService.resizeColumnsByCellContent();
837
+ }
838
+ }
839
+ }
840
+ /**
841
+ * Show the filter row displayed on first row, we can optionally pass false to hide it.
842
+ * @param showing
843
+ */
844
+ showHeaderRow(showing = true) {
845
+ var _a;
846
+ (_a = this.slickGrid) === null || _a === void 0 ? void 0 : _a.setHeaderRowVisibility(showing, false);
847
+ if (this.slickGrid && showing === true && this._isGridInitialized) {
848
+ this.slickGrid.setColumns(this.columnDefinitions);
849
+ }
850
+ return showing;
851
+ }
852
+ /**
853
+ * Check if there's any Pagination Presets defined in the Grid Options,
854
+ * if there are then load them in the paginationOptions object
855
+ */
856
+ setPaginationOptionsWhenPresetDefined(gridOptions, paginationOptions) {
857
+ var _a;
858
+ if (((_a = gridOptions.presets) === null || _a === void 0 ? void 0 : _a.pagination) && paginationOptions && !this._isPaginationInitialized) {
859
+ paginationOptions.pageSize = gridOptions.presets.pagination.pageSize;
860
+ paginationOptions.pageNumber = gridOptions.presets.pagination.pageNumber;
861
+ }
862
+ return paginationOptions;
863
+ }
864
+ // --
865
+ // protected functions
866
+ // ------------------
867
+ /**
868
+ * Loop through all column definitions and copy the original optional `width` properties optionally provided by the user.
869
+ * We will use this when doing a resize by cell content, if user provided a `width` it won't override it.
870
+ */
871
+ copyColumnWidthsReference(columnDefinitions) {
872
+ columnDefinitions.forEach(col => col.originalWidth = col.width);
873
+ }
874
+ displayEmptyDataWarning(showWarning = true) {
875
+ var _a;
876
+ (_a = this.slickEmptyWarning) === null || _a === void 0 ? void 0 : _a.showEmptyDataMessage(showWarning);
877
+ }
878
+ /** When data changes in the DataView, we'll refresh the metrics and/or display a warning if the dataset is empty */
879
+ handleOnItemCountChanged(currentPageRowItemCount, totalItemCount) {
880
+ var _a;
881
+ this._currentDatasetLength = totalItemCount;
882
+ this.metrics = {
883
+ startTime: new Date(),
884
+ endTime: new Date(),
885
+ itemCount: currentPageRowItemCount,
886
+ totalItemCount
887
+ };
888
+ // if custom footer is enabled, then we'll update its metrics
889
+ if (this.slickFooter) {
890
+ this.slickFooter.metrics = this.metrics;
891
+ }
892
+ // when using local (in-memory) dataset, we'll display a warning message when filtered data is empty
893
+ if (this._isLocalGrid && ((_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.enableEmptyDataWarningMessage)) {
894
+ this.displayEmptyDataWarning(currentPageRowItemCount === 0);
895
+ }
896
+ }
897
+ /** Initialize the Pagination Service once */
898
+ initializePaginationService(paginationOptions) {
899
+ if (this.slickGrid && this.gridOptions) {
900
+ this.paginationData = {
901
+ gridOptions: this.gridOptions,
902
+ paginationService: this.paginationService,
903
+ };
904
+ this.paginationService.totalItems = this.totalItems;
905
+ this.paginationService.init(this.slickGrid, paginationOptions, this.backendServiceApi);
906
+ this.subscriptions.push(this._eventPubSubService.subscribe('onPaginationChanged', paginationChanges => this.paginationChanged(paginationChanges)), this._eventPubSubService.subscribe('onPaginationVisibilityChanged', visibility => {
907
+ var _a, _b, _c;
908
+ this.showPagination = (_a = visibility === null || visibility === void 0 ? void 0 : visibility.visible) !== null && _a !== void 0 ? _a : false;
909
+ if ((_b = this.gridOptions) === null || _b === void 0 ? void 0 : _b.backendServiceApi) {
910
+ (_c = this.backendUtilityService) === null || _c === void 0 ? void 0 : _c.refreshBackendDataset(this.gridOptions);
911
+ }
912
+ this.renderPagination(this.showPagination);
913
+ }));
914
+ // also initialize (render) the pagination component
915
+ this.renderPagination();
916
+ this._isPaginationInitialized = true;
917
+ }
918
+ }
919
+ /**
920
+ * Render (or dispose) the Pagination Component, user can optionally provide False (to not show it) which will in term dispose of the Pagination,
921
+ * also while disposing we can choose to omit the disposable of the Pagination Service (if we are simply toggling the Pagination, we want to keep the Service alive)
922
+ * @param {Boolean} showPagination - show (new render) or not (dispose) the Pagination
923
+ * @param {Boolean} shouldDisposePaginationService - when disposing the Pagination, do we also want to dispose of the Pagination Service? (defaults to True)
924
+ */
925
+ renderPagination(showPagination = true) {
926
+ var _a;
927
+ if (((_a = this._gridOptions) === null || _a === void 0 ? void 0 : _a.enablePagination) && !this._isPaginationInitialized && showPagination) {
928
+ this.slickPagination = new pagination_component_1.SlickPaginationComponent(this.paginationService, this._eventPubSubService, this.sharedService, this.translaterService);
929
+ this.slickPagination.renderPagination(this._gridParentContainerElm);
930
+ this._isPaginationInitialized = true;
931
+ }
932
+ else if (!showPagination) {
933
+ if (this.slickPagination) {
934
+ this.slickPagination.dispose();
935
+ }
936
+ this._isPaginationInitialized = false;
937
+ }
938
+ }
939
+ /** Load the Editor Collection asynchronously and replace the "collection" property when Promise resolves */
940
+ loadEditorCollectionAsync(column) {
941
+ var _a;
942
+ const collectionAsync = (column === null || column === void 0 ? void 0 : column.editor).collectionAsync;
943
+ (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()"
944
+ if (collectionAsync instanceof Promise) {
945
+ // wait for the "collectionAsync", once resolved we will save it into the "collection"
946
+ // the collectionAsync can be of 3 types HttpClient, HttpFetch or a Promise
947
+ collectionAsync.then((response) => {
948
+ if (Array.isArray(response)) {
949
+ this.updateEditorCollection(column, response); // from Promise
950
+ }
951
+ else if ((response === null || response === void 0 ? void 0 : response.status) >= 200 && response.status < 300 && typeof response.json === 'function') {
952
+ if (response.bodyUsed) {
953
+ console.warn(`[SlickGrid-Universal] The response body passed to collectionAsync was already read.`
954
+ + `Either pass the dataset from the Response or clone the response first using response.clone()`);
955
+ }
956
+ else {
957
+ // from Fetch
958
+ response.json().then(data => this.updateEditorCollection(column, data));
959
+ }
960
+ }
961
+ else if (response === null || response === void 0 ? void 0 : response.content) {
962
+ this.updateEditorCollection(column, response['content']); // from http-client
963
+ }
964
+ });
965
+ }
966
+ else if ((_a = this.rxjs) === null || _a === void 0 ? void 0 : _a.isObservable(collectionAsync)) {
967
+ // wrap this inside a setTimeout to avoid timing issue since updateEditorCollection requires to call SlickGrid getColumns() method
968
+ setTimeout(() => {
969
+ this.subscriptions.push(collectionAsync.subscribe((resolvedCollection) => this.updateEditorCollection(column, resolvedCollection)));
970
+ });
971
+ }
972
+ }
973
+ /** Load any possible Columns Grid Presets */
974
+ loadColumnPresetsWhenDatasetInitialized() {
975
+ // if user entered some Columns "presets", we need to reflect them all in the grid
976
+ if (this.slickGrid && this.gridOptions.presets && Array.isArray(this.gridOptions.presets.columns) && this.gridOptions.presets.columns.length > 0) {
977
+ const gridColumns = this.gridStateService.getAssociatedGridColumns(this.slickGrid, this.gridOptions.presets.columns);
978
+ if (gridColumns && Array.isArray(gridColumns) && gridColumns.length > 0) {
979
+ // make sure that the checkbox selector is also visible if it is enabled
980
+ if (this.gridOptions.enableCheckboxSelector) {
981
+ const checkboxColumn = (Array.isArray(this._columnDefinitions) && this._columnDefinitions.length > 0) ? this._columnDefinitions[0] : null;
982
+ if (checkboxColumn && checkboxColumn.id === '_checkbox_selector' && gridColumns[0].id !== '_checkbox_selector') {
983
+ gridColumns.unshift(checkboxColumn);
984
+ }
985
+ }
986
+ // keep copy the original optional `width` properties optionally provided by the user.
987
+ // We will use this when doing a resize by cell content, if user provided a `width` it won't override it.
988
+ gridColumns.forEach(col => col.originalWidth = col.width);
989
+ // finally set the new presets columns (including checkbox selector if need be)
990
+ this.slickGrid.setColumns(gridColumns);
991
+ this.sharedService.visibleColumns = gridColumns;
992
+ }
993
+ }
994
+ }
995
+ /** Load any possible Filters Grid Presets */
996
+ loadFilterPresetsWhenDatasetInitialized() {
997
+ var _a, _b, _c;
998
+ if (this.gridOptions && !this.customDataView) {
999
+ // if user entered some Filter "presets", we need to reflect them all in the DOM
1000
+ // also note that a presets of Tree Data Toggling will also call this method because Tree Data toggling does work with data filtering
1001
+ // (collapsing a parent will basically use Filter for hidding (aka collapsing) away the child underneat it)
1002
+ if (this.gridOptions.presets && (Array.isArray(this.gridOptions.presets.filters) || Array.isArray((_b = (_a = this.gridOptions.presets) === null || _a === void 0 ? void 0 : _a.treeData) === null || _b === void 0 ? void 0 : _b.toggledItems))) {
1003
+ this.filterService.populateColumnFilterSearchTermPresets(((_c = this.gridOptions.presets) === null || _c === void 0 ? void 0 : _c.filters) || []);
1004
+ }
1005
+ }
1006
+ }
1007
+ /**
1008
+ * local grid, check if we need to show the Pagination
1009
+ * if so then also check if there's any presets and finally initialize the PaginationService
1010
+ * 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
1011
+ */
1012
+ loadLocalGridPagination(dataset) {
1013
+ var _a;
1014
+ if (this.gridOptions && this._paginationOptions) {
1015
+ this.totalItems = Array.isArray(dataset) ? dataset.length : 0;
1016
+ if (this._paginationOptions && ((_a = this.dataView) === null || _a === void 0 ? void 0 : _a.getPagingInfo)) {
1017
+ const slickPagingInfo = this.dataView.getPagingInfo();
1018
+ if ((slickPagingInfo === null || slickPagingInfo === void 0 ? void 0 : slickPagingInfo.hasOwnProperty('totalRows')) && this._paginationOptions.totalItems !== slickPagingInfo.totalRows) {
1019
+ this.totalItems = (slickPagingInfo === null || slickPagingInfo === void 0 ? void 0 : slickPagingInfo.totalRows) || 0;
1020
+ }
1021
+ }
1022
+ this._paginationOptions.totalItems = this.totalItems;
1023
+ const paginationOptions = this.setPaginationOptionsWhenPresetDefined(this.gridOptions, this._paginationOptions);
1024
+ this.initializePaginationService(paginationOptions);
1025
+ }
1026
+ }
1027
+ /** Load any Row Selections into the DataView that were presets by the user */
1028
+ loadRowSelectionPresetWhenExists() {
1029
+ var _a, _b, _c;
1030
+ // if user entered some Row Selections "presets"
1031
+ const presets = (_a = this.gridOptions) === null || _a === void 0 ? void 0 : _a.presets;
1032
+ const selectionModel = (_c = (_b = this.slickGrid) === null || _b === void 0 ? void 0 : _b.getSelectionModel) === null || _c === void 0 ? void 0 : _c.call(_b);
1033
+ const enableRowSelection = this.gridOptions && (this.gridOptions.enableCheckboxSelector || this.gridOptions.enableRowSelection);
1034
+ if (this.slickGrid && this.dataView && enableRowSelection && selectionModel && (presets === null || presets === void 0 ? void 0 : presets.rowSelection) && (Array.isArray(presets.rowSelection.gridRowIndexes) || Array.isArray(presets.rowSelection.dataContextIds))) {
1035
+ let dataContextIds = presets.rowSelection.dataContextIds;
1036
+ let gridRowIndexes = presets.rowSelection.gridRowIndexes;
1037
+ // maps the IDs to the Grid Rows and vice versa, the "dataContextIds" has precedence over the other
1038
+ if (Array.isArray(dataContextIds) && dataContextIds.length > 0) {
1039
+ gridRowIndexes = this.dataView.mapIdsToRows(dataContextIds) || [];
1040
+ }
1041
+ else if (Array.isArray(gridRowIndexes) && gridRowIndexes.length > 0) {
1042
+ dataContextIds = this.dataView.mapRowsToIds(gridRowIndexes) || [];
1043
+ }
1044
+ // apply row selection when defined as grid presets
1045
+ if (this.slickGrid && Array.isArray(gridRowIndexes)) {
1046
+ this.slickGrid.setSelectedRows(gridRowIndexes);
1047
+ this.dataView.setSelectedIds(dataContextIds || [], {
1048
+ isRowBeingAdded: true,
1049
+ shouldTriggerEvent: false,
1050
+ applyRowSelectionToGrid: true
1051
+ });
1052
+ }
1053
+ }
1054
+ }
1055
+ /** Pre-Register any Resource that don't require SlickGrid to be instantiated (for example RxJS Resource) */
1056
+ preRegisterResources() {
1057
+ this._registeredResources = this.gridOptions.registerExternalResources || [];
1058
+ // bind & initialize all Components/Services that were tagged as enabled
1059
+ // register all services by executing their init method and providing them with the Grid object
1060
+ if (Array.isArray(this._registeredResources)) {
1061
+ for (const resource of this._registeredResources) {
1062
+ if ((resource === null || resource === void 0 ? void 0 : resource.className) === 'RxJsResource') {
1063
+ this.registerRxJsResource(resource);
1064
+ }
1065
+ }
1066
+ }
1067
+ }
1068
+ registerResources() {
1069
+ // at this point, we consider all the registered services as external services, anything else registered afterward aren't external
1070
+ if (Array.isArray(this._registeredResources)) {
1071
+ this.sharedService.externalRegisteredResources = this._registeredResources;
1072
+ }
1073
+ // push all other Services that we want to be registered
1074
+ this._registeredResources.push(this.gridService, this.gridStateService);
1075
+ // when using Grouping/DraggableGrouping/Colspan register its Service
1076
+ if (this.gridOptions.createPreHeaderPanel && !this.gridOptions.enableDraggableGrouping) {
1077
+ this._registeredResources.push(this.groupingService);
1078
+ }
1079
+ // when using Tree Data View, register its Service
1080
+ if (this.gridOptions.enableTreeData) {
1081
+ this._registeredResources.push(this.treeDataService);
1082
+ }
1083
+ // when user enables translation, we need to translate Headers on first pass & subsequently in the bindDifferentHooks
1084
+ if (this.gridOptions.enableTranslate) {
1085
+ this.extensionService.translateColumnHeaders();
1086
+ }
1087
+ // also initialize (render) the empty warning component
1088
+ this.slickEmptyWarning = new empty_warning_component_1.SlickEmptyWarningComponent();
1089
+ this._registeredResources.push(this.slickEmptyWarning);
1090
+ // bind & initialize all Components/Services that were tagged as enabled
1091
+ // register all services by executing their init method and providing them with the Grid object
1092
+ if (Array.isArray(this._registeredResources)) {
1093
+ for (const resource of this._registeredResources) {
1094
+ if (this.slickGrid && typeof resource.init === 'function') {
1095
+ resource.init(this.slickGrid, this.universalContainerService);
1096
+ }
1097
+ }
1098
+ }
1099
+ }
1100
+ /** Register the RxJS Resource in all necessary services which uses */
1101
+ registerRxJsResource(resource) {
1102
+ this.rxjs = resource;
1103
+ this.backendUtilityService.addRxJsResource(this.rxjs);
1104
+ this.filterFactory.addRxJsResource(this.rxjs);
1105
+ this.filterService.addRxJsResource(this.rxjs);
1106
+ this.sortService.addRxJsResource(this.rxjs);
1107
+ this.paginationService.addRxJsResource(this.rxjs);
1108
+ this.universalContainerService.registerInstance('RxJsFacade', this.rxjs);
1109
+ this.universalContainerService.registerInstance('RxJsResource', this.rxjs);
1110
+ }
1111
+ /**
1112
+ * Takes a flat dataset with parent/child relationship, sort it (via its tree structure) and return the sorted flat array
1113
+ * @returns {Array<Object>} sort flat parent/child dataset
1114
+ */
1115
+ sortTreeDataset(flatDatasetInput, forceGridRefresh = false) {
1116
+ var _a, _b;
1117
+ const prevDatasetLn = this._currentDatasetLength;
1118
+ let sortedDatasetResult;
1119
+ let flatDatasetOutput = [];
1120
+ // if the hierarchical dataset was already initialized then no need to re-convert it, we can use it directly from the shared service ref
1121
+ if (this._isDatasetHierarchicalInitialized && this.datasetHierarchical) {
1122
+ sortedDatasetResult = this.treeDataService.sortHierarchicalDataset(this.datasetHierarchical);
1123
+ flatDatasetOutput = sortedDatasetResult.flat;
1124
+ }
1125
+ else if (Array.isArray(flatDatasetInput) && flatDatasetInput.length > 0) {
1126
+ if ((_b = (_a = this.gridOptions) === null || _a === void 0 ? void 0 : _a.treeDataOptions) === null || _b === void 0 ? void 0 : _b.initialSort) {
1127
+ // else we need to first convert the flat dataset to a hierarchical dataset and then sort
1128
+ sortedDatasetResult = this.treeDataService.convertFlatParentChildToTreeDatasetAndSort(flatDatasetInput, this._columnDefinitions || [], this.gridOptions);
1129
+ this.sharedService.hierarchicalDataset = sortedDatasetResult.hierarchical;
1130
+ flatDatasetOutput = sortedDatasetResult.flat;
1131
+ }
1132
+ else {
1133
+ // else we assume that the user provided an array that is already sorted (user's responsability)
1134
+ // and so we can simply convert the array to a tree structure and we're done, no need to sort
1135
+ this.sharedService.hierarchicalDataset = this.treeDataService.convertFlatParentChildToTreeDataset(flatDatasetInput, this.gridOptions);
1136
+ flatDatasetOutput = flatDatasetInput || [];
1137
+ }
1138
+ }
1139
+ // if we add/remove item(s) from the dataset, we need to also refresh our tree data filters
1140
+ if (flatDatasetInput.length > 0 && (forceGridRefresh || flatDatasetInput.length !== prevDatasetLn)) {
1141
+ this.filterService.refreshTreeDataFilters(flatDatasetOutput);
1142
+ }
1143
+ return flatDatasetOutput;
1144
+ }
1145
+ /**
1146
+ * For convenience to the user, we provide the property "editor" as an Slickgrid-Universal editor complex object
1147
+ * however "editor" is used internally by SlickGrid for it's own Editor Factory
1148
+ * so in our lib we will swap "editor" and copy it into a new property called "internalColumnEditor"
1149
+ * then take back "editor.model" and make it the new "editor" so that SlickGrid Editor Factory still works
1150
+ */
1151
+ swapInternalEditorToSlickGridFactoryEditor(columnDefinitions) {
1152
+ const columns = Array.isArray(columnDefinitions) ? columnDefinitions : [];
1153
+ if (columns.some(col => `${col.id}`.includes('.'))) {
1154
+ 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".');
1155
+ }
1156
+ return columns.map((column) => {
1157
+ var _a;
1158
+ // on every Editor that have a "collectionAsync", resolve the data and assign it to the "collection" property
1159
+ if ((_a = column.editor) === null || _a === void 0 ? void 0 : _a.collectionAsync) {
1160
+ this.loadEditorCollectionAsync(column);
1161
+ }
1162
+ // if there's already an internalColumnEditor we'll use it, else it would be inside the editor
1163
+ const columnEditor = column.internalColumnEditor || column.editor;
1164
+ return { ...column, editor: columnEditor === null || columnEditor === void 0 ? void 0 : columnEditor.model, internalColumnEditor: { ...columnEditor } };
1165
+ });
1166
+ }
1167
+ /** translate all columns (including hidden columns) */
1168
+ translateColumnHeaderTitleKeys() {
1169
+ this.extensionUtility.translateItems(this.sharedService.allColumns, 'nameKey', 'name');
1170
+ }
1171
+ /** translate all column groups (including hidden columns) */
1172
+ translateColumnGroupKeys() {
1173
+ this.extensionUtility.translateItems(this.sharedService.allColumns, 'columnGroupKey', 'columnGroup');
1174
+ }
1175
+ /**
1176
+ * Update the "internalColumnEditor.collection" property.
1177
+ * Since this is called after the async call resolves, the pointer will not be the same as the "column" argument passed.
1178
+ * Once we found the new pointer, we will reassign the "editor" and "collection" to the "internalColumnEditor" so it has newest collection
1179
+ */
1180
+ updateEditorCollection(column, newCollection) {
1181
+ column.editor.collection = newCollection;
1182
+ column.editor.disabled = false;
1183
+ if (this.slickGrid) {
1184
+ // find the new column reference pointer & re-assign the new editor to the internalColumnEditor
1185
+ if (Array.isArray(this.columnDefinitions)) {
1186
+ const columnRef = this.columnDefinitions.find((col) => col.id === column.id);
1187
+ if (columnRef) {
1188
+ columnRef.internalColumnEditor = column.editor;
1189
+ }
1190
+ }
1191
+ // get current Editor, remove it from the DOm then re-enable it and re-render it with the new collection.
1192
+ const currentEditor = this.slickGrid.getCellEditor();
1193
+ if ((currentEditor === null || currentEditor === void 0 ? void 0 : currentEditor.disable) && (currentEditor === null || currentEditor === void 0 ? void 0 : currentEditor.renderDomElement)) {
1194
+ currentEditor.destroy();
1195
+ currentEditor.disable(false);
1196
+ currentEditor.renderDomElement(newCollection);
1197
+ }
1198
+ }
1199
+ }
1200
+ }
1201
+ exports.SlickVanillaGridBundle = SlickVanillaGridBundle;
1202
1202
  //# sourceMappingURL=slick-vanilla-grid-bundle.js.map