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