@refinitiv-ui/efx-grid 6.0.21 → 6.0.22

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
  */
@@ -128,6 +132,31 @@ ColumnGroupingPlugin._isValidGroup = function (groupDef) {
128
132
  };
129
133
  /** @private
130
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
131
160
  * @param {Object} obj
132
161
  * @return {Object}
133
162
  */
@@ -400,8 +429,8 @@ ColumnGroupingPlugin.prototype._applyGrouping = function () {
400
429
  */
401
430
  ColumnGroupingPlugin.prototype._evaluateGroupStructure = function () {
402
431
  // Clear existing group structure
403
- var groupMap = this._groupMap = {};
404
- var childToParent = this._childToParent = {};
432
+ var groupMap = this._groupMap = {}; // TODO: This is bad
433
+ var childToParent = this._childToParent = {}; // TODO: This is bad
405
434
  var visibleGroupMap = this._visibleGroupMap = {};
406
435
  this._maxDepth = -1;
407
436
 
@@ -501,7 +530,7 @@ ColumnGroupingPlugin.prototype._flattenGroupDefs = function (groupDef, groupDefs
501
530
  }
502
531
  this._flattenGroupDefs(member, groupDefs);
503
532
  }
504
- }
533
+ } // TODO: Invalid group is not flatten
505
534
  }
506
535
  }
507
536
  };
@@ -813,25 +842,27 @@ ColumnGroupingPlugin.prototype._onColumnChanged = function () {
813
842
  * @param {Object} e dispatching of columnMoved event object
814
843
  */
815
844
  ColumnGroupingPlugin.prototype._onColumnMoved = function (e) {
816
- var toColIndex = e.toColIndex;
817
- var colId = this.getColumnId(toColIndex);
818
- var groupId = this._childToParent[colId];
819
- if (groupId) {
820
- var colIdLeft = this.getColumnId(toColIndex - 1);
821
- var colIdRight = this.getColumnId(toColIndex + 1);
822
- var groupIdLeft = this._childToParent[colIdLeft];
823
- var groupIdRight = this._childToParent[colIdRight];
824
- if (groupId != groupIdLeft && groupId != groupIdRight) {
825
- // Remove column from previous group
826
- var children = this.getGroupChildren(groupId);
827
- var removeIndex = children.indexOf(colId);
828
- if (removeIndex > -1) {
829
- 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);
830
862
  }
831
- this.setGroupChildren(groupId, children);
832
863
  }
864
+ this._applyNearestGrouping(toColIndex);
833
865
  }
834
- this._applyNearestGrouping(toColIndex);
835
866
  this._requestApplyGrouping();
836
867
  };
837
868
  /** @private
@@ -956,21 +987,48 @@ ColumnGroupingPlugin.prototype.addColumnToGroup = function (column, groupId, col
956
987
  * @param {Array.<string>} children
957
988
  */
