@refinitiv-ui/efx-grid 6.0.157 → 6.0.159

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.
@@ -1,6 +1,6 @@
1
1
  import Ext from "../../../tr-grid-util/es6/Ext.js";
2
2
  import EventDispatcher from "../../../tr-grid-util/es6/EventDispatcher.js";
3
- import Segment from "./Segment.js";
3
+ import { Segment, UNCATEGORY } from "./Segment.js";
4
4
 
5
5
  /** @constructor
6
6
  * @extends {EventDispatcher}
@@ -42,7 +42,7 @@ SegmentCollection.prototype._shared;
42
42
  /** @type {Array.<Segment>}
43
43
  * @private
44
44
  */
45
- SegmentCollection.prototype._segmentList = null; // Array of main segments
45
+ SegmentCollection.prototype._segmentList = null; // Array of main/root segments
46
46
  /** @type {Array.<Segment>}
47
47
  * @private
48
48
  */
@@ -59,6 +59,10 @@ SegmentCollection.prototype._classification = false;
59
59
  * @private
60
60
  */
61
61
  SegmentCollection.prototype._classifierChanged = false;
62
+ /** @type {Object.<string, number>}
63
+ * @private
64
+ */
65
+ SegmentCollection.prototype._rowOrders = null;
62
66
 
63
67
  /** @public
64
68
  */
@@ -66,7 +70,7 @@ SegmentCollection.prototype.dispose = function() {
66
70
  this.removeAllSegments();
67
71
  this.removeAllEventListeners();
68
72
  this._collapsedRids = null;
69
- this._segmentList = this._insertionList = this._removalList = null;
73
+ this._segmentList = this._rowOrders = this._insertionList = this._removalList = null;
70
74
  };
71
75
  /** @public
72
76
  * @param {string} rid
@@ -79,7 +83,7 @@ SegmentCollection.prototype.addSegment = function(rid, childRids) {
79
83
  segment.addEventListener("subSegmentAdded", this._onSubSegmentAdded);
80
84
  segment.addEventListener("subSegmentRemoved", this._onSubSegmentRemoved);
81
85
  ++this._segmentCount;
82
- this._segmentList = null; // order could be changed
86
+ this.invalidateSegmentOrder(); // order could be changed
83
87
 
84
88
  if(childRids && childRids.length) {
85
89
  segment.addChildren(childRids);
@@ -155,6 +159,7 @@ SegmentCollection.prototype.removeSegment = function(rid) {
155
159
 
156
160
  delete this._segments[rid]; // Slow
157
161
  --this._segmentCount;
162
+ this.invalidateSegmentOrder();
158
163
  return true;
159
164
  };
160
165
  /** @public
@@ -167,7 +172,7 @@ SegmentCollection.prototype.removeAllSegments = function() {
167
172
  }
168
173
  this._segments = {};
169
174
  this._segmentCount = 0;
170
- this._segmentList = null;
175
+ this._segmentList = this._rowOrders = null;
171
176
  this._shared.segments = this._segments;
172
177
  this._shared.childToSegment = {};
173
178
 
@@ -228,6 +233,7 @@ SegmentCollection.prototype.sortSegments = function(comparer) {
228
233
  }
229
234
  }
230
235
  rootSegments.sort(comparer);
236
+ this.invalidateSegmentOrder();
231
237
  return rootSegments;
232
238
  };
233
239
 
@@ -323,28 +329,14 @@ SegmentCollection.prototype.getCollapsedRows = function() {
323
329
  return this._collapsedRids;
324
330
  };
325
331
 
326
- /** Invalidate segment order cache, if the given row id is a segment separator
327
- * @private
328
- * @param {string|Array.<string>} segmentIds
332
+ /** Invalidate segment order cache
333
+ * @public
329
334
  * @returns {boolean} Returns true if there is any change
330
335
  */
