@refinitiv-ui/efx-grid 6.0.13 → 6.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/lib/column-format-dialog/index.d.ts +2 -1
  2. package/lib/column-format-dialog/index.js +2 -1
  3. package/lib/column-selection-dialog/index.d.ts +2 -1
  4. package/lib/column-selection-dialog/index.js +2 -1
  5. package/lib/core/dist/core.js +1220 -161
  6. package/lib/core/dist/core.min.js +1 -1
  7. package/lib/core/es6/data/DataCache.js +1 -1
  8. package/lib/core/es6/data/DataTable.d.ts +18 -3
  9. package/lib/core/es6/data/DataTable.js +203 -17
  10. package/lib/core/es6/data/DataView.d.ts +8 -1
  11. package/lib/core/es6/data/DataView.js +30 -2
  12. package/lib/core/es6/data/Segment.d.ts +37 -12
  13. package/lib/core/es6/data/Segment.js +584 -60
  14. package/lib/core/es6/data/SegmentCollection.d.ts +16 -2
  15. package/lib/core/es6/data/SegmentCollection.js +238 -80
  16. package/lib/core/es6/grid/Core.js +1 -1
  17. package/lib/filter-dialog/index.d.ts +2 -1
  18. package/lib/filter-dialog/index.js +2 -1
  19. package/lib/grid/index.d.ts +2 -1
  20. package/lib/grid/index.js +3 -2
  21. package/lib/row-segmenting/es6/RowSegmenting.d.ts +2 -0
  22. package/lib/row-segmenting/es6/RowSegmenting.js +26 -3
  23. package/lib/rt-grid/dist/rt-grid.js +1194 -158
  24. package/lib/rt-grid/dist/rt-grid.min.js +1 -1
  25. package/lib/rt-grid/es6/Grid.d.ts +4 -0
  26. package/lib/rt-grid/es6/Grid.js +75 -0
  27. package/lib/rt-grid/es6/RowDefinition.d.ts +4 -0
  28. package/lib/rt-grid/es6/RowDefinition.js +79 -2
  29. package/lib/tr-grid-column-grouping/es6/ColumnGrouping.d.ts +1 -0
  30. package/lib/tr-grid-column-grouping/es6/ColumnGrouping.js +194 -366
  31. package/lib/tr-grid-column-stack/es6/ColumnStack.d.ts +10 -3
  32. package/lib/tr-grid-column-stack/es6/ColumnStack.js +93 -36
  33. package/lib/tr-grid-util/es6/RowPainter.d.ts +2 -1
  34. package/lib/tr-grid-util/es6/RowPainter.js +7 -1
  35. package/lib/tr-grid-util/es6/jet/mockDataAPI.d.ts +1 -0
  36. package/lib/tr-grid-util/es6/jet/mockDataAPI.js +191 -52
  37. package/lib/types/es6/ColumnGrouping.d.ts +1 -0
  38. package/lib/types/es6/ColumnStack.d.ts +10 -3
  39. package/lib/types/es6/Core/data/DataTable.d.ts +18 -3
  40. package/lib/types/es6/Core/data/DataView.d.ts +8 -1
  41. package/lib/types/es6/Core/data/Segment.d.ts +36 -11
  42. package/lib/types/es6/Core/data/SegmentCollection.d.ts +15 -1
  43. package/lib/types/es6/RealtimeGrid/ColumnDefinition.d.ts +6 -1
  44. package/lib/types/es6/RealtimeGrid/Grid.d.ts +2 -0
  45. package/lib/types/es6/RowSegmenting.d.ts +2 -0
  46. package/lib/versions.json +4 -4
  47. package/package.json +15 -2
@@ -1,6 +1,8 @@
1
1
  import { Ext } from "../../tr-grid-util/es6/Ext.js";
2
+ import { cloneObject } from "../../tr-grid-util/es6/Util.js";
2
3
  import { GridPlugin } from "../../tr-grid-util/es6/GridPlugin.js";
3
4
  import { injectCss, prettifyCss } from "../../tr-grid-util/es6/Util.js";
5
+
4
6
  /** @typedef {Array<ColumnGroupingPlugin~GroupDefinition>} ColumnGroupingPlugin~Options
5
7
  * @description This options can be specified by `columnGrouping` property of the main grid's options or extension options.
6
8
  */
@@ -23,69 +25,69 @@ import { injectCss, prettifyCss } from "../../tr-grid-util/es6/Util.js";
23
25
  * @extends {GridPlugin}
24
26
  * @param {ColumnGroupingPlugin~Options=} options
25
27
  */
26
-
27
28
  var ColumnGroupingPlugin = function ColumnGroupingPlugin(options) {
28
29
  var t = this;
29
30
  t._hosts = [];
30
31
  t._onColumnChanged = t._onColumnChanged.bind(t);
31
32
  t._onColumnAdded = t._onColumnAdded.bind(t);
32
33
  t._onColumnMoved = t._onColumnMoved.bind(t);
34
+ t._requestApplyAddChildGroup = t._requestApplyAddChildGroup.bind(this);
33
35
  t._onPostSectionRender = t._onPostSectionRender.bind(t);
34
36
  t._onBeforeColumnBoundUpdate = t._onBeforeColumnBoundUpdate.bind(t);
35
37
  t._groupDefs = [];
36
38
  t._groupMap = {};
37
39
  t._childToParent = {};
38
-
39
40
  if (options) {
40
41
  t.config({
41
42
  "columnGrouping": options
42
43
  });
43
44
  }
44
45
  };
45
-
46
46
  Ext.inherits(ColumnGroupingPlugin, GridPlugin);
47
+
47
48
  /** @type {!ColumnGroupingPlugin~GroupDefinitions}
48
49
  * @description An array of group definition objects
49
50
  * @private
50
51
  */
51
-
52
52
  ColumnGroupingPlugin.prototype._groupDefs;
53
53
  /** @type {!Object.<string, ColumnGroupingPlugin~GroupDefinition>}
54
54
  * @description A map of group id to group defintion
55
55
  * @private
56
56
  */
57
-
58
57
  ColumnGroupingPlugin.prototype._groupMap;
59
58
  /** @type {!Object.<string, string>}
60
59
  * @description A map of child id to parent id
61
60
  * @private
62
61
  */
63
-
64
62
  ColumnGroupingPlugin.prototype._childToParent;
65
63
  /** @type {number}
66
64
  * @private
67
65
  */
68
-
69
66
  ColumnGroupingPlugin.prototype._maxDepth = 0;
70
67
  /** @type {boolean}
71
68
  * @private
72
69
  */
73
-
74
70
  ColumnGroupingPlugin.prototype._restructuring = false;
75
71
  /** @type {number}
76
72
  * @private
77
73
  */
78
-
79
74
  ColumnGroupingPlugin.prototype._rerenderTimerId = 0;
75
+ /** @type {number}
76
+ * @private
77
+ */
78
+ ColumnGroupingPlugin.prototype._addingTimerId = 0;
79
+ /** @type {Array<Object>}
80
+ * @private
81
+ */
82
+ ColumnGroupingPlugin.prototype._addingEvents = null;
83
+
80
84
  /** @private
81
85
  * @param {ColumnGroupingPlugin~GroupDefinition} groupingOptions
82
86
  * @return {string}
83
87
  */
