slickgrid-react 2.6.4 → 3.0.1

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