@refinitiv-ui/efx-grid 6.0.107 → 6.0.109

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,22 +25,23 @@ import { cloneObject, injectCss, prettifyCss, deepEqual } from "../../tr-grid-ut
25
25
  * @extends {GridPlugin}
26
26
  * @param {ColumnGroupingPlugin~Options=} options
27
27
  */
28
- var ColumnGroupingPlugin = function ColumnGroupingPlugin(options) {
29
- var t = this;
30
- t._hosts = [];
31
- t._onColumnChanged = t._onColumnChanged.bind(t);
32
- t._onColumnAdded = t._onColumnAdded.bind(t);
33
- t._onColumnMoved = t._onColumnMoved.bind(t);
34
- t._onColumnRemoved = t._onColumnRemoved.bind(t);
35
- t._requestApplyAddChildGroup = t._requestApplyAddChildGroup.bind(this);
36
- t._onPostSectionRender = t._onPostSectionRender.bind(t);
37
- t._onBeforeColumnBoundUpdate = t._onBeforeColumnBoundUpdate.bind(t);
38
- t._groupDefs = new GroupDefinitions();
39
- if (options) {
40
- t.config({
41
- "columnGrouping": options
42
- });
43
- }
28
+ let ColumnGroupingPlugin = function (options) {
29
+ let t = this;
30
+ t._hosts = [];
31
+
32
+ t._onColumnChanged = t._onColumnChanged.bind(t);
33
+ t._onColumnAdded = t._onColumnAdded.bind(t);
34
+ t._onColumnMoved = t._onColumnMoved.bind(t);
35
+ t._onColumnRemoved = t._onColumnRemoved.bind(t);
36
+ t._requestApplyAddChildGroup = t._requestApplyAddChildGroup.bind(this);
37
+ t._onPostSectionRender = t._onPostSectionRender.bind(t);
38
+ t._onBeforeColumnBoundUpdate = t._onBeforeColumnBoundUpdate.bind(t);
39
+
40
+ t._groupDefs = new GroupDefinitions();
41
+
42
+ if(options) {
43
+ t.config({ "columnGrouping": options });
44
+ }
44
45
  };
45
46
  Ext.inherits(ColumnGroupingPlugin, GridPlugin);
46
47
 
@@ -93,39 +94,39 @@ ColumnGroupingPlugin.prototype._selectedColMap;
93
94
  * @param {number} b
94
95
  * @return {number}
95
96
  */
96
- ColumnGroupingPlugin._ascSortLogic = function (a, b) {
97
- return a - b;
97
+ ColumnGroupingPlugin._ascSortLogic = function(a, b) {
98
+ return a - b;
98
99
  };
99
100
  /** @private
100
101
  * @param {ColumnGroupingPlugin~GroupDefinition} groupingOptions
101
102
  * @return {string}
102
103
  */
103
- ColumnGroupingPlugin._getTooltip = function (groupingOptions) {
104
- var tooltip = groupingOptions["tooltip"];
105
- var title = groupingOptions["title"] || groupingOptions["name"];
106
- if (tooltip != null) {
107
- if (typeof tooltip === "string") {
108
- return tooltip; // There is a custom tooltip
109
- } else if (tooltip === true) {
110
- return title;
111
- } else if (tooltip === false) {
112
- return "";
113
- }
114
- }
115
- return title;
104
+ ColumnGroupingPlugin._getTooltip = function(groupingOptions) {
105
+ let tooltip = groupingOptions["tooltip"];
106
+ let title = groupingOptions["title"] || groupingOptions["name"];
107
+ if(tooltip != null) {
108
+ if(typeof tooltip === "string") {
109
+ return tooltip; // There is a custom tooltip
110
+ } else if(tooltip === true) {
111
+ return title;
112
+ } else if(tooltip === false) {
113
+ return "";
114
+ }
115
+ }
116
+ return title;
116
117
  };
117
118
  /** @private
118
119
  * @function
119
120
  * @param {Object} groupDef
120
121
  * @return {boolean}
121
122
  */
122
- ColumnGroupingPlugin._hasGroupId = function (groupDef) {
123
- if (groupDef) {
124
- if (groupDef.id) {
125
- return true;
126
- }
127
- }
128
- return false;
123
+ ColumnGroupingPlugin._hasGroupId = function(groupDef) {
124
+ if(groupDef) {
125
+ if(groupDef.id) {
126
+ return true;
127
+ }
128
+ }
129
+ return false;
129
130
  };
130
131
 
131
132
  /** @private
@@ -134,47 +135,47 @@ ColumnGroupingPlugin._hasGroupId = function (groupDef) {
134
135
  * @param {string=} groupId
135
136
  * @return {ColumnGroupingPlugin~GroupDefinition}
136
137
  */
137
- ColumnGroupingPlugin._toGroupDefinition = function (obj, groupId) {
138
- var groupDef = null;
139
- if (obj) {
140
- if (Array.isArray(obj)) {
141
- groupDef = {
142
- children: obj
143
- };
144
- } else {
145
- groupDef = ColumnGroupingPlugin._cloneObject(obj);
146
- }
147
- if (groupId) {
148
- if (!groupDef.id) {
149
- groupDef.name = groupId;
150
- }
151
- groupDef.id = groupId;
152
- }
153
- }
154
- return groupDef;
138
+ ColumnGroupingPlugin._toGroupDefinition = function(obj, groupId) {
139
+ let groupDef = null;
140
+ if(obj) {
141
+ if(Array.isArray(obj)) {
142
+ groupDef = {
143
+ children: obj
144
+ };
145
+ } else {
146
+ groupDef = ColumnGroupingPlugin._cloneObject(obj);
147
+ }
148
+ if(groupId) {
149
+ if(!groupDef.id) {
150
+ groupDef.name = groupId;
151
+ }
152
+ groupDef.id = groupId;
153
+ }
154
+ }
155
+ return groupDef;
155
156
  };
156
157
  /** @private
157
158
  * @function
158
159
  * @param {Object} obj
159
160
  * @return {Object}
160
161
  */
161
- ColumnGroupingPlugin._cloneObject = function (obj) {
162
- var newObj = cloneObject(obj);
163
- if (!Array.isArray(newObj.children)) {
164
- newObj.children = [];
165
- }
166
- return newObj;
162
+ ColumnGroupingPlugin._cloneObject = function(obj) {
163
+ let newObj = cloneObject(obj);
164
+ if(!Array.isArray(newObj.children)) {
165
+ newObj.children = [];
166
+ }
167
+ return newObj;
167
168
  };
168
169
  /** Flatten tree structure to simple dictionary
169
170
  * @private
170
171
  * @function
171
172
  * @param {ColumnGroupingPlugin~GroupDefinitions} groupDefs
172
173
  */
173
- ColumnGroupingPlugin._flattenGroupDefs = function (groupDefs) {
174
- var grpCount = groupDefs ? groupDefs.length : 0;
175
- for (var _i = 0; _i < grpCount; _i++) {
176
- ColumnGroupingPlugin._recursivelyFlatten(groupDefs[_i], groupDefs);
177
- }
174
+ ColumnGroupingPlugin._flattenGroupDefs = function(groupDefs) {
175
+ let grpCount = groupDefs ? groupDefs.length : 0;
176
+ for(let i = 0; i < grpCount; i++) {
177
+ ColumnGroupingPlugin._recursivelyFlatten(groupDefs[i], groupDefs);
178
+ }
178
179
  };
179
180
  /** Flatten group definition structure by using group ID instead of nested group definitions.
180
181
  * @private
@@ -183,24 +184,23 @@ ColumnGroupingPlugin._flattenGroupDefs = function (groupDefs) {
183
184
  * @param {Array} groupDefs
184
185
  */
185
186
  ColumnGroupingPlugin._recursivelyFlatten = function (groupDef, groupDefs) {
186
- if (groupDef && groupDef.children) {
187
- var children = groupDef.children;
188
- var member, groupId;
189
- for (var _i2 = 0; _i2 < children.length; _i2++) {
190
- member = children[_i2];
191
- if (typeof member !== "string") {
192
- // member is nested group definition
193
- groupId = member.id;
194
- if (groupId) {
195
- children[_i2] = groupId; // Use group ID instead of nested group definition
196
- if (groupDefs.indexOf(member) < 0) {
197
- groupDefs.push(member);
198
- }
199
- ColumnGroupingPlugin._recursivelyFlatten(member, groupDefs);
200
- }
201
- } // TODO: Invalid group is not flatten
202
- }
203
- }
187
+ if(groupDef && groupDef.children) {
188
+ let children = groupDef.children;
189
+ let member, groupId;
190
+ for(let i = 0; i < children.length; i++) {
191
+ member = children[i];
192
+ if(typeof member !== "string") { // member is nested group definition
193
+ groupId = member.id;
194
+ if(groupId) {
195
+ children[i] = groupId; // Use group ID instead of nested group definition
196
+ if(groupDefs.indexOf(member) < 0) {
197
+ groupDefs.push(member);
198
+ }
199
+ ColumnGroupingPlugin._recursivelyFlatten(member, groupDefs);
200
+ }
201
+ } // TODO: Invalid group is not flatten
202
+ }
203
+ }
204
204
  };
205
205
 
206
206
  /** Filter time series group out
@@ -209,21 +209,21 @@ ColumnGroupingPlugin._recursivelyFlatten = function (groupDef, groupDefs) {
209
209
  * @return {boolean}
210
210
  */
211
211
  ColumnGroupingPlugin._isNotTimeSeriesGroup = function (groupDef) {
212
- return groupDef.timeSeriesGroup ? false : true;
212
+ return groupDef.timeSeriesGroup ? false : true;
213
213
  };
214
214
 
215
215
  /** @public
216
216
  * @return {string}
217
217
  */
218
218
  ColumnGroupingPlugin.prototype.getName = function () {
219
- return "ColumnGroupingPlugin"; // Read Only
219
+ return "ColumnGroupingPlugin"; // Read Only
220
220
  };
221
221
  /**
222
222
  * @override
223
223
  * @return {boolean}
224
224
  */
225
- ColumnGroupingPlugin.prototype.hasMultiTableSupport = function () {
226
- return true;
225
+ ColumnGroupingPlugin.prototype.hasMultiTableSupport = function() {
226
+ return true;
227
227
  };
228
228
 
229
229
  /** @public
@@ -231,37 +231,43 @@ ColumnGroupingPlugin.prototype.hasMultiTableSupport = function () {
231
231
  * @param {Object=} options
232
232
  */
233
233
  ColumnGroupingPlugin.prototype.initialize = function (host, options) {
234
- if (this._hosts.indexOf(host) >= 0) {
235
- return;
236
- }
237
- this._hosts.push(host);
238
- if (typeof host.setColumnGrouping === "function") {
239
- host.setColumnGrouping(this._groupDefs);
240
- }
241
- if (!this._addingEvents) {
242
- this._addingEvents = [];
243
- }
244
- if (this._hosts.length === 1) {
245
- host.listen("columnAdded", this._onColumnAdded);
246
- host.listen("columnMoved", this._onColumnMoved);
247
- host.listen("columnRemoved", this._onColumnRemoved);
248
- host.listen("columnVisibilityChanged", this._onColumnChanged);
249
- host.listen("postSectionRender", this._onPostSectionRender);
250
- host.listen("beforeColumnBoundUpdate", this._onBeforeColumnBoundUpdate);
251
- }
252
- this.config(options);
253
- this._legacyColumnGroups = null;
254
- if (this._initializedGrid && host.getSection("title")) {
255
- // For run-time loading
256
- this._applyGrouping();
257
- }
258
- if (!ColumnGroupingPlugin._styles) {
259
- ColumnGroupingPlugin._styles = prettifyCss([".tr-grid .title .column .cell:not(:last-child)", ["box-shadow: none;"]]);
260
- }
261
- if (!host._columnGroupingStyles) {
262
- host._columnGroupingStyles = true;
263
- injectCss(ColumnGroupingPlugin._styles, host.getElement());
264
- }
234
+ if(this._hosts.indexOf(host) >= 0) { return; }
235
+ this._hosts.push(host);
236
+ if(typeof host.setColumnGrouping === "function") {
237
+ host.setColumnGrouping(this._groupDefs);
238
+ }
239
+
240
+ if(!this._addingEvents) {
241
+ this._addingEvents = [];
242
+ }
243
+
244
+ if(this._hosts.length === 1) {
245
+ host.listen("columnAdded", this._onColumnAdded);
246
+ host.listen("columnMoved", this._onColumnMoved);
247
+ host.listen("columnRemoved", this._onColumnRemoved);
248
+ host.listen("columnVisibilityChanged", this._onColumnChanged);
249
+ host.listen("postSectionRender", this._onPostSectionRender);
250
+ host.listen("beforeColumnBoundUpdate", this._onBeforeColumnBoundUpdate);
251
+ }
252
+ this.config(options);
253
+ this._legacyColumnGroups = null;
254
+
255
+ if(this._initializedGrid && host.getSection("title")) { // For run-time loading
256
+ this._applyGrouping();
257
+ }
258
+
259
+ if(!ColumnGroupingPlugin._styles) {
260
+ ColumnGroupingPlugin._styles = prettifyCss([
261
+ ".tr-grid .title .column .cell:not(:last-child)", [
262
+ "box-shadow: none;"
263
+ ]
264
+ ]);
265
+ }
266
+
267
+ if(!host._columnGroupingStyles){
268
+ host._columnGroupingStyles = true;
269
+ injectCss(ColumnGroupingPlugin._styles, host.getElement());
270
+ }
265
271
  };
266
272
  /** Prevent built-in config
267
273
  * @public
@@ -270,90 +276,92 @@ ColumnGroupingPlugin.prototype.initialize = function (host, options) {
270
276
  * @return {*}
271
277
  */
272
278
  ColumnGroupingPlugin.prototype.beforeProcessOption = function (optionName, optionValue) {
273
- if (optionName === "columnGroups") {
274
- this._legacyColumnGroups = optionValue;
275
- return false; // eslint-disable-line
276
- }
277
-
278
- return; // eslint-disable-line
279
+ if(optionName === "columnGroups") {
280
+ this._legacyColumnGroups = optionValue;
281
+ return false; // eslint-disable-line
282
+ }
283
+ return; // eslint-disable-line
279
284
  };
280
285
  /**
281
286
  * @protected
282
287
  * @ignore
283
288
  */
284
- ColumnGroupingPlugin.prototype._afterInit = function () {
285
- this._applyGrouping();
289
+ ColumnGroupingPlugin.prototype._afterInit = function() {
290
+ this._applyGrouping();
286
291
  };
287
292
  /** @public
288
293
  * @param {Object} host core grid object
289
294
  */
290
295
  ColumnGroupingPlugin.prototype.unload = function (host) {
291
- var at = this._hosts.indexOf(host);
292
- if (at < 0) {
293
- return;
294
- }
295
- this._hosts.splice(at, 1);
296
- if (typeof host.setColumnGrouping === "function") {
297
- host.setColumnGrouping(null);
298
- }
299
- host.unlisten("columnAdded", this._onColumnChanged);
300
- host.unlisten("columnMoved", this._onColumnMoved);
301
- host.unlisten("columnRemoved", this._onColumnRemoved);
302
- host.unlisten("postSectionRender", this._onPostSectionRender);
303
- host.unlisten("beforeColumnBoundUpdate", this._onBeforeColumnBoundUpdate);
304
- if (!this._hosts.length) {
305
- if (this._rerenderTimerId) {
306
- clearTimeout(this._rerenderTimerId);
307
- this._rerenderTimerId = 0;
308
- }
309
- if (this._groupHeaderTimerId) {
310
- clearTimeout(this._groupHeaderTimerId);
311
- this._groupHeaderTimerId = 0;
312
- }
313
- if (this._addingTimerId) {
314
- clearTimeout(this._addingTimerId);
315
- this._addingTimerId = 0;
316
- this._addingEvents.length = 0;
317
- }
318
- }
319
- this._dispose();
296
+ let at = this._hosts.indexOf(host);
297
+ if(at < 0) { return; }
298
+ this._hosts.splice(at, 1);
299
+ if(typeof host.setColumnGrouping === "function") {
300
+ host.setColumnGrouping(null);
301
+ }
302
+
303
+ host.unlisten("columnAdded", this._onColumnChanged);
304
+ host.unlisten("columnMoved", this._onColumnMoved);
305
+ host.unlisten("columnRemoved", this._onColumnRemoved);
306
+ host.unlisten("postSectionRender", this._onPostSectionRender);
307
+ host.unlisten("beforeColumnBoundUpdate", this._onBeforeColumnBoundUpdate);
308
+
309
+ if(!this._hosts.length) {
310
+ if(this._rerenderTimerId){
311
+ clearTimeout(this._rerenderTimerId);
312
+ this._rerenderTimerId = 0;
313
+ }
314
+ if(this._groupHeaderTimerId){
315
+ clearTimeout(this._groupHeaderTimerId);
316
+ this._groupHeaderTimerId = 0;
317
+ }
318
+ if(this._addingTimerId) {
319
+ clearTimeout(this._addingTimerId);
320
+ this._addingTimerId = 0;
321
+ this._addingEvents.length = 0;
322
+ }
323
+ }
324
+
325
+ this._dispose();
320
326
  };
321
327
  /** @public
322
328
  * @param {Object} options
323
329
  */
324
330
  ColumnGroupingPlugin.prototype.config = function (options) {
325
- if (!options) {
326
- return;
327
- }
328
- var extOptions = options["columnGrouping"];
329
- var groupDefs = null;
330
- if (Array.isArray(extOptions)) {
331
- groupDefs = extOptions.filter(ColumnGroupingPlugin._hasGroupId);
332
- groupDefs = groupDefs.map(ColumnGroupingPlugin._cloneObject);
333
- }
334
- var columns = options["columns"];
335
- if (columns) {
336
- groupDefs = this._migrateLegacyStructure(groupDefs, columns);
337
- }
338
- if (groupDefs) {
339
- ColumnGroupingPlugin._flattenGroupDefs(groupDefs);
340
- this._groupDefs.setGroups(groupDefs);
341
- }
331
+ if(!options) { return; }
332
+
333
+ let extOptions = options["columnGrouping"];
334
+ let groupDefs = null;
335
+ if(Array.isArray(extOptions)) {
336
+ groupDefs = extOptions.filter(ColumnGroupingPlugin._hasGroupId);
337
+ groupDefs = groupDefs.map(ColumnGroupingPlugin._cloneObject);
338
+ }
339
+
340
+ let columns = options["columns"];
341
+ if(columns) {
342
+ groupDefs = this._migrateLegacyStructure(groupDefs, columns);
343
+ }
344
+
345
+ if(groupDefs) {
346
+ ColumnGroupingPlugin._flattenGroupDefs(groupDefs);
347
+ this._groupDefs.setGroups(groupDefs);
348
+ }
342
349
  };
343
350
  /** @public
344
351
  * @param {Object=} gridOptions
345
352
  * @return {!Object}
346
353
  */
347
354
  ColumnGroupingPlugin.prototype.getConfigObject = function (gridOptions) {
348
- var obj = gridOptions || {};
355
+ let obj = gridOptions || {};
349
356
 
350
- // TODO: Handle legacyRender method that has been migrated
351
- var groupDefs = this.getGroupDefinitions();
352
- groupDefs = groupDefs.filter(ColumnGroupingPlugin._isNotTimeSeriesGroup);
353
- if (groupDefs.length) {
354
- obj.columnGrouping = groupDefs;
355
- }
356
- return obj;
357
+ // TODO: Handle legacyRender method that has been migrated
358
+ let groupDefs = this.getGroupDefinitions();
359
+ groupDefs = groupDefs.filter(ColumnGroupingPlugin._isNotTimeSeriesGroup);
360
+ if(groupDefs.length) {
361
+ obj.columnGrouping = groupDefs;
362
+ }
363
+
364
+ return obj;
357
365
  };
358
366
 
359
367
  /** @private
@@ -363,15 +371,15 @@ ColumnGroupingPlugin.prototype.getConfigObject = function (gridOptions) {
363
371
  * @return {boolean} Returns true if there is any change
364
372
  */
365
373
  ColumnGroupingPlugin._mapParentToChildren = function (objMap, parentId, childId) {
366
- if (parentId && childId) {
367
- var ary = objMap[parentId];
368
- if (!ary) {
369
- ary = objMap[parentId] = [];
370
- }
371
- ary.push(childId);
372
- return true;
373
- }
374
- return false;
374
+ if(parentId && childId) {
375
+ let ary = objMap[parentId];
376
+ if(!ary) {
377
+ ary = objMap[parentId] = [];
378
+ }
379
+ ary.push(childId);
380
+ return true;
381
+ }
382
+ return false;
375
383
  };
376
384
  /** Legacy group structure from composite grid will be converted to the new structure
377
385
  * @private
@@ -380,169 +388,184 @@ ColumnGroupingPlugin._mapParentToChildren = function (objMap, parentId, childId)
380
388
  * @return {ColumnGroupingPlugin~GroupDefinitions}
381
389
  */
382
390
  ColumnGroupingPlugin.prototype._migrateLegacyStructure = function (groupDefs, colModels) {
383
- var legacyColumnGroups = this._legacyColumnGroups;
384
- if (!legacyColumnGroups || !this._compositeGrid) {
385
- return groupDefs;
386
- }
387
- if (!groupDefs) {
388
- groupDefs = [];
389
- }
390
-
391
- // Collecting parent groups from col models (leaf node)
392
- var colCount = colModels.length;
393
- var groupMap = {}; // Parent-children pair map
394
- for (var c = 0; c < colCount; ++c) {
395
- var colModel = colModels[c];
396
- if (colModel) {
397
- ColumnGroupingPlugin._mapParentToChildren(groupMap, colModel.columnGroup, colModel.id);
398
- }
399
- }
400
- // Collecting parent groups from the group list (groups can have parent as well)
401
- var groupCount = legacyColumnGroups.length;
402
- var i, groupDef;
403
- for (i = 0; i < groupCount; ++i) {
404
- groupDef = legacyColumnGroups[i];
405
- if (groupDef) {
406
- ColumnGroupingPlugin._mapParentToChildren(groupMap, groupDef.parent, groupDef.id);
407
- }
408
- }
409
- // TODO: Merge child relationship to existing group structure
410
-
411
- // Add new definitions and structure to the given legacy objects
412
- for (i = 0; i < groupCount; ++i) {
413
- groupDef = ColumnGroupingPlugin._cloneObject(legacyColumnGroups[i]);
414
- if (groupDef && groupDef.id) {
415
- // WARNING: Modify user's object
416
- var childAry = groupMap[groupDef.id];
417
- groupDef.children = childAry ? childAry : [];
418
- if (groupDef["formatter"] && groupDef["formatter"]["render"]) {
419
- groupDef["legacyRender"] = groupDef["formatter"]["render"];
420
- delete groupDef["formatter"];
421
- }
422
- groupDefs.push(groupDef);
423
- }
424
- }
425
- return groupDefs.filter(ColumnGroupingPlugin._hasGroupId);
391
+ let legacyColumnGroups = this._legacyColumnGroups;
392
+ if(!legacyColumnGroups || !this._compositeGrid) {
393
+ return groupDefs;
394
+ }
395
+ if(!groupDefs) {
396
+ groupDefs = [];
397
+ }
398
+
399
+ // Collecting parent groups from col models (leaf node)
400
+ let colCount = colModels.length;
401
+ let groupMap = {}; // Parent-children pair map
402
+ for(let c = 0; c < colCount; ++c) {
403
+ let colModel = colModels[c];
404
+ if(colModel) {
405
+ ColumnGroupingPlugin._mapParentToChildren(
406
+ groupMap, colModel.columnGroup, colModel.id
407
+ );
408
+ }
409
+ }
410
+ // Collecting parent groups from the group list (groups can have parent as well)
411
+ let groupCount = legacyColumnGroups.length;
412
+ let i, groupDef;
413
+ for(i = 0; i < groupCount; ++i) {
414
+ groupDef = legacyColumnGroups[i];
415
+ if(groupDef) {
416
+ ColumnGroupingPlugin._mapParentToChildren(
417
+ groupMap, groupDef.parent, groupDef.id
418
+ );
419
+ }
420
+ }
421
+ // TODO: Merge child relationship to existing group structure
422
+
423
+ // Add new definitions and structure to the given legacy objects
424
+ for(i = 0; i < groupCount; ++i) {
425
+ groupDef = ColumnGroupingPlugin._cloneObject(legacyColumnGroups[i]);
426
+ if(groupDef && groupDef.id) {
427
+ // WARNING: Modify user's object
428
+ let childAry = groupMap[groupDef.id];
429
+ groupDef.children = childAry ? childAry : [];
430
+
431
+ if(groupDef["formatter"] && groupDef["formatter"]["render"]) {
432
+ groupDef["legacyRender"] = groupDef["formatter"]["render"];
433
+ delete groupDef["formatter"];
434
+ }
435
+
436
+ groupDefs.push(groupDef);
437
+ }
438
+ }
439
+
440
+ return groupDefs.filter(ColumnGroupingPlugin._hasGroupId);
426
441
  };
427
442
  /** @private
428
443
  * @param {number} frozenColIndex
429
444
  * @param {number=} numRightColumn
430
445
  */
431
- ColumnGroupingPlugin.prototype._freezeColumn = function (frozenColIndex, numRightColumn) {
432
- var hosts = this._hosts;
433
- for (var _i3 = 0; _i3 < hosts.length; _i3++) {
434
- hosts[_i3].freezeColumn(frozenColIndex, numRightColumn);
435
- }
446
+ ColumnGroupingPlugin.prototype._freezeColumn = function(frozenColIndex, numRightColumn) {
447
+ let hosts = this._hosts;
448
+ for(let i = 0; i < hosts.length; i++) {
449
+ hosts[i].freezeColumn(frozenColIndex, numRightColumn);
450
+ }
436
451
  };
437
452
  /** @private
438
453
  */
439
- ColumnGroupingPlugin.prototype._applyPinning = function () {
440
- var colCount = this.getColumnCount();
441
- var columnIds = this.getColumnIds();
442
- var leftPinnedIndex = this._hosts[0].getFrozenColumnCount() - 1;
443
- var rightPinnedIndex = this._hosts[0].getFirstPinnedRightIndex();
444
- var i, groupId, groupDef;
445
- var dirty = false;
446
- for (i = colCount; i > leftPinnedIndex; i--) {
447
- groupId = this._groupDefs.getParentId(columnIds[i]);
448
- groupDef = this._visibleGroupMap[groupId];
449
- if (groupDef && groupDef.leftPinned) {
450
- leftPinnedIndex = i;
451
- dirty = true;
452
- break;
453
- }
454
- }
455
- for (i = leftPinnedIndex; i < rightPinnedIndex; i++) {
456
- groupId = this._groupDefs.getParentId(columnIds[i]);
457
- groupDef = this._visibleGroupMap[groupId];
458
- if (groupDef && groupDef.rightPinned) {
459
- rightPinnedIndex = i;
460
- dirty = true;
461
- break;
462
- }
463
- }
464
- if (dirty) {
465
- var rightPinnedCount = colCount - rightPinnedIndex;
466
- this._freezeColumn(leftPinnedIndex, rightPinnedCount);
467
- }
454
+ ColumnGroupingPlugin.prototype._applyPinning = function() {
455
+ let colCount = this.getColumnCount();
456
+ let columnIds = this.getColumnIds();
457
+ let leftPinnedIndex = this._hosts[0].getFrozenColumnCount() - 1;
458
+ let rightPinnedIndex = this._hosts[0].getFirstPinnedRightIndex();
459
+ let i, groupId, groupDef;
460
+ let dirty = false;
461
+ for(i = colCount; i > leftPinnedIndex; i--) {
462
+ groupId = this._groupDefs.getParentId(columnIds[i]);
463
+ groupDef = this._visibleGroupMap[groupId];
464
+ if(groupDef && groupDef.leftPinned) {
465
+ leftPinnedIndex = i;
466
+ dirty = true;
467
+ break;
468
+ }
469
+ }
470
+
471
+ for(i = leftPinnedIndex; i < rightPinnedIndex; i++) {
472
+ groupId = this._groupDefs.getParentId(columnIds[i]);
473
+ groupDef = this._visibleGroupMap[groupId];
474
+ if(groupDef && groupDef.rightPinned) {
475
+ rightPinnedIndex = i;
476
+ dirty = true;
477
+ break;
478
+ }
479
+ }
480
+ if(dirty) {
481
+ let rightPinnedCount = colCount - rightPinnedIndex;
482
+ this._freezeColumn(leftPinnedIndex, rightPinnedCount);
483
+ }
468
484
  };
469
485
  /** Consolidate and process configuration. Force rerendering on column adding, removing, moving, initializaing, and run-time API execution.
470
486
  * @private
471
487
  */
472
488
  ColumnGroupingPlugin.prototype._applyGrouping = function () {
473
- this._rerenderTimerId = 0;
474
- if (this._restructuring) {
475
- return;
476
- }
477
- this._restructuring = true;
478
- this._evaluateGroupStructure();
479
-
480
- // Apply column pinning
481
- this._applyPinning();
482
- var i, c, r, cell, section, colCount;
483
- var rowCount = this._maxDepth + 1;
484
- var hostCount = this._hosts.length;
485
- for (i = hostCount; --i >= 0;) {
486
- section = this._hosts[i].getSection("title");
487
- if (section) {
488
- section.setRowCount(rowCount); // This will cause postSectionRender event to be fired
489
- section.clearCellSpans();
490
-
491
- // Remove additional cell settings from _renderGroups() method
492
- colCount = section.getColumnCount();
493
- for (c = 0; c < colCount; c++) {
494
- for (r = 0; r < rowCount; r++) {
495
- cell = section.getCell(c, r, false);
496
- if (cell) {
497
- // TODO: The style and class from the user will not be reset, for example, the color or background
498
- cell.removeClass("no-sort");
499
- cell.removeClass("selected-group");
500
- cell.removeAttribute("group-id");
501
- }
502
- }
503
- }
504
- this._spanGroupVertically(section);
505
- // TODO: Some calculation in here should not be done in this loop
506
- this._spanGroupHorizontally(section);
507
- }
508
- }
509
- this._restructuring = false;
510
-
511
- // Request re-rendering
512
- for (i = hostCount; --i >= 0;) {
513
- var settings = this._hosts[i].getSectionSettings("title");
514
- if (settings) {
515
- settings.rerender();
516
- }
517
- }
489
+ this._rerenderTimerId = 0;
490
+ if(this._restructuring) {
491
+ return;
492
+ }
493
+ this._restructuring = true;
494
+
495
+ this._evaluateGroupStructure();
496
+
497
+ // Apply column pinning
498
+ this._applyPinning();
499
+
500
+ let i, c, r, cell, section, colCount;
501
+ let rowCount = this._maxDepth + 1;
502
+ let hostCount = this._hosts.length;
503
+ for(i = hostCount; --i >= 0;) {
504
+ section = this._hosts[i].getSection("title");
505
+ if(section) {
506
+ section.setRowCount(rowCount); // This will cause postSectionRender event to be fired
507
+ section.clearCellSpans();
508
+
509
+ // Remove additional cell settings from _renderGroups() method
510
+ colCount = section.getColumnCount();
511
+ for(c = 0; c < colCount; c++) {
512
+ for(r = 0; r < rowCount; r++) {
513
+ cell = section.getCell(c, r, false);
514
+ if(cell) {
515
+ // TODO: The style and class from the user will not be reset, for example, the color or background
516
+ cell.removeClass("no-sort");
517
+ cell.removeClass("selected-group");
518
+ cell.removeAttribute("group-id");
519
+ }
520
+ }
521
+ }
522
+
523
+ this._spanGroupVertically(section);
524
+ // TODO: Some calculation in here should not be done in this loop
525
+ this._spanGroupHorizontally(section);
526
+ }
527
+ }
528
+
529
+ this._restructuring = false;
530
+
531
+ // Request re-rendering
532
+ for(i = hostCount; --i >= 0;) {
533
+ let settings = this._hosts[i].getSectionSettings("title");
534
+ if(settings) {
535
+ settings.rerender();
536
+ }
537
+ }
518
538
  };
519
539
 
520
540
  /** @private
521
541
  */
522
542
  ColumnGroupingPlugin.prototype._evaluateGroupStructure = function () {
523
- // Clone group definitions for rendering
524
- var visibleGroupMap = this._visibleGroupMap = this._groupDefs.cloneGroupMap();
525
- this._verifySingleChild(visibleGroupMap);
526
- this._verifyColumnPinning(visibleGroupMap);
527
-
528
- // Update depth (onRow) and parentId
529
- var maxDepth = this._maxDepth = -1;
530
- for (var groupId in visibleGroupMap) {
531
- var groupDef = visibleGroupMap[groupId];
532
- var parentId = groupDef.parentId;
533
- if (parentId) {
534
- if (!visibleGroupMap[parentId]) {
535
- groupDef.parentId = ""; // Parent has been removed from visible view
536
- }
537
- }
538
-
539
- var depth = GroupDefinitions.calcTreeDepth(visibleGroupMap, groupDef);
540
- groupDef["onRow"] = depth;
541
- if (depth > maxDepth) {
542
- maxDepth = depth;
543
- }
544
- }
545
- this._maxDepth = maxDepth + 1; // Column header depth = maximum group depth + 1
543
+ // Clone group definitions for rendering
544
+ let visibleGroupMap = this._visibleGroupMap = this._groupDefs.cloneGroupMap();
545
+
546
+ this._verifySingleChild(visibleGroupMap);
547
+ this._verifyColumnPinning(visibleGroupMap);
548
+
549
+ // Update depth (onRow) and parentId
550
+ let maxDepth = this._maxDepth = -1;
551
+ for(let groupId in visibleGroupMap) {
552
+ let groupDef = visibleGroupMap[groupId];
553
+
554
+ let parentId = groupDef.parentId;
555
+ if(parentId) {
556
+ if(!visibleGroupMap[parentId]) {
557
+ groupDef.parentId = ""; // Parent has been removed from visible view
558
+ }
559
+ }
560
+
561
+ let depth = GroupDefinitions.calcTreeDepth(visibleGroupMap, groupDef);
562
+ groupDef["onRow"] = depth;
563
+ if(depth > maxDepth) {
564
+ maxDepth = depth;
565
+ }
566
+ }
567
+
568
+ this._maxDepth = maxDepth + 1; // Column header depth = maximum group depth + 1
546
569
  };
547
570
 
548
571
  /** Add pinning state to group definition for further verification.
@@ -550,561 +573,606 @@ ColumnGroupingPlugin.prototype._evaluateGroupStructure = function () {
550
573
  * @param {Object} groupDef
551
574
  * @param {string} side
552
575
  */
553
- ColumnGroupingPlugin.prototype._setGroupPinning = function (groupDef, side) {
554
- if (!groupDef || groupDef.leftPinned || groupDef.rightPinned) {
555
- return;
556
- }
557
- if (side === "left") {
558
- groupDef.leftPinned = true;
559
- } else {
560
- groupDef.rightPinned = true;
561
- }
562
- var children = groupDef["children"];
563
- for (var _i4 = 0; _i4 < children.length; _i4++) {
564
- var child = children[_i4];
565
- var group = this._visibleGroupMap[child];
566
- if (group) {
567
- this._setGroupPinning(group, side);
568
- }
569
- }
576
+ ColumnGroupingPlugin.prototype._setGroupPinning = function(groupDef, side) {
577
+ if(!groupDef || groupDef.leftPinned || groupDef.rightPinned) {
578
+ return;
579
+ }
580
+
581
+ if(side === "left") {
582
+ groupDef.leftPinned = true;
583
+ } else {
584
+ groupDef.rightPinned = true;
585
+ }
586
+
587
+ let children = groupDef["children"];
588
+ for(let i = 0; i < children.length; i++){
589
+ let child = children[i];
590
+ let group = this._visibleGroupMap[child];
591
+ if(group) {
592
+ this._setGroupPinning(group, side);
593
+ }
594
+ }
570
595
  };
571
596
 
572
597
  /** @private
573
598
  * @param {Object} groupMap
574
599
  */
575
- ColumnGroupingPlugin.prototype._verifyColumnPinning = function (groupMap) {
576
- var host = this._hosts[0];
577
- var leftPinnedIndex = host.getFrozenColumnCount() - 1;
578
- var rightPinnedIndex = host.getFirstPinnedRightIndex();
579
- var colCount = this.getColumnCount();
580
- var i, groupId, rootGroup, colId;
581
- var groupDefs = this._groupDefs;
582
- var visibleGroupMap = this._visibleGroupMap;
583
- if (leftPinnedIndex >= 0) {
584
- for (i = leftPinnedIndex; i >= 0; i--) {
585
- colId = this.getColumnId(i);
586
- groupId = groupDefs.getParentId(colId);
587
- if (groupId && visibleGroupMap[groupId]) {
588
- rootGroup = groupDefs.getRootGroup(groupId);
589
- if (rootGroup) {
590
- this._setGroupPinning(visibleGroupMap[rootGroup["id"]], "left");
591
- }
592
- }
593
- }
594
- }
595
- if (rightPinnedIndex < colCount) {
596
- for (i = rightPinnedIndex; i < colCount; i++) {
597
- colId = this.getColumnId(i);
598
- groupId = groupDefs.getParentId(colId);
599
- if (groupId && visibleGroupMap[groupId]) {
600
- rootGroup = groupDefs.getRootGroup(groupId);
601
- if (rootGroup) {
602
- this._setGroupPinning(visibleGroupMap[rootGroup["id"]], "right");
603
- }
604
- }
605
- }
606
- }
600
+ ColumnGroupingPlugin.prototype._verifyColumnPinning = function(groupMap) {
601
+ let host = this._hosts[0];
602
+ let leftPinnedIndex = host.getFrozenColumnCount() - 1;
603
+ let rightPinnedIndex = host.getFirstPinnedRightIndex();
604
+ let colCount = this.getColumnCount();
605
+
606
+ let i, groupId, rootGroup, colId;
607
+ let groupDefs = this._groupDefs;
608
+ let visibleGroupMap = this._visibleGroupMap;
609
+ if(leftPinnedIndex >= 0) {
610
+ for(i = leftPinnedIndex; i >= 0; i--) {
611
+ colId = this.getColumnId(i);
612
+ groupId = groupDefs.getParentId(colId);
613
+ if(groupId && visibleGroupMap[groupId]) {
614
+ rootGroup = groupDefs.getRootGroup(groupId);
615
+ if(rootGroup) {
616
+ this._setGroupPinning(visibleGroupMap[rootGroup["id"]], "left");
617
+ }
618
+ }
619
+ }
620
+ }
621
+
622
+ if(rightPinnedIndex < colCount) {
623
+ for(i = rightPinnedIndex; i < colCount; i++) {
624
+ colId = this.getColumnId(i);
625
+ groupId = groupDefs.getParentId(colId);
626
+ if(groupId && visibleGroupMap[groupId]) {
627
+ rootGroup = groupDefs.getRootGroup(groupId);
628
+ if(rootGroup) {
629
+ this._setGroupPinning(visibleGroupMap[rootGroup["id"]], "right");
630
+ }
631
+ }
632
+ }
633
+ }
607
634
  };
608
635
  /** @private
609
636
  * @param {Object} groupMap
610
637
  */
611
- ColumnGroupingPlugin.prototype._verifySingleChild = function (groupMap) {
612
- var api = this.getGridApi();
613
- if (!api) {
614
- return;
615
- }
616
- var core = this._hosts[0];
617
- var colCount = this.getColumnCount();
618
- var validIds = {};
619
- var i, j;
620
- // initialize a map for all valid and hidden ids of groups and columns
621
- for (i = 0; i < colCount; i++) {
622
- var colId = this.getColumnId(i);
623
- if (colId) {
624
- if (core.isColumnVisible(i)) {
625
- validIds[colId] = 1;
626
- }
627
- }
628
- }
629
- var groupIds = Object.keys(groupMap);
630
- var groupCount = groupIds.length;
631
- for (i = 0; i < groupCount; i++) {
632
- validIds[groupIds[i]] = 1;
633
- }
634
- var removable = true;
635
- while (removable) {
636
- removable = false;
637
- for (i = 0; i < groupCount; i++) {
638
- var groupId = groupIds[i];
639
- var group = groupMap[groupId];
640
- if (!group) {
641
- continue;
642
- }
643
- var children = group["children"];
644
- var childCount = children.length;
645
- var validChildren = [];
646
- for (j = 0; j < childCount; j++) {
647
- var child = children[j];
648
- if (validIds[child]) {
649
- validChildren.push(child);
650
- }
651
- }
652
- if (validChildren.length < 2) {
653
- delete groupMap[groupId];
654
- validIds[groupId] = 0;
655
- removable = true;
656
- } else {
657
- group.children = validChildren;
658
- }
659
- }
660
- }
638
+ ColumnGroupingPlugin.prototype._verifySingleChild = function(groupMap) {
639
+ let api = this.getGridApi();
640
+ if(!api) {
641
+ return;
642
+ }
643
+ let core = this._hosts[0];
644
+ let colCount = this.getColumnCount();
645
+ let validIds = {};
646
+
647
+ let i, j;
648
+ // initialize a map for all valid and hidden ids of groups and columns
649
+ for(i = 0; i < colCount; i++){
650
+ let colId = this.getColumnId(i);
651
+ if(colId){
652
+ if(core.isColumnVisible(i)){
653
+ validIds[colId] = 1;
654
+ }
655
+ }
656
+ }
657
+
658
+ let groupIds = Object.keys(groupMap);
659
+ let groupCount = groupIds.length;
660
+ for(i = 0; i < groupCount; i++){
661
+ validIds[groupIds[i]] = 1;
662
+ }
663
+
664
+ let removable = true;
665
+ while(removable){
666
+ removable = false;
667
+ for(i = 0; i < groupCount; i++){
668
+ let groupId = groupIds[i];
669
+ let group = groupMap[groupId];
670
+ if(!group){
671
+ continue;
672
+ }
673
+
674
+ let children = group["children"];
675
+ let childCount = children.length;
676
+ let validChildren = [];
677
+ for(j = 0; j < childCount; j++){
678
+ let child = children[j];
679
+ if(validIds[child]){
680
+ validChildren.push(child);
681
+ }
682
+ }
683
+
684
+ if(validChildren.length < 2) {
685
+ delete groupMap[groupId];
686
+ validIds[groupId] = 0;
687
+ removable = true;
688
+ } else {
689
+ group.children = validChildren;
690
+ }
691
+ }
692
+ }
661
693
  };
662
694
 
663
695
  /** Set a timer to call applyGrouping only once to avoid performance issue
664
696
  * @private
665
697
  */
666
- ColumnGroupingPlugin.prototype._requestApplyGrouping = function () {
667
- if (!this._rerenderTimerId) {
668
- this._rerenderTimerId = setTimeout(this._applyGrouping.bind(this), 10);
669
- }
698
+ ColumnGroupingPlugin.prototype._requestApplyGrouping = function() {
699
+ if(!this._rerenderTimerId) {
700
+ this._rerenderTimerId = setTimeout(this._applyGrouping.bind(this), 10);
701
+ }
670
702
  };
671
703
  /** Set a timer to call renderGroups only once to avoid performance issue
672
704
  * @private
673
705
  */
674
- ColumnGroupingPlugin.prototype._requestGroupRendering = function () {
675
- if (!this._groupHeaderTimerId) {
676
- this._groupHeaderTimerId = setTimeout(this.renderGroups.bind(this), 10);
677
- }
706
+ ColumnGroupingPlugin.prototype._requestGroupRendering = function() {
707
+ if(!this._groupHeaderTimerId) {
708
+ this._groupHeaderTimerId = setTimeout(this.renderGroups.bind(this), 10);
709
+ }
678
710
  };
679
711
  /** Apply nearest grouping to column.
680
712
  * @private
681
713
  * @param {number} colIndex
682
714
  */
683
715
  ColumnGroupingPlugin.prototype._applyNearestGrouping = function (colIndex) {
684
- if (colIndex == null || colIndex < 0) {
685
- return;
686
- }
687
- var colId = this.getColumnId(colIndex);
688
- var colIndexLeft = colIndex - 1;
689
- var colIndexRight = colIndex + 1;
690
- var groupLeftIds = this.getGroupIds(colIndexLeft);
691
- var groupRightIds = this.getGroupIds(colIndexRight);
692
- var groupLeftCount = groupLeftIds ? groupLeftIds.length : 0;
693
- var groupRightCount = groupRightIds ? groupRightIds.length : 0;
694
- var parentId = this._groupDefs.getParentId(colId);
695
- if (parentId) {
696
- var chdr = this._groupDefs.getGroupChildren(parentId);
697
- var childCount = chdr ? chdr.length : 0;
698
- if (childCount <= 1) {
699
- // If current column is only child in the group
700
- return; // there is no need to put column into another group because its parent group will be moved along
701
- }
702
-
703
- // If current column has a group and stays close to its siblings, it stay in the same group
704
- if (groupLeftCount) {
705
- if (groupLeftIds[0] === parentId) {
706
- return;
707
- }
708
- }
709
- if (groupRightCount) {
710
- if (groupRightIds[0] === parentId) {
711
- return;
712
- }
713
- }
714
- // The current column is no longer close to its parent
715
- if (this._groupDefs.unsetParent(colId)) {
716
- chdr = this._groupDefs.getGroupChildren(parentId);
717
- childCount = chdr ? chdr.length : 0;
718
- if (childCount === 1) {
719
- // If there is only one child left, move the remaning child to its parent
720
- var grandParentId = this._groupDefs.getParentId(parentId);
721
- if (grandParentId) {
722
- this._groupDefs.addGroupChild(grandParentId, chdr[0]);
723
- }
724
- }
725
- }
726
- }
727
- if (groupLeftCount && groupRightCount) {
728
- for (var _i5 = 0; _i5 < groupLeftCount; _i5++) {
729
- var groupLeftId = groupLeftIds[_i5];
730
- var sharedParentIdx = groupRightIds.indexOf(groupLeftId);
731
- if (sharedParentIdx >= 0) {
732
- this._groupDefs.addGroupChild(groupRightIds[sharedParentIdx], colId);
733
- break;
734
- }
735
- }
736
- }
716
+ if(colIndex == null || colIndex < 0 ){
717
+ return;
718
+ }
719
+
720
+ let colId = this.getColumnId(colIndex);
721
+ let colIndexLeft = colIndex - 1;
722
+ let colIndexRight = colIndex + 1;
723
+
724
+ let groupLeftIds = this.getGroupIds(colIndexLeft);
725
+ let groupRightIds = this.getGroupIds(colIndexRight);
726
+ let groupLeftCount = groupLeftIds ? groupLeftIds.length : 0;
727
+ let groupRightCount = groupRightIds ? groupRightIds.length : 0;
728
+
729
+ let parentId = this._groupDefs.getParentId(colId);
730
+ if(parentId) {
731
+ let chdr = this._groupDefs.getGroupChildren(parentId);
732
+ let childCount = chdr ? chdr.length : 0;
733
+ if(childCount <= 1) { // If current column is only child in the group
734
+ return; // there is no need to put column into another group because its parent group will be moved along
735
+ }
736
+
737
+ // If current column has a group and stays close to its siblings, it stay in the same group
738
+ if(groupLeftCount) {
739
+ if(groupLeftIds[0] === parentId) {
740
+ return;
741
+ }
742
+ }
743
+ if(groupRightCount) {
744
+ if(groupRightIds[0] === parentId) {
745
+ return;
746
+ }
747
+ }
748
+ // The current column is no longer close to its parent
749
+ if(this._groupDefs.unsetParent(colId)) {
750
+ chdr = this._groupDefs.getGroupChildren(parentId);
751
+ childCount = chdr ? chdr.length : 0;
752
+ if(childCount === 1) { // If there is only one child left, move the remaning child to its parent
753
+ let grandParentId = this._groupDefs.getParentId(parentId);
754
+ if(grandParentId) {
755
+ this._groupDefs.addGroupChild(grandParentId, chdr[0]);
756
+ }
757
+ }
758
+ }
759
+ }
760
+
761
+ if(groupLeftCount && groupRightCount) {
762
+ for(let i = 0; i < groupLeftCount; i++) {
763
+ let groupLeftId = groupLeftIds[i];
764
+ let sharedParentIdx = groupRightIds.indexOf(groupLeftId);
765
+ if(sharedParentIdx >= 0) {
766
+ this._groupDefs.addGroupChild(groupRightIds[sharedParentIdx], colId);
767
+ break;
768
+ }
769
+ }
770
+ }
737
771
  };
738
772
  /** @private
739
773
  * @param {Object=} titleSection
740
774
  */
741
775
  ColumnGroupingPlugin.prototype._spanGroupVertically = function (titleSection) {
742
- var api = this.getGridApi();
743
- if (!api) {
744
- return;
745
- }
746
- var core = this._hosts[0];
747
- var maxDepth = this._maxDepth;
748
- var rowCount = maxDepth + 1;
749
- var colCount = api.getColumnCount();
750
- for (var col = 0; col < colCount; col++) {
751
- var toSpan = rowCount;
752
- var parentNode = this._getVisibleParentGroup(this.getColumnId(col));
753
- if (parentNode) {
754
- var depth = parentNode["onRow"] + 1;
755
- toSpan = rowCount - depth;
756
- }
757
-
758
- // Note that invisible column cannot have row span
759
- if (core.isColumnVisible(col) && toSpan > 1) {
760
- titleSection.setCellRowSpan(col, rowCount - toSpan, toSpan);
761
- }
762
- }
776
+ let api = this.getGridApi();
777
+ if(!api) {
778
+ return;
779
+ }
780
+ let core = this._hosts[0];
781
+
782
+ let maxDepth = this._maxDepth;
783
+ let rowCount = maxDepth + 1;
784
+ let colCount = api.getColumnCount();
785
+
786
+ for(let col = 0; col < colCount; col++) {
787
+ let toSpan = rowCount;
788
+ let parentNode = this._getVisibleParentGroup(this.getColumnId(col));
789
+
790
+ if(parentNode) {
791
+ let depth = parentNode["onRow"] + 1;
792
+ toSpan = rowCount - depth;
793
+ }
794
+
795
+ // Note that invisible column cannot have row span
796
+ if(core.isColumnVisible(col) && toSpan > 1) {
797
+ titleSection.setCellRowSpan(col, rowCount - toSpan, toSpan);
798
+ }
799
+ }
763
800
  };
764
801
  /** @private
765
802
  * @param {Object} titleSection
766
803
  */
767
804
  ColumnGroupingPlugin.prototype._spanGroupHorizontally = function (titleSection) {
768
- var section = titleSection;
769
- var visibleGroupMap = this._visibleGroupMap;
770
-
771
- // Span column of column group
772
- var groupDef, spanIndices, len, colIds, index, i;
773
- for (var id in visibleGroupMap) {
774
- spanIndices = [];
775
- groupDef = visibleGroupMap[id];
776
- colIds = GroupDefinitions.getLeafDescendants(visibleGroupMap, id);
777
- var isAllSelected = this._selectedColMap ? true : false;
778
- for (i = 0; i < colIds.length; i++) {
779
- var colId = colIds[i];
780
- index = this._getColumnIndexById(colId);
781
- if (index > -1) {
782
- spanIndices.push(index);
783
- }
784
- if (isAllSelected && this._selectedColMap) {
785
- isAllSelected &= this._selectedColMap[colId];
786
- }
787
- }
788
- spanIndices.sort(ColumnGroupingPlugin._ascSortLogic);
789
- len = spanIndices.length;
790
- if (len > 0) {
791
- // This could be unnecessary
792
- var start = spanIndices[0];
793
- var end = spanIndices[len - 1];
794
- section.setCellColSpan(start, groupDef["onRow"], end - start + 1);
795
- groupDef["colIndex"] = start;
796
- if (isAllSelected) {
797
- var cell = section.getCell(start, groupDef["onRow"]);
798
- cell.addClass("selected-group");
799
- }
800
- }
801
- }
805
+ let section = titleSection;
806
+ let visibleGroupMap = this._visibleGroupMap;
807
+
808
+ // Span column of column group
809
+ let groupDef, spanIndices, len, colIds, index, i;
810
+ for(let id in visibleGroupMap) {
811
+ spanIndices = [];
812
+ groupDef = visibleGroupMap[id];
813
+ colIds = GroupDefinitions.getLeafDescendants(visibleGroupMap, id);
814
+ let isAllSelected = this._selectedColMap ? true : false;
815
+ for(i = 0; i < colIds.length; i++) {
816
+ let colId = colIds[i];
817
+ index = this._getColumnIndexById(colId);
818
+ if(index > -1) {
819
+ spanIndices.push(index);
820
+ }
821
+ if(isAllSelected && this._selectedColMap){
822
+ isAllSelected &= this._selectedColMap[colId];
823
+ }
824
+ }
825
+ spanIndices.sort(ColumnGroupingPlugin._ascSortLogic);
826
+ len = spanIndices.length;
827
+ if(len > 0) { // This could be unnecessary
828
+ let start = spanIndices[0];
829
+ let end = spanIndices[len - 1];
830
+ section.setCellColSpan(start, groupDef["onRow"], end - start + 1);
831
+ groupDef["colIndex"] = start;
832
+
833
+ if(isAllSelected){
834
+ let cell = section.getCell(start, groupDef["onRow"]);
835
+ cell.addClass("selected-group");
836
+ }
837
+ }
838
+ }
802
839
  };
803
840
  /** Render all column group headers without affecting cell spans.
804
841
  * @public
805
842
  */
806
843
  ColumnGroupingPlugin.prototype.renderGroups = function () {
807
- this._groupHeaderTimerId = 0;
808
- var hostCount = this._hosts.length;
809
- var groupMap = this._visibleGroupMap;
810
- for (var _i6 = 0; _i6 < hostCount; ++_i6) {
811
- var section = this._hosts[_i6].getSection("title");
812
- if (!section) {
813
- continue;
814
- }
815
- for (var id in groupMap) {
816
- this._renderGroup(groupMap[id], section);
817
- }
818
- }
844
+ this._groupHeaderTimerId = 0;
845
+ let hostCount = this._hosts.length;
846
+ let groupMap = this._visibleGroupMap;
847
+ for(let i = 0; i < hostCount; ++i) {
848
+ let section = this._hosts[i].getSection("title");
849
+ if(!section) {
850
+ continue;
851
+ }
852
+
853
+ for(let id in groupMap) {
854
+ this._renderGroup(groupMap[id], section);
855
+ }
856
+ }
819
857
  };
820
858
 
821
859
  /** @public
822
860
  * @param {Array<string|number>} colRefs
823
861
  * @return {string} groupId if all the given columns are children of that groupId, otherwise empty string
824
862
  */
825
- ColumnGroupingPlugin.prototype.getMutualGroupId = function (colRefs) {
826
- var colCount = colRefs.length;
827
- for (var _i7 = 0; _i7 < colCount; _i7++) {
828
- if (typeof colRefs[_i7] === "string") {
829
- colRefs[_i7] = this.getColumnIndex(colRefs[_i7]);
830
- }
831
- var colIndex = colRefs[_i7];
832
- var groupIds = this.getGroupIds(colIndex);
833
- if (!groupIds) {
834
- // If at least 1 column is not part of a group, there is no need to find the groupId.
835
- return "";
836
- }
837
- var groupCount = groupIds.length;
838
- for (var j = 0; j < groupCount; j++) {
839
- var groupId = groupIds[j];
840
- var childrenIndices = this.getChildColumnIndices(groupId);
841
- if (deepEqual(childrenIndices, colRefs)) {
842
- return groupId;
843
- }
844
- }
845
- }
846
- return "";
863
+ ColumnGroupingPlugin.prototype.getMutualGroupId = function(colRefs) {
864
+ let colCount = colRefs.length;
865
+ for(let i = 0; i < colCount; i++) {
866
+ if(typeof colRefs[i] === "string") {
867
+ colRefs[i] = this.getColumnIndex(colRefs[i]);
868
+ }
869
+ let colIndex = colRefs[i];
870
+ let groupIds = this.getGroupIds(colIndex);
871
+ if(!groupIds) { // If at least 1 column is not part of a group, there is no need to find the groupId.
872
+ return "";
873
+ }
874
+ let groupCount = groupIds.length;
875
+ for(let j = 0; j < groupCount; j++) {
876
+ let groupId = groupIds[j];
877
+ let childrenIndices = this.getChildColumnIndices(groupId);
878
+ if(deepEqual(childrenIndices, colRefs)) {
879
+ return groupId;
880
+ }
881
+ }
882
+ }
883
+ return "";
847
884
  };
848
885
  /** Render single column group header without affecting cell span.
849
886
  * @private
850
887
  * @param {Object} groupDef
851
888
  * @param {Object} section
852
889
  */
853
- ColumnGroupingPlugin.prototype._renderGroup = function (groupDef, section) {
854
- var colIndex = groupDef["colIndex"];
855
- if (colIndex == null) {
856
- return;
857
- }
858
- var rowIndex = groupDef["onRow"];
859
- var cell = section.getCell(colIndex, rowIndex);
860
- var colIds = GroupDefinitions.getLeafDescendants(this._visibleGroupMap, groupDef["id"]);
861
- var isAllSelected = false;
862
- if (this._selectedColMap) {
863
- isAllSelected = true;
864
- for (var _i8 = 0; _i8 < colIds.length; _i8++) {
865
- if (!this._selectedColMap[colIds[_i8]]) {
866
- isAllSelected = false;
867
- break;
868
- }
869
- }
870
- }
871
- if (cell) {
872
- // Overide the defaults
873
- cell.setStyle("text-align", groupDef["alignment"] || "");
874
- cell.setTooltip(ColumnGroupingPlugin._getTooltip(groupDef));
875
- cell.setContent(groupDef["name"] || groupDef["title"]);
876
-
877
- // Additional cell settings must be removed in the _applyGrouping() method
878
- cell.addClass("no-sort");
879
- cell.setAttribute("group-id", groupDef["id"]);
880
- if (isAllSelected) {
881
- cell.addClass("selected-group");
882
- } else {
883
- cell.removeClass("selected-group");
884
- }
885
- if (groupDef["legacyRender"]) {
886
- // Built-in version if render receive colIndex, cell, groupDefinition as arguments
887
- groupDef["legacyRender"](colIndex, cell, groupDef);
888
- }
889
- if (groupDef["render"]) {
890
- var arg = {};
891
- arg["cell"] = cell;
892
- arg["colIndex"] = colIndex;
893
- arg["groupNode"] = groupDef;
894
- groupDef["render"](arg);
895
- }
896
- }
890
+ ColumnGroupingPlugin.prototype._renderGroup = function(groupDef, section) {
891
+ let colIndex = groupDef["colIndex"];
892
+ if(colIndex == null) {
893
+ return;
894
+ }
895
+ let rowIndex = groupDef["onRow"];
896
+ let cell = section.getCell(colIndex, rowIndex);
897
+ let colIds = GroupDefinitions.getLeafDescendants(this._visibleGroupMap, groupDef["id"]);
898
+ let isAllSelected = false;
899
+ if(this._selectedColMap){
900
+ isAllSelected = true;
901
+ for(let i = 0; i < colIds.length; i++) {
902
+ if(!this._selectedColMap[colIds[i]]){
903
+ isAllSelected = false;
904
+ break;
905
+ }
906
+ }
907
+ }
908
+
909
+ if(cell) {
910
+ // Overide the defaults
911
+ cell.setStyle("text-align", groupDef["alignment"] || "");
912
+ cell.setTooltip(ColumnGroupingPlugin._getTooltip(groupDef));
913
+ cell.setContent(groupDef["name"] || groupDef["title"]);
914
+
915
+ // Additional cell settings must be removed in the _applyGrouping() method
916
+ cell.addClass("no-sort");
917
+ cell.setAttribute("group-id", groupDef["id"]);
918
+
919
+ if(isAllSelected){
920
+ cell.addClass("selected-group");
921
+ } else {
922
+ cell.removeClass("selected-group");
923
+ }
924
+
925
+ if(groupDef["legacyRender"]) {
926
+ // Built-in version if render receive colIndex, cell, groupDefinition as arguments
927
+ groupDef["legacyRender"](colIndex, cell, groupDef);
928
+ }
929
+
930
+ if(groupDef["render"]) {
931
+ let arg = {};
932
+ arg["cell"] = cell;
933
+ arg["colIndex"] = colIndex;
934
+ arg["groupNode"] = groupDef;
935
+ groupDef["render"](arg);
936
+ }
937
+ }
897
938
  };
898
939
 
899
940
  /** @private
900
941
  * @param {Object} e
901
942
  */
902
943
  ColumnGroupingPlugin.prototype._onPostSectionRender = function (e) {
903
- if (e.sectionType === "title" && !this._restructuring) {
904
- this.renderGroups();
905
- }
944
+ if(e.sectionType === "title" && !this._restructuring) {
945
+ this.renderGroups();
946
+ }
906
947
  };
907
948
 
908
949
  /** @private
909
950
  * @param {Object} e dispatching of columnAdded event object
910
951
  */
911
952
  ColumnGroupingPlugin.prototype._requestApplyAddChildGroup = function (e) {
912
- var ctx = e.context;
913
- var tsParentDef = ctx ? ctx.parent : null;
914
- if (tsParentDef) {
915
- this._addingEvents.push(e);
916
- if (!this._addingTimerId) {
917
- this._addingTimerId = setTimeout(this._applyTimeSeries.bind(this, e), 10);
918
- }
919
- }
953
+ let ctx = e.context;
954
+ let tsParentDef = ctx ? ctx.parent : null;
955
+
956
+ if(tsParentDef) {
957
+ this._addingEvents.push(e);
958
+ if(!this._addingTimerId) {
959
+ this._addingTimerId = setTimeout(this._applyTimeSeries.bind(this, e), 10);
960
+ }
961
+ }
920
962
  };
921
963
 
964
+
922
965
  /** @private
923
966
  * @param {Object} e dispatching of columnAdded event object
924
967
  */
925
968
  ColumnGroupingPlugin.prototype._applyTimeSeries = function (e) {
926
- this._addingTimerId = 0; // clear timer
927
- var addingEvents = this._addingEvents;
928
- this._addingEvents = [];
929
- if (addingEvents.length > 0) {
930
- var children = [];
931
- var timeSeriesId, timeSeriesName;
932
- var tsgChild = {};
933
- for (var _i9 = 0; _i9 < addingEvents.length; _i9++) {
934
- // WARNING: addingEvents column can be difference group
935
- var addingEvent = addingEvents[_i9];
936
- timeSeriesName = addingEvent.context.timeSeriesName;
937
- timeSeriesId = addingEvent.context.timeSeriesId;
938
- var childIndex = void 0,
939
- childId = void 0;
940
- if (!tsgChild[timeSeriesId]) {
941
- tsgChild[timeSeriesId] = {
942
- name: timeSeriesName,
943
- children: []
944
- };
945
- childIndex = addingEvent.colIndex;
946
- childId = this.getColumnId(childIndex);
947
- tsgChild[timeSeriesId].children.push(childId);
948
- } else {
949
- childIndex = addingEvent.colIndex;
950
- childId = this.getColumnId(childIndex);
951
- tsgChild[timeSeriesId].children.push(childId);
952
- }
953
- }
954
- for (timeSeriesId in tsgChild) {
955
- var groupId = "timeSerieGroup_" + timeSeriesId;
956
- var groupDef = this._groupDefs.getGroup(groupId);
957
- if (groupDef) {
958
- // add children time series field to parent
959
- for (i = 0; i < children.length; i++) {
960
- this._groupDefs.addGroupChild(groupId, children[i]);
961
- }
962
- } else {
963
- // create new group
964
- this.addGroup({
965
- id: groupId,
966
- title: tsgChild[timeSeriesId].name,
967
- children: tsgChild[timeSeriesId].children,
968
- timeSeriesGroup: true // For remove it when getConfigObject
969
- });
970
- }
971
- }
972
- }
973
-
974
- this._requestApplyGrouping();
969
+ this._addingTimerId = 0; // clear timer
970
+ let addingEvents = this._addingEvents;
971
+ this._addingEvents = [];
972
+ if(addingEvents.length > 0) {
973
+ let children = [];
974
+ let timeSeriesId, timeSeriesName;
975
+ let tsgChild = {};
976
+ for(let i = 0; i < addingEvents.length; i++) { // WARNING: addingEvents column can be difference group
977
+ let addingEvent = addingEvents[i];
978
+ timeSeriesName = addingEvent.context.timeSeriesName;
979
+ timeSeriesId = addingEvent.context.timeSeriesId;
980
+ let childIndex, childId;
981
+ if(!tsgChild[timeSeriesId]) {
982
+ tsgChild[timeSeriesId] = {
983
+ name: timeSeriesName,
984
+ children: []
985
+ };
986
+ childIndex = addingEvent.colIndex;
987
+ childId = this.getColumnId(childIndex);
988
+ tsgChild[timeSeriesId].children.push(childId);
989
+ } else {
990
+ childIndex = addingEvent.colIndex;
991
+ childId = this.getColumnId(childIndex);
992
+ tsgChild[timeSeriesId].children.push(childId);
993
+ }
994
+ }
995
+ for(timeSeriesId in tsgChild) {
996
+ let groupId = "timeSerieGroup_" + timeSeriesId;
997
+ let groupDef = this._groupDefs.getGroup(groupId);
998
+ if(groupDef) {
999
+ // add children time series field to parent
1000
+ for(i = 0; i < children.length; i++) {
1001
+ this._groupDefs.addGroupChild(groupId, children[i]);
1002
+ }
1003
+ } else {
1004
+ // create new group
1005
+ this.addGroup({
1006
+ id: groupId,
1007
+ title: tsgChild[timeSeriesId].name,
1008
+ children: tsgChild[timeSeriesId].children,
1009
+ timeSeriesGroup: true // For remove it when getConfigObject
1010
+ });
1011
+ }
1012
+ }
1013
+ }
1014
+ this._requestApplyGrouping();
975
1015
  };
976
1016
 
977
1017
  /** @private
978
1018
  * @param {Object} e dispatching of columnAdded event object
979
1019
  */
980
1020
  ColumnGroupingPlugin.prototype._onColumnAdded = function (e) {
981
- var batches = e["batches"];
982
- if (!(batches && batches["reset"])) {
983
- this._requestApplyAddChildGroup(e);
984
- this._applyNearestGrouping(e.colIndex);
985
- }
986
- this._requestApplyGrouping();
1021
+ let batches = e["batches"];
1022
+ if(!(batches && batches["reset"])) {
1023
+ this._requestApplyAddChildGroup(e);
1024
+ this._applyNearestGrouping(e.colIndex);
1025
+ }
1026
+
1027
+ this._requestApplyGrouping();
987
1028
  };
988
1029
  /** @private
989
1030
  */
990
1031
  ColumnGroupingPlugin.prototype._onColumnChanged = function () {
991
- this._requestApplyGrouping();
1032
+ this._requestApplyGrouping();
992
1033
  };
993
1034
  /** @private
994
1035
  * @param {Object} e dispatching of columnMoved event object
995
1036
  */
996
1037
  ColumnGroupingPlugin.prototype._onColumnMoved = function (e) {
997
- var batches = e["batches"];
998
- if (!(batches && batches["move"])) {
999
- this._applyNearestGrouping(e.toColIndex);
1000
- }
1001
- this._requestApplyGrouping();
1038
+ let batches = e["batches"];
1039
+ if(!(batches && batches["move"])) {
1040
+ this._applyNearestGrouping(e.toColIndex);
1041
+ }
1042
+ this._requestApplyGrouping();
1002
1043
  };
1003
1044
  /** @private
1004
1045
  * @param {Object} e
1005
1046
  */
1006
- ColumnGroupingPlugin.prototype._onColumnRemoved = function (e) {
1007
- var batches = e["batches"];
1008
- if (!(batches && batches["reset"])) {
1009
- var colId = e.colId;
1010
- if (colId) {
1011
- if (this._groupDefs.unsetParent(colId)) {
1012
- this._requestApplyGrouping();
1013
- }
1014
- }
1015
- } else {
1016
- this._requestApplyGrouping();
1017
- }
1047
+ ColumnGroupingPlugin.prototype._onColumnRemoved = function(e) {
1048
+ let batches = e["batches"];
1049
+ if(!(batches && batches["reset"])) {
1050
+ let colId = e.colId;
1051
+ if(colId) {
1052
+ if(this._groupDefs.unsetParent(colId)) {
1053
+ this._requestApplyGrouping();
1054
+ }
1055
+ }
1056
+ } else {
1057
+ this._requestApplyGrouping();
1058
+ }
1018
1059
  };
1019
1060
  /** @private
1020
1061
  * @param {Object} e
1021
1062
  */
1022
- ColumnGroupingPlugin.prototype._onBeforeColumnBoundUpdate = function (e) {
1023
- var selectedColumns = e.selectedColumns; // Hidden columns are included
1024
-
1025
- // Find non-grouped column
1026
- var i, colId, nonGroupedColId, groupId;
1027
- var colIds = [];
1028
- var groupMap = {};
1029
- for (i = 0; i < selectedColumns.length; i++) {
1030
- colId = this.getColumnId(selectedColumns[i]);
1031
- if (colId) {
1032
- groupId = this._groupDefs.getParentId(colId);
1033
- if (!groupId) {
1034
- nonGroupedColId = colId;
1035
- break;
1036
- } else {
1037
- groupMap[groupId] = this._groupDefs.getGroup(groupId); // Cache group node for further calculation
1038
- }
1039
-
1040
- colIds.push(colId); // Cache column id for further calculation
1041
- }
1042
- }
1043
-
1044
- if (nonGroupedColId) {
1045
- e.topBoundRowIndex = 0;
1046
- return;
1047
- }
1048
- var topBoundRowIndex = this._maxDepth; // Column title row
1049
-
1050
- // Find minimum row index of group
1051
- var rootGroupMap = {};
1052
- var headerRowIndex, group;
1053
- for (groupId in groupMap) {
1054
- group = this._groupDefs.getRootGroup(groupId);
1055
- rootGroupMap[group.id] = group;
1056
- headerRowIndex = groupMap[groupId].onRow + 1;
1057
- if (headerRowIndex < topBoundRowIndex) {
1058
- topBoundRowIndex = headerRowIndex;
1059
- }
1060
- }
1061
-
1062
- // Traverse down from the root group to find group that its all members are selected
1063
- var n, members, allSelected, findingGroup, children;
1064
- var nextLevelGroups = rootGroupMap;
1065
- for (i = 0; i < topBoundRowIndex; i++) {
1066
- findingGroup = nextLevelGroups;
1067
- nextLevelGroups = {};
1068
- for (groupId in findingGroup) {
1069
- group = findingGroup[groupId];
1070
- allSelected = true;
1071
- members = this._groupDefs.getLeafDescendants(groupId);
1072
- if (members.length <= colIds.length) {
1073
- for (n = 0; n < members.length; n++) {
1074
- if (colIds.indexOf(members[n]) < 0) {
1075
- allSelected = false;
1076
- break;
1077
- }
1078
- }
1079
- if (allSelected) {
1080
- e.topBoundRowIndex = i;
1081
- return;
1082
- }
1083
- }
1084
-
1085
- // Cache the next level group
1086
- children = group.children;
1087
- for (n = 0; n < children.length; n++) {
1088
- var id = children[n];
1089
- group = this._groupDefs.getGroup(id);
1090
- if (group) {
1091
- nextLevelGroups[id] = group;
1092
- }
1093
- }
1094
- }
1095
- }
1096
-
1097
- // Find maximum spanned row count
1098
- var section = this._hosts[0].getSection("title");
1099
- var minRowSpanCount = 0;
1100
- var bottomRowIndex = this._maxDepth;
1101
- for (i = 0; i < selectedColumns.length; i++) {
1102
- var rowSpanCount = section.getCellRowSpan(selectedColumns[i], bottomRowIndex);
1103
- if (rowSpanCount < minRowSpanCount) {
1104
- minRowSpanCount = rowSpanCount;
1105
- }
1106
- }
1107
- e.topBoundRowIndex = bottomRowIndex + minRowSpanCount;
1063
+ ColumnGroupingPlugin.prototype._onBeforeColumnBoundUpdate = function(e) {
1064
+ let selectedColumns = e.selectedColumns; // Hidden columns are included
1065
+
1066
+ // Find non-grouped column
1067
+ let i, colId, nonGroupedColId, groupId;
1068
+ let colIds = [];
1069
+ let groupMap = {};
1070
+ for(i = 0; i < selectedColumns.length; i++) {
1071
+ colId = this.getColumnId(selectedColumns[i]);
1072
+ if(colId) {
1073
+ groupId = this._groupDefs.getParentId(colId);
1074
+ if(!groupId) {
1075
+ nonGroupedColId = colId;
1076
+ break;
1077
+ } else {
1078
+ groupMap[groupId] = this._groupDefs.getGroup(groupId); // Cache group node for further calculation
1079
+ }
1080
+ colIds.push(colId); // Cache column id for further calculation
1081
+ }
1082
+ }
1083
+ if(nonGroupedColId) {
1084
+ e.topBoundRowIndex = 0;
1085
+ return;
1086
+ }
1087
+
1088
+ let topBoundRowIndex = this._maxDepth; // Column title row
1089
+
1090
+ // Find minimum row index of group
1091
+ let rootGroupMap = {};
1092
+ let headerRowIndex, group;
1093
+ for(groupId in groupMap) {
1094
+ group = this._groupDefs.getRootGroup(groupId);
1095
+ rootGroupMap[group.id] = group;
1096
+ headerRowIndex = groupMap[groupId].onRow + 1;
1097
+ if(headerRowIndex < topBoundRowIndex) {
1098
+ topBoundRowIndex = headerRowIndex;
1099
+ }
1100
+ }
1101
+
1102
+ // Traverse down from the root group to find group that its all members are selected
1103
+ let n, members, allSelected, findingGroup, children;
1104
+ let nextLevelGroups = rootGroupMap;
1105
+ for(i = 0; i < topBoundRowIndex; i++) {
1106
+ findingGroup = nextLevelGroups;
1107
+ nextLevelGroups = {};
1108
+ for(groupId in findingGroup) {
1109
+ group = findingGroup[groupId];
1110
+ allSelected = true;
1111
+ members = this._groupDefs.getLeafDescendants(groupId);
1112
+ if(members.length <= colIds.length) {
1113
+ for(n = 0; n < members.length; n++) {
1114
+ if(colIds.indexOf(members[n]) < 0) {
1115
+ allSelected = false;
1116
+ break;
1117
+ }
1118
+ }
1119
+ if(allSelected) {
1120
+ e.topBoundRowIndex = i;
1121
+ return;
1122
+ }
1123
+ }
1124
+
1125
+ // Cache the next level group
1126
+ children = group.children;
1127
+ for(n = 0; n < children.length; n++) {
1128
+ let id = children[n];
1129
+ group = this._groupDefs.getGroup(id);
1130
+ if(group) {
1131
+ nextLevelGroups[id] = group;
1132
+ }
1133
+ }
1134
+ }
1135
+ }
1136
+
1137
+ // Find maximum spanned row count
1138
+ let section = this._hosts[0].getSection("title");
1139
+ let minRowSpanCount = 0;
1140
+ let bottomRowIndex = this._maxDepth;
1141
+ for (i = 0; i < selectedColumns.length; i++) {
1142
+ let rowSpanCount = section.getCellRowSpan(selectedColumns[i], bottomRowIndex);
1143
+ if(rowSpanCount < minRowSpanCount) {
1144
+ minRowSpanCount = rowSpanCount;
1145
+ }
1146
+ }
1147
+
1148
+ e.topBoundRowIndex = bottomRowIndex + minRowSpanCount;
1149
+ };
1150
+ /** @private
1151
+ * @param {String} groupId
1152
+ * @return {boolean}
1153
+ */
1154
+ ColumnGroupingPlugin.prototype._isChildSelected = function(groupId) {
1155
+ let childIndices = this.getChildColumnIndices(groupId);
1156
+ if(childIndices && childIndices.length) {
1157
+ let host = this._hosts[0];
1158
+ for(let i = 0; i < childIndices.length; i++) {
1159
+ if(host.isSelectedColumn(childIndices[i])) {
1160
+ return true;
1161
+ }
1162
+ }
1163
+ }
1164
+ return false;
1165
+ };
1166
+ /** @private
1167
+ */
1168
+ ColumnGroupingPlugin.prototype._updateColumnBounds = function() {
1169
+ let hosts = this._hosts;
1170
+ for(let i = 0; i < hosts.length; i++) {
1171
+ let host = hosts[i];
1172
+ if(host.updateColumnBounds) { // Keep backward compatibility
1173
+ host.updateColumnBounds();
1174
+ }
1175
+ }
1108
1176
  };
1109
1177
  /** Deprecated. Column should be directly added through grid APIs.
1110
1178
  * @deprecated
@@ -1114,24 +1182,26 @@ ColumnGroupingPlugin.prototype._onBeforeColumnBoundUpdate = function (e) {
1114
1182
  * @param {number} colIndex Column index
1115
1183
  */
1116
1184
  ColumnGroupingPlugin.prototype.addColumnToGroup = function (column, groupId, colIndex) {
1117
- if (!column) return;
1118
- var destIndex = this.getColumnCount();
1119
- if (colIndex != null) {
1120
- var groupDef = this._groupDefs.getGroup(groupId);
1121
- if (groupDef) {
1122
- this._groupDefs.addGroupChild(groupId, column.id);
1123
- }
1124
- destIndex = colIndex;
1125
- }
1126
- if (this._realTimeGrid) {
1127
- // TODO: Support multi-table feature
1128
- this._realTimeGrid.insertColumn(column, destIndex);
1129
- } else if (this._compositeGrid) {
1130
- this._compositeGrid.insertColumn(destIndex, column);
1131
- }
1132
- if (colIndex == null) {
1133
- this.setColumnParent(column.id || destColIndex, groupId);
1134
- }
1185
+ if(!column) return;
1186
+
1187
+ let destIndex = this.getColumnCount();
1188
+ if(colIndex != null) {
1189
+ let groupDef = this._groupDefs.getGroup(groupId);
1190
+ if(groupDef) {
1191
+ this._groupDefs.addGroupChild(groupId, column.id);
1192
+ }
1193
+ destIndex = colIndex;
1194
+ }
1195
+
1196
+ if(this._realTimeGrid) { // TODO: Support multi-table feature
1197
+ this._realTimeGrid.insertColumn(column, destIndex);
1198
+ } else if(this._compositeGrid) {
1199
+ this._compositeGrid.insertColumn(destIndex, column);
1200
+ }
1201
+
1202
+ if(colIndex == null) {
1203
+ this.setColumnParent(column.id || destColIndex, groupId);
1204
+ }
1135
1205
  };
1136
1206
 
1137
1207
  /** Add new group definition to existing group structure. Existing group with the same id will be replaced.
@@ -1140,10 +1210,10 @@ ColumnGroupingPlugin.prototype.addColumnToGroup = function (column, groupId, col
1140
1210
  * @return {string} Return group ID
1141
1211
  */
1142
1212
  ColumnGroupingPlugin.prototype.addGroup = function (groupDef) {
1143
- if (ColumnGroupingPlugin._hasGroupId(groupDef)) {
1144
- return this.setGroupDefinition(groupDef.id, groupDef);
1145
- }
1146
- return "";
1213
+ if(ColumnGroupingPlugin._hasGroupId(groupDef)) {
1214
+ return this.setGroupDefinition(groupDef.id, groupDef);
1215
+ }
1216
+ return "";
1147
1217
  };
1148
1218
  /** Deprecated. Use addGroup() method instead
1149
1219
  * @deprecated
@@ -1158,11 +1228,15 @@ ColumnGroupingPlugin.prototype.addColumnGrouping = ColumnGroupingPlugin.prototyp
1158
1228
  * @return {boolean}
1159
1229
  */
1160
1230
  ColumnGroupingPlugin.prototype.removeGroup = function (groupId) {
1161
- if (this._groupDefs.removeGroup(groupId)) {
1162
- this._applyGrouping();
1163
- return true;
1164
- }
1165
- return false;
1231
+ let isChildSelected = this._isChildSelected(groupId);
1232
+ if(this._groupDefs.removeGroup(groupId)) {
1233
+ this._applyGrouping();
1234
+ if(isChildSelected) {
1235
+ this._updateColumnBounds();
1236
+ }
1237
+ return true;
1238
+ }
1239
+ return false;
1166
1240
  };
1167
1241
 
1168
1242
  /** @public
@@ -1170,30 +1244,31 @@ ColumnGroupingPlugin.prototype.removeGroup = function (groupId) {
1170
1244
  * @return {ColumnGroupingPlugin~GroupDefinition}
1171
1245
  */
1172
1246
  ColumnGroupingPlugin.prototype.getGroupDefinition = function (groupId) {
1173
- var chdr = this._getAvaliableChildren(groupId);
1174
- if (chdr.length > 1) {
1175
- var groupDef = this._groupDefs.getGroup(groupId);
1176
- groupDef = ColumnGroupingPlugin._cloneObject(groupDef); // TODO: this is slow
1177
- groupDef.children = chdr;
1178
- return groupDef;
1179
- }
1180
- return null;
1247
+ let chdr = this._getAvaliableChildren(groupId);
1248
+ if(chdr.length > 1) {
1249
+ let groupDef = this._groupDefs.getGroup(groupId);
1250
+ groupDef = ColumnGroupingPlugin._cloneObject(groupDef); // TODO: this is slow
1251
+ groupDef.children = chdr;
1252
+ return groupDef;
1253
+ }
1254
+ return null;
1181
1255
  };
1182
1256
  /** Get a shallow copy of all existing group definitions
1183
1257
  * @public
1184
1258
  * @return {!ColumnGroupingPlugin~GroupDefinitions}
1185
1259
  */
1186
1260
  ColumnGroupingPlugin.prototype.getGroupDefinitions = function () {
1187
- var validGroupDefs = [];
1188
- var groupMap = this._groupDefs.getGroupMap();
1189
- for (var grpId in groupMap) {
1190
- var groupDef = this.getGroupDefinition(grpId); // Clone
1191
- if (groupDef) {
1192
- delete groupDef.parentId;
1193
- validGroupDefs.push(groupDef);
1194
- }
1195
- }
1196
- return validGroupDefs;
1261
+ let validGroupDefs = [];
1262
+ let groupMap = this._groupDefs.getGroupMap();
1263
+ for(let grpId in groupMap) {
1264
+ let groupDef = this.getGroupDefinition(grpId); // Clone
1265
+ if(groupDef) {
1266
+ delete groupDef.parentId;
1267
+ validGroupDefs.push(groupDef);
1268
+ }
1269
+ }
1270
+
1271
+ return validGroupDefs;
1197
1272
  };
1198
1273
  /** Replace and update existing group definition. New group is added if the given id has no match. Existing group will be removed of no new definition is given.
1199
1274
  * @public
@@ -1202,35 +1277,47 @@ ColumnGroupingPlugin.prototype.getGroupDefinitions = function () {
1202
1277
  * @return {string} Return group Id. Return empty string if nothing has been changed.
1203
1278
  */
1204
1279
  ColumnGroupingPlugin.prototype.setGroupDefinition = function (groupId, groupDef) {
1205
- if (this._groupDefs.setGroup(groupId, groupDef)) {
1206
- var newDef = this._groupDefs.getGroup(groupId);
1207
- if (newDef) {
1208
- var host = this._hosts[0];
1209
- var chdr = host.getValidColumnList(newDef.children).map(ColumnGroupingPlugin.getObjectId); //this return only valid columns without group
1210
- var len = chdr.length;
1211
- if (len > 1) {
1212
- this.reorderColumns(chdr, chdr[0]);
1213
- }
1214
- }
1215
- this._applyGrouping();
1216
- return groupId;
1217
- }
1218
- return "";
1280
+ if(this._groupDefs.setGroup(groupId, groupDef)) {
1281
+ let newDef = this._groupDefs.getGroup(groupId);
1282
+ if(newDef) {
1283
+ let host = this._hosts[0];
1284
+ let chdr = host.getValidColumnList(newDef.children).map(ColumnGroupingPlugin.getObjectId); //this return only valid columns without group
1285
+ let len = chdr.length;
1286
+ if(len > 1) {
1287
+ this.reorderColumns(chdr, chdr[0]);
1288
+ }
1289
+ }
1290
+ this._applyGrouping();
1291
+ if(this._isChildSelected(groupId)) {
1292
+ this._updateColumnBounds();
1293
+ }
1294
+ return groupId;
1295
+ }
1296
+ return "";
1219
1297
  };
1220
1298
  /** Remove all existing group definitions and replace with the given definitions.
1221
1299
  * @public
1222
1300
  * @param {ColumnGroupingPlugin~GroupDefinitions} groupDefs Use null or empty array to remove all existing groups
1223
1301
  */
1224
1302
  ColumnGroupingPlugin.prototype.setGroupDefinitions = function (groupDefs) {
1225
- if (Array.isArray(groupDefs)) {
1226
- groupDefs = groupDefs.filter(ColumnGroupingPlugin._hasGroupId);
1227
- groupDefs = groupDefs.map(ColumnGroupingPlugin._cloneObject);
1228
- } else {
1229
- groupDefs = null;
1230
- }
1231
- ColumnGroupingPlugin._flattenGroupDefs(groupDefs);
1232
- this._groupDefs.setGroups(groupDefs);
1233
- this._applyGrouping();
1303
+ if(Array.isArray(groupDefs)) {
1304
+ groupDefs = groupDefs.filter(ColumnGroupingPlugin._hasGroupId);
1305
+ groupDefs = groupDefs.map(ColumnGroupingPlugin._cloneObject);
1306
+ } else {
1307
+ groupDefs = null;
1308
+ }
1309
+ ColumnGroupingPlugin._flattenGroupDefs(groupDefs);
1310
+ this._groupDefs.setGroups(groupDefs);
1311
+ this._applyGrouping();
1312
+
1313
+ let groupIds = this._groupDefs.getGroupIds();
1314
+ for(let i = 0; i < groupIds.length; i++) {
1315
+ if(this._isChildSelected(groupIds[i])) {
1316
+ this._updateColumnBounds();
1317
+ break;
1318
+ }
1319
+ }
1320
+ this._updateColumnBounds();
1234
1321
  };
1235
1322
  /** Replace and update existing group definition.
1236
1323
  * @public
@@ -1239,53 +1326,58 @@ ColumnGroupingPlugin.prototype.setGroupDefinitions = function (groupDefs) {
1239
1326
  * @return {boolean}
1240
1327
  */
1241
1328
  ColumnGroupingPlugin.prototype.setGroupChildren = function (groupId, newChildList) {
1242
- if (this._groupDefs.setGroupChildren(groupId, newChildList)) {
1243
- this._applyGrouping();
1244
- return true;
1245
- }
1246
- return false;
1329
+ if(this._groupDefs.setGroupChildren(groupId, newChildList)) {
1330
+ this._applyGrouping();
1331
+ if(this._isChildSelected(groupId)) {
1332
+ this._updateColumnBounds();
1333
+ }
1334
+ return true;
1335
+ }
1336
+ return false;
1247
1337
  };
1248
1338
  /** @public
1249
1339
  * @param {string} groupId
1250
1340
  * @param {string} groupName
1251
1341
  */
1252
1342
  ColumnGroupingPlugin.prototype.setGroupName = function (groupId, groupName) {
1253
- if (this._groupDefs.setGroupName(groupId, groupName)) {
1254
- var groupDef = this._visibleGroupMap[groupId];
1255
- if (groupDef) {
1256
- groupDef.name = groupName;
1257
- var hostCount = this._hosts.length;
1258
- for (var _i10 = 0; _i10 < hostCount; ++_i10) {
1259
- var section = this._hosts[_i10].getSection("title");
1260
- if (!section) {
1261
- continue;
1262
- }
1263
- this._renderGroup(groupDef, section);
1264
- }
1265
- }
1266
- }
1343
+ if(this._groupDefs.setGroupName(groupId, groupName)) {
1344
+ let groupDef = this._visibleGroupMap[groupId];
1345
+ if(groupDef) {
1346
+ groupDef.name = groupName;
1347
+
1348
+ let hostCount = this._hosts.length;
1349
+ for(let i = 0; i < hostCount; ++i) {
1350
+ let section = this._hosts[i].getSection("title");
1351
+ if(!section) {
1352
+ continue;
1353
+ }
1354
+
1355
+ this._renderGroup(groupDef, section);
1356
+ }
1357
+ }
1358
+ }
1267
1359
  };
1268
1360
  /** @private
1269
1361
  * @param {string} groupId
1270
1362
  * @return {!Array.<string>} The list of immediate valid child, including invisible child groups
1271
1363
  */
1272
1364
  ColumnGroupingPlugin.prototype._getAvaliableChildren = function (groupId) {
1273
- var chdr = this._groupDefs.getGroupChildren(groupId);
1274
- var childCount = chdr ? chdr.length : 0;
1275
- var validChildren = [];
1276
- if (childCount) {
1277
- var host = this._hosts[0];
1278
- var validCols = host.getValidColumnList(chdr);
1279
- validChildren = validCols.map(ColumnGroupingPlugin.getObjectId);
1280
- var groupMap = this._groupDefs.getGroupMap();
1281
- for (var _i11 = 0; _i11 < childCount; _i11++) {
1282
- var childId = chdr[_i11];
1283
- if (groupMap[childId]) {
1284
- validChildren.push(childId);
1285
- }
1286
- }
1287
- }
1288
- return validChildren;
1365
+ let chdr = this._groupDefs.getGroupChildren(groupId);
1366
+ let childCount = chdr ? chdr.length : 0;
1367
+ let validChildren = [];
1368
+ if(childCount) {
1369
+ let host = this._hosts[0];
1370
+ let validCols = host.getValidColumnList(chdr);
1371
+ validChildren = validCols.map(ColumnGroupingPlugin.getObjectId);
1372
+ let groupMap = this._groupDefs.getGroupMap();
1373
+ for(let i = 0; i < childCount; i++) {
1374
+ let childId = chdr[i];
1375
+ if(groupMap[childId]) {
1376
+ validChildren.push(childId);
1377
+ }
1378
+ }
1379
+ }
1380
+ return validChildren;
1289
1381
  };
1290
1382
 
1291
1383
  /** @public
@@ -1293,11 +1385,11 @@ ColumnGroupingPlugin.prototype._getAvaliableChildren = function (groupId) {
1293
1385
  * @return {Array.<string>}
1294
1386
  */
1295
1387
  ColumnGroupingPlugin.prototype.getGroupChildren = function (groupId) {
1296
- var children = this._getAvaliableChildren(groupId);
1297
- if (children.length > 1) {
1298
- return children;
1299
- }
1300
- return null;
1388
+ let children = this._getAvaliableChildren(groupId);
1389
+ if(children.length > 1) {
1390
+ return children;
1391
+ }
1392
+ return null;
1301
1393
  };
1302
1394
 
1303
1395
  /** Return all column indices under the given group id
@@ -1305,36 +1397,36 @@ ColumnGroupingPlugin.prototype.getGroupChildren = function (groupId) {
1305
1397
  * @param {string} groupId
1306
1398
  * @return {Array.<number>}
1307
1399
  */
1308
- ColumnGroupingPlugin.prototype.getChildColumnIndices = function (groupId) {
1309
- var colIndices = [];
1310
- var host = this._hosts[0];
1311
- var colIds = this._groupDefs.getLeafDescendants(groupId);
1312
- if (colIds) {
1313
- var validColList = host.getValidColumnList(colIds);
1314
- colIndices = validColList.map(ColumnGroupingPlugin.getObjectIndex);
1315
- return colIndices;
1316
- }
1317
- return null;
1400
+ ColumnGroupingPlugin.prototype.getChildColumnIndices = function(groupId) {
1401
+ let colIndices = [];
1402
+ let host = this._hosts[0];
1403
+ let colIds = this._groupDefs.getLeafDescendants(groupId);
1404
+ if(colIds) {
1405
+ let validColList = host.getValidColumnList(colIds);
1406
+ colIndices = validColList.map(ColumnGroupingPlugin.getObjectIndex);
1407
+ return colIndices;
1408
+ }
1409
+ return null;
1318
1410
  };
1319
1411
 
1320
1412
  /** @public
1321
1413
  * @param {string|number} colRef
1322
1414
  * @return {Array.<string>}
1323
1415
  */
1324
- ColumnGroupingPlugin.prototype.getGroupIds = function (colRef) {
1325
- if (colRef == null) {
1326
- return null;
1327
- }
1328
- var colId = typeof colRef === "number" ? this.getColumnId(colRef) : colRef;
1329
- return this._groupDefs.getParentIds(colId);
1416
+ ColumnGroupingPlugin.prototype.getGroupIds = function(colRef) {
1417
+ if(colRef == null) {
1418
+ return null;
1419
+ }
1420
+ let colId = (typeof colRef === "number") ? this.getColumnId(colRef) : colRef;
1421
+ return this._groupDefs.getParentIds(colId);
1330
1422
  };
1331
1423
 
1332
1424
  /** Return deepest row index of column headers
1333
1425
  * @public
1334
1426
  * @return {number}
1335
1427
  */
1336
- ColumnGroupingPlugin.prototype.getMaxGroupLevel = function () {
1337
- return this._maxDepth;
1428
+ ColumnGroupingPlugin.prototype.getMaxGroupLevel = function() {
1429
+ return this._maxDepth;
1338
1430
  };
1339
1431
 
1340
1432
  /** Return row index of the given group id
@@ -1342,12 +1434,12 @@ ColumnGroupingPlugin.prototype.getMaxGroupLevel = function () {
1342
1434
  * @param {string} groupId
1343
1435
  * @return {number}
1344
1436
  */
1345
- ColumnGroupingPlugin.prototype.getGroupLevel = function (groupId) {
1346
- var group = this._visibleGroupMap[groupId];
1347
- if (group) {
1348
- return group.onRow;
1349
- }
1350
- return -1;
1437
+ ColumnGroupingPlugin.prototype.getGroupLevel = function(groupId) {
1438
+ let group = this._visibleGroupMap[groupId];
1439
+ if(group) {
1440
+ return group.onRow;
1441
+ }
1442
+ return -1;
1351
1443
  };
1352
1444
 
1353
1445
  /** This version exclude invisible column unlike the one in GridPlugin
@@ -1356,135 +1448,150 @@ ColumnGroupingPlugin.prototype.getGroupLevel = function (groupId) {
1356
1448
  * @return {number} index of the column
1357
1449
  */
1358
1450
  ColumnGroupingPlugin.prototype._getColumnIndexById = function (id) {
1359
- var api = this.getGridApi();
1360
- if (api && id) {
1361
- var core = this._hosts[0];
1362
- var colCount = core.getColumnCount();
1363
- for (var c = 0; c < colCount; c++) {
1364
- if (this.getColumnId(c) === id && core.isColumnVisible(c)) {
1365
- return c;
1366
- }
1367
- }
1368
- }
1369
- return -1;
1451
+ let api = this.getGridApi();
1452
+ if(api && id) {
1453
+ let core = this._hosts[0];
1454
+ let colCount = core.getColumnCount();
1455
+ for(let c = 0; c < colCount; c++) {
1456
+ if(this.getColumnId(c) === id && core.isColumnVisible(c)) {
1457
+ return c;
1458
+ }
1459
+ }
1460
+ }
1461
+ return -1;
1370
1462
  };
1371
1463
  /** @private
1372
1464
  * @param {string} childId
1373
1465
  * @return {ColumnGroupingPlugin~GroupDefinition}
1374
1466
  */
1375
1467
  ColumnGroupingPlugin.prototype._getVisibleParentGroup = function (childId) {
1376
- return this._visibleGroupMap[this._groupDefs.getParentId(childId)] || null;
1468
+ return this._visibleGroupMap[this._groupDefs.getParentId(childId)] || null;
1377
1469
  };
1378
1470
  /** @public
1379
1471
  * @param {Element|Event|MouseEvent} e
1380
1472
  * @return {Object}
1381
1473
  */
1382
- ColumnGroupingPlugin.prototype.getCellInfo = function (e) {
1383
- var api = this.getGridApi();
1384
- var grid = e["grid"] || this.getRelativeGrid(e);
1385
- if (!api || !grid) {
1386
- return null;
1387
- }
1388
- var cellInfo = grid.getCellInfo(e);
1389
- if (!cellInfo) {
1390
- return e;
1391
- }
1392
- if (!cellInfo["cell"]) {
1393
- var cell = cellInfo.section.getCell(cellInfo.colIndex, cellInfo.rowIndex);
1394
- cellInfo["cell"] = cell;
1395
- }
1396
- var colId = this.getColumnId(cellInfo.colIndex);
1397
- var groupId = this._groupDefs.getParentId(colId, cellInfo.sectionType == "title" ? cellInfo.rowIndex : null);
1398
- if (!groupId) {
1399
- cellInfo["columnId"] = colId;
1400
- return cellInfo;
1401
- }
1402
- var groupInfo = this._groupDefs.getGroup(groupId); // TODO: Check if we need visible group
1403
- if (groupInfo) {
1404
- var isGroupHeader = cellInfo.sectionType == "title" && cellInfo.rowIndex == this.getGroupLevel(groupId);
1405
- if (isGroupHeader) {
1406
- cellInfo["groupId"] = groupInfo.id;
1407
- cellInfo["groupName"] = groupInfo.name || "";
1408
- cellInfo["children"] = groupInfo.children;
1409
- } else {
1410
- cellInfo["columnId"] = colId;
1411
- }
1412
- cellInfo["parent"] = isGroupHeader ? groupInfo.parentId || null : groupInfo.id;
1413
- }
1414
- return cellInfo;
1474
+ ColumnGroupingPlugin.prototype.getCellInfo = function(e) {
1475
+ let api = this.getGridApi();
1476
+ let grid = e["grid"] || this.getRelativeGrid(e);
1477
+ if(!api || !grid) {
1478
+ return null;
1479
+ }
1480
+
1481
+ let cellInfo = grid.getCellInfo(e);
1482
+ if(!cellInfo){
1483
+ return e;
1484
+ }
1485
+
1486
+ if(!cellInfo["cell"]){
1487
+ let cell = cellInfo.section.getCell(cellInfo.colIndex, cellInfo.rowIndex);
1488
+ cellInfo["cell"] = cell;
1489
+ }
1490
+
1491
+ let colId = this.getColumnId(cellInfo.colIndex);
1492
+ let groupId = this._groupDefs.getParentId(colId, cellInfo.sectionType == "title" ? cellInfo.rowIndex : null);
1493
+ if(!groupId){
1494
+ cellInfo["columnId"] = colId;
1495
+ return cellInfo;
1496
+ }
1497
+
1498
+ let groupInfo = this._groupDefs.getGroup(groupId); // TODO: Check if we need visible group
1499
+ if(groupInfo) {
1500
+ let isGroupHeader = cellInfo.sectionType == "title" && cellInfo.rowIndex == this.getGroupLevel(groupId);
1501
+ if(isGroupHeader){
1502
+ cellInfo["groupId"] = groupInfo.id;
1503
+ cellInfo["groupName"] = groupInfo.name || "";
1504
+ cellInfo["children"] = groupInfo.children;
1505
+ } else {
1506
+ cellInfo["columnId"] = colId;
1507
+ }
1508
+ cellInfo["parent"] = isGroupHeader ? groupInfo.parentId || null : groupInfo.id;
1509
+ }
1510
+
1511
+ return cellInfo;
1415
1512
  };
1416
1513
  /** @public
1417
1514
  * @param {number|string} colRef Column index or id that should be moved
1418
1515
  * @param {number} to
1419
1516
  * @param {string} groupId
1420
1517
  */
1421
- ColumnGroupingPlugin.prototype.moveColumnIntoGroup = function (colRef, to, groupId) {
1422
- var fromIndex = this.getColumnIndex(colRef);
1423
- if (fromIndex == -1) {
1424
- return;
1425
- }
1426
- var groupDef = this._groupDefs.getGroup(groupId);
1427
- if (!groupDef) {
1428
- for (var j = this._hosts.length; --j >= 0;) {
1429
- var grid = this._hosts[j];
1430
- grid.moveColumn(fromIndex, to);
1431
- }
1432
- return;
1433
- }
1434
- var childIndices = this.getChildColumnIndices(groupId);
1435
- var startIndex = -1;
1436
- var endIndex = -1;
1437
- if (childIndices && childIndices.length) {
1438
- startIndex = childIndices[0];
1439
- endIndex = childIndices[childIndices.length - 1];
1440
- } else {
1441
- startIndex = 0;
1442
- endIndex = this.getColumnCount();
1443
- }
1444
- if (to < startIndex) {
1445
- to = startIndex;
1446
- // handle move column to right
1447
- if (to > fromIndex) {
1448
- to -= 1;
1449
- }
1450
- } else if (to > endIndex) {
1451
- to = endIndex;
1452
- // handle move column to left
1453
- if (to < fromIndex) {
1454
- to += 1;
1455
- }
1456
- }
1457
-
1458
- // Calculate left and right bound of the group, which column can be moved to.
1459
- // destination should be between the bound, and it should not be placed between columns in child group
1460
- for (var _i12 = 0; _i12 < groupDef.children.length; _i12++) {
1461
- var notAllowIndices = this.getChildColumnIndices(groupDef.children[_i12]);
1462
- if (notAllowIndices && notAllowIndices.length) {
1463
- var leftLimit = notAllowIndices[0];
1464
- var rightLimit = notAllowIndices[notAllowIndices.length - 1];
1465
- if (to > fromIndex) {
1466
- leftLimit -= 1;
1467
- }
1468
- if (to < fromIndex) {
1469
- rightLimit += 1;
1470
- }
1471
- if (to > leftLimit && to < rightLimit) {
1472
- to = rightLimit;
1473
- }
1474
- }
1475
- }
1476
-
1477
- // Get column id before start moving
1478
- var colId = this.getColumnId(fromIndex);
1479
- for (var gridIndex = this._hosts.length; --gridIndex >= 0;) {
1480
- var host = this._hosts[gridIndex];
1481
- host.moveColumn(fromIndex, to);
1482
- }
1483
- if (colId) {
1484
- if (this._groupDefs.addGroupChild(groupId, colId)) {
1485
- this._applyGrouping();
1486
- }
1487
- }
1518
+ ColumnGroupingPlugin.prototype.moveColumnIntoGroup = function(colRef, to, groupId) {
1519
+ let fromIndex = this.getColumnIndex(colRef);
1520
+ if(fromIndex == -1){
1521
+ return;
1522
+ }
1523
+
1524
+ let groupDef = this._groupDefs.getGroup(groupId);
1525
+ if(!groupDef){
1526
+ for(let j = this._hosts.length; --j >= 0;) {
1527
+ let grid = this._hosts[j];
1528
+ grid.moveColumn(fromIndex, to);
1529
+ }
1530
+ return;
1531
+ }
1532
+
1533
+ let childIndices = this.getChildColumnIndices(groupId);
1534
+ let startIndex = -1;
1535
+ let endIndex = -1;
1536
+
1537
+ if(childIndices && childIndices.length){
1538
+ startIndex = childIndices[0];
1539
+ endIndex = childIndices[childIndices.length - 1];
1540
+ } else {
1541
+ startIndex = 0;
1542
+ endIndex = this.getColumnCount();
1543
+ }
1544
+
1545
+ if(to < startIndex){
1546
+ to = startIndex;
1547
+ // handle move column to right
1548
+ if(to > fromIndex){
1549
+ to -= 1;
1550
+ }
1551
+ } else
1552
+ if(to > endIndex) {
1553
+ to = endIndex;
1554
+ // handle move column to left
1555
+ if(to < fromIndex){
1556
+ to += 1;
1557
+ }
1558
+ }
1559
+
1560
+ // Calculate left and right bound of the group, which column can be moved to.
1561
+ // destination should be between the bound, and it should not be placed between columns in child group
1562
+ for(let i = 0; i < groupDef.children.length; i++){
1563
+ let notAllowIndices = this.getChildColumnIndices(groupDef.children[i]);
1564
+ if(notAllowIndices && notAllowIndices.length){
1565
+ let leftLimit = notAllowIndices[0];
1566
+ let rightLimit = notAllowIndices[notAllowIndices.length - 1];
1567
+
1568
+ if(to > fromIndex){
1569
+ leftLimit -= 1;
1570
+ }
1571
+
1572
+ if(to < fromIndex){
1573
+ rightLimit += 1;
1574
+ }
1575
+
1576
+ if(to > leftLimit && to < rightLimit){
1577
+ to = rightLimit;
1578
+ }
1579
+ }
1580
+ }
1581
+
1582
+ // Get column id before start moving
1583
+ let colId = this.getColumnId(fromIndex);
1584
+
1585
+ for(let gridIndex = this._hosts.length; --gridIndex >= 0;) {
1586
+ let host = this._hosts[gridIndex];
1587
+ host.moveColumn(fromIndex, to);
1588
+ }
1589
+
1590
+ if(colId) {
1591
+ if(this._groupDefs.addGroupChild(groupId, colId)) {
1592
+ this._applyGrouping();
1593
+ }
1594
+ }
1488
1595
  };
1489
1596
  /**
1490
1597
  * @public
@@ -1492,11 +1599,11 @@ ColumnGroupingPlugin.prototype.moveColumnIntoGroup = function (colRef, to, group
1492
1599
  * @param {string} groupId
1493
1600
  * @return {boolean}
1494
1601
  */
1495
- ColumnGroupingPlugin.prototype.setColumnParent = function (colRef, groupId) {
1496
- if (groupId) {
1497
- return this.addGroupChild(groupId, colRef);
1498
- }
1499
- return this.unsetParent(colRef);
1602
+ ColumnGroupingPlugin.prototype.setColumnParent = function(colRef, groupId) {
1603
+ if(groupId) {
1604
+ return this.addGroupChild(groupId, colRef);
1605
+ }
1606
+ return this.unsetParent(colRef);
1500
1607
  };
1501
1608
  /** If a column is added as a new child in a group, the column will be moved to the last position in the group. If the column is already a child of the group, nothing happens.
1502
1609
  * @public
@@ -1504,97 +1611,116 @@ ColumnGroupingPlugin.prototype.setColumnParent = function (colRef, groupId) {
1504
1611
  * @param {number|string} childRef Column index, column id, group id to be added
1505
1612
  * @return {boolean}
1506
1613
  */
1507
- ColumnGroupingPlugin.prototype.addGroupChild = function (parentId, childRef) {
1508
- var parentDef = this._groupDefs.getGroup(parentId);
1509
- if (!parentDef) {
1510
- return false;
1511
- }
1512
- var colId = "";
1513
- if (typeof childRef === "string") {
1514
- var groupDef = this._groupDefs.getGroup(childRef);
1515
- if (groupDef) {
1516
- if (this._groupDefs.addGroupChild(parentId, childRef)) {
1517
- this._applyGrouping();
1518
- return true;
1519
- }
1520
- } else {
1521
- colId = childRef;
1522
- }
1523
- } else {
1524
- colId = this.getColumnId(childRef);
1525
- }
1526
- if (!colId) {
1527
- return false;
1528
- }
1529
- var leafIndices = this.getChildColumnIndices(parentId);
1530
- if (this._groupDefs.addGroupChild(parentId, colId)) {
1531
- if (leafIndices && leafIndices.length) {
1532
- if (this.moveColumnById(colId, leafIndices[leafIndices.length - 1] + 1)) {
1533
- return true;
1534
- }
1535
- }
1536
- this._applyGrouping();
1537
- return true;
1538
- }
1539
- return false;
1614
+ ColumnGroupingPlugin.prototype.addGroupChild = function(parentId, childRef) {
1615
+ let parentDef = this._groupDefs.getGroup(parentId);
1616
+ if(!parentDef) {
1617
+ return false;
1618
+ }
1619
+ let colId = "";
1620
+ if(typeof childRef === "string") {
1621
+ let groupDef = this._groupDefs.getGroup(childRef);
1622
+ if(groupDef) {
1623
+ if(this._groupDefs.addGroupChild(parentId, childRef)) {
1624
+ this._applyGrouping();
1625
+ if(this._isChildSelected(parentId)) {
1626
+ this._updateColumnBounds();
1627
+ }
1628
+ return true;
1629
+ }
1630
+ } else {
1631
+ colId = childRef;
1632
+ }
1633
+ } else {
1634
+ colId = this.getColumnId(childRef);
1635
+ }
1636
+ if(!colId) {
1637
+ return false;
1638
+ }
1639
+
1640
+ let leafIndices = this.getChildColumnIndices(parentId);
1641
+ if(this._groupDefs.addGroupChild(parentId, colId)) {
1642
+ if(leafIndices && leafIndices.length) {
1643
+ if(this.moveColumnById(colId, leafIndices[leafIndices.length - 1] + 1)) {
1644
+ return true;
1645
+ }
1646
+ }
1647
+
1648
+ this._applyGrouping();
1649
+ if(this._isChildSelected(parentId)) {
1650
+ this._updateColumnBounds();
1651
+ }
1652
+ return true;
1653
+ }
1654
+
1655
+ return false;
1540
1656
  };
1541
1657
  /**
1542
1658
  * @public
1543
1659
  * @param {string} parentId
1544
- * @param {number|string} childRef Column index, column id, group id to be added
1660
+ * @param {number|string} childRef Column index, column id, group id to be removed
1545
1661
  * @return {boolean}
1546
1662
  */
1547
- ColumnGroupingPlugin.prototype.removeGroupChild = function (parentId, childRef) {
1548
- var parentDef = this._groupDefs.getGroup(parentId);
1549
- if (!parentDef) {
1550
- return false;
1551
- }
1552
- var colId = "";
1553
- if (typeof childRef === "string") {
1554
- var groupDef = this._groupDefs.getGroup(childRef);
1555
- if (groupDef) {
1556
- if (this._groupDefs.unsetParent(childRef)) {
1557
- this._applyGrouping();
1558
- return true;
1559
- }
1560
- } else {
1561
- colId = childRef;
1562
- }
1563
- } else {
1564
- colId = this.getColumnId(childRef);
1565
- }
1566
- if (!colId) {
1567
- return false;
1568
- }
1569
- var rootId = parentId;
1570
- var group = this._visibleGroupMap[parentId];
1571
- if (group.onRow !== 0) {
1572
- rootId = this._groupDefs.getParentId(parentId, 0);
1573
- }
1574
- var leafIndices = this.getChildColumnIndices(rootId);
1575
- if (this._groupDefs.removeGroupChild(parentId, colId)) {
1576
- if (leafIndices && leafIndices.length > 1) {
1577
- if (this.moveColumnById(colId, leafIndices[leafIndices.length - 1] + 1)) {
1578
- return true;
1579
- }
1580
- }
1581
- this._applyGrouping();
1582
- return true;
1583
- }
1584
- return false;
1663
+ ColumnGroupingPlugin.prototype.removeGroupChild = function(parentId, childRef) {
1664
+ let parentDef = this._groupDefs.getGroup(parentId);
1665
+ if(!parentDef) {
1666
+ return false;
1667
+ }
1668
+ let colId = "";
1669
+ if(typeof childRef === "string") {
1670
+ let groupDef = this._groupDefs.getGroup(childRef);
1671
+ if(groupDef) {
1672
+ if(this._groupDefs.unsetParent(childRef)) {
1673
+ this._applyGrouping();
1674
+ if(this._isChildSelected(parentId)) {
1675
+ this._updateColumnBounds();
1676
+ }
1677
+ return true;
1678
+ }
1679
+ } else {
1680
+ colId = childRef;
1681
+ }
1682
+ } else {
1683
+ colId = this.getColumnId(childRef);
1684
+ }
1685
+ if(!colId) {
1686
+ return false;
1687
+ }
1688
+
1689
+ let rootId = parentId;
1690
+ let group = this._visibleGroupMap[parentId];
1691
+ if(group.onRow !== 0) {
1692
+ rootId = this._groupDefs.getParentId(parentId, 0);
1693
+ }
1694
+
1695
+ let leafIndices = this.getChildColumnIndices(rootId);
1696
+ if(this._groupDefs.removeGroupChild(parentId, colId)) {
1697
+ if(leafIndices && leafIndices.length > 1) {
1698
+ if(this.moveColumnById(colId, leafIndices[leafIndices.length - 1] + 1)) {
1699
+ return true;
1700
+ }
1701
+ }
1702
+
1703
+ this._applyGrouping();
1704
+ if(this._isChildSelected(parentId)) {
1705
+ this._updateColumnBounds();
1706
+ }
1707
+ return true;
1708
+ }
1709
+
1710
+ return false;
1585
1711
  };
1586
1712
  /**
1587
1713
  * @public
1588
1714
  * @param {number|string} childRef Column index, column id, group id to be removed from its own parent
1589
1715
  * @return {boolean}
1590
1716
  */
1591
- ColumnGroupingPlugin.prototype.unsetParent = function (childRef) {
1592
- var refId = typeof childRef === "string" ? childRef : this.getColumnId(childRef);
1593
- var parentId = this._groupDefs.getParentId(refId);
1594
- if (parentId) {
1595
- return this.removeGroupChild(parentId, refId);
1596
- }
1597
- return false;
1717
+ ColumnGroupingPlugin.prototype.unsetParent = function(childRef) {
1718
+ let refId = (typeof childRef === "string") ? childRef : this.getColumnId(childRef);
1719
+ let parentId = this._groupDefs.getParentId(refId);
1720
+ if(parentId) {
1721
+ return this.removeGroupChild(parentId, refId);
1722
+ }
1723
+ return false;
1598
1724
  };
1599
1725
 
1600
1726
  /** @public
@@ -1603,63 +1729,70 @@ ColumnGroupingPlugin.prototype.unsetParent = function (childRef) {
1603
1729
  * @param {number|string} destCol destination column index / id
1604
1730
  * @returns {number} destination index
1605
1731
  */
1606
- ColumnGroupingPlugin.prototype.getValidDestinationIndex = function (id, destCol) {
1607
- var parentGroupDef = null;
1608
- if (this._groupDefs.getGroup(id)) {
1609
- parentGroupDef = this._getVisibleParentGroup(id);
1610
- } else if (this.getColumnIndex(id) > -1) {
1611
- parentGroupDef = this._getVisibleParentGroup(id);
1612
- }
1613
- var startIndex = -1;
1614
- var endIndex = -1;
1615
- var destColIndex = typeof destCol === "string" ? this.getColumnIndex(destCol) : destCol;
1616
- if (parentGroupDef) {
1617
- // If group/column is a child of a group, it should be move within the parent group
1618
- var childIndices = this.getChildColumnIndices(parentGroupDef["id"]);
1619
- if (childIndices && childIndices.length) {
1620
- startIndex = childIndices[0];
1621
- endIndex = childIndices[childIndices.length - 1];
1622
- }
1623
- if (destColIndex < startIndex && destColIndex != -1) {
1624
- destColIndex = this.getColumnId(startIndex);
1625
- } else if (destColIndex > endIndex || destColIndex == -1) {
1626
- destColIndex = this.getColumnId(endIndex + 1);
1627
- }
1628
-
1629
- // handle group/column should not insert between group
1630
- var groupChildren = this.getGroupChildren(parentGroupDef["id"]);
1631
- for (var _i13 = 0; _i13 < groupChildren.length; _i13++) {
1632
- var childId = groupChildren[_i13];
1633
- var childGroupIndices = this.getChildColumnIndices(childId);
1634
- if (childGroupIndices && childGroupIndices.length) {
1635
- startIndex = childGroupIndices[0];
1636
- endIndex = childGroupIndices[childGroupIndices.length - 1];
1637
- if (destColIndex > startIndex && destColIndex <= endIndex) {
1638
- destColIndex = endIndex + 1;
1639
- break;
1640
- }
1641
- }
1642
- }
1643
- } else {
1644
- // handle group/column should not insert between group when group/column is not a child of any group
1645
- var destMemberIndices = [];
1646
- var destColId = this.getColumnId(destColIndex);
1647
- var destParent = this._getVisibleParentGroup(destColId);
1648
- if (destParent) {
1649
- if (destParent.parentId) {
1650
- destParent = this._groupDefs.getRootGroup(destParent["id"]);
1651
- }
1652
- destMemberIndices = this.getChildColumnIndices(destParent["id"]);
1653
- }
1654
- if (destMemberIndices && destMemberIndices.length) {
1655
- startIndex = destMemberIndices[0];
1656
- endIndex = destMemberIndices[destMemberIndices.length - 1];
1657
- if (destColIndex > startIndex && destColIndex <= endIndex) {
1658
- destColIndex = endIndex + 1;
1659
- }
1660
- }
1661
- }
1662
- return destColIndex;
1732
+ ColumnGroupingPlugin.prototype.getValidDestinationIndex = function(id, destCol) {
1733
+ let parentGroupDef = null;
1734
+ if(this._groupDefs.getGroup(id)){
1735
+ parentGroupDef = this._getVisibleParentGroup(id);
1736
+ } else if(this.getColumnIndex(id) > -1) {
1737
+ parentGroupDef = this._getVisibleParentGroup(id);
1738
+ }
1739
+
1740
+ let startIndex = -1;
1741
+ let endIndex = -1;
1742
+ let destColIndex = typeof destCol === "string" ? this.getColumnIndex(destCol) : destCol;
1743
+
1744
+ if(parentGroupDef){
1745
+
1746
+ // If group/column is a child of a group, it should be move within the parent group
1747
+ let childIndices = this.getChildColumnIndices(parentGroupDef["id"]);
1748
+ if(childIndices && childIndices.length){
1749
+ startIndex = childIndices[0];
1750
+ endIndex = childIndices[childIndices.length - 1];
1751
+ }
1752
+ if(destColIndex < startIndex && destColIndex != -1){
1753
+ destColIndex = this.getColumnId(startIndex);
1754
+ } else
1755
+ if(destColIndex > endIndex || destColIndex == -1) {
1756
+ destColIndex = this.getColumnId(endIndex + 1);
1757
+ }
1758
+
1759
+ // handle group/column should not insert between group
1760
+ let groupChildren = this.getGroupChildren(parentGroupDef["id"]);
1761
+ for(let i = 0; i < groupChildren.length; i++){
1762
+ let childId = groupChildren[i];
1763
+ let childGroupIndices = this.getChildColumnIndices(childId);
1764
+ if(childGroupIndices && childGroupIndices.length){
1765
+ startIndex = childGroupIndices[0];
1766
+ endIndex = childGroupIndices[childGroupIndices.length - 1];
1767
+ if(destColIndex > startIndex && destColIndex <= endIndex){
1768
+ destColIndex = endIndex + 1;
1769
+ break;
1770
+ }
1771
+ }
1772
+ }
1773
+
1774
+ } else {
1775
+ // handle group/column should not insert between group when group/column is not a child of any group
1776
+ let destMemberIndices = [];
1777
+ let destColId = this.getColumnId(destColIndex);
1778
+ let destParent = this._getVisibleParentGroup(destColId);
1779
+ if(destParent){
1780
+ if(destParent.parentId){
1781
+ destParent = this._groupDefs.getRootGroup(destParent["id"]);
1782
+ }
1783
+ destMemberIndices = this.getChildColumnIndices(destParent["id"]);
1784
+ }
1785
+
1786
+ if(destMemberIndices && destMemberIndices.length){
1787
+ startIndex = destMemberIndices[0];
1788
+ endIndex = destMemberIndices[destMemberIndices.length - 1];
1789
+ if(destColIndex > startIndex && destColIndex <= endIndex){
1790
+ destColIndex = endIndex + 1;
1791
+ }
1792
+ }
1793
+ }
1794
+
1795
+ return destColIndex;
1663
1796
  };
1664
1797
 
1665
1798
  /** @public
@@ -1669,26 +1802,28 @@ ColumnGroupingPlugin.prototype.getValidDestinationIndex = function (id, destCol)
1669
1802
  * @param {string} id group id or column id
1670
1803
  * @param {(number|string)=} destCol destination column index / id
1671
1804
  */
1672
- ColumnGroupingPlugin.prototype.moveGroup = function (id, destCol) {
1673
- var groupDef;
1674
- var members = [];
1675
- groupDef = this._groupDefs.getGroup(id);
1676
- if (groupDef) {
1677
- var indices = this.getChildColumnIndices(groupDef["id"]);
1678
- for (var _i14 = 0; _i14 < indices.length; _i14++) {
1679
- var index = indices[_i14];
1680
- var colId = this.getColumnId(index);
1681
- members.push(colId);
1682
- }
1683
- } else if (this.getColumnIndex(id) > -1) {
1684
- members.push(id);
1685
- } else {
1686
- return;
1687
- }
1688
- var destColIndex = this.getValidDestinationIndex(id, destCol);
1689
- var destColId = this.getColumnId(destColIndex); // TODO: This may not necessary
1690
-
1691
- this.reorderColumns(members, destColId);
1805
+ ColumnGroupingPlugin.prototype.moveGroup = function(id, destCol) {
1806
+ let groupDef;
1807
+ let members = [];
1808
+
1809
+ groupDef = this._groupDefs.getGroup(id);
1810
+ if(groupDef){
1811
+ let indices = this.getChildColumnIndices(groupDef["id"]);
1812
+ for(let i = 0; i < indices.length; i++){
1813
+ let index = indices[i];
1814
+ let colId = this.getColumnId(index);
1815
+ members.push(colId);
1816
+ }
1817
+ } else if(this.getColumnIndex(id) > -1) {
1818
+ members.push(id);
1819
+ } else {
1820
+ return;
1821
+ }
1822
+
1823
+ let destColIndex = this.getValidDestinationIndex(id, destCol);
1824
+ let destColId = this.getColumnId(destColIndex); // TODO: This may not necessary
1825
+
1826
+ this.reorderColumns(members, destColId);
1692
1827
  };
1693
1828
  /** Move and reorder the specified columns to position before the destination
1694
1829
  * @public
@@ -1696,8 +1831,8 @@ ColumnGroupingPlugin.prototype.moveGroup = function (id, destCol) {
1696
1831
  * @param {(number|string)=} destCol Destination column id or index
1697
1832
  * @return {boolean}
1698
1833
  */
1699
- ColumnGroupingPlugin.prototype.reorderColumns = function (colList, destCol) {
1700
- return this._reorderColumns(colList, destCol);
1834
+ ColumnGroupingPlugin.prototype.reorderColumns = function(colList, destCol) {
1835
+ return this._reorderColumns(colList, destCol);
1701
1836
  };
1702
1837
  /** Move the specified column to position before the destination
1703
1838
  * @public
@@ -1705,113 +1840,123 @@ ColumnGroupingPlugin.prototype.reorderColumns = function (colList, destCol) {
1705
1840
  * @param {(number|string)=} destCol Destination column id or index
1706
1841
  * @return {boolean}
1707
1842
  */
1708
- ColumnGroupingPlugin.prototype.moveColumnById = function (srcCol, destCol) {
1709
- return this._moveColumnById(srcCol, destCol);
1843
+ ColumnGroupingPlugin.prototype.moveColumnById = function(srcCol, destCol) {
1844
+ return this._moveColumnById(srcCol, destCol);
1710
1845
  };
1711
1846
  /** @public
1712
1847
  * @param {string} groupId
1713
1848
  * @param {string=} side Available values are: left|right. If no value is supplied, all columns will be pinned to the left.
1714
1849
  */
1715
- ColumnGroupingPlugin.prototype.pinGroup = function (groupId, side) {
1716
- if (!groupId) {
1717
- return;
1718
- }
1719
- var groupDef = this._visibleGroupMap[groupId];
1720
- if (!groupDef) {
1721
- return;
1722
- }
1723
- var host = this._hosts[0];
1724
- var leftPinnedIndex = host.getFrozenColumnCount() - 1;
1725
- var rightPinnedCount = host.getPinnedRightColumnCount();
1726
- var colCount = this.getColumnCount();
1727
- var colList = this.getChildColumnIndices(groupId);
1728
- var len = colList.length;
1729
- var dest;
1730
- if (side === "right") {
1731
- if (groupDef.rightPinned) {
1732
- return;
1733
- }
1734
- if (groupDef.leftPinned) {
1735
- this.unpinGroup(groupId);
1736
- leftPinnedIndex = host.getFrozenColumnCount() - 1;
1737
- }
1738
- groupDef.rightPinned = true;
1739
- dest = colCount - rightPinnedCount;
1740
- rightPinnedCount = rightPinnedCount + len;
1741
- } else {
1742
- if (groupDef.leftPinned) {
1743
- return;
1744
- }
1745
- if (groupDef.rightPinned) {
1746
- this.unpinGroup(groupId);
1747
- rightPinnedCount = host.getPinnedRightColumnCount();
1748
- }
1749
- groupDef.leftPinned = true;
1750
- dest = leftPinnedIndex === -1 ? 0 : leftPinnedIndex + 1;
1751
- leftPinnedIndex = leftPinnedIndex + len;
1752
- }
1753
- this.moveGroup(groupId, dest);
1754
- this._freezeColumn(leftPinnedIndex, rightPinnedCount);
1850
+ ColumnGroupingPlugin.prototype.pinGroup = function(groupId, side) {
1851
+ if(!groupId) {
1852
+ return;
1853
+ }
1854
+
1855
+ let groupDef = this._visibleGroupMap[groupId];
1856
+ if(!groupDef) {
1857
+ return;
1858
+ }
1859
+
1860
+ let host = this._hosts[0];
1861
+ let leftPinnedIndex = host.getFrozenColumnCount() - 1;
1862
+ let rightPinnedCount = host.getPinnedRightColumnCount();
1863
+ let colCount = this.getColumnCount();
1864
+ let colList = this.getChildColumnIndices(groupId);
1865
+ let len = colList.length;
1866
+
1867
+ let dest;
1868
+ if(side === "right") {
1869
+ if(groupDef.rightPinned) {
1870
+ return;
1871
+ }
1872
+ if(groupDef.leftPinned) {
1873
+ this.unpinGroup(groupId);
1874
+ leftPinnedIndex = host.getFrozenColumnCount() - 1;
1875
+ }
1876
+ groupDef.rightPinned = true;
1877
+ dest = colCount - rightPinnedCount;
1878
+ rightPinnedCount = rightPinnedCount + len;
1879
+ } else {
1880
+ if(groupDef.leftPinned) {
1881
+ return;
1882
+ }
1883
+ if(groupDef.rightPinned) {
1884
+ this.unpinGroup(groupId);
1885
+ rightPinnedCount = host.getPinnedRightColumnCount();
1886
+ }
1887
+ groupDef.leftPinned = true;
1888
+ dest = leftPinnedIndex === -1 ? 0 : leftPinnedIndex + 1;
1889
+ leftPinnedIndex = leftPinnedIndex + len;
1890
+ }
1891
+
1892
+ this.moveGroup(groupId, dest);
1893
+ this._freezeColumn(leftPinnedIndex, rightPinnedCount);
1755
1894
  };
1756
1895
  /** @public
1757
1896
  * @param {string} groupId
1758
1897
  * @param {(number|string)=} dest The unpinned group will be placed before the destination position after the operation
1759
1898
  */
1760
- ColumnGroupingPlugin.prototype.unpinGroup = function (groupId, dest) {
1761
- if (!groupId) {
1762
- return;
1763
- }
1764
- var groupDef = this._visibleGroupMap[groupId];
1765
- if (!groupDef) {
1766
- return;
1767
- }
1768
- if (!groupDef.leftPinned && !groupDef.rightPinned) {
1769
- return;
1770
- }
1771
- var host = this._hosts[0];
1772
- var leftPinnedCount = host.getFrozenColumnCount();
1773
- var rightPinnedCount = host.getPinnedRightColumnCount();
1774
- var colCount = this.getColumnCount();
1775
- var firstRightPinnedIndex = colCount - rightPinnedCount;
1776
- var colList = this.getChildColumnIndices(groupId);
1777
- var len = colList.length;
1778
- var destId = null;
1779
- if (dest != null) {
1780
- var destIdx = this.getColumnIndex(dest);
1781
- destId = this.getColumnId(destIdx);
1782
- }
1783
- if (groupDef.leftPinned) {
1784
- groupDef.leftPinned = false;
1785
- this.moveGroup(groupId, leftPinnedCount);
1786
- this._freezeColumn(leftPinnedCount - (1 + len));
1787
- } else if (groupDef.rightPinned) {
1788
- groupDef.rightPinned = false;
1789
- this.moveGroup(groupId, firstRightPinnedIndex);
1790
- this._freezeColumn(leftPinnedCount - 1, rightPinnedCount - len);
1791
- }
1792
- if (destId != null) {
1793
- this.moveGroup(groupId, destId);
1794
- }
1899
+ ColumnGroupingPlugin.prototype.unpinGroup = function(groupId, dest) {
1900
+ if(!groupId) {
1901
+ return;
1902
+ }
1903
+
1904
+ let groupDef = this._visibleGroupMap[groupId];
1905
+ if(!groupDef) {
1906
+ return;
1907
+ }
1908
+
1909
+ if(!groupDef.leftPinned && !groupDef.rightPinned) {
1910
+ return;
1911
+ }
1912
+
1913
+ let host = this._hosts[0];
1914
+ let leftPinnedCount = host.getFrozenColumnCount();
1915
+ let rightPinnedCount = host.getPinnedRightColumnCount();
1916
+ let colCount = this.getColumnCount();
1917
+ let firstRightPinnedIndex = colCount - rightPinnedCount;
1918
+ let colList = this.getChildColumnIndices(groupId);
1919
+ let len = colList.length;
1920
+
1921
+ let destId = null;
1922
+ if(dest != null) {
1923
+ let destIdx = this.getColumnIndex(dest);
1924
+ destId = this.getColumnId(destIdx);
1925
+ }
1926
+
1927
+ if(groupDef.leftPinned) {
1928
+ groupDef.leftPinned = false;
1929
+ this.moveGroup(groupId, leftPinnedCount);
1930
+ this._freezeColumn(leftPinnedCount - (1 + len));
1931
+ } else if(groupDef.rightPinned) {
1932
+ groupDef.rightPinned = false;
1933
+ this.moveGroup(groupId, firstRightPinnedIndex);
1934
+ this._freezeColumn(leftPinnedCount - 1, rightPinnedCount - len);
1935
+ }
1936
+
1937
+ if(destId != null) {
1938
+ this.moveGroup(groupId, destId);
1939
+ }
1795
1940
  };
1796
1941
  /** @public
1797
1942
  * @param {Array<number>} colIndices
1798
1943
  */
1799
- ColumnGroupingPlugin.prototype.selectGroupHeaders = function (colIndices) {
1800
- var host = this._hosts[0];
1801
- var count = colIndices.length;
1802
- if (host && count) {
1803
- var colIds = [];
1804
- for (var _i15 = 0; _i15 < count; _i15++) {
1805
- colIds.push(host.getColumnId(colIndices[_i15]));
1806
- }
1807
- var colMap = host.createColumnMap(colIds);
1808
- if (colMap) {
1809
- this._selectedColMap = colMap;
1810
- }
1811
- } else {
1812
- this._selectedColMap = null;
1813
- }
1814
- this._requestGroupRendering();
1944
+ ColumnGroupingPlugin.prototype.selectGroupHeaders = function(colIndices) {
1945
+ let host = this._hosts[0];
1946
+ let count = colIndices.length;
1947
+ if(host && count){
1948
+ let colIds = [];
1949
+ for(let i = 0; i < count; i++){
1950
+ colIds.push(host.getColumnId(colIndices[i]));
1951
+ }
1952
+ let colMap = host.createColumnMap(colIds);
1953
+ if(colMap){
1954
+ this._selectedColMap = colMap;
1955
+ }
1956
+ } else {
1957
+ this._selectedColMap = null;
1958
+ }
1959
+ this._requestGroupRendering();
1815
1960
  };
1816
1961
 
1817
1962
  /** Get column index from column object
@@ -1820,8 +1965,8 @@ ColumnGroupingPlugin.prototype.selectGroupHeaders = function (colIndices) {
1820
1965
  * @param {Object} column
1821
1966
  * @return {number}
1822
1967
  */
1823
- ColumnGroupingPlugin.getObjectIndex = function (column) {
1824
- return column["index"];
1968
+ ColumnGroupingPlugin.getObjectIndex = function(column) {
1969
+ return column["index"];
1825
1970
  };
1826
1971
 
1827
1972
  /** Get column id from column object
@@ -1830,8 +1975,11 @@ ColumnGroupingPlugin.getObjectIndex = function (column) {
1830
1975
  * @param {Object} column
1831
1976
  * @return {string}
1832
1977
  */
1833
- ColumnGroupingPlugin.getObjectId = function (column) {
1834
- return column["id"];
1978
+ ColumnGroupingPlugin.getObjectId = function(column) {
1979
+ return column["id"];
1835
1980
  };
1981
+
1982
+
1983
+
1836
1984
  export default ColumnGroupingPlugin;
1837
- export { ColumnGroupingPlugin, ColumnGroupingPlugin as ColumnGrouping, ColumnGroupingPlugin as ColumnGroupingExtension };
1985
+ export { ColumnGroupingPlugin, ColumnGroupingPlugin as ColumnGrouping, ColumnGroupingPlugin as ColumnGroupingExtension };