@refinitiv-ui/efx-grid 6.0.20 → 6.0.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. package/lib/column-dragging/es6/ColumnDragging.js +46 -24
  2. package/lib/core/dist/core.js +61 -14
  3. package/lib/core/dist/core.min.js +1 -1
  4. package/lib/core/es6/grid/Core.js +11 -1
  5. package/lib/core/es6/grid/LayoutGrid.js +1 -0
  6. package/lib/core/es6/grid/components/CellSpans.d.ts +2 -0
  7. package/lib/core/es6/grid/components/CellSpans.js +35 -10
  8. package/lib/core/es6/grid/plugins/SortableTitlePlugin.d.ts +2 -0
  9. package/lib/core/es6/grid/plugins/SortableTitlePlugin.js +14 -3
  10. package/lib/grid/index.js +1 -1
  11. package/lib/rt-grid/dist/rt-grid.js +362 -41
  12. package/lib/rt-grid/dist/rt-grid.min.js +1 -1
  13. package/lib/rt-grid/es6/Grid.d.ts +10 -1
  14. package/lib/rt-grid/es6/Grid.js +196 -17
  15. package/lib/rt-grid/es6/ReferenceCounter.js +13 -2
  16. package/lib/rt-grid/es6/RowDefinition.d.ts +2 -0
  17. package/lib/rt-grid/es6/RowDefinition.js +74 -8
  18. package/lib/tr-grid-column-grouping/es6/ColumnGrouping.d.ts +9 -5
  19. package/lib/tr-grid-column-grouping/es6/ColumnGrouping.js +365 -133
  20. package/lib/tr-grid-column-resizing/es6/ColumnResizing.js +11 -37
  21. package/lib/tr-grid-row-selection/es6/RowSelection.d.ts +15 -15
  22. package/lib/tr-grid-row-selection/es6/RowSelection.js +9 -1
  23. package/lib/types/es6/ColumnGrouping.d.ts +9 -5
  24. package/lib/types/es6/Core/grid/components/CellSpans.d.ts +2 -0
  25. package/lib/types/es6/Core/grid/plugins/SortableTitlePlugin.d.ts +2 -0
  26. package/lib/types/es6/RealtimeGrid/Grid.d.ts +10 -1
  27. package/lib/types/es6/RealtimeGrid/RowDefinition.d.ts +2 -0
  28. package/lib/types/es6/RowSelection.d.ts +15 -15
  29. package/lib/versions.json +4 -4
  30. package/package.json +6 -2
@@ -74,6 +74,10 @@ ColumnGroupingPlugin.prototype._maxDepth = 0;
74
74
  * @private
75
75
  */
76
76
  ColumnGroupingPlugin.prototype._restructuring = false;
77
+ /** @type {boolean}
78
+ * @private
79
+ */
80
+ ColumnGroupingPlugin.prototype._autoGrouping = true;
77
81
  /** @type {number}
78
82
  * @private
79
83
  */
@@ -113,6 +117,59 @@ ColumnGroupingPlugin._getTooltip = function (groupingOptions) {
113
117
  }
114
118
  return title;
115
119
  };
120
+ /** @private
121
+ * @function
122
+ * @param {Object} groupDef
123
+ * @return {boolean}
124
+ */
125
+ ColumnGroupingPlugin._isValidGroup = function (groupDef) {
126
+ if (groupDef) {
127
+ if (groupDef.id) {
128
+ return true;
129
+ }
130
+ }
131
+ return false;
132
+ };
133
+ /** @private
134
+ * @function
135
+ * @param {Array|Object} obj
136
+ * @param {string=} groupId
137
+ * @return {ColumnGroupingPlugin~GroupDefinition}
138
+ */
139
+ ColumnGroupingPlugin._toGroupDefinition = function (obj, groupId) {
140
+ var groupDef = null;
141
+ if (obj) {
142
+ if (Array.isArray(obj)) {
143
+ groupDef = {
144
+ children: obj
145
+ };
146
+ } else {
147
+ groupDef = ColumnGroupingPlugin._cloneObject(obj);
148
+ }
149
+ if (groupId) {
150
+ if (!groupDef.id) {
151
+ groupDef.name = groupId;
152
+ }
153
+ groupDef.id = groupId;
154
+ }
155
+ }
156
+ return groupDef;
157
+ };
158
+ /** @private
159
+ * @function
160
+ * @param {Object} obj
161
+ * @return {Object}
162
+ */
163
+ ColumnGroupingPlugin._cloneObject = function (obj) {
164
+ var newObj = cloneObject(obj);
165
+ if (Array.isArray(newObj.children)) {
166
+ newObj.children = newObj.children;
167
+ } else {
168
+ newObj.children = [];
169
+ }
170
+ return newObj;
171
+ };
172
+
116
173
  /** @public
117
174
  * @return {string}
118
175
  */
