@refinitiv-ui/efx-grid 6.0.24 → 6.0.25

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.
@@ -42,7 +42,7 @@ import Engine from "../../tr-grid-util/es6/formula/Engine.js";
42
42
  * @property {string=} headerAlignment="" Text alignment for column header. This will override `textAlign` option for column header.
43
43
  * @property {string=} titleAlignment="" Alias to `headerAlignment`
44
44
  * @property {boolean=} hidden=false
45
- * @property {string=} id Id for unique identifier
45
+ * @property {string=} id A unique identifier for the column
46
46
  * @property {boolean=} textSelect=false If enabled, user can select text in this column
47
47
  * @property {boolean=} keepModel If enabled, initial column's options will be kept
48
48
  * @property {boolean=} stationary=false If enabled, the column order cannot be changed (i.e., this column and any column to its left cannot be moved)
@@ -8,6 +8,8 @@ declare namespace FieldDefinition {
8
8
 
9
9
  function get(field: string): any;
10
10
 
11
+ function hasFieldInfo(field: string): boolean;
12
+
11
13
  function getTimeSeriesChildren(field: string): any;
12
14
 
13
15
  function addTimeSeriesChild(tsDef: string, childDef: any): void;
@@ -214,6 +214,17 @@ FieldDefinition.get = function(field) {
214
214
  }
215
215
  return null;
216
216
  };
217
+
218
+ /** @public
219
+ * @function
220
+ * @param {string} field
221
+ * @return {boolean}
222
+ */
223
+ FieldDefinition.hasFieldInfo = function(field) {
224
+ var val = FieldDefinition.get(field);
225
+ return val && val.field; // Already preventing an error caused by accessing a property on a null value
226
+ };
227
+
217
228
  /** @public
218
229
  * @function
219
230
  * @param {string} field
@@ -376,8 +387,8 @@ FieldDefinition.loadFieldInfo = function (field) {
376
387
  defer.resolve(null);
377
388
  }
378
389
  // already have field definition then return
379
- else if (FieldDefinition._defs[field]) {
380
- defer.resolve(FieldDefinition._defs[field]);
390
+ else if (FieldDefinition.hasFieldInfo(field)) {
391
+ defer.resolve(FieldDefinition.get(field));
381
392
  }
382
393
  // in debug using mock data instead
383
394
  else if (synapse.debug) {
@@ -1264,7 +1264,9 @@ Grid.prototype._onFieldAdded = function(e) {
1264
1264
  // JET
1265
1265
  if (this._subs) {
1266
1266
  var realtimeFields = addedFields.filter(FieldDefinition.isRealTimeField);
1267
- this._subs["addFields"](realtimeFields);
1267
+ if(realtimeFields.length > 0) {
1268
+ this._subs["addFields"](realtimeFields);
1269
+ }
1268
1270
  }
1269
1271
 
1270
1272
  this._dispatch(e.type, e);
@@ -1556,19 +1558,31 @@ Grid.prototype._setScrollbarParent = function (host) {
1556
1558
  /**
1557
1559
  * @private
1558
1560
  * @param {string} field
1559
- * @param {boolean} isRealTime
1560
1561
  * @returns {boolean}
1561
1562
  */