331
- SegmentCollection.prototype._invalidateSegmentOrder = function(segmentIds) {
336
+ SegmentCollection.prototype.invalidateSegmentOrder = function() {
332
337
  if(this._segmentList) {
333
- if(typeof segmentIds === "string") {
334
- if(this._segments[segmentIds]) {
335
- this._segmentList = null;
336
- return true;
337
- }
338
- } else if(Array.isArray(segmentIds)) {
339
- let len = segmentIds.length;
340
- for(let i = 0; i < len; ++i) {
341
- let segmentId = segmentIds[i];
342
- if(this._segments[segmentId]) {
343
- this._segmentList = null;
344
- return true;
345
- }
346
- }
347
- }
338
+ this._segmentList = this._rowOrders = null;
339
+ return true;
348
340
  }
349
341
  return false;
350
342
  };
@@ -358,7 +350,7 @@ SegmentCollection.prototype.addSegmentChild = function(segmentId, rid, dataId) {
358
350
  let segment = this._segments[segmentId];
359
351
  if(segment && !segment.isSubSegment()) {
360
352
  // If a segment becomes a child of other segment, then the segment order needs to be recalculated
361
- this._invalidateSegmentOrder(rid);
353
+ this.invalidateSegmentOrder();
362
354
  return segment.addChild(rid, dataId);
363
355
  }
364
356
  return false;
@@ -373,7 +365,7 @@ SegmentCollection.prototype.addSegmentChildren = function(segmentId, rids, dataI
373
365
  let segment = this._segments[segmentId];
374
366
  if(segment && !segment.isSubSegment()) {
375
367
  // If a segment becomes a child of other segment, then the segment order needs to be recalculated
376
- this._invalidateSegmentOrder(rids);
368
+ this.invalidateSegmentOrder();
377
369
  return segment.addChildren(rids, dataIds);
378
370
  }
379
371
  return false;
@@ -399,7 +391,7 @@ SegmentCollection.prototype.containsSegmentChild = function(segmentId, rid) {
399
391
  SegmentCollection.prototype.removeSegmentChild = function(segmentId, rid) {
400
392
  let segment = this._segments[segmentId];
401
393
  if(segment) {
402
- this._invalidateSegmentOrder(rid);
394
+ this.invalidateSegmentOrder();
403
395
  return segment.removeChild(rid);
404
396
  }
405
397
  return false;
@@ -412,7 +404,7 @@ SegmentCollection.prototype.removeSegmentChild = function(segmentId, rid) {
412
404
  SegmentCollection.prototype.removeSegmentChildren = function(segmentId, rids) {
413
405
  let segment = this._segments[segmentId];
414
406
  if(segment) {
415
- this._invalidateSegmentOrder(rids);
407
+ this.invalidateSegmentOrder();
416
408
  return segment.removeChildren(rids);
417
409
  }
418
410
  return false;
@@ -432,7 +424,7 @@ SegmentCollection.prototype.removeAllSegmentChildren = function() {
432
424
  }
433
425
 
434
426
  if(dirty) {
435
- this._segmentList = null; // WARNING: not optimized
427
+ this.invalidateSegmentOrder();
436
428
  this.classify(null);
437
429
  }
438
430
 
@@ -462,6 +454,7 @@ SegmentCollection.prototype.fillSegment = function(segmentId, rids) {
462
454
  }
463
455
  curSegment.addChild(rid);
464
456
  }
457
+ this.invalidateSegmentOrder();
465
458
  }
466
459
  }
467
460
  };
@@ -487,8 +480,19 @@ SegmentCollection.prototype.fillSegments = function(rids) {
487
480
  change = true;
488
481
  }
489
482
  }
483
+ if(change) {
484
+ this.invalidateSegmentOrder();
485
+ }
490
486
  return change;
491
487
  };
488
+
489
+ /** The number represent maximum nested segments that can be created in a single segment
490
+ * @private
491
+ * @type {number}
492
+ * @constant
493
+ */
494
+ const SEGMENT_STEP = 10000;
495
+
492
496
  /** @public
493
497
  * @param {Array.<string>} rids
494
498
  * @param {boolean=} useCache=false If this is true, skip the calculation when there is already a cache for segment order
@@ -504,21 +508,29 @@ SegmentCollection.prototype.calcSegmentOrder = function(rids, useCache) {
504
508
  segmentList = this._segmentList = [];
505
509
  }
506
510
 
507
- let ridCount = rids ? rids.length : 0;
511
+ this._rowOrders = {};
512
+ let rowOrders = this._rowOrders;
508
513
  let segmentSeparators = this._segments;
509
- let segmentCount = this._segmentCount;
514
+ let childToSegmentId = this._shared.childToSegment;
515
+ let prevSeg = UNCATEGORY;
516
+ let ridCount = rids ? rids.length : 0;
510
517
  let order = 0;
511
518
  for(let i = 0; i < ridCount; ++i) {
512
519
  let rid = rids[i];
513
- let segment = segmentSeparators[rid];
514
- if(segment) {
515
- if(segment.isRootSegment()) {
516
- this._segmentList.push(segment);
517
- segment.setOrder(++order); // WARNING: Segments and sub segments start with 1
518
- segment.updateTreeStructure(0);
520
+ if(!childToSegmentId[rid]) {
521
+ let segment = segmentSeparators[rid];
522
+ let segmentId = (segment) ? segment.getId() : UNCATEGORY;
523
+ if(prevSeg !== segmentId) {
524
+ ++order; // WARNING: Segments and sub segments start with 1
525
+ prevSeg = segmentId;
519
526
  }
520
- if(--segmentCount <= 0) {
521
- break;
527
+
528
+ let rootOrder = order * SEGMENT_STEP;
529
+ rowOrders[rid] = rootOrder;
530
+ if(segment) {
531
+ this._segmentList.push(segment);
532
+ segment.setOrder(rootOrder);
533
+ segment.updateTreeStructure(0, rootOrder, rowOrders);
522
534
  }
523
535
  }
524
536
  }
@@ -527,57 +539,33 @@ SegmentCollection.prototype.calcSegmentOrder = function(rids, useCache) {
527
539
  * @param {!Array.<string>} rids Array of row ids
528
540
  * @param {boolean=} partial Indicating that the given ids are not the whole list
529
541
  * @return {Array.<number>} Returns Array of segment values, if there are at least one segment, otherwise returns null
530
- */ //
542
+ */
531
543
  SegmentCollection.prototype.getSegmentValues = function(rids, partial) {
532
544
  let rowCount = rids ? rids.length : 0;
533
545
  if(!rowCount) {
534
546
  return null;
535
547
  }
536
- let segmentSeparators = this._segments;
537
- let childToSegmentId = this._shared.childToSegment;
538
- let curSegment = null;
539
- let prevSegment = null;
548
+ let rowOrders = this._rowOrders;
549
+ if(!rowOrders) { // calcSegmentOrder has not been called (no cache detected)
550
+ return null;
551
+ }
552
+
540
553
  let segmentValues = new Array(rowCount);
541
- let segmentVal = 0;
542
554
  let highestVal = 0;
543
- let offset = 0;
544
555
  for(let r = 0; r < rowCount; ++r) {
545
556
  let rid = rids[r];
546
- curSegment = segmentSeparators[rid];
547
- if(curSegment) { // segment separator
548
- segmentVal = curSegment.getOrder() * 100;
549
- offset = 0;
550
- if(curSegment.isRootSegment()) {
551
- if(prevSegment !== curSegment) {
552
- prevSegment = curSegment;
553
- highestVal = curSegment.getLastOrder() * 100;
554
- }
557
+ let segmentVal = rowOrders[rid];
558
+ if(segmentVal != null) {
559
+ if(highestVal < segmentVal) {
560
+ highestVal = segmentVal;
555
561
  }
556
562
  } else {
557
- let parentId = childToSegmentId[rid];
558
- if(parentId) { // segment member
559
- curSegment = segmentSeparators[parentId];
560
- segmentVal = curSegment.getOrder() * 100;
561
- offset = 1;
562
- if(partial) { // This fixes the out of order sub segment
563
- highestVal = curSegment.getLastOrder() * 100;
564
- }
565
- } else { // row outside of segments
566
- if(highestVal) {
567
- if(segmentVal < highestVal) {
568
- segmentVal = highestVal;
569
- }
570
- offset = 10;
571
- } else {
572
- segmentVal = offset = 0;
573
- }
574
- }
563
+ segmentVal = highestVal ? highestVal + SEGMENT_STEP : 0;
575
564
  }
576
-
577
- segmentValues[r] = segmentVal + offset;
565
+ segmentValues[r] = segmentVal;
578
566
  }
579
567
 
580
- return prevSegment ? segmentValues : null;
568
+ return highestVal ? segmentValues : null;
581
569
  };
582
570
  /** @public
583
571
  * @return {string}
@@ -666,6 +654,7 @@ SegmentCollection.prototype.classify = function(rows) {
666
654
  }
667
655
  }
668
656
  if(this._insertionList.length || this._removalList.length) {
657
+ this.invalidateSegmentOrder();
669
658
  this._dispatch("subSegmentChanged", {
670
659
  "insertionList": this._insertionList,
671
660
  "removalList": this._removalList
@@ -622,7 +622,7 @@ Core.prototype._hasPendingRowChange = false;
622
622
  * @return {string}
623
623
  */
624
624
  Core.getVersion = function () {
625
- return "5.1.140";
625
+ return "5.2.2";
626
626
  };
627
627
  /** {@link ElementWrapper#dispose}
628
628
  * @override
@@ -4292,6 +4292,9 @@ Core.prototype.initSimpleTable = function (columns) {
4292
4292
  colCount = columns.length;
4293
4293
  this.setColumnCount(colCount);
4294
4294
  this.setDataColumnMap(columns);
4295
+ for(let c = 0; c < colCount; ++c) {
4296
+ this.setColumnField(c, columns[c]);
4297
+ }
4295
4298
  }
4296
4299
 
4297
4300
  let titleSect = this.addSection("title");
@@ -40,6 +40,12 @@ import { isEmptyObject } from "../../../../tr-grid-util/es6/Util.js";
40
40
  * @property {Array.<string>} sortedFields An array of sortedField
41
41
  */
42
42
 
43
+ /** @private
44
+ * @type {string}
45
+ *@constant
46
+ */
47
+ const ROW_DEF = "ROW_DEF";
48
+
43
49
  /** @constructor
44
50
  * @extends {EventDispatcher}
45
51
  * @param {SortableTitlePlugin.Options=} options
@@ -55,6 +61,7 @@ let SortableTitlePlugin = function (options) { // TODO: Extract SortableTitlePlu
55
61
  _t._onColumnRemoved = _t._onColumnRemoved.bind(_t);
56
62
  _t._onItemSortingClicked = _t._onItemSortingClicked.bind(_t);
57
63
  _t.refresh = _t.refresh.bind(_t);
64
+ _t._rowDefSorter = _t._rowDefSorter.bind(_t);
58
65
 
59
66
  _t._hosts = [];
60
67
  _t._sortLogic = {};
@@ -216,6 +223,11 @@ SortableTitlePlugin.prototype._frozenIndicator = false;
216
223
  * @type {boolean}
217
224
  */
218
225
  SortableTitlePlugin.prototype._rowDefMode = false;
226
+ /**
227
+ * @private
228
+ * @type {Function}
229
+ */
230
+ SortableTitlePlugin.prototype._userComparer = null;
219
231
 
220
232
  /** @private
221
233
  * @type {!Object.<string, string>}
@@ -1392,6 +1404,21 @@ SortableTitlePlugin.prototype.setSortingSequence = function (sequence, colRef) {
1392
1404
  SortableTitlePlugin.prototype.clearAllColumnSortingSequences = function () {
1393
1405
  this._sortingSequenceMap = null;
1394
1406
  };
1407
+ /** @private
1408
+ * @param {Object} rowA
1409
+ * @param {Object} rowB
1410
+ * @param {number} sortOrder
1411
+ * @param {*} context
1412
+ * @returns {number}
1413
+ */
1414
+ SortableTitlePlugin.prototype._rowDefSorter = function (rowA, rowB, sortOrder, context) {
1415
+ return this._userComparer(
1416
+ rowA[ROW_DEF].getRowData(),
1417
+ rowB[ROW_DEF].getRowData(),
1418
+ sortOrder,
1419
+ context
1420
+ );
1421
+ };
1395
1422
  /** @public
1396
1423
  * @description Sorting all separators according to compare function. If compare function is not specified, separators will will be sort by current sorting states.
1397
1424
  * @param {Function} comparer Compare function
@@ -1400,16 +1427,21 @@ SortableTitlePlugin.prototype.sortSeparators = function (comparer) {
1400
1427
  let host = this._hosts[0];
1401
1428
  let dv = host.getDataSource();
1402
1429
  if(comparer){
1403
- dv.sortSeparators(comparer);
1430
+ if(this._rowDefMode) {
1431
+ this._userComparer = comparer;
1432
+ dv.sortSeparators(this._rowDefSorter);
1433
+ this._userComparer = null;
1434
+ } else {
1435
+ dv.sortSeparators(comparer);
1436
+ }
1404
1437
  } else {
1405
1438
  let sortLogics = dv.getSortingLogics();
1406
1439
  let sortOrders = [];
1407
1440
  let sortFields = [];
1408
1441
  let sortStateCount = this._sortStates.length;
1409
- let rowDefField = SortableTitlePlugin._toRowDefField();
1410
1442
  for(let i = 0; i < sortStateCount; i++){
1411
1443
  let sortState = this._sortStates[i];
1412
- let field = this._rowDefMode ? rowDefField : sortState["field"];
1444
+ let field = this._rowDefMode ? ROW_DEF : sortState["field"];
1413
1445
  sortOrders.push(sortState["sortOrder"]);
1414
1446
  sortFields.push(field);
1415
1447
  }
@@ -1659,11 +1691,10 @@ SortableTitlePlugin.prototype._onColumnRemoved = function (e) {
1659
1691
  };
1660
1692
 
1661
1693
  /** @private
1662
- * @param {Object=} sortState
1663
1694
  * @return {string}
1664
1695
  */
1665
- SortableTitlePlugin._toRowDefField = function(sortState) {
1666
- return "ROW_DEF";
1696
+ SortableTitlePlugin._toRowDefField = function() {
1697
+ return ROW_DEF;
1667
1698
  };
1668
1699
  /** @private
1669
1700
  * @param {Object=} opt_action Action that raised the sort. This is optional
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.157" };
3
+ window.EFX_GRID = { version: "6.0.159" };