@@ -219,8 +276,8 @@ ColumnGroupingPlugin.prototype.config = function (options) {
219
276
  }
220
277
  var extOptions = options["columnGrouping"];
221
278
  if (Array.isArray(extOptions)) {
222
- var groupDefs = extOptions.map(ColumnGroupingPlugin._cloneObject);
223
- this._groupDefs = groupDefs.filter(ColumnGroupingPlugin._isValidGroup);
279
+ var groupDefs = extOptions.filter(ColumnGroupingPlugin._isValidGroup);
280
+ this._groupDefs = groupDefs.map(ColumnGroupingPlugin._cloneObject);
224
281
  }
225
282
  var columns = options["columns"];
226
283
  if (!columns) {
@@ -243,8 +300,10 @@ ColumnGroupingPlugin.prototype.getConfigObject = function (gridOptions) {
243
300
  var obj = gridOptions || {};
244
301
 
245
302
  // TODO: Handle legacyRender method that has been migrated
246
- var columnGroupingDefs = this.getGroupDefinitions();
247
- obj.columnGrouping = columnGroupingDefs;
303
+ var groupDefs = this.getGroupDefinitions();
304
+ if (groupDefs.length) {
305
+ obj.columnGrouping = groupDefs;
306
+ }
248
307
  return obj;
249
308
  };
250
309
 
@@ -256,14 +315,6 @@ ColumnGroupingPlugin.prototype._setColumnGrouping = function (colIndex, data) {
256
315
  var colData = this._newColumnData(colIndex);
257
316
  colData["columnGrouping"] = data;
258
317
  };
259
- /** @private
260
- * @param {number} colIndex
261
- * @return {Object}
262
- */
263
- ColumnGroupingPlugin.prototype._getColumnGrouping = function (colIndex) {
264
- return this._getColumnOption(colIndex, "columnGrouping");
265
- };
266
-
267
318
  /** Legacy group structure from composite grid will be converted to the new structure
268
319
  * @private
269
320
  * @param {Object.<string, Array>} objMap
@@ -378,8 +429,8 @@ ColumnGroupingPlugin.prototype._applyGrouping = function () {
378
429
  */
379
430
  ColumnGroupingPlugin.prototype._evaluateGroupStructure = function () {
380
431
  // Clear existing group structure
381
- var groupMap = this._groupMap = {};
382
- var childToParent = this._childToParent = {};
432
+ var groupMap = this._groupMap = {}; // TODO: This is bad
433
+ var childToParent = this._childToParent = {}; // TODO: This is bad
383
434
  var visibleGroupMap = this._visibleGroupMap = {};
384
435
  this._maxDepth = -1;
385
436
 
@@ -406,11 +457,12 @@ ColumnGroupingPlugin.prototype._evaluateGroupStructure = function () {
406
457
  // Create child to parent map
407
458
  var gid, children, member;
408
459
  for (gid in groupMap) {
409
- groupDef = groupMap[gid];
410
- children = groupDef.children;
411
- for (i = 0; i < children.length; i++) {
412
- member = children[i];
413
- childToParent[member] = gid;
460
+ children = this._getAvaliableChildren(gid);
461
+ if (children.length > 1) {
462
+ for (i = 0; i < children.length; i++) {
463
+ member = children[i];
464
+ childToParent[member] = gid;
465
+ }
414
466
  }
415
467
  }
416
468
 
@@ -424,7 +476,7 @@ ColumnGroupingPlugin.prototype._evaluateGroupStructure = function () {
424
476
  }
425
477
  }
426
478
 
427
- // Filter invisible groups out
479
+ // Filter out groups that are invisible
428
480
  var rootGroup = [];
429
481
  for (gid in visibleGroupMap) {
430
482
  groupDef = visibleGroupMap[gid];
@@ -478,7 +530,7 @@ ColumnGroupingPlugin.prototype._flattenGroupDefs = function (groupDef, groupDefs
478
530
  }
479
531
  this._flattenGroupDefs(member, groupDefs);
480
532
  }
481
- }
533
+ } // TODO: Invalid group is not flatten
482
534
  }
