slickgrid-react 3.0.0 → 3.0.2

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