958
989
  ColumnGroupingPlugin.prototype._ungroupChildren = function (children) {
959
- if (Array.isArray(children) && children.length) {
960
- var childToParent = this._childToParent;
961
- var groupMap = this._groupMap;
990
+ if (Array.isArray(children)) {
962
991
  var len = children.length;
963
- var childId, parentId, groupDef, at;
964
- for (var i = 0; i < len; i++) {
965
- childId = children[i];
966
- parentId = childToParent[childId];
967
- if (parentId) {
968
- groupDef = groupMap[parentId];
969
- if (groupDef) {
970
- at = groupDef.children.indexOf(childId);
971
- if (at > -1) {
972
- groupDef.children.splice(at, 1);
973
- }
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] = "";
974
1032
  }
975
1033
  }
976
1034
  }
@@ -984,16 +1042,7 @@ ColumnGroupingPlugin.prototype._ungroupChildren = function (children) {
984
1042
  */
985
1043
  ColumnGroupingPlugin.prototype.addGroup = function (groupDef) {
986
1044
  if (ColumnGroupingPlugin._isValidGroup(groupDef)) {
987
- var curDef = this._groupMap[groupDef.id];
988
- if (!curDef) {
989
- var newGroupDef = ColumnGroupingPlugin._cloneObject(groupDef);
990
- this._ungroupChildren(newGroupDef.children);
991
- this._groupDefs.push(newGroupDef);
992
- this._applyGrouping();
993
- } else {
994
- this.setGroupDefinition(groupDef.id, groupDef);
995
- }
996
- return groupDef.id;
1045
+ return this.setGroupDefinition(groupDef.id, groupDef);
997
1046
  }
998
1047
  return "";
999
1048
  };
@@ -1030,7 +1079,7 @@ ColumnGroupingPlugin.prototype.getGroupDefinition = function (groupId) {
1030
1079
  if (!groupDef) {
1031
1080
  return null;
1032
1081
  }
1033
- groupDef = ColumnGroupingPlugin._cloneObject(groupDef);
1082
+ groupDef = ColumnGroupingPlugin._cloneObject(groupDef); // TODO: this is slow
1034
1083
  var children = this._getAvaliableChildren(groupId);
1035
1084
  groupDef.children = children;
1036
1085
  return groupDef;
@@ -1053,24 +1102,44 @@ ColumnGroupingPlugin.prototype.getGroupDefinitions = function () {
1053
1102
  }
1054
1103
  return validGroupDefs;
1055
1104
  };
1056
- /** Replace and update existing group definition. Existing group id will not be modified
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.
1057
1106
  * @public
1058
1107
  * @param {string} groupId
1059
- * @param {ColumnGroupingPlugin~GroupDefinition} newDef
1108
+ * @param {ColumnGroupingPlugin~GroupDefinition=} groupDef
1109
+ * @return {string} Group Id
1060
1110
  */
1061
- ColumnGroupingPlugin.prototype.setGroupDefinition = function (groupId, newDef) {
1111
+ ColumnGroupingPlugin.prototype.setGroupDefinition = function (groupId, groupDef) {
1062
1112
  if (!groupId) {
1063
- return;
1113
+ return "";
1064
1114
  }
1065
- var curDef = this._groupMap[groupId];
1066
- if (curDef) {
1067
- newDef = ColumnGroupingPlugin._cloneObject(newDef);
1068
- newDef.id = groupId;
1115
+ if (groupDef) {
1116
+ var newDef = ColumnGroupingPlugin._toGroupDefinition(groupDef, groupId);
1069
1117
  this._ungroupChildren(newDef.children);
1070
- var at = this._groupDefs.indexOf(curDef);
1071
- this._groupDefs[at] = newDef;
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
+
1072
1137
  this._applyGrouping();
1138
+ } else {
1139
+ // Remove
1140
+ this.removeGroup(groupId);
1073
1141
  }
1142
+ return groupId;
1074
1143
  };
1075
1144
  /** Remove all existing group definitions and replace with the given definitions.
1076
1145
  * @public
@@ -1128,10 +1197,11 @@ ColumnGroupingPlugin.prototype._getAvaliableChildren = function (groupId) {
1128
1197
  for (var i = 0; i < children.length; i++) {
1129
1198
  childId = children[i];
1130
1199
  if (groupMap[childId] || this.getColumnIndex(childId) > -1) {
1131
- validChildren.push(childId);
1200
+ validChildren.push(childId); // TODO: This is slow
1132
1201
  }
1133
1202
  }
1134
1203
  }
1204
+
1135
1205
  return validChildren;
1136
1206
  };
1137
1207
 
@@ -1429,6 +1499,7 @@ ColumnGroupingPlugin.prototype.moveColumnIntoGroup = function (colRef, to, group
1429
1499
  host.moveColumn(fromIndex, to);
1430
1500
  }
1431
1501
  if (colId) {
1502
+ // TODO:
1432
1503
  // Remove from current group
1433
1504
  var previousGroup = this._childToParent[colId];
1434
1505
  if (previousGroup) {
@@ -1470,5 +1541,107 @@ ColumnGroupingPlugin.prototype.setColumnParent = function (colRef, groupId) {
1470
1541
  }
1471
1542
  this.moveColumnIntoGroup(colRef, toIndex, groupId);
1472
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
+ };
1473
1646
  export default ColumnGroupingPlugin;
1474
1647
  export { ColumnGroupingPlugin, ColumnGroupingPlugin as ColumnGrouping, ColumnGroupingPlugin as ColumnGroupingExtension };
@@ -48,7 +48,7 @@ declare class ColumnGroupingPlugin extends GridPlugin {
48
48
 
49
49
  public getGroupDefinitions(): ColumnGroupingPlugin.GroupDefinitions;
50
50
 
51
- public setGroupDefinition(groupId: string, newDef: ColumnGroupingPlugin.GroupDefinition|null): void;
51
+ public setGroupDefinition(groupId: string, groupDef?: ColumnGroupingPlugin.GroupDefinition|null): string;
52
52
 
53
53
  public setGroupDefinitions(groupDefs: ColumnGroupingPlugin.GroupDefinitions|null): void;
54
54
 
@@ -70,6 +70,10 @@ declare class ColumnGroupingPlugin extends GridPlugin {
70
70
 
71
71
  public setColumnParent(colRef: number|string|null, groupId: string): void;
72
72
 
73
+ public getValidDestinationIndex(id: string, destCol: number|string|null): number;
74
+
75
+ public moveGroup(id: string, destCol: number|string|null): void;
76
+
73
77
  }
74
78
 
75
79
  export default ColumnGroupingPlugin;
@@ -6,6 +6,8 @@ declare class CellSpans {
6
6
 
7
7
  public removeColumn(at: number): boolean;
8
8
 
9
+ public freezeMapping(bool?: boolean|null): void;
10
+
9
11
  public shiftColumn(from: number, amount: number): boolean;
10
12
 
11
13
  public removeSpan(indexX: number, indexY: number): CellSpan|null;
@@ -110,6 +110,8 @@ declare class SortableTitlePlugin extends EventDispatcher {
110
110
 
111
111
  public disableTwoStateSorting(disabled?: boolean|null): void;
112
112
 
113
+ public freezeIndicator(bool?: boolean|null): void;
114
+
113
115
  public disableSortSymbols(disabled?: boolean|null): void;
114
116
 
115
117
  public disableDataSorting(disabled?: boolean|null): void;
@@ -82,7 +82,8 @@ declare namespace Grid {
82
82
  scrollbarParent?: Element|null,
83
83
  formulaEngine?: boolean|null,
84
84
  adcPollingInterval?: number|null,
85
- fieldCaching?: boolean|null
85
+ fieldCaching?: boolean|null,
86
+ childDataField?: string|null
86
87
  };
87
88
 
88
89
  type RowReference = number|string|RowDefinition|null;
@@ -145,6 +146,8 @@ declare class Grid extends EventDispatcher {
145
146
 
146
147
  public moveColumnById(srcCol: number|string|null, destCol?: (number|string)|null): boolean;
147
148
 
149
+ public reorderColumns(colRefs: number|string|(number|string)[]|null, destCol: number|string|null): boolean;
150
+
148
151
  public hideColumn(colRef: Grid.ColumnReference|null, hidden?: boolean|null): void;
149
152
 
150
153
  public hideColumns(colRefs: (Grid.ColumnReference)[]|null, hidden?: boolean|null): void;
@@ -45,6 +45,8 @@ declare class RowDefinition {
45
45
 
46
46
  public setStaticRowData(data: { [key: string]: any }|any[], opt_fields?: (string)[]|null): void;
47
47
 
48
+ public _getStaticRowData(): { [key: string]: any };
49
+
48
50
  public updateRowData(data: { [key: string]: any }|any[], opt_fields?: (string)[]|null): void;
49
51
 
50
52
  public setStaticData(field: string, value: any): void;
package/lib/versions.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "tr-grid-util": "1.3.82",
3
- "@grid/column-dragging": "1.0.10",
3
+ "@grid/column-dragging": "1.0.11",
4
4
  "@grid/row-segmenting": "1.0.22",
5
5
  "@grid/statistics-row": "1.0.13",
6
6
  "@grid/zoom": "1.0.11",
@@ -9,7 +9,7 @@
9
9
  "tr-grid-checkbox": "1.0.60",
10
10
  "tr-grid-column-fitter": "1.0.39",
11
11
  "tr-grid-column-formatting": "0.9.34",
12
- "tr-grid-column-grouping": "1.0.37",
12
+ "tr-grid-column-grouping": "1.0.41",
13
13
  "tr-grid-column-resizing": "1.0.28",
14
14
  "tr-grid-column-selection": "1.0.25",
15
15
  "tr-grid-column-stack": "1.0.48",
package/package.json CHANGED
@@ -52,7 +52,8 @@
52
52
  "./filter-dialog/themes/solar/pearl": "./lib/filter-dialog/themes/solar/pearl.js",
53
53
  "./extensions": "./lib/index.js",
54
54
  "./window-exporter": "./lib/window-exporter.js",
55
- "./grid": "./lib/grid/lib/efx-grid.js"
55
+ "./grid": "./lib/grid/lib/efx-grid.js",
56
+ "./formatters/": "./lib/formatters/es6/"
56
57
  },
57
58
  "peerDependencies": {
58
59
  "@refinitiv-ui/core": "^6.2.0",
@@ -61,5 +62,5 @@
61
62
  "publishConfig": {
62
63
  "access": "public"
63
64
  },
64
- "version": "6.0.21"
65
+ "version": "6.0.22"
65
66
  }