84
-
85
88
  ColumnGroupingPlugin._getTooltip = function (groupingOptions) {
86
89
  var tooltip = groupingOptions["tooltip"];
87
90
  var title = groupingOptions["title"] || groupingOptions["name"];
88
-
89
91
  if (tooltip != null) {
90
92
  if (typeof tooltip === "string") {
91
93
  return tooltip; // There is a custom tooltip
@@ -95,7 +97,6 @@ ColumnGroupingPlugin._getTooltip = function (groupingOptions) {
95
97
  return "";
96
98
  }
97
99
  }
98
-
99
100
  return title;
100
101
  };
101
102
  /** Prevent built-in config
@@ -104,8 +105,6 @@ ColumnGroupingPlugin._getTooltip = function (groupingOptions) {
104
105
  * @param {Object} optionValue
105
106
  * @return {*}
106
107
  */
107
-
108
-
109
108
  ColumnGroupingPlugin.prototype.beforeProcessOption = function (optionName, optionValue) {
110
109
  if (optionName === "columnGroups") {
111
110
  this._legacyColumnGroups = optionValue;
@@ -117,8 +116,6 @@ ColumnGroupingPlugin.prototype.beforeProcessOption = function (optionName, optio
117
116
  /** @public
118
117
  * @return {string}
119
118
  */
120
-
121
-
122
119
  ColumnGroupingPlugin.prototype.getName = function () {
123
120
  return "ColumnGroupingPlugin"; // Read Only
124
121
  };
@@ -126,24 +123,22 @@ ColumnGroupingPlugin.prototype.getName = function () {
126
123
  * @override
127
124
  * @return {boolean}
128
125
  */
129
-
130
-
131
126
  ColumnGroupingPlugin.prototype.hasMultiTableSupport = function () {
132
127
  return true;
133
128
  };
129
+
134
130
  /** @public
135
131
  * @param {Object} host core grid object
136
132
  * @param {Object=} options
137
133
  */
138
-
139
-
140
134
  ColumnGroupingPlugin.prototype.initialize = function (host, options) {
141
135
  if (this._hosts.indexOf(host) >= 0) {
142
136
  return;
143
137
  }
144
-
145
138
  this._hosts.push(host);
146
-
139
+ if (!this._addingEvents) {
140
+ this._addingEvents = [];
141
+ }
147
142
  if (this._hosts.length === 1) {
148
143
  host.listen("columnAdded", this._onColumnAdded);
149
144
  host.listen("columnMoved", this._onColumnMoved);
@@ -152,93 +147,84 @@ ColumnGroupingPlugin.prototype.initialize = function (host, options) {
152
147
  host.listen("postSectionRender", this._onPostSectionRender);
153
148
  host.listen("beforeColumnBoundUpdate", this._onBeforeColumnBoundUpdate);
154
149
  }
155
-
156
150
  this.config(options);
157
151
  this._legacyColumnGroups = null;
158
-
159
152
  if (this._initializedGrid && host.getSection("title")) {
160
153
  // For run-time loading
161
154
  this._applyGrouping();
162
155
  }
163
-
164
156
  if (!ColumnGroupingPlugin._styles) {
165
157
  ColumnGroupingPlugin._styles = prettifyCss([".tr-grid .title .column .cell:not(:last-child)", ["box-shadow: none;"]]);
166
158
  }
167
-
168
159
  if (!host._columnGroupingStyles) {
169
160
  host._columnGroupingStyles = true;
170
161
  injectCss(ColumnGroupingPlugin._styles, host.getElement());
171
- } // TODO: wrong render group in hide/show column
172
-
162
+ }
163
+ // TODO: wrong render group in hide/show column
173
164
  };
174
165
  /**
175
166
  * @protected
176
167
  * @ignore
177
168
  */
178
-
179
-
180
169
  ColumnGroupingPlugin.prototype._afterInit = function () {
181
170
  this._applyGrouping();
182
171
  };
183
172
  /** @public
184
173
  * @param {Object} host core grid object
185
174
  */
186
-
187
-
188
175
  ColumnGroupingPlugin.prototype.unload = function (host) {
189
176
  var at = this._hosts.indexOf(host);
190
-
191
177
  if (at < 0) {
192
178
  return;
193
179
  }
194
-
195
180
  this._hosts.splice(at, 1);
196
-
197
181
  host.unlisten("columnAdded", this._onColumnChanged);
198
182
  host.unlisten("columnMoved", this._onColumnMoved);
199
183
  host.unlisten("columnRemoved", this._onColumnChanged);
200
184
  host.unlisten("postSectionRender", this._onPostSectionRender);
201
185
  host.unlisten("beforeColumnBoundUpdate", this._onBeforeColumnBoundUpdate);
202
-
203
186
  if (!this._hosts.length) {
204
187
  if (this._rerenderTimerId) {
205
188
  clearTimeout(this._rerenderTimerId);
206
189
  this._rerenderTimerId = 0;
207
190
  }
191
+ if (this._addingTimerId) {
192
+ clearTimeout(this._addingTimerId);
193
+ this._addingTimerId = 0;
194
+ this._addingEvents.length = 0;
195
+ }
208
196
  }
209
-
210
197
  this._dispose();
211
198
  };
212
199
  /** @public
213
200
  * @param {Object} options
214
201
  */
215
-
216
-
217
202
  ColumnGroupingPlugin.prototype.config = function (options) {
218
203
  if (!options) {
219
204
  return;
220
205
  }
221
-
222
206
  var extOptions = options["columnGrouping"];
223
-
224
207
  if (Array.isArray(extOptions)) {
225
- this._groupDefs = extOptions.filter(ColumnGroupingPlugin._isValidGroup); // Shallow copy
208
+ this._groupDefs = extOptions.filter(ColumnGroupingPlugin._isValidGroup).map(ColumnGroupingPlugin._cloneObject);
226
209
  }
227
-
228
210
  this._migrateLegacyStructure(options["columns"]);
229
211
  };
230
212
  /** @public
231
213
  * @param {Object=} gridOptions
232
214
  * @return {!Object}
233
215
  */
234
-
235
-
236
216
  ColumnGroupingPlugin.prototype.getConfigObject = function (gridOptions) {
237
- var obj = gridOptions || {}; // TODO: Handle legacyRender method that has been migrated
217
+ var obj = gridOptions || {};
238
218
 
239
- obj.columnGrouping = this.getGroupDefinitions();
219
+ // TODO: Handle legacyRender method that has been migrated
220
+ var columnGroupingDefs = this.getGroupDefinitions();
221
+ for (var i = 0; i < columnGroupingDefs.length; i++) {
222
+ columnGroupingDefs[i] = this._groupMap[columnGroupingDefs[i].id];
223
+ }
224
+ obj.columnGrouping = columnGroupingDefs;
240
225
  return obj;
241
226
  };
227
+
242
228
  /** Legacy group structure from composite grid will be converted to the new structure
243
229
  * @private
244
230
  * @param {Object.<string, Array>} objMap
@@ -246,119 +232,102 @@ ColumnGroupingPlugin.prototype.getConfigObject = function (gridOptions) {
246
232
  * @param {string} childId
247
233
  * @return {boolean} Returns true if there is any change
248
234
  */
249
-
250
-
251
235
  ColumnGroupingPlugin._mapParentToChildren = function (objMap, parentId, childId) {
252
236
  if (parentId && childId) {
253
237
  var ary = objMap[parentId];
254
-
255
238
  if (!ary) {
256
239
  ary = objMap[parentId] = [];
257
240
  }
258
-
259
241
  ary.push(childId);
260
242
  return true;
261
243
  }
262
-
263
244
  return false;
264
245
  };
265
246
  /** Legacy group structure from composite grid will be converted to the new structure
266
247
  * @private
267
248
  * @param {Array.<Object>} colModels
268
249
  */
269
-
270
-
271
250
  ColumnGroupingPlugin.prototype._migrateLegacyStructure = function (colModels) {
272
251
  var legacyColumnGroups = this._legacyColumnGroups;
273
-
274
252
  if (!legacyColumnGroups || !this._compositeGrid) {
275
253
  return;
276
- } // Collecting parent groups from col models (leaf node)
277
-
278
-
254
+ }
255
+ // Collecting parent groups from col models (leaf node)
279
256
  var colCount = colModels.length;
280
257
  var groupMap = {}; // Parent-children pair map
281
-
282
258
  for (var c = 0; c < colCount; ++c) {
283
259
  var colModel = colModels[c];
284
-
285
260
  if (colModel) {
286
261
  ColumnGroupingPlugin._mapParentToChildren(groupMap, colModel.columnGroup, colModel.id);
287
262
  }
288
- } // Collecting parent groups from the group list (groups can have parent as well)
289
-
290
-
263
+ }
264
+ // Collecting parent groups from the group list (groups can have parent as well)
291
265
  var groupCount = legacyColumnGroups.length;
292
266
  var i, groupDef;
293
-
294
267
  for (i = 0; i < groupCount; ++i) {
295
268
  groupDef = legacyColumnGroups[i];
296
-
297
269
  if (groupDef) {
298
270
  ColumnGroupingPlugin._mapParentToChildren(groupMap, groupDef.parent, groupDef.id);
299
271
  }
300
- } // TODO: Merge child relationship to existing group structure
301
- // Add new definitions and structure to the given legacy objects
302
-
272
+ }
273
+ // TODO: Merge child relationship to existing group structure
303
274
 
275
+ // Add new definitions and structure to the given legacy objects
304
276
  for (i = 0; i < groupCount; ++i) {
305
277
  groupDef = legacyColumnGroups[i];
306
-
307
278
  if (groupDef && groupDef.id) {
308
279
  // WARNING: Modify user's object
309
280
  var childAry = groupMap[groupDef.id];
310
281
  groupDef.children = childAry ? childAry : [];
311
-
312
282
  if (groupDef["formatter"] && groupDef["formatter"]["render"]) {
313
283
  groupDef["legacyRender"] = groupDef["formatter"]["render"];
314
284
  delete groupDef["formatter"];
315
285
  }
316
-
317
286
  this._groupDefs.push(groupDef);
318
287
  }
319
288
  }
320
289
  };
290
+
321
291
  /** Consolidate and process configuration. Force rerendering on column adding, removing, moving, initializaing, and run-time API execution.
322
292
  * @private
323
293
  */
324
-
325
-
326
294
  ColumnGroupingPlugin.prototype._applyGrouping = function () {
327
295
  this._rerenderTimerId = 0;
328
-
329
296
  if (this._restructuring) {
330
297
  return;
331
298
  }
332
-
333
299
  this._restructuring = true;
334
-
335
300
  this._evaluateGroupStructure();
336
-
337
- var i;
301
+ var i, c, r, cell, section, colCount;
302
+ var rowCount = this._maxDepth + 1;
338
303
  var hostCount = this._hosts.length;
339
-
340
304
  for (i = hostCount; --i >= 0;) {
341
- var host = this._hosts[i];
342
- var titleSection = host.getSection("title");
343
-
344
- if (titleSection) {
345
- var rowCount = this._maxDepth + 1;
346
- titleSection.setRowCount(rowCount); // This will cause postSectionRender event to be fired
347
-
348
- titleSection.clearCellSpans();
349
-
350
- this._spanGroupVertically(titleSection); // TODO: Some calculation in here should not be done in this loop
351
-
352
-
353
- this._spanGroupHorizontally(titleSection);
305
+ section = this._hosts[i].getSection("title");
306
+ if (section) {
307
+ section.setRowCount(rowCount); // This will cause postSectionRender event to be fired
308
+ section.clearCellSpans();
309
+
310
+ // Remove additional cell settings from _renderGroups() method
311
+ colCount = section.getColumnCount();
312
+ for (c = 0; c < colCount; c++) {
313
+ for (r = 0; r < rowCount; r++) {
314
+ cell = section.getCell(c, r, false);
315
+ if (cell) {
316
+ cell.removeClass("no-sort");
317
+ cell.removeAttribute("group-id");
318
+ }
319
+ }
320
+ }
321
+ this._spanGroupVertically(section);
322
+ // TODO: Some calculation in here should not be done in this loop
323
+ this._spanGroupHorizontally(section);
354
324
  }
355
325
  }
326
+ this._restructuring = false;
356
327
 
357
- this._restructuring = false; // Request re-rendering
358
-
328
+ // Request re-rendering
359
329
  for (i = hostCount; --i >= 0;) {
360
330
  var settings = this._hosts[i].getSectionSettings("title");
361
-
362
331
  if (settings) {
363
332
  settings.rerender();
364
333
  }
@@ -367,8 +336,6 @@ ColumnGroupingPlugin.prototype._applyGrouping = function () {
367
336
  /** Set a timer to call applyGrouping only once to avoid performance issue
368
337
  * @private
369
338
  */
370
-
371
-
372
339
  ColumnGroupingPlugin.prototype._requestApplyGrouping = function () {
373
340
  if (!this._rerenderTimerId) {
374
341
  this._rerenderTimerId = setTimeout(this._applyGrouping.bind(this), 10);
@@ -378,38 +345,28 @@ ColumnGroupingPlugin.prototype._requestApplyGrouping = function () {
378
345
  * @private
379
346
  * @param {number} colIndex
380
347
  */
381
-
382
-
383
348
  ColumnGroupingPlugin.prototype._applyNearestGrouping = function (colIndex) {
384
349
  if (colIndex == null || colIndex < 0) {
385
350
  return;
386
351
  }
387
-
388
352
  var colIndexLeft = colIndex - 1;
389
353
  var colIndexRight = colIndex + 1;
390
354
  var groupLeftIds = this.getGroupIds(colIndexLeft);
391
355
  var groupRightIds = this.getGroupIds(colIndexRight);
392
-
393
356
  if (groupLeftIds && groupRightIds) {
394
357
  var i, j, groupLeftId, groupRightId, field;
395
358
  var found = false;
396
-
397
359
  for (i = 0; i < groupLeftIds.length; i++) {
398
360
  groupLeftId = groupLeftIds[i];
399
-
400
361
  for (j = 0; j < groupRightIds.length; j++) {
401
362
  groupRightId = groupRightIds[j];
402
-
403
363
  if (groupLeftId === groupRightId) {
404
364
  // found same Id between group
405
365
  field = this.getColumnId(colIndex);
406
-
407
366
  this._addGroupChild(field, groupRightId);
408
-
409
367
  found = true;
410
368
  }
411
369
  }
412
-
413
370
  if (found) {
414
371
  break;
415
372
  }
@@ -419,31 +376,24 @@ ColumnGroupingPlugin.prototype._applyNearestGrouping = function (colIndex) {
419
376
  /** @private
420
377
  * @param {Object=} titleSection
421
378
  */
422
-
423
-
424
379
  ColumnGroupingPlugin.prototype._spanGroupVertically = function (titleSection) {
425
380
  var api = this.getGridApi();
426
-
427
381
  if (!api) {
428
382
  return;
429
383
  }
430
-
431
384
  var core = this._hosts[0];
432
385
  var maxDepth = this._maxDepth;
433
386
  var rowCount = maxDepth + 1;
434
387
  var colCount = api.getColumnCount();
435
-
436
388
  for (var col = 0; col < colCount; col++) {
437
389
  var toSpan = rowCount;
438
-
439
390
  var parentNode = this._getParentGroup(this.getColumnId(col));
440
-
441
391
  if (parentNode) {
442
392
  var depth = parentNode["onRow"] + 1;
443
393
  toSpan = rowCount - depth;
444
- } // Note that invisible column cannot have row span
445
-
394
+ }
446
395
 
396
+ // Note that invisible column cannot have row span
447
397
  if (core.isColumnVisible(col) && toSpan > 1) {
448
398
  titleSection.setCellRowSpan(col, rowCount - toSpan, toSpan);
449
399
  }
@@ -452,21 +402,17 @@ ColumnGroupingPlugin.prototype._spanGroupVertically = function (titleSection) {
452
402
  /** @private
453
403
  * @param {Object} titleSection
454
404
  */
455
-
456
-
457
405
  ColumnGroupingPlugin.prototype._spanGroupHorizontally = function (titleSection) {
458
406
  var section = titleSection;
459
- var groupTable = this._groupMap; // Span column of column group
407
+ var groupTable = this._groupMap;
460
408
 
409
+ // Span column of column group
461
410
  for (var id in groupTable) {
462
411
  var node = groupTable[id];
463
-
464
412
  var colSpans = this._findColumnSpans(node); // find appropriate span
465
413
 
466
-
467
414
  for (var col = 0; col < colSpans.length; col++) {
468
415
  var spanIndexes = colSpans[col];
469
-
470
416
  if (spanIndexes.length > 0) {
471
417
  // This could be unnecessary
472
418
  var start = spanIndexes[0];
@@ -479,38 +425,33 @@ ColumnGroupingPlugin.prototype._spanGroupHorizontally = function (titleSection)
479
425
  };
480
426
  /** @private
481
427
  */
482
-
483
-
484
428
  ColumnGroupingPlugin.prototype._renderGroups = function () {
485
429
  var hostCount = this._hosts.length;
486
430
  var groupMap = this._groupMap;
487
-
488
431
  for (var i = 0; i < hostCount; ++i) {
489
432
  var section = this._hosts[i].getSection("title");
490
-
491
433
  if (!section) {
492
434
  continue;
493
435
  }
494
-
495
436
  var arg = {};
496
-
497
437
  for (var id in groupMap) {
498
438
  var node = groupMap[id];
499
439
  var colIndex = node["colIndex"];
500
440
  var rowIndex = node["onRow"];
501
441
  var cell = section.getCell(colIndex, rowIndex);
502
-
503
442
  if (cell) {
443
+ // Overide the defaults
504
444
  cell.setStyle("text-align", node["alignment"] || "");
505
445
  cell.setTooltip(ColumnGroupingPlugin._getTooltip(node));
506
446
  cell.setContent(node["title"] || node["name"]);
507
- cell.addClass("no-sort"); // TODO: This should be removed after rerendering
508
447
 
448
+ // Additional cell settings must be removed in the _applyGrouping() method
449
+ cell.addClass("no-sort");
450
+ cell.setAttribute("group-id", node["id"]);
509
451
  if (node["legacyRender"]) {
510
452
  // Built-in version if render receive colIndex, cell, groupDefinition as arguments
511
453
  node["legacyRender"](colIndex, cell, node);
512
454
  }
513
-
514
455
  if (node["render"]) {
515
456
  arg["cell"] = cell;
516
457
  arg["colIndex"] = colIndex;
@@ -521,40 +462,98 @@ ColumnGroupingPlugin.prototype._renderGroups = function () {
521
462
  }
522
463
  }
523
464
  };
465
+
524
466
  /** @private
525
467
  * @param {Object} e
526
468
  */
527
-
528
-
529
469
  ColumnGroupingPlugin.prototype._onPostSectionRender = function (e) {
530
470
  if (e.sectionType === "title" && !this._restructuring) {
531
471
  this._renderGroups();
532
472
  }
533
473
  };
474
+
534
475
  /** @private
535
- * @param {Object} e dispatching of columnAdded event object
536
- */
476
+ * @param {Object} e dispatching of columnAdded event object
477
+ */
478
+ ColumnGroupingPlugin.prototype._requestApplyAddChildGroup = function (e) {
479
+ this._addingEvents.push(e);
480
+ if (!this._addingTimerId) {
481
+ this._addingTimerId = setTimeout(this._applyTimeSeries.bind(this, e), 10);
482
+ }
483
+ };
537
484
 
485
+ /** @private
486
+ * @param {Object} e dispatching of columnAdded event object
487
+ */
488
+ ColumnGroupingPlugin.prototype._applyTimeSeries = function (e) {
489
+ this._addingTimerId = 0; // clear timer
490
+ var addingEvents = this._addingEvents.map(function (eventObj) {
491
+ return eventObj;
492
+ });
493
+ this._addingEvents.length = 0; // clear conflation value
538
494
 
539
- ColumnGroupingPlugin.prototype._onColumnAdded = function (e) {
540
495
  var colIndex = e.colIndex;
541
-
496
+ var i;
497
+ if (addingEvents.length > 0) {
498
+ var addingEvent;
499
+ var children = [];
500
+ var firstChildColumn;
501
+ for (i = 0; i < addingEvents.length; i++) {
502
+ addingEvent = addingEvents[i];
503
+ if (addingEvent.context.asChildrenTimeSeries) {
504
+ if (!firstChildColumn) {
505
+ firstChildColumn = addingEvent.context;
506
+ }
507
+ var childIndex = addingEvent.colIndex; // Assume time series column ordered
508
+ var childId = this.getColumnId(childIndex);
509
+ children.push(childId);
510
+ }
511
+ }
512
+ if (firstChildColumn && firstChildColumn.asChildrenTimeSeries) {
513
+ var tsParentDef = firstChildColumn.parent;
514
+ if (tsParentDef) {
515
+ var parentName = tsParentDef.getName();
516
+ var parentId = tsParentDef.getId();
517
+ var groupId = "timeSerieGroup_" + parentId;
518
+ var getGroupDefintion = this.getGroupDefinition(groupId);
519
+ if (getGroupDefintion) {
520
+ // add children time series field to parent
521
+ for (i = 0; i < children.length; i++) {
522
+ var child = children[i];
523
+ this._addGroupChild(child, groupId);
524
+ }
525
+ } else {
526
+ // create new group
527
+ this.addGroup({
528
+ id: groupId,
529
+ title: parentName,
530
+ children: children
531
+ });
532
+ }
533
+ }
534
+ }
535
+ }
542
536
  this._applyNearestGrouping(colIndex);
537
+ this._requestApplyGrouping();
538
+ };
543
539
 
540
+ /** @private
541
+ * @param {Object} e dispatching of columnAdded event object
542
+ */
543
+ ColumnGroupingPlugin.prototype._onColumnAdded = function (e) {
544
+ var colIndex = e.colIndex;
545
+ this._requestApplyAddChildGroup(e);
546
+ this._applyNearestGrouping(colIndex);
544
547
  this._requestApplyGrouping();
545
548
  };
546
549
  /** @private
547
550
  */
548
-
549
-
550
551
  ColumnGroupingPlugin.prototype._onColumnChanged = function () {
551
552
  this._requestApplyGrouping();
552
553
  };
553
554
  /** @private
554
555
  * @param {Object} e dispatching of columnMoved event object
555
556
  */
556
-
557
-
558
557
  ColumnGroupingPlugin.prototype._onColumnMoved = function (e) {
559
558
  var toColIndex = e.toColIndex;
560
559
  var colId = this.getColumnId(toColIndex);
@@ -565,44 +564,35 @@ ColumnGroupingPlugin.prototype._onColumnMoved = function (e) {
565
564
  var colIdRight = this.getColumnId(colIndexRight);
566
565
  var groupIdLeft = this._childToParent[colIdLeft];
567
566
  var groupIdRight = this._childToParent[colIdRight];
568
-
569
567
  if (groupId != groupIdLeft && groupId != groupIdRight) {
570
568
  // remove column from previous group
571
569
  if (groupId) {
572
570
  var groupChild = this.getGroupChildren(groupId);
573
571
  var removeIndex = groupChild.indexOf(colId);
574
-
575
572
  if (removeIndex > -1) {
576
573
  groupChild.splice(removeIndex, 1);
577
574
  }
578
-
579
575
  this.setGroupChildren(groupId, groupChild);
580
576
  }
581
-
582
577
  this._applyNearestGrouping(toColIndex);
583
578
  }
584
-
585
579
  this._requestApplyGrouping();
586
580
  };
587
581
  /** @private
588
582
  * @param {Object} e
589
583
  */
590
-
591
-
592
584
  ColumnGroupingPlugin.prototype._onBeforeColumnBoundUpdate = function (e) {
593
585
  var selectedColumns = e.selectedColumns;
594
- var parentMap = this._childToParent; // Find non-grouped column
586
+ var parentMap = this._childToParent;
595
587
 
588
+ // Find non-grouped column
596
589
  var i, colId, nonGroupedColId, groupId;
597
590
  var colIds = [];
598
591
  var groupMap = {};
599
-
600
592
  for (i = 0; i < selectedColumns.length; i++) {
601
593
  colId = this.getColumnId(selectedColumns[i]);
602
-
603
594
  if (colId) {
604
595
  groupId = parentMap[colId];
605
-
606
596
  if (!groupId) {
607
597
  nonGroupedColId = colId;
608
598
  break;
@@ -618,36 +608,30 @@ ColumnGroupingPlugin.prototype._onBeforeColumnBoundUpdate = function (e) {
618
608
  e.topBoundRowIndex = 0;
619
609
  return;
620
610
  }
621
-
622
611
  var topBoundRowIndex = this._maxDepth; // Column title row
623
- // Find minimum row index of group
624
612
 
613
+ // Find minimum row index of group
625
614
  var rootGroupMap = {};
626
615
  var headerRowIndex, group;
627
-
628
616
  for (groupId in groupMap) {
629
617
  group = this._getRootGroup(groupId);
630
618
  rootGroupMap[group.id] = group;
631
619
  headerRowIndex = groupMap[groupId].onRow + 1;
632
-
633
620
  if (headerRowIndex < topBoundRowIndex) {
634
621
  topBoundRowIndex = headerRowIndex;
635
622
  }
636
- } // Traverse down from the root group to find group that its all members are selected
637
-
623
+ }
638
624
 
625
+ // Traverse down from the root group to find group that its all members are selected
639
626
  var n, members, allSelected, findingGroup, children;
640
627
  var nextLevelGroups = rootGroupMap;
641
-
642
628
  for (i = 0; i < topBoundRowIndex; i++) {
643
629
  findingGroup = nextLevelGroups;
644
630
  nextLevelGroups = {};
645
-
646
631
  for (groupId in findingGroup) {
647
632
  group = findingGroup[groupId];
648
633
  allSelected = true;
649
634
  members = this._getGroupMembers(group);
650
-
651
635
  if (members.length <= colIds.length) {
652
636
  for (n = 0; n < members.length; n++) {
653
637
  if (colIds.indexOf(members[n]) < 0) {
@@ -655,27 +639,23 @@ ColumnGroupingPlugin.prototype._onBeforeColumnBoundUpdate = function (e) {
655
639
  break;
656
640
  }
657
641
  }
658
-
659
642
  if (allSelected) {
660
643
  e.topBoundRowIndex = i;
661
644
  return;
662
645
  }
663
- } // Cache the next level group
664
-
646
+ }
665
647
 
648
+ // Cache the next level group
666
649
  children = group.children;
667
-
668
650
  for (n = 0; n < children.length; n++) {
669
651
  var id = children[n];
670
652
  group = this._groupMap[id];
671
-
672
653
  if (group) {
673
654
  nextLevelGroups[id] = group;
674
655
  }
675
656
  }
676
657
  }
677
658
  }
678
-
679
659
  e.topBoundRowIndex = topBoundRowIndex;
680
660
  };
681
661
  /** Deprecated. Column should be directly added through grid APIs.
@@ -685,40 +665,32 @@ ColumnGroupingPlugin.prototype._onBeforeColumnBoundUpdate = function (e) {
685
665
  * @param {string} groupId
686
666
  * @param {number} colIndex Column index
687
667
  */
688
-
689
-
690
668
  ColumnGroupingPlugin.prototype.addColumnToGroup = function (column, groupId, colIndex) {
691
669
  if (!column || !groupId) return;
692
670
  var columnIndex = colIndex || this.getColumnCount();
693
-
694
671
  this._addGroupChild(column.id, groupId);
695
-
696
672
  if (this._realTimeGrid) {
697
673
  this._realTimeGrid.insertColumn(column, columnIndex);
698
674
  } else if (this._compositeGrid) {
699
675
  this._compositeGrid.insertColumn(columnIndex, column);
700
676
  }
701
677
  };
678
+
702
679
  /** Add new group definition to existing group structure. Inexisting or duplicate group id is not allowed
703
680
  * @public
704
681
  * @param {ColumnGroupingPlugin~GroupDefinition} groupDef Group definition object
705
682
  * @return {boolean} Return true if there is any change
706
683
  */
707
-
708
-
709
684
  ColumnGroupingPlugin.prototype.addGroup = function (groupDef) {
710
685
  if (groupDef && groupDef.id) {
711
686
  var curDef = this.getGroupDefinition(groupDef.id);
712
-
713
687
  if (!curDef) {
714
- this._groupDefs.push(groupDef);
715
-
688
+ var newGroupDef = cloneObject(groupDef);
689
+ this._groupDefs.push(newGroupDef);
716
690
  this._applyGrouping();
717
-
718
691
  return true;
719
692
  }
720
693
  }
721
-
722
694
  return false;
723
695
  };
724
696
  /** Deprecated. Use addGroup() method instead
@@ -728,51 +700,39 @@ ColumnGroupingPlugin.prototype.addGroup = function (groupDef) {
728
700
  * @param {ColumnGroupingPlugin~GroupDefinition} groupDef Group definition object
729
701
  * @see {@link ColumnGroupingPlugin#addGroup}
730
702
  */
731
-
732
-
733
703
  ColumnGroupingPlugin.prototype.addColumnGrouping = ColumnGroupingPlugin.prototype.addGroup;
734
704
  /** @public
735
705
  * @param {string} groupId
736
706
  * @return {Object} Return removed group definition object.
737
707
  */
738
-
739
708
  ColumnGroupingPlugin.prototype.removeGroup = function (groupId) {
740
709
  var curDef = this.getGroupDefinition(groupId);
741
-
742
710
  if (curDef) {
743
711
  var at = this._groupDefs.indexOf(curDef);
744
-
745
712
  this._groupDefs.splice(at, 1);
746
-
747
713
  this._applyGrouping();
748
714
  }
749
-
750
715
  return curDef;
751
716
  };
717
+
752
718
  /** Remove all existing group definitions and replace with the given definitions.
753
719
  * @public
754
720
  * @param {ColumnGroupingPlugin~GroupDefinitions} groupDefs Use null or empty array to remove all existing groups
755
721
  */
756
-
757
-
758
722
  ColumnGroupingPlugin.prototype.setGroupDefinitions = function (groupDefs) {
759
723
  if (Array.isArray(groupDefs)) {
760
724
  groupDefs = groupDefs.filter(ColumnGroupingPlugin._isValidGroup);
761
-
762
725
  if (!groupDefs.length) {
763
726
  groupDefs = null;
764
727
  }
765
728
  } else {
766
729
  groupDefs = null;
767
730
  }
768
-
769
731
  if (groupDefs) {
770
732
  this._groupDefs = groupDefs;
771
-
772
733
  this._applyGrouping();
773
734
  } else if (this._groupDefs.length) {
774
735
  this._groupDefs = [];
775
-
776
736
  this._applyGrouping();
777
737
  }
778
738
  };
@@ -781,8 +741,6 @@ ColumnGroupingPlugin.prototype.setGroupDefinitions = function (groupDefs) {
781
741
  * @param {Object} groupDef
782
742
  * @return {boolean}
783
743
  */
784
-
785
-
786
744
  ColumnGroupingPlugin._isValidGroup = function (groupDef) {
787
745
  if (groupDef) {
788
746
  if (groupDef.id) {
@@ -793,15 +751,20 @@ ColumnGroupingPlugin._isValidGroup = function (groupDef) {
793
751
  return true;
794
752
  }
795
753
  }
796
-
797
754
  return false;
798
755
  };
756
+ /** @private
757
+ * @function
758
+ * @param {Object} obj
759
+ * @return {boolean}
760
+ */
761
+ ColumnGroupingPlugin._cloneObject = function (obj) {
762
+ return cloneObject(obj);
763
+ };
799
764
  /** Get a shallow copy of all existing group definitions
800
765
  * @public
801
766
  * @return {!ColumnGroupingPlugin~GroupDefinitions}
802
767
  */
803
-
804
-
805
768
  ColumnGroupingPlugin.prototype.getGroupDefinitions = function () {
806
769
  return this._groupDefs.slice();
807
770
  };
@@ -810,17 +773,12 @@ ColumnGroupingPlugin.prototype.getGroupDefinitions = function () {
810
773
  * @param {string} groupId
811
774
  * @param {ColumnGroupingPlugin~GroupDefinition} newDef
812
775
  */
813
-
814
-
815
776
  ColumnGroupingPlugin.prototype.setGroupDefinition = function (groupId, newDef) {
816
777
  var curDef = this.getGroupDefinition(groupId);
817
-
818
778
  if (curDef) {
819
779
  var at = this._groupDefs.indexOf(curDef);
820
-
821
780
  newDef.id = groupId;
822
781
  this._groupDefs[at] = newDef;
823
-
824
782
  this._applyGrouping();
825
783
  }
826
784
  };
@@ -828,13 +786,10 @@ ColumnGroupingPlugin.prototype.setGroupDefinition = function (groupId, newDef) {
828
786
  * @param {string} groupId
829
787
  * @return {ColumnGroupingPlugin~GroupDefinition}
830
788
  */
831
-
832
-
833
789
  ColumnGroupingPlugin.prototype.getGroupDefinition = function (groupId) {
834
790
  if (groupId) {
835
791
  return this._groupMap[groupId] || null;
836
792
  }
837
-
838
793
  return null;
839
794
  };
840
795
  /** Replace and update existing group definition.
@@ -842,19 +797,14 @@ ColumnGroupingPlugin.prototype.getGroupDefinition = function (groupId) {
842
797
  * @param {string} groupId
843
798
  * @param {Array.<string>} newChildList If null is given, all existing children in the group will be removed
844
799
  */
845
-
846
-
847
800
  ColumnGroupingPlugin.prototype.setGroupChildren = function (groupId, newChildList) {
848
801
  var groupDef = this.getGroupDefinition(groupId);
849
-
850
802
  if (groupDef) {
851
803
  if (Array.isArray(newChildList)) {
852
804
  groupDef.children = newChildList.slice();
853
-
854
805
  this._applyGrouping();
855
806
  } else if (!newChildList && groupDef.children.length) {
856
807
  groupDef.children = [];
857
-
858
808
  this._applyGrouping();
859
809
  }
860
810
  }
@@ -863,250 +813,202 @@ ColumnGroupingPlugin.prototype.setGroupChildren = function (groupId, newChildLis
863
813
  * @param {string} groupId
864
814
  * @return {Array.<string>}
865
815
  */
866
-
867
-
868
816
  ColumnGroupingPlugin.prototype.getGroupChildren = function (groupId) {
869
817
  var groupDef = this.getGroupDefinition(groupId);
870
-
871
818
  if (groupDef) {
872
819
  return groupDef.children.slice(); // Shallow copy
873
820
  }
874
821
 
875
822
  return null;
876
823
  };
824
+
877
825
  /** Return all column indices under the given group id
878
826
  * @public
879
827
  * @param {string} groupId
880
828
  * @return {Array.<number>}
881
829
  */
882
-
883
-
884
830
  ColumnGroupingPlugin.prototype.getChildColumnIndices = function (groupId) {
885
831
  var group = this._groupMap[groupId];
886
-
887
832
  if (group) {
888
833
  var colIds = this._getGroupMembers(group);
889
-
890
834
  var colIndices = [];
891
835
  var id;
892
-
893
836
  for (var i = 0; i < colIds.length; i++) {
894
837
  id = this._getColumnIndexById(colIds[i]);
895
-
896
838
  if (id > -1) {
897
839
  colIndices.push(id);
898
840
  }
899
841
  }
900
-
901
842
  return colIndices.sort();
902
843
  }
903
-
904
844
  return null;
905
845
  };
846
+
906
847
  /** @public
907
848
  * @param {string|number} colRef
908
849
  * @return {Array.<string>}
909
850
  */
910
-
911
-
912
851
  ColumnGroupingPlugin.prototype.getGroupIds = function (colRef) {
913
852
  if (colRef != null) {
914
853
  var colId = colRef;
915
-
916
854
  if (typeof colRef === "number") {
917
855
  colId = this.getColumnId(colRef);
918
856
  }
919
-
920
857
  if (colId) {
921
858
  var groupId = this._childToParent[colId];
922
-
923
859
  if (groupId) {
924
860
  var groupIds = [groupId];
925
861
  var group = this._groupMap[groupId];
926
-
927
862
  while (group && group.parent) {
928
863
  group = this.getGroupDefinition(group.parent);
929
-
930
864
  if (group) {
931
865
  groupIds.push(group.id);
932
866
  }
933
867
  }
934
-
935
868
  return groupIds;
936
869
  }
937
870
  }
938
871
  }
939
-
940
872
  return null;
941
873
  };
874
+
942
875
  /** Return deepest row index of column headers
943
876
  * @public
944
877
  * @return {number}
945
878
  */
946
-
947
-
948
879
  ColumnGroupingPlugin.prototype.getMaxGroupLevel = function () {
949
880
  return this._maxDepth;
950
881
  };
882
+
951
883
  /** Return row index of the given group id
952
884
  * @public
953
885
  * @param {string} groupId
954
886
  * @return {number}
955
887
  */
956
-
957
-
958
888
  ColumnGroupingPlugin.prototype.getGroupLevel = function (groupId) {
959
889
  var group = this._groupMap[groupId];
960
-
961
890
  if (group) {
962
891
  return group.onRow;
963
892
  }
964
-
965
893
  return -1;
966
894
  };
895
+
967
896
  /** @private
968
897
  * @param {ColumnGroupingPlugin~GroupDefinition} group Group definition
969
898
  * @param {Array=} members
970
899
  * @return {Array.<string>}
971
900
  */
972
-
973
-
974
901
  ColumnGroupingPlugin.prototype._getGroupMembers = function (group, members) {
975
902
  if (!members) {
976
903
  members = [];
977
904
  }
978
-
979
905
  var children = group.children;
980
906
  var groupMap = this._groupMap;
981
907
  var g, id;
982
-
983
908
  for (var i = 0; i < children.length; i++) {
984
909
  id = children[i];
985
910
  g = groupMap[id];
986
-
987
911
  if (g) {
988
912
  this._getGroupMembers(g, members);
989
913
  } else {
990
914
  members.push(id);
991
915
  }
992
916
  }
993
-
994
917
  return members;
995
918
  };
919
+
996
920
  /** @private
997
921
  * @param {String} groupId
998
922
  * @return {ColumnGroupingPlugin~GroupDefinition}
999
923
  */
1000
-
1001
-
1002
924
  ColumnGroupingPlugin.prototype._getRootGroup = function (groupId) {
1003
925
  if (!groupId) {
1004
926
  return null;
1005
927
  }
1006
-
1007
928
  var group = this._groupMap[groupId];
1008
-
1009
929
  while (group.parent) {
1010
930
  group = this.getGroupDefinition(group.parent);
1011
931
  }
1012
-
1013
932
  return group;
1014
933
  };
934
+
1015
935
  /** @private
1016
936
  */
1017
-
1018
-
1019
937
  ColumnGroupingPlugin.prototype._evaluateGroupStructure = function () {
1020
938
  // Clear existing group structure
1021
939
  this._groupMap = {};
1022
940
  this._childToParent = {};
1023
- this._maxDepth = -1; // Flatten tree to dictionary
941
+ this._maxDepth = -1;
1024
942
 
943
+ // Flatten tree to dictionary
1025
944
  var columnGroups = this._groupDefs;
1026
945
  var inUsedGroup = {};
1027
946
  var node;
1028
-
1029
947
  for (var cg = 0; cg < columnGroups.length; cg++) {
1030
948
  // node can be a root or child
1031
- node = columnGroups[cg]; // skip tree that don't have a child
1032
-
949
+ node = columnGroups[cg];
950
+ // skip tree that don't have a child
1033
951
  if (node.children && node.children.length) {
1034
952
  this._flattenTree(node, inUsedGroup);
1035
953
  }
1036
954
  }
1037
-
1038
- var id; // Apply parent id to columnGroup for easy to find depth
1039
-
955
+ var id;
956
+ // Apply parent id to columnGroup for easy to find depth
1040
957
  for (id in this._groupMap) {
1041
958
  node = this._groupMap[id];
1042
-
1043
959
  if (this._childToParent[node.id]) {
1044
960
  var parentId = this._childToParent[node.id];
1045
961
  node["parent"] = parentId;
1046
962
  }
1047
- } // find depth of each group
1048
-
963
+ }
1049
964
 
965
+ // find depth of each group
1050
966
  for (id in this._groupMap) {
1051
967
  node = this._groupMap[id];
1052
-
1053
968
  var depth = this._findGroupTreeDepth(node, 1);
1054
-
1055
969
  node["onRow"] = depth - 1; // Modify user's object
1056
- } // Calculate max depth
1057
-
970
+ }
1058
971
 
972
+ // Calculate max depth
1059
973
  var maxDepth = 0;
1060
-
1061
974
  for (id in this._groupMap) {
1062
975
  node = this._groupMap[id];
1063
976
  depth = node["onRow"] + 1;
1064
-
1065
977
  if (depth > maxDepth) {
1066
978
  maxDepth = depth;
1067
979
  }
1068
980
  }
1069
-
1070
981
  this._maxDepth = maxDepth;
1071
982
  };
1072
983
  /** @private
1073
984
  * @param {Object} node
1074
985
  * @param {boolean} inUsedGroup
1075
986
  */
1076
-
1077
-
1078
987
  ColumnGroupingPlugin.prototype._flattenTree = function (node, inUsedGroup) {
1079
988
  var childrens = node.children;
1080
-
1081
989
  if (childrens && childrens.length > 0) {
1082
990
  var childId;
1083
-
1084
991
  for (var c = 0; c < childrens.length; c++) {
1085
992
  var child = childrens[c];
1086
-
1087
993
  if (child.id) {
1088
994
  // child is group object
1089
995
  childId = child.id;
1090
-
1091
996
  this._flattenTree(child, inUsedGroup);
1092
997
  } else {
1093
998
  // child can be column id or group id
1094
999
  childId = child;
1095
-
1096
1000
  if (inUsedGroup[childId] || this._getColumnIndexById(childId) !== -1) {
1097
1001
  inUsedGroup[node.id] = true;
1098
1002
  }
1099
1003
  }
1100
-
1101
1004
  if (!this._childToParent[childId] && childId != node.id) {
1102
1005
  this._childToParent[childId] = node.id;
1103
1006
  }
1104
- } // Create Tree node for only in-used group
1105
-
1007
+ }
1106
1008
 
1009
+ // Create Tree node for only in-used group
1107
1010
  if (!this._groupMap[node.id] && inUsedGroup[node.id]) {
1108
- // need to change
1109
- this._groupMap[node.id] = node; // TODO: Check if we need to clone
1011
+ this._groupMap[node.id] = cloneObject(node); // clone node
1110
1012
  }
1111
1013
  }
1112
1014
  };
@@ -1115,59 +1017,47 @@ ColumnGroupingPlugin.prototype._flattenTree = function (node, inUsedGroup) {
1115
1017
  * @param {number} currentDepth
1116
1018
  * @return {number}
1117
1019
  */
1118
-
1119
-
1120
1020
  ColumnGroupingPlugin.prototype._findGroupTreeDepth = function (node, currentDepth) {
1121
1021
  var parentId = node["parent"];
1122
1022
  var parentNode = this._groupMap[parentId];
1123
-
1124
1023
  if (parentNode) {
1125
1024
  return this._findGroupTreeDepth(parentNode, currentDepth + 1);
1126
1025
  } else {
1127
1026
  return currentDepth;
1128
1027
  }
1129
1028
  };
1029
+
1130
1030
  /** This version exclude invisible column unlike the one in GridPlugin
1131
1031
  * @private
1132
1032
  * @param {string} id
1133
1033
  * @return {number} index of the column
1134
1034
  */
1135
-
1136
-
1137
1035
  ColumnGroupingPlugin.prototype._getColumnIndexById = function (id) {
1138
1036
  var api = this.getGridApi();
1139
-
1140
1037
  if (api && id) {
1141
1038
  var core = this._hosts[0];
1142
1039
  var colCount = core.getColumnCount();
1143
-
1144
1040
  for (var c = 0; c < colCount; c++) {
1145
1041
  if (this.getColumnId(c) === id && core.isColumnVisible(c)) {
1146
1042
  return c;
1147
1043
  }
1148
1044
  }
1149
1045
  }
1150
-
1151
1046
  return -1;
1152
1047
  };
1153
1048
  /** @private
1154
1049
  * @param {Object} node
1155
1050
  * @param {Array} cluster
1156
1051
  */
1157
-
1158
-
1159
1052
  ColumnGroupingPlugin.prototype._findColumnIndexArr = function (node, cluster) {
1160
1053
  if (node) {
1161
1054
  var childrens = node.children;
1162
-
1163
1055
  if (childrens && childrens.length) {
1164
1056
  for (var i = 0; i < childrens.length; i++) {
1165
1057
  var child = childrens[i];
1166
-
1167
1058
  if (!child.id) {
1168
1059
  if (!this._groupMap[child]) {
1169
1060
  var colIndex = this._getColumnIndexById(child);
1170
-
1171
1061
  if (colIndex !== -1) {
1172
1062
  cluster.push(colIndex);
1173
1063
  }
@@ -1179,7 +1069,6 @@ ColumnGroupingPlugin.prototype._findColumnIndexArr = function (node, cluster) {
1179
1069
  if (child.id === node.id) {
1180
1070
  return;
1181
1071
  }
1182
-
1183
1072
  this._findColumnIndexArr(this._groupMap[child.id], cluster);
1184
1073
  }
1185
1074
  }
@@ -1190,38 +1079,29 @@ ColumnGroupingPlugin.prototype._findColumnIndexArr = function (node, cluster) {
1190
1079
  * @param {Object} node
1191
1080
  * @return {Array} group of span index
1192
1081
  */
1193
-
1194
-
1195
1082
  ColumnGroupingPlugin.prototype._findColumnSpans = function (node) {
1196
1083
  var cluster = [];
1197
-
1198
1084
  this._findColumnIndexArr(node, cluster); // Recursively get column index
1199
1085
 
1200
-
1201
1086
  return ColumnGroupingPlugin._groupConsecutiveArr(cluster);
1202
1087
  };
1203
1088
  /** @private
1204
1089
  * @param {Array} arr
1205
1090
  * @return {Array} group of Consecutive number
1206
1091
  */
1207
-
1208
-
1209
1092
  ColumnGroupingPlugin._groupConsecutiveArr = function (arr) {
1210
1093
  var result = [];
1211
-
1212
1094
  if (!arr || !arr.length) {
1213
1095
  return result;
1214
1096
  }
1215
-
1216
1097
  var array = arr.sort(function (a, b) {
1217
1098
  return a - b;
1218
1099
  });
1219
1100
  var start = array[0];
1220
- var stop = start; // start at second member of array
1221
-
1101
+ var stop = start;
1102
+ // start at second member of array
1222
1103
  for (var i = 1; i <= array.length; i++) {
1223
1104
  var next = array[i];
1224
-
1225
1105
  if (next === stop + 1) {
1226
1106
  // move to next member
1227
1107
  stop = next;
@@ -1230,28 +1110,22 @@ ColumnGroupingPlugin._groupConsecutiveArr = function (arr) {
1230
1110
  result.push([start, start]);
1231
1111
  } else {
1232
1112
  result.push([start, stop]);
1233
- } // reset the start and stop pointers
1234
-
1235
-
1113
+ }
1114
+ // reset the start and stop pointers
1236
1115
  start = array[i];
1237
1116
  stop = start;
1238
1117
  }
1239
1118
  }
1240
-
1241
1119
  return result;
1242
1120
  };
1243
1121
  /** @private
1244
1122
  * @param {string} childId
1245
1123
  * @param {string} groupId
1246
1124
  */
1247
-
1248
-
1249
1125
  ColumnGroupingPlugin.prototype._addGroupChild = function (childId, groupId) {
1250
1126
  var groupDef = this.getGroupDefinition(groupId);
1251
-
1252
1127
  if (childId && groupDef) {
1253
1128
  var chdr = groupDef.children;
1254
-
1255
1129
  if (chdr && chdr.indexOf(childId) < 0) {
1256
1130
  this._childToParent[childId] = groupId;
1257
1131
  chdr.push(childId);
@@ -1262,8 +1136,6 @@ ColumnGroupingPlugin.prototype._addGroupChild = function (childId, groupId) {
1262
1136
  * @param {string} childId
1263
1137
  * @return {ColumnGroupingPlugin~GroupDefinition}
1264
1138
  */
1265
-
1266
-
1267
1139
  ColumnGroupingPlugin.prototype._getParentGroup = function (childId) {
1268
1140
  return this.getGroupDefinition(this._childToParent[childId]);
1269
1141
  };
@@ -1272,63 +1144,45 @@ ColumnGroupingPlugin.prototype._getParentGroup = function (childId) {
1272
1144
  * @param {number} groupLevel
1273
1145
  * @return {string}
1274
1146
  */
1275
-
1276
-
1277
1147
  ColumnGroupingPlugin.prototype._getGroupId = function (colId, groupLevel) {
1278
1148
  var groupId = this._childToParent[colId];
1279
-
1280
1149
  if (!groupId) {
1281
1150
  return "";
1282
1151
  }
1283
-
1284
1152
  if (groupLevel == null) {
1285
1153
  return groupId;
1286
1154
  }
1287
-
1288
1155
  var currentLevel = this.getGroupLevel(groupId);
1289
-
1290
1156
  while (currentLevel > groupLevel && groupId) {
1291
1157
  groupId = this._childToParent[groupId];
1292
1158
  currentLevel--;
1293
1159
  }
1294
-
1295
1160
  return groupId || "";
1296
1161
  };
1297
1162
  /** @public
1298
1163
  * @param {Element|Event|MouseEvent} e
1299
1164
  * @return {Object}
1300
1165
  */
1301
-
1302
-
1303
1166
  ColumnGroupingPlugin.prototype.getCellInfo = function (e) {
1304
1167
  var api = this.getGridApi();
1305
1168
  var grid = e["grid"] || this.getRelativeGrid(e);
1306
-
1307
1169
  if (!api || !grid) {
1308
1170
  return null;
1309
1171
  }
1310
-
1311
1172
  var cellInfo = grid.getCellInfo(e);
1312
-
1313
1173
  if (!cellInfo.cell) {
1314
1174
  var cell = cellInfo.section.getCell(cellInfo.colIndex, cellInfo.rowIndex);
1315
1175
  cellInfo["cell"] = cell;
1316
1176
  }
1317
-
1318
1177
  var colId = this.getColumnId(cellInfo.colIndex);
1319
-
1320
1178
  var groupId = this._getGroupId(colId, cellInfo.sectionType == "title" ? cellInfo.rowIndex : null);
1321
-
1322
1179
  if (!groupId) {
1323
1180
  cellInfo["columnId"] = colId;
1324
1181
  return cellInfo;
1325
1182
  }
1326
-
1327
1183
  var groupInfo = this.getGroupDefinition(groupId);
1328
-
1329
1184
  if (groupInfo) {
1330
1185
  var isGroupHeader = cellInfo.sectionType == "title" && cellInfo.rowIndex == this.getGroupLevel(groupId);
1331
-
1332
1186
  if (isGroupHeader) {
1333
1187
  cellInfo["groupId"] = groupInfo.id;
1334
1188
  cellInfo["groupName"] = groupInfo.name;
@@ -1336,10 +1190,8 @@ ColumnGroupingPlugin.prototype.getCellInfo = function (e) {
1336
1190
  } else {
1337
1191
  cellInfo["columnId"] = colId;
1338
1192
  }
1339
-
1340
1193
  cellInfo["parent"] = isGroupHeader ? groupInfo.parent || null : groupInfo.id;
1341
1194
  }
1342
-
1343
1195
  return cellInfo;
1344
1196
  };
1345
1197
  /** @public
@@ -1347,122 +1199,98 @@ ColumnGroupingPlugin.prototype.getCellInfo = function (e) {
1347
1199
  * @param {number} to
1348
1200
  * @param {string} groupId
1349
1201
  */
1350
-
1351
-
1352
1202
  ColumnGroupingPlugin.prototype.moveColumnIntoGroup = function (from, to, groupId) {
1353
1203
  var fromIndex = -1;
1354
-
1355
1204
  if (typeof from == "string") {
1356
1205
  fromIndex = this._getColumnIndexById(from);
1357
1206
  } else {
1358
1207
  fromIndex = from;
1359
1208
  }
1360
-
1361
1209
  if (fromIndex == -1) {
1362
1210
  return;
1363
1211
  }
1364
-
1365
1212
  var groupDef = this.getGroupDefinition(groupId);
1366
-
1367
1213
  if (!groupDef) {
1368
1214
  for (var j = this._hosts.length; --j >= 0;) {
1369
1215
  var grid = this._hosts[j];
1370
1216
  grid.moveColumn(fromIndex, to);
1371
1217
  }
1372
-
1373
1218
  return;
1374
1219
  }
1375
-
1376
1220
  var childIndices = this.getChildColumnIndices(groupId);
1377
1221
  var startIndex = -1;
1378
1222
  var endIndex = -1;
1379
-
1380
1223
  if (childIndices && childIndices.length) {
1381
1224
  startIndex = childIndices[0];
1382
1225
  endIndex = childIndices[childIndices.length - 1];
1383
1226
  }
1384
-
1385
1227
  if (to < startIndex) {
1386
- to = startIndex; // handle move column to right
1387
-
1228
+ to = startIndex;
1229
+ // handle move column to right
1388
1230
  if (to > fromIndex) {
1389
1231
  to -= 1;
1390
1232
  }
1391
1233
  } else if (to > endIndex) {
1392
- to = endIndex; // handle move column to left
1393
-
1234
+ to = endIndex;
1235
+ // handle move column to left
1394
1236
  if (to < fromIndex) {
1395
1237
  to += 1;
1396
1238
  }
1397
- } //find column index that should be moved, it should not be between columns in child group
1398
-
1239
+ }
1399
1240
 
1241
+ //find column index that should be moved, it should not be between columns in child group
1400
1242
  for (var i = 0; i < groupDef.children.length; i++) {
1401
1243
  var notAllowIndices = this.getChildColumnIndices(groupDef.children[i]);
1402
-
1403
1244
  if (notAllowIndices && notAllowIndices.length) {
1404
1245
  var notAllowStart = notAllowIndices[0];
1405
1246
  var notAllowEnd = notAllowIndices[notAllowIndices.length - 1];
1406
-
1407
1247
  if (to > fromIndex) {
1408
1248
  notAllowStart -= 1;
1409
1249
  }
1410
-
1411
1250
  if (to < fromIndex) {
1412
1251
  notAllowEnd += 1;
1413
1252
  }
1414
-
1415
1253
  if (to > notAllowStart && to < notAllowEnd) {
1416
1254
  to = notAllowEnd;
1417
1255
  }
1418
1256
  }
1419
1257
  }
1420
-
1421
1258
  for (var gridIndex = this._hosts.length; --gridIndex >= 0;) {
1422
1259
  var host = this._hosts[gridIndex];
1423
1260
  host.moveColumn(fromIndex, to);
1424
- } //remove previous group apply to column
1425
-
1261
+ }
1426
1262
 
1263
+ //remove previous group apply to column
1427
1264
  var colId = this.getColumnId(to);
1428
1265
  var previousGroup = this._childToParent[colId];
1429
-
1430
1266
  if (previousGroup) {
1431
1267
  var previousGroupChild = this.getGroupChildren(previousGroup);
1432
1268
  previousGroupChild.splice(previousGroupChild.indexOf(colId), 1);
1433
1269
  this.setGroupChildren(previousGroup, previousGroupChild);
1434
- } //apply new group
1435
-
1270
+ }
1436
1271
 
1272
+ //apply new group
1437
1273
  var children = this.getGroupChildren(groupId);
1438
-
1439
1274
  if (children.indexOf(colId) == -1) {
1440
1275
  if (colId) {
1441
1276
  children.push(colId);
1442
1277
  }
1443
1278
  }
1444
-
1445
1279
  this.setGroupChildren(groupId, children);
1446
-
1447
1280
  this._requestApplyGrouping();
1448
1281
  };
1449
1282
  /** @public
1450
1283
  * @param {number|string} columnIndex //Column index or id that should be moved
1451
1284
  * @param {string} groupId
1452
1285
  */
1453
-
1454
-
1455
1286
  ColumnGroupingPlugin.prototype.setColumnParent = function (columnIndex, groupId) {
1456
1287
  var api = this.getGridApi();
1457
-
1458
1288
  if (!api) {
1459
1289
  return;
1460
1290
  }
1461
-
1462
1291
  var grid = this._hosts[0];
1463
1292
  var colCount = grid.getColumnCount();
1464
1293
  this.moveColumnIntoGroup(columnIndex, colCount, groupId);
1465
1294
  };
1466
-
1467
1295
  export default ColumnGroupingPlugin;
1468
1296
  export { ColumnGroupingPlugin, ColumnGroupingPlugin as ColumnGrouping, ColumnGroupingPlugin as ColumnGroupingExtension };