1562
- Grid.prototype._shouldLoadFieldInfo = function (field, isRealTime) {
1563
- var fieldDef = FieldDefinition.get(field);
1564
- if (!fieldDef &&
1565
- field !== 'X_RIC_NAME' && // ignore X_RIC_NAME
1566
- (isRealTime || FieldDefinition.isAdc(field)) && // realtime field or adc field (Without static field)
1567
- (this._RTK || window["JET"]) // have rtk instance or window jet sub
1568
- ) {
1569
- return true;
1563
+ Grid.prototype._shouldLoadFieldInfo = function (field) {
1564
+
1565
+ var val = this._RTK || window["JET"]; // Fastest checking can be performed by checking the first condition.
1566
+ if(!val) {
1567
+ return false;
1570
1568
  }
1571
- return false;
1569
+
1570
+ // WARNING: If field caching is disabled, it shouldn't load field info
1571
+ if(!this._fieldCaching) {
1572
+ return false;
1573
+ }
1574
+
1575
+ val = FieldDefinition.hasFieldInfo(field);
1576
+ if(val) {
1577
+ return false;
1578
+ }
1579
+
1580
+ val = FieldDefinition.isAdc(field) || FieldDefinition.isRealTimeField(field);
1581
+ if(!val) {
1582
+ return false;
1583
+ }
1584
+
1585
+ return true;
1572
1586
  };
1573
1587
  /** Remove all existing columns and add new columns based on the given objects
1574
1588
  * @public
@@ -1670,11 +1684,10 @@ Grid.prototype._onColumnAdded = function(e) {
1670
1684
  var fields = colDef.getAllFields();
1671
1685
  var referrer = colDef.getId();
1672
1686
  var len = fields.length;
1673
- var field, dataType, prom, isRealTimeField, onLoaded;
1687
+ var field, dataType, prom, onLoaded;
1674
1688
  for(i = 0; i < len; i++) {
1675
1689
  field = fields[i];
1676
- isRealTimeField = FieldDefinition.isRealTimeField(field);
1677
- if(this._shouldLoadFieldInfo(field, isRealTimeField)) {
1690
+ if(this._shouldLoadFieldInfo(field)) {
1678
1691
  if(field === colField) {
1679
1692
  dataType = colDef.getDataType(); // Data-type from user's column options
1680
1693
  } else { // Other required fields
@@ -1843,6 +1856,15 @@ Grid.prototype.moveColumnById = function (srcCol, destCol) {
1843
1856
  if(destIndex < 0) {
1844
1857
  destIndex = colCount;
1845
1858
  }
1859
+ return this._moveColumnByIndex(srcIndex, destIndex);
1860
+ };
1861
+ /** Move column without verification for better performance
1862
+ * @private
1863
+ * @param {number} srcIndex Column index
1864
+ * @param {number} destIndex Column index of the destination
1865
+ * @return {boolean} Return true if there is any change, and false otherwise
1866
+ */
1867
+ Grid.prototype._moveColumnByIndex = function (srcIndex, destIndex) {
1846
1868
  if(srcIndex < destIndex) { // Ensure that the source column is put in front of the destination index
1847
1869
  --destIndex;
1848
1870
  }
@@ -1864,23 +1886,31 @@ Grid.prototype.reorderColumns = function (colRefs, destCol) {
1864
1886
  var srcLen = colRefs.length;
1865
1887
  if(srcLen > 1) {
1866
1888
  var colIds = this.getColumnIds();
1889
+ var colCount = colIds.length;
1867
1890
  var srcIds = [];
1868
1891
  var invalidDest = false;
1869
- var i;
1892
+ var i, srcId, srcIdx;
1870
1893
  for(i = 0; i < srcLen; ++i) {
1871
1894
  var colRef = colRefs[i];
1872
- var srcId = (typeof colRef === "number") ? colIds[colRef] : colRef;
1873
- if(srcId) {
1895
+ if(typeof colRef === "number") {
1896
+ srcIdx = colRef;
1897
+ srcId = colIds[colRef] || "";
1898
+ } else {
1899
+ srcId = colRef;
1900
+ srcIdx = colIds.indexOf(srcId);
1901
+ }
1902
+ if(srcId && srcIdx >= 0) {
1874
1903
  srcIds.push(srcId);
1875
1904
  if(destId === srcId) {
1876
1905
  invalidDest = true; // Destination must not exist in source columns
1877
1906
  }
1878
1907
  }
1879
1908
  }
1909
+
1910
+ var destIdx;
1880
1911
  srcLen = srcIds.length;
1881
1912
  if(invalidDest) { // Find the next valid destination where it is not contained in the source columns
1882
- var colCount = colIds.length;
1883
- var destIdx = this.getColumnIndex(destId);
1913
+ destIdx = this.getColumnIndex(destId);
1884
1914
  if(destIdx >= 0) {
1885
1915
  while(++destIdx < colCount) {
1886
1916
  destId = colIds[destIdx];
@@ -1895,10 +1925,16 @@ Grid.prototype.reorderColumns = function (colRefs, destCol) {
1895
1925
  }
1896
1926
 
1897
1927
  var dirty = 0;
1898
- for(i = 0; i < srcLen; ++i) {
1899
- dirty |= this.moveColumnById(srcIds[i], destId);
1928
+ for(i = srcLen; --i >= 0;) {
1929
+ srcId = srcIds[i]; // Only valid source columns are left at this point
1930
+ srcIdx = this.getColumnIndex(srcId);
1931
+ destIdx = this.getColumnIndex(destId);
1932
+ if(destIdx < 0) { // Insert to the back when id is not found
1933
+ destIdx = colCount;
1934
+ }
1935
+ dirty |= this._moveColumnByIndex(srcIdx, destIdx);
1936
+ destId = srcId;
1900
1937
  }
1901
- // TODO: Handle the case where all columns stay in the same place
1902
1938
  return dirty ? true : false;
1903
1939
  } else {
1904
1940
  return this.moveColumnById(colRefs[0], destId);
@@ -1975,11 +2011,10 @@ Grid.prototype.addDataFields = function(fieldRef, referrer) {
1975
2011
 
1976
2012
  var fields = Array.isArray(fieldRef) ? fieldRef : [fieldRef];
1977
2013
  var len = fields.length;
1978
- var i, field, dataType, prom, isRealTimeField, onLoaded;
2014
+ var i, field, dataType, prom, onLoaded;
1979
2015
  for(i = 0; i < len; i++) {
1980
2016
  field = fields[i];
1981
- isRealTimeField = FieldDefinition.isRealTimeField(field);
1982
- if(this._shouldLoadFieldInfo(field, isRealTimeField)) {
2017
+ if(this._shouldLoadFieldInfo(field)) {
1983
2018
  dataType = ColumnDefinition.getDataType(field);
1984
2019
  prom = FieldDefinition.loadFieldInfo(field)
1985
2020
  .catch(this._onFieldLoadedError);
@@ -2943,20 +2978,22 @@ Grid.prototype.getColumnIndex = function(colRef) {
2943
2978
  return colRef;
2944
2979
  }
2945
2980
 
2946
- var colCount = this.getColumnCount();
2947
- var i, colDef;
2948
- if(colRef instanceof ColumnDefinition) {
2949
- for(i = 0; i < colCount; ++i) {
2950
- colDef = this.getColumnDefinition(i);
2951
- if(colDef === colRef) {
2952
- return i;
2981
+ if(colRef) {
2982
+ var colCount = this.getColumnCount();
2983
+ var i, colDef;
2984
+ if(colRef instanceof ColumnDefinition) {
2985
+ for(i = 0; i < colCount; ++i) {
2986
+ colDef = this.getColumnDefinition(i);
2987
+ if(colDef === colRef) {
2988
+ return i;
2989
+ }
2953
2990
  }
2954
- }
2955
- } else if(typeof colRef === "string") {
2956
- for(i = 0; i < colCount; ++i) {
2957
- colDef = this.getColumnDefinition(i);
2958
- if(_hasFieldOrId(colDef, colRef)) {
2959
- return i; // Return the first found field
2991
+ } else if(typeof colRef === "string") {
2992
+ for(i = 0; i < colCount; ++i) {
2993
+ colDef = this.getColumnDefinition(i);
2994
+ if(_hasFieldOrId(colDef, colRef)) {
2995
+ return i; // Return the first found field
2996
+ }
2960
2997
  }
2961
2998
  }
2962
2999
  }
@@ -1,6 +1,7 @@
1
1
  import { Ext } from "../../tr-grid-util/es6/Ext.js";
2
2
  import { cloneObject } from "../../tr-grid-util/es6/Util.js";
3
3
  import { GridPlugin } from "../../tr-grid-util/es6/GridPlugin.js";
4
+ import { GroupDefinitions } from "../../tr-grid-util/es6/GroupDefinitions.js";
4
5
  import { injectCss, prettifyCss } from "../../tr-grid-util/es6/Util.js";
5
6
 
6
7
  declare namespace ColumnGroupingPlugin {
@@ -42,7 +43,7 @@ declare class ColumnGroupingPlugin extends GridPlugin {
42
43
 
43
44
  public addColumnGrouping(groupDef: ColumnGroupingPlugin.GroupDefinition|null): void;
44
45
 
45
- public removeGroup(groupId: string): ColumnGroupingPlugin.GroupDefinition|null;
46
+ public removeGroup(groupId: string): boolean;
46
47
 
47
48
  public getGroupDefinition(groupId: string): ColumnGroupingPlugin.GroupDefinition|null;
48
49
 
@@ -52,7 +53,7 @@ declare class ColumnGroupingPlugin extends GridPlugin {
52
53
 
53
54
  public setGroupDefinitions(groupDefs: ColumnGroupingPlugin.GroupDefinitions|null): void;
54
55
 
55
- public setGroupChildren(groupId: string, newChildList: (string)[]|null): void;
56
+ public setGroupChildren(groupId: string, newChildList: (string)[]|null): boolean;
56
57
 
57
58
  public getGroupChildren(groupId: string): (string)[]|null;
58
59