483
535
  }
484
536
  };
@@ -790,25 +842,27 @@ ColumnGroupingPlugin.prototype._onColumnChanged = function () {
790
842
  * @param {Object} e dispatching of columnMoved event object
791
843
  */
792
844
  ColumnGroupingPlugin.prototype._onColumnMoved = function (e) {
793
- var toColIndex = e.toColIndex;
794
- var colId = this.getColumnId(toColIndex);
795
- var groupId = this._childToParent[colId];
796
- if (groupId) {
797
- var colIdLeft = this.getColumnId(toColIndex - 1);
798
- var colIdRight = this.getColumnId(toColIndex + 1);
799
- var groupIdLeft = this._childToParent[colIdLeft];
800
- var groupIdRight = this._childToParent[colIdRight];
801
- if (groupId != groupIdLeft && groupId != groupIdRight) {
802
- // Remove column from previous group
803
- var children = this.getGroupChildren(groupId);
804
- var removeIndex = children.indexOf(colId);
805
- if (removeIndex > -1) {
806
- children.splice(removeIndex, 1);
845
+ if (this._autoGrouping) {
846
+ var toColIndex = e.toColIndex;
847
+ var colId = this.getColumnId(toColIndex);
848
+ var groupId = this._childToParent[colId];
849
+ if (groupId) {
850
+ var colIdLeft = this.getColumnId(toColIndex - 1);
851
+ var colIdRight = this.getColumnId(toColIndex + 1);
852
+ var groupIdLeft = this._childToParent[colIdLeft];
853
+ var groupIdRight = this._childToParent[colIdRight];
854
+ if (groupId != groupIdLeft && groupId != groupIdRight) {
855
+ // Remove column from previous group
856
+ var children = this.getGroupChildren(groupId);
857
+ var removeIndex = children.indexOf(colId);
858
+ if (removeIndex > -1) {
859
+ children.splice(removeIndex, 1);
860
+ }
861
+ this.setGroupChildren(groupId, children);
807
862
  }
808
- this.setGroupChildren(groupId, children);
809
863
  }
864
+ this._applyNearestGrouping(toColIndex);
810
865
  }
811
- this._applyNearestGrouping(toColIndex);
812
866
  this._requestApplyGrouping();
813
867
  };
814
868
  /** @private
@@ -820,19 +874,7 @@ ColumnGroupingPlugin.prototype._onColumnRemoved = function (e) {
820
874
  var colId = colData.columnGrouping.id;
821
875
  var groupId = this._childToParent[colId];
822
876
  if (groupId) {
823
- var groupDef = this._groupMap[groupId];
824
- if (groupDef) {
825
- var children = groupDef.children;
826
- var index = children.indexOf(colId);
827
- if (index > -1) {
828
- if (children.length < 3) {
829
- this._groupDefs.splice(this._groupDefs.indexOf(groupDef), 1);
830
- } else {
831
- children.splice(index, 1);
832
- }
833
- this._requestApplyGrouping();
834
- }
835
- }
877
+ this._requestApplyGrouping();
836
878
  }
837
879
  }
838
880
  };
@@ -940,22 +982,69 @@ ColumnGroupingPlugin.prototype.addColumnToGroup = function (column, groupId, col
940
982
  }
941
983
  };
942
984
 
943
- /** Add new group definition to existing group structure. Inexisting or duplicate group id is not allowed
985
+ /** Remove each child from another group
986
+ * @private
987
+ * @param {Array.<string>} children
988
+ */
989
+ ColumnGroupingPlugin.prototype._ungroupChildren = function (children) {
990
+ if (Array.isArray(children)) {
991
+ var len = children.length;
992
+ for (var i = 0; i < len; ++i) {
993
+ this._unsetParent(children[i]);
994
+ }
995
+ }
996
+ };
997
+ /** Unset parent of the specified id
998
+ * @private
999
+ * @param {string} childId
1000
+ */
1001
+ ColumnGroupingPlugin.prototype._unsetParent = function (childId) {
1002
+ var parentId = this._childToParent[childId];
1003
+ if (parentId) {
1004
+ this._childToParent[childId] = "";
1005
+ var grpDef = this._groupMap[parentId];
1006
+ if (grpDef) {
1007
+ var chdr = grpDef.children;
1008
+ if (chdr.length) {
1009
+ var at = chdr.indexOf(childId);
1010
+ if (at >= 0) {
1011
+ chdr.splice(at, 1); // splice is slow
1012
+ }
1013
+ }
1014
+ }
1015
+ }
1016
+ };
1017
+ /** Remove all children from the specified group
1018
+ * @private
1019
+ * @param {string} grpId
1020
+ */
1021
+ ColumnGroupingPlugin.prototype._removeAllChildren = function (grpId) {
1022
+ var grpDef = this._groupMap[grpId];
1023
+ if (grpDef) {
1024
+ var chdr = grpDef.children;
1025
+ var len = chdr.length;
1026
+ if (len) {
1027
+ grpDef.children = [];
1028
+ for (var i = 0; i < len; ++i) {
1029
+ var childId = chdr[i];
1030
+ if (this._childToParent[childId]) {
1031
+ this._childToParent[childId] = "";
1032
+ }
1033
+ }
1034
+ }
1035
+ }
1036
+ };
1037
+
1038
+ /** Add new group definition to existing group structure. Existing group with the same id will be replaced.
944
1039
  * @public
945
1040
  * @param {ColumnGroupingPlugin~GroupDefinition} groupDef Group definition object
946
- * @return {boolean} Return true if there is any change
1041
+ * @return {string} Return group ID
947
1042
  */
948
1043
  ColumnGroupingPlugin.prototype.addGroup = function (groupDef) {
949
- if (groupDef && groupDef.id) {
950
- var curDef = this.getGroupDefinition(groupDef.id);
951
- if (!curDef) {
952
- var newGroupDef = ColumnGroupingPlugin._cloneObject(groupDef);
953
- this._groupDefs.push(newGroupDef);
954
- this._applyGrouping();
955
- return true;
956
- }
1044
+ if (ColumnGroupingPlugin._isValidGroup(groupDef)) {
1045
+ return this.setGroupDefinition(groupDef.id, groupDef);
957
1046
  }
958
- return false;
1047
+ return "";
959
1048
  };
960
1049
  /** Deprecated. Use addGroup() method instead
961
1050
  * @deprecated
@@ -967,10 +1056,10 @@ ColumnGroupingPlugin.prototype.addGroup = function (groupDef) {
967
1056
  ColumnGroupingPlugin.prototype.addColumnGrouping = ColumnGroupingPlugin.prototype.addGroup;
968
1057
  /** @public
969
1058
  * @param {string} groupId
970
- * @return {Object} Return removed group definition object.
1059
+ * @return {ColumnGroupingPlugin~GroupDefinition} Return removed group definition object.
971
1060
  */
972
1061
  ColumnGroupingPlugin.prototype.removeGroup = function (groupId) {
973
- var curDef = this.getGroupDefinition(groupId);
1062
+ var curDef = this._groupMap[groupId];
974
1063
  if (curDef) {
975
1064
  var at = this._groupDefs.indexOf(curDef);
976
1065
  this._groupDefs.splice(at, 1);
@@ -979,14 +1068,87 @@ ColumnGroupingPlugin.prototype.removeGroup = function (groupId) {
979
1068
  return curDef;
980
1069
  };
981
1070
 
1071
+ /** @public
1072
+ * @param {string} groupId
1073
+ * @return {ColumnGroupingPlugin~GroupDefinition}
1074
+ */
1075
+ ColumnGroupingPlugin.prototype.getGroupDefinition = function (groupId) {
1076
+ if (groupId) {
1077
+ // Check for group validility
1078
+ var groupDef = this._groupMap[groupId];
1079
+ if (!groupDef) {
1080
+ return null;
1081
+ }
1082
+ groupDef = ColumnGroupingPlugin._cloneObject(groupDef); // TODO: this is slow
1083
+ var children = this._getAvaliableChildren(groupId);
1084
+ groupDef.children = children;
1085
+ return groupDef;
1086
+ }
1087
+ return null;
1088
+ };
1089
+ /** Get a shallow copy of all existing group definitions
1090
+ * @public
1091
+ * @return {!ColumnGroupingPlugin~GroupDefinitions}
1092
+ */
1093
+ ColumnGroupingPlugin.prototype.getGroupDefinitions = function () {
1094
+ var validGroupDefs = [];
1095
+ var len = this._groupDefs.length;
1096
+ var groupDef;
1097
+ for (var i = 0; i < len; i++) {
1098
+ groupDef = this.getGroupDefinition(this._groupDefs[i].id);
1099
+ if (groupDef && groupDef.children.length > 1) {
1100
+ validGroupDefs.push(groupDef);
1101
+ }
1102
+ }
1103
+ return validGroupDefs;
1104
+ };
1105
+ /** 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.
1106
+ * @public
1107
+ * @param {string} groupId
1108
+ * @param {ColumnGroupingPlugin~GroupDefinition=} groupDef
1109
+ * @return {string} Group Id
1110
+ */
1111
+ ColumnGroupingPlugin.prototype.setGroupDefinition = function (groupId, groupDef) {
1112
+ if (!groupId) {
1113
+ return "";
1114
+ }
1115
+ if (groupDef) {
1116
+ var newDef = ColumnGroupingPlugin._toGroupDefinition(groupDef, groupId);
1117
+ this._ungroupChildren(newDef.children);
1118
+ var curDef = this._groupMap[groupId];
1119
+ if (curDef) {
1120
+ // Replace
1121
+ var at = this._groupDefs.indexOf(curDef);
1122
+ this._groupDefs[at] = newDef;
1123
+ } else {
1124
+ // Add
1125
+ this._groupDefs.push(newDef);
1126
+ }
1127
+ var chdr = newDef.children;
1128
+ var len = chdr.length;
1129
+ // TODO: Filter out group id
1130
+ if (len > 1) {
1131
+ var gridApi = this.getGridApi();
1132
+ if (gridApi && gridApi.reorderColumns) {
1133
+ gridApi.reorderColumns(chdr, chdr[0]); // WARNING: group id doesn't work
1134
+ }
1135
+ }
1136
+
1137
+ this._applyGrouping();
1138
+ } else {
1139
+ // Remove
1140
+ this.removeGroup(groupId);
1141
+ }
1142
+ return groupId;
1143
+ };
982
1144
  /** Remove all existing group definitions and replace with the given definitions.
983
1145
  * @public
984
1146
  * @param {ColumnGroupingPlugin~GroupDefinitions} groupDefs Use null or empty array to remove all existing groups
985
1147
  */
986
1148
  ColumnGroupingPlugin.prototype.setGroupDefinitions = function (groupDefs) {
987
1149
  if (Array.isArray(groupDefs)) {
988
- groupDefs = groupDefs.map(ColumnGroupingPlugin._cloneObject);
989
1150
  groupDefs = groupDefs.filter(ColumnGroupingPlugin._isValidGroup);
1151
+ groupDefs = groupDefs.map(ColumnGroupingPlugin._cloneObject);
990
1152
  if (!groupDefs.length) {
991
1153
  groupDefs = null;
992
1154
  }
@@ -996,80 +1158,22 @@ ColumnGroupingPlugin.prototype.setGroupDefinitions = function (groupDefs) {
996
1158
  if (groupDefs) {
997
1159
  this._groupDefs = groupDefs;
998
1160
  this._applyGrouping();
999
- } else if (this._groupDefs.length) {
1000
- this._groupDefs = [];
1001
- this._applyGrouping();
1002
- }
1003
- };
1004
- /** @private
1005
- * @function
1006
- * @param {Object} groupDef
1007
- * @return {boolean}
1008
- */
1009
- ColumnGroupingPlugin._isValidGroup = function (groupDef) {
1010
- if (groupDef) {
1011
- if (groupDef.id) {
1012
- return true;
1013
- }
1014
- }
1015
- return false;
1016
- };
1017
- /** @private
1018
- * @function
1019
- * @param {Object} obj
1020
- * @return {boolean}
1021
- */
1022
- ColumnGroupingPlugin._cloneObject = function (obj) {
1023
- var newObj = cloneObject(obj);
1024
- if (Array.isArray(newObj.children)) {
1025
- newObj.children = newObj.children;
1026
1161
  } else {
1027
- newObj.children = [];
1028
- }
1029
- return newObj;
1030
- };
1031
- /** Get a shallow copy of all existing group definitions
1032
- * @public
1033
- * @return {!ColumnGroupingPlugin~GroupDefinitions}
1034
- */
1035
- ColumnGroupingPlugin.prototype.getGroupDefinitions = function () {
1036
- return this._groupDefs.slice();
1037
- };
1038
- /** Replace and update existing group definition. Existing group id will not be modified
1039
- * @public
1040
- * @param {string} groupId
1041
- * @param {ColumnGroupingPlugin~GroupDefinition} newDef
1042
- */
1043
- ColumnGroupingPlugin.prototype.setGroupDefinition = function (groupId, newDef) {
1044
- var curDef = this.getGroupDefinition(groupId);
1045
- if (curDef) {
1046
- var at = this._groupDefs.indexOf(curDef);
1047
- newDef = ColumnGroupingPlugin._cloneObject(newDef);
1048
- newDef.id = groupId;
1049
- this._groupDefs[at] = newDef;
1162
+ this._groupDefs = [];
1050
1163
  this._applyGrouping();
1051
1164
  }
1052
1165
  };
1053
- /** @public
1054
- * @param {string} groupId
1055
- * @return {ColumnGroupingPlugin~GroupDefinition}
1056
- */
1057
- ColumnGroupingPlugin.prototype.getGroupDefinition = function (groupId) {
1058
- if (groupId) {
1059
- return this._groupMap[groupId] || null;
1060
- }
1061
- return null;
1062
- };
1063
1166
  /** Replace and update existing group definition.
1064
1167
  * @public
1065
1168
  * @param {string} groupId
1066
1169
  * @param {Array.<string>} newChildList If null is given, all existing children in the group will be removed
1067
1170
  */
1068
1171
  ColumnGroupingPlugin.prototype.setGroupChildren = function (groupId, newChildList) {
1069
- var groupDef = this.getGroupDefinition(groupId);
1172
+ var groupDef = this._groupMap[groupId];
1070
1173
  if (groupDef) {
1071
1174
  if (Array.isArray(newChildList)) {
1072
1175
  groupDef.aaa = 0; // TODO: for testing, need to be removed
1176
+ this._ungroupChildren(newChildList);
1073
1177
  groupDef.children = newChildList.slice();
1074
1178
  this._applyGrouping();
1075
1179
  } else if (!newChildList && groupDef.children.length) {
@@ -1078,14 +1182,37 @@ ColumnGroupingPlugin.prototype.setGroupChildren = function (groupId, newChildLis
1078
1182
  }
1079
1183
  }
1080
1184
  };
1185
+ /** @private
1186
+ * @param {string} groupId
1187
+ * @return {!Array.<string>}
1188
+ */
1189
+ ColumnGroupingPlugin.prototype._getAvaliableChildren = function (groupId) {
1190
+ var groupDef = this._groupMap[groupId];
1191
+ var validChildren = [];
1192
+ if (groupDef) {
1193
+ // Filter out columns that do not exist
1194
+ var groupMap = this._groupMap;
1195
+ var children = groupDef.children;
1196
+ var childId;
1197
+ for (var i = 0; i < children.length; i++) {
1198
+ childId = children[i];
1199
+ if (groupMap[childId] || this.getColumnIndex(childId) > -1) {
1200
+ validChildren.push(childId); // TODO: This is slow
1201
+ }
1202
+ }
1203
+ }
1204
+
1205
+ return validChildren;
1206
+ };
1207
+
1081
1208
  /** @public
1082
1209
  * @param {string} groupId
1083
1210
  * @return {Array.<string>}
1084
1211
  */
1085
1212
  ColumnGroupingPlugin.prototype.getGroupChildren = function (groupId) {
1086
- var groupDef = this.getGroupDefinition(groupId);
1087
- if (groupDef) {
1088
- return groupDef.children;
1213
+ var children = this._getAvaliableChildren(groupId);
1214
+ if (children.length > 1) {
1215
+ return children;
1089
1216
  }
1090
1217
  return null;
1091
1218
  };
@@ -1164,14 +1291,17 @@ ColumnGroupingPlugin.prototype.getGroupLevel = function (groupId) {
1164
1291
  /** @private
1165
1292
  * @param {Object.<string, ColumnGroupingPlugin~GroupDefinition>} groupMap
1166
1293
  * @param {ColumnGroupingPlugin~GroupDefinition} group Group definition
1167
- * @param {Array=} members
1294
+ * @param {Array.<string>=} members
1168
1295
  * @return {Array.<string>}
1169
1296
  */
1170
1297
  ColumnGroupingPlugin.prototype._getGroupMembers = function (groupMap, group, members) {
1171
1298
  if (!members) {
1172
1299
  members = [];
1173
1300
  }
1174
- var children = group.children;
1301
+ var children = this._getAvaliableChildren(group.id);
1302
+ if (children.length < 2) {
1303
+ return members;
1304
+ }
1175
1305
  var g, id;
1176
1306
  for (var i = 0; i < children.length; i++) {
1177
1307
  id = children[i];
@@ -1311,7 +1441,7 @@ ColumnGroupingPlugin.prototype.moveColumnIntoGroup = function (colRef, to, group
1311
1441
  if (fromIndex == -1) {
1312
1442
  return;
1313
1443
  }
1314
- var groupDef = this.getGroupDefinition(groupId);
1444
+ var groupDef = this._groupMap[groupId];
1315
1445
  if (!groupDef) {
1316
1446
  for (var j = this._hosts.length; --j >= 0;) {
1317
1447
  var grid = this._hosts[j];
@@ -1369,6 +1499,7 @@ ColumnGroupingPlugin.prototype.moveColumnIntoGroup = function (colRef, to, group
1369
1499
  host.moveColumn(fromIndex, to);
1370
1500
  }
1371
1501
  if (colId) {
1502
+ // TODO:
1372
1503
  // Remove from current group
1373
1504
  var previousGroup = this._childToParent[colId];
1374
1505
  if (previousGroup) {
@@ -1397,8 +1528,7 @@ ColumnGroupingPlugin.prototype.setColumnParent = function (colRef, groupId) {
1397
1528
  if (!api) {
1398
1529
  return;
1399
1530
  }
1400
- var grid = this._hosts[0];
1401
- var colCount = grid.getColumnCount();
1531
+ var colCount = this.getColumnCount();
1402
1532
  var toIndex = -1;
1403
1533
  var childIndices = this.getChildColumnIndices(groupId);
1404
1534
 
@@ -1411,5 +1541,107 @@ ColumnGroupingPlugin.prototype.setColumnParent = function (colRef, groupId) {
1411
1541
  }
1412
1542
  this.moveColumnIntoGroup(colRef, toIndex, groupId);
1413
1543
  };
1544
+
1545
+ /** @public
1546
+ * Get a valid index for moving group/column to specific index
1547
+ * @param {string} id group id or column id
1548
+ * @param {number|string} destCol destination column index / id
1549
+ * @returns {number} destination index
1550
+ */
1551
+ ColumnGroupingPlugin.prototype.getValidDestinationIndex = function (id, destCol) {
1552
+ var groupDef, parentGroupDef;
1553
+ groupDef = this._groupMap[id];
1554
+ if (groupDef) {
1555
+ parentGroupDef = this.getGroupDefinition(groupDef["parent"]);
1556
+ } else if (this.getColumnIndex(id) > -1) {
1557
+ parentGroupDef = this._getParentGroup(id);
1558
+ }
1559
+ var startIndex = -1;
1560
+ var endIndex = -1;
1561
+ var destColIndex = typeof destCol === "string" ? this.getColumnIndex(destCol) : destCol;
1562
+ if (parentGroupDef) {
1563
+ // If group/column is a child of a group, it should be move within the parent group
1564
+ var childIndices = this.getChildColumnIndices(parentGroupDef["id"]);
1565
+ if (childIndices && childIndices.length) {
1566
+ startIndex = childIndices[0];
1567
+ endIndex = childIndices[childIndices.length - 1];
1568
+ }
1569
+ if (destColIndex < startIndex && destColIndex != -1) {
1570
+ destColIndex = this.getColumnId(startIndex);
1571
+ } else if (destColIndex > endIndex || destColIndex == -1) {
1572
+ destColIndex = this.getColumnId(endIndex + 1);
1573
+ }
1574
+
1575
+ // handle group/column should not insert between group
1576
+ var groupChildren = this.getGroupChildren(parentGroupDef["id"]);
1577
+ for (var i = 0; i < groupChildren.length; i++) {
1578
+ var childId = groupChildren[i];
1579
+ var childGroupIndices = this.getChildColumnIndices(childId);
1580
+ if (childGroupIndices && childGroupIndices.length) {
1581
+ startIndex = childGroupIndices[0];
1582
+ endIndex = childGroupIndices[childGroupIndices.length - 1];
1583
+ if (destColIndex > startIndex && destColIndex <= endIndex) {
1584
+ destColIndex = endIndex + 1;
1585
+ break;
1586
+ }
1587
+ }
1588
+ }
1589
+ } else {
1590
+ // handle group/column should not insert between group when group/column is not a child of any group
1591
+ var destMemberIndices = [];
1592
+ var destColId = this.getColumnId(destColIndex);
1593
+ var destParent = this._getParentGroup(destColId);
1594
+ if (destParent) {
1595
+ if (destParent["parent"]) {
1596
+ destParent = this._getRootGroup(destParent["id"]);
1597
+ }
1598
+ destMemberIndices = this.getChildColumnIndices(destParent["id"]);
1599
+ }
1600
+ if (destMemberIndices && destMemberIndices.length) {
1601
+ startIndex = destMemberIndices[0];
1602
+ endIndex = destMemberIndices[destMemberIndices.length - 1];
1603
+ if (destColIndex > startIndex && destColIndex <= endIndex) {
1604
+ destColIndex = endIndex + 1;
1605
+ }
1606
+ }
1607
+ }
1608
+ return destColIndex;
1609
+ };
1610
+
1611
+ /** @public
1612
+ * Move group or column to left side of the destination column.
1613
+ * Group or column can only be moved within the parent group.
1614
+ * If the destination is between other column group, the destination will change to the end of that group instead.
1615
+ * @param {string} id group id or column id
1616
+ * @param {number|string} destCol destination column index / id
1617
+ */
1618
+ ColumnGroupingPlugin.prototype.moveGroup = function (id, destCol) {
1619
+ var groupDef;
1620
+ var members = [];
1621
+ groupDef = this._groupMap[id];
1622
+ if (groupDef) {
1623
+ var indices = this.getChildColumnIndices(groupDef["id"]);
1624
+ for (var i = 0; i < indices.length; i++) {
1625
+ var index = indices[i];
1626
+ var colId = this.getColumnId(index);
1627
+ members.push(colId);
1628
+ }
1629
+ } else if (this.getColumnIndex(id) > -1) {
1630
+ members.push(id);
1631
+ } else {
1632
+ return;
1633
+ }
1634
+ var destColIndex = this.getValidDestinationIndex(id, destCol);
1635
+ var destColId = this.getColumnId(destColIndex);
1636
+
1637
+ // TODO: create method for toggling autoGrouping flag
1638
+ this._autoGrouping = false;
1639
+ if (this._realTimeGrid) {
1640
+ this._realTimeGrid.reorderColumns(members, destColId);
1641
+ } else if (this._compositeGrid) {
1642
+ this._compositeGrid.reorderColumns(members, destColId);
1643
+ }
1644
+ this._autoGrouping = true;
1645
+ };
1414
1646
  export default ColumnGroupingPlugin;
1415
1647
  export { ColumnGroupingPlugin, ColumnGroupingPlugin as ColumnGrouping, ColumnGroupingPlugin as ColumnGroupingExtension };