@refinitiv-ui/efx-grid 6.0.154 → 6.0.155

Sign up to get free protection for your applications and to get access to all the features.
@@ -66,7 +66,7 @@ declare class DataTable extends DataCache {
66
66
 
67
67
  public setDataSource(source: any): void;
68
68
 
69
- public sortOnce(cid: string|(string)[]|null, sortOrders?: string|number|(string|number)[]|null, customComparer?: DataTable.SortLogic|null, contextObj?: any): boolean;
69
+ public sortOnce(cid: string|(string)[]|null, sortOrders?: (string|number|(string|number)[])|null, customComparer?: DataTable.SortLogic|null, contextObj?: any): boolean;
70
70
 
71
71
  public setSortingLogic(func: DataTable.SortLogic|null): void;
72
72
 
@@ -122,7 +122,7 @@ declare class DataTable extends DataCache {
122
122
 
123
123
  public getSegmentChildIds(segmentId: string): (string)[]|null;
124
124
 
125
- public sortSeparators(sortLogics: ((...params: any[]) => any)|(((...params: any[]) => any))[]|any|null, sortOrders?: (number)[]|null, cids?: (string)[]|null): boolean;
125
+ public sortSeparators(sortLogics: ((...params: any[]) => any)|(((...params: any[]) => any))[]|any|null, sortOrders?: (number|string)[]|null, cids?: (string)[]|null): boolean;
126
126
 
127
127
  public sortSegments(compare: ((...params: any[]) => any)|null): boolean;
128
128
 
@@ -911,7 +911,7 @@ DataTable.prototype.getSortingLogics = function() {
911
911
  };
912
912
  /** @public
913
913
  * @param {string|Array.<string>} cid Column id
914
- * @param {string|number|Array.<string|number>=} sortOrders "a"|"d"|"n"
914
+ * @param {(string|number|Array.<string|number>)=} sortOrders "a"|"d"|"n"
915
915
  * @param {DataTable.SortLogic=} customComparer
916
916
  * @param {*=} contextObj Context object that will be provided as the forth parameter of the given comparer method
917
917
  * @return {boolean} Return true if there is any change, otherwise false
@@ -1421,50 +1421,51 @@ DataTable.prototype.getSegmentChildIds = function(segmentId) {
1421
1421
  }
1422
1422
  return null;
1423
1423
  };
1424
+ /**
1425
+ * @private
1426
+ * @param {(Array|number)} sortOrder
1427
+ * @param {*} context
1428
+ */
1429
+ DataTable.prototype._setSegmentSortContext = function (sortOrder, context) {
1430
+ this._segmentSortOrder = sortOrder;
1431
+ this._segmentSortContext = context;
1432
+ };
1424
1433
  /** Sort all of existing segments by multiple sort logics
1425
1434
  * @public
1426
1435
  * @param {Function|Array.<Function>|Object} sortLogics
1427
- * @param {Array.<number>=} sortOrders
1436
+ * @param {Array.<number|string>=} sortOrders
1428
1437
  * @param {Array.<string>=} cids
1429
1438
  * @return {boolean}
1430
1439
  */
1431
1440
  DataTable.prototype.sortSeparators = function (sortLogics, sortOrders, cids) {
1432
- let dirty = false;
1433
1441
  if(!this._segments){
1434
1442
  return false;
1435
1443
  }
1436
1444
  if(typeof sortLogics === "function"){
1445
+ this._setSegmentSortContext(DataTable._getSortOrder(sortOrders), cids);
1437
1446
  return this.sortSegments(sortLogics);
1438
1447
  }
1448
+ if(!cids) {
1449
+ return false;
1450
+ }
1439
1451
  let sortingDefs = DataTable._buildSortContext(
1440
1452
  [],
1441
1453
  cids,
1442
1454
  sortOrders,
1443
- sortLogics
1455
+ sortLogics || this._compMap
1444
1456
  );
1445
- let defCount = sortingDefs ? sortingDefs.length : 0;
1446
- if(!defCount){
1447
- return dirty;
1448
- }
1449
-
1450
- let sortOrder = 0;
1451
- let sortLogic, sortContext;
1457
+ let defCount = sortingDefs.length;
1458
+ let sortLogic = null;
1452
1459
  if(defCount > 1) {
1453
1460
  sortLogic = DataTable._multiColumnSeparatorCompareLogic;
1454
- sortContext = sortingDefs;
1455
- sortOrder = 1; // sortOrder is not used by _multiColumnSeparatorCompareLogic
1456
- } else { // Single level sorting
1461
+ this._setSegmentSortContext(1, sortingDefs);
1462
+ } else if(defCount === 1) { // Single level sorting
1457
1463
  sortLogic = DataTable._singleColumnSeparatorCompareLogic;
1458
- sortContext = sortingDefs[0];
1459
- sortOrder = /** @type{number} */(sortContext[3]);
1464
+ this._setSegmentSortContext(sortingDefs[0][3], sortingDefs[0]); // sortOrder and context
1465
+ } else {
1466
+ return false;
1460
1467
  }
1461
- this._segmentSortOrder = sortOrder;
1462
- this._segmentSortContext = sortContext;
1463
- dirty = this.sortSegments(sortLogic);
1464
- this._segmentSortOrder = 0;
1465
- this._segmentSortContext = null;
1466
-
1467
- return dirty;
1468
+ return this.sortSegments(sortLogic);
1468
1469
  };
1469
1470
  /** Sort all of existing segments by given compare function
1470
1471
  * @public
@@ -1479,40 +1480,33 @@ DataTable.prototype.sortSegments = function (compare) {
1479
1480
  this._segments.calcSegmentOrder(this._rids);
1480
1481
  return false;
1481
1482
  }
1482
- let rids = this._rids;
1483
- let segments = this._segments;
1484
- let segmentCount = segments.getSegmentCount();
1485
- let segmentList = [];
1486
- let origOrder = [];
1487
- let itemCount = 0;
1488
- let rowCount = rids.length;
1489
- let rid = "";
1490
- let segment = null;
1491
- let i;
1492
- for(i = 0; i < rowCount; ++i) {
1493
- rid = rids[i];
1494
- segment = segments.getSegment(rid);
1495
- if(segment) {
1496
- origOrder.push(i);
1497
- segmentList.push(segment);
1498
- if(++itemCount >= segmentCount) {
1499
- break;
1500
- }
1501
- }
1502
- }
1503
1483
 
1504
1484
  this._userSegmentComparer = compare;
1505
- segmentList.sort(this._bySegmentSeparator);
1485
+
1486
+ let segments = this._segments;
1487
+ let rootSegments = segments.sortSegments(this._bySegmentSeparator);
1488
+
1506
1489
  this._userSegmentComparer = null;
1490
+ this._setSegmentSortContext(0, null);
1507
1491
 
1492
+ let rids = this._rids;
1493
+ let origRids = rids.slice();
1494
+ let rowCount = rids.length;
1495
+ rids.length = 0;
1496
+
1497
+ let segmentCount = 0;
1508
1498
  let dirty = false;
1509
- for(i = 0; i < itemCount; ++i) {
1510
- let idx = origOrder[i];
1511
- rid = rids[idx];
1512
- segment = segmentList[i];
1513
- let newRid = segment.getId();
1514
- if(rid !== newRid) {
1515
- rids[idx] = newRid;
1499
+ for(let i = 0; i < rowCount; ++i) {
1500
+ let rid = origRids[i];
1501
+ let segment = segments.getSegment(rid);
1502
+ if(segment) {
1503
+ if(segment.isRootSegment()) {
1504
+ rootSegments[segmentCount++].getFlattenTreeIds(rids);
1505
+ }
1506
+ } else if(!segments.getParentRowId(rid)) {
1507
+ rids.push(rid);
1508
+ }
1509
+ if(rid !== rids[i]) {
1516
1510
  dirty = true;
1517
1511
  }
1518
1512
  }
@@ -1521,9 +1515,8 @@ DataTable.prototype.sortSegments = function (compare) {
1521
1515
  this._segments.calcSegmentOrder(rids);
1522
1516
  this._sort(null);
1523
1517
  this._dispatchPositionChange();
1524
- return true;
1525
1518
  }
1526
- return false;
1519
+ return dirty;
1527
1520
  };
1528
1521
  /** Sort all of existing segments by given compare function
1529
1522
  * @private
@@ -1806,7 +1799,7 @@ DataTable._positionChangeArg = {"globalChange": true, "positionChangeOnly": true
1806
1799
  * @function
1807
1800
  * @public
1808
1801
  * @ignore
1809
- * @param {Array.<Array>} out_defs Output object. Array is used to optimize property accessing time.
1802
+ * @param {!Array.<Array>} out_defs Output object. Array is used to optimize property accessing time.
1810
1803
  * @param {string|Array.<string>} cids
1811
1804
  * @param {string|number|Array.<string|number>=} sortOrders
1812
1805
  * @param {Function|Array.<Function>|Object.<string, DataTable.SortLogic>=} logics
@@ -294,7 +294,7 @@ declare class DataView extends EventDispatcher {
294
294
 
295
295
  public getSegmentChildIds(segmentRef: string|number|null): (string)[]|null;
296
296
 
297
- public sortSeparators(sortLogics: ((...params: any[]) => any)|(((...params: any[]) => any))[]|any|null, sortOrders?: (number)[]|null, cids?: (string)[]|null): void;
297
+ public sortSeparators(sortLogics: ((...params: any[]) => any)|(((...params: any[]) => any))[]|any|null, sortOrders?: (number|(number)[])|null, cids?: (string|(string)[])|null): void;
298
298
 
299
299
  public sortSegments(compare: ((...params: any[]) => any)|null): void;
300
300
 
@@ -2697,10 +2697,22 @@ DataView.prototype.getSegmentChildIds = function(segmentRef) {
2697
2697
  /** Sort all of existing segments by multiple sort logics
2698
2698
  * @public
2699
2699
  * @param {Function|Array.<Function>|Object} sortLogics
2700
- * @param {Array.<number>=} sortOrders
2701
- * @param {Array.<string>=} cids
2700
+ * @param {(number|Array.<number>)=} sortOrders
2701
+ * @param {(string|Array.<string>)=} cids
2702
2702
  */
2703
2703
  DataView.prototype.sortSeparators = function (sortLogics, sortOrders, cids) {
2704
+ let sortingDefs = this._sortingDefs;
2705
+ if(sortingDefs.length) {
2706
+ if(!cids) {
2707
+ cids = sortingDefs[0][0]; // field
2708
+ }
2709
+ if(!sortOrders) {
2710
+ sortOrders = sortingDefs[0][3];
2711
+ }
2712
+ } else if(!sortLogics) {
2713
+ return;
2714
+ }
2715
+
2704
2716
  this._dt.sortSeparators(sortLogics, sortOrders, cids);
2705
2717
  };
2706
2718
  /** Sort all of existing segments by given compare function
@@ -63,6 +63,10 @@ declare class Segment extends EventDispatcher {
63
63
 
64
64
  public getSubSegmentName(row?: any): string;
65
65
 
66
+ public sortSegments(comparer: ((...params: any[]) => any)): boolean;
67
+
68
+ public getFlattenTreeIds(ary: (string)[]|null): (string)[];
69
+
66
70
  public collapse(bool?: boolean|null): boolean;
67
71
 
68
72
  public expand(bool?: boolean|null): boolean;
@@ -366,7 +366,7 @@ Segment.prototype.getChildCount = function() {
366
366
  */
367
367
  Segment.prototype.markCollapsingStateDirty = function() {
368
368
  // A segment can have a child and/or autogenerated segment (subsegment) to not be considered as empty.
369
- if(this._childIds.length || this._subSegDef) {
369
+ if(this._childIds.length || this._subSegDef) {
370
370
  this._shared.dirtyCollapsingState = true;
371
371
  }
372
372
  };
@@ -760,6 +760,83 @@ Segment.prototype.getSubSegmentName = function(row) {
760
760
  }
761
761
  return this._subSegName;
762
762
  };
763
+ /**
764
+ * @private
765
+ * @param {!Segment} segment
766
+ * @returns {string}
767
+ */
768
+ let _toSegmentId = function(segment) {
769
+ return segment.getId();
770
+ };
771
+ /**
772
+ * @public
773
+ * @param {!Function} comparer
774
+ * @returns {boolean} Returns true if there is any change
775
+ */
776
+ Segment.prototype.sortSegments = function(comparer) {
777
+ if(!comparer || this.hasSubSegments()) {
778
+ return false;
779
+ }
780
+
781
+ let segmentList = [];
782
+ let rids = [];
783
+ let childIds = this._childIds;
784
+ let childCount = childIds.length;
785
+ let segments = this._shared.segments;
786
+ for(let i = 0; i < childCount; ++i) {
787
+ let childId = childIds[i];
788
+ let childSegment = segments[childId];
789
+ if(childSegment) {
790
+ segmentList.push(childSegment);
791
+ } else {
792
+ rids.push(childId);
793
+ }
794
+ }
795
+ if(segmentList.length < 2) {
796
+ return false;
797
+ }
798
+ segmentList.sort(comparer);
799
+ this._childIds = rids.concat(segmentList.map(_toSegmentId));
800
+ return true;
801
+ };
802
+ /** Get segment id and ids of children, including nested segments, but excluding sub segments
803
+ * @public
804
+ * @param {Array.<string>} ary
805
+ * @return {!Array.<string>}
806
+ */
807
+ Segment.prototype.getFlattenTreeIds = function(ary) {
808
+ if(!ary) {
809
+ ary = [];
810
+ }
811
+
812
+ if(!this._subSegment) { // Sub segments are excluded from tree
813
+ ary.push(this._rid);
814
+ }
815
+ let i;
816
+ let segmentNames = this._subSegNames;
817
+ if(segmentNames) { // Classified segment
818
+ let segmentCount = segmentNames.length;
819
+ let segmentMap = this._subSegMap;
820
+ for(i = 0; i < segmentCount; ++i) {
821
+ segmentMap[segmentNames[i]].getFlattenTreeIds(ary);
822
+ }
823
+ } else {
824
+ let childIds = this._childIds;
825
+ let childCount = childIds.length;
826
+ let segments = this._shared.segments;
827
+ for(i = 0; i < childCount; ++i) {
828
+ let childId = childIds[i];
829
+ let childSegment = segments[childId];
830
+ if(childSegment) {
831
+ childSegment.getFlattenTreeIds(ary);
832
+ } else {
833
+ ary.push(childId);
834
+ }
835
+ }
836
+ }
837
+
838
+ return ary;
839
+ };
763
840
 
764
841
  /** @public
765
842
  * @param {boolean=} bool
@@ -30,6 +30,8 @@ declare class SegmentCollection extends EventDispatcher {
30
30
 
31
31
  public getSegmentIds(): (string)[];
32
32
 
33
+ public sortSegments(comparer: ((...params: any[]) => any)): (Segment)[];
34
+
33
35
  public collapseSegments(segmentIds: (string)[]|null, bool?: boolean|null): boolean;
34
36
 
35
37
  public collapseSegment(segmentId: string, bool?: boolean|null): boolean;
@@ -213,6 +213,23 @@ SegmentCollection.prototype.getSegments = function() {
213
213
  SegmentCollection.prototype.getSegmentIds = function() {
214
214
  return Object.keys(this._segments);
215
215
  };
216
+ /** @public
217
+ * @param {!Function} comparer
218
+ * @return {!Array.<Segment>}
219
+ */
220
+ SegmentCollection.prototype.sortSegments = function(comparer) {
221
+ let rootSegments = [];
222
+ let segmentSeparators = this._segments;
223
+ for(let rid in segmentSeparators) {
224
+ let segment = segmentSeparators[rid];
225
+ segment.sortSegments(comparer);
226
+ if(segment.isRootSegment()) {
227
+ rootSegments.push(segment);
228
+ }
229
+ }
230
+ rootSegments.sort(comparer);
231
+ return rootSegments;
232
+ };
216
233
 
217
234
 
218
235
  /** @public
@@ -622,7 +622,7 @@ Core.prototype._hasPendingRowChange = false;
622
622
  * @return {string}
623
623
  */
624
624
  Core.getVersion = function () {
625
- return "5.1.139";
625
+ return "5.1.140";
626
626
  };
627
627
  /** {@link ElementWrapper#dispose}
628
628
  * @override
package/lib/grid/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import {Grid} from "./lib/efx-grid.js";
2
2
  export {Grid}
3
- window.EFX_GRID = { version: "6.0.154" };
3
+ window.EFX_GRID = { version: "6.0.155" };