cx 24.3.6 → 24.3.8

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,138 +1,141 @@
1
- import { ArrayAdapter } from "./ArrayAdapter";
2
- import { ReadOnlyDataView } from "../../data/ReadOnlyDataView";
3
- import { Grouper } from "../../data/Grouper";
4
- import { isArray } from "../../util/isArray";
5
- import { isDefined } from "../../util/isDefined";
6
- import { getComparer } from "../../data/comparer";
7
- import { Culture } from "../Culture";
8
-
9
- export class GroupAdapter extends ArrayAdapter {
10
- init() {
11
- super.init();
12
-
13
- if (this.groupRecordsAlias) this.groupRecordsName = this.groupRecordsAlias;
14
-
15
- if (this.groupings) this.groupBy(this.groupings);
16
- }
17
-
18
- getRecords(context, instance, records, parentStore) {
19
- let result = super.getRecords(context, instance, records, parentStore);
20
-
21
- if (this.groupings) {
22
- let groupedResults = [];
23
- this.processLevel([], result, groupedResults, parentStore);
24
- result = groupedResults;
25
- }
26
-
27
- return result;
28
- }
29
-
30
- processLevel(keys, records, result, parentStore) {
31
- let level = keys.length;
32
- let inverseLevel = this.groupings.length - level;
33
-
34
- if (inverseLevel == 0) {
35
- for (let i = 0; i < records.length; i++) {
36
- records[i].store.setStore(parentStore);
37
- result.push(records[i]);
38
- }
39
- return;
40
- }
41
-
42
- let grouping = this.groupings[level];
43
- let { grouper } = grouping;
44
- grouper.reset();
45
- grouper.processAll(records);
46
- let results = grouper.getResults();
47
- if (grouping.comparer) results.sort(grouping.comparer);
48
-
49
- results.forEach((gr) => {
50
- keys.push(gr.key);
51
-
52
- let key = keys
53
- .map((key) =>
54
- Object.keys(key)
55
- .map((k) => key[k])
56
- .join(":")
57
- )
58
- .join("|");
59
-
60
- let $group = {
61
- ...gr.key,
62
- ...gr.aggregates,
63
- $name: gr.name,
64
- $level: inverseLevel,
65
- $records: gr.records || [],
66
- $key: key,
67
- };
68
-
69
- let data = {
70
- [this.recordName]: gr.records.length > 0 ? gr.records[0].data : null,
71
- [this.groupName]: $group,
72
- };
73
-
74
- let groupStore = new ReadOnlyDataView({
75
- store: parentStore,
76
- data,
77
- immutable: this.immutable,
78
- });
79
-
80
- let group = {
81
- key,
82
- data,
83
- group: $group,
84
- grouping,
85
- store: groupStore,
86
- level: inverseLevel,
87
- };
88
-
89
- if (grouping.includeHeader !== false)
90
- result.push({
91
- ...group,
92
- type: "group-header",
93
- key: "header:" + group.key,
94
- });
95
-
96
- this.processLevel(keys, gr.records, result, groupStore);
97
-
98
- if (grouping.includeFooter !== false)
99
- result.push({
100
- ...group,
101
- type: "group-footer",
102
- key: "footer:" + group.key,
103
- });
104
-
105
- keys.pop();
106
- });
107
- }
108
-
109
- groupBy(groupings) {
110
- if (!groupings) this.groupings = null;
111
- else if (isArray(groupings)) {
112
- this.groupings = groupings;
113
- this.groupings.forEach((g) => {
114
- let groupSorters = [];
115
- let key = {};
116
- for (let name in g.key) {
117
- if (!g.key[name] || !isDefined(g.key[name].direction) || !isDefined(g.key[name].value))
118
- g.key[name] = { value: g.key[name], direction: "ASC" };
119
- key[name] = g.key[name].value;
120
- groupSorters.push({
121
- field: name,
122
- direction: g.key[name].direction,
123
- });
124
- }
125
- g.grouper = new Grouper(key, { ...this.aggregates, ...g.aggregates }, (r) => r.store.getData(), g.text);
126
- g.comparer = null;
127
- if (groupSorters.length > 0)
128
- g.comparer = getComparer(
129
- groupSorters,
130
- (x) => x.key,
131
- this.sortOptions ? Culture.getComparer(this.sortOptions) : null
132
- );
133
- });
134
- } else throw new Error("Invalid grouping provided.");
135
- }
136
- }
137
-
138
- GroupAdapter.prototype.groupName = "$group";
1
+ import { ArrayAdapter } from "./ArrayAdapter";
2
+ import { ReadOnlyDataView } from "../../data/ReadOnlyDataView";
3
+ import { Grouper } from "../../data/Grouper";
4
+ import { isArray } from "../../util/isArray";
5
+ import { isDefined } from "../../util/isDefined";
6
+ import { getComparer } from "../../data/comparer";
7
+ import { Culture } from "../Culture";
8
+ import { isObject } from "../../util/isObject";
9
+
10
+ export class GroupAdapter extends ArrayAdapter {
11
+ init() {
12
+ super.init();
13
+
14
+ if (this.groupRecordsAlias) this.groupRecordsName = this.groupRecordsAlias;
15
+
16
+ if (this.groupings) this.groupBy(this.groupings);
17
+ }
18
+
19
+ getRecords(context, instance, records, parentStore) {
20
+ let result = super.getRecords(context, instance, records, parentStore);
21
+
22
+ if (this.groupings) {
23
+ let groupedResults = [];
24
+ this.processLevel([], result, groupedResults, parentStore);
25
+ result = groupedResults;
26
+ }
27
+
28
+ return result;
29
+ }
30
+
31
+ processLevel(keys, records, result, parentStore) {
32
+ let level = keys.length;
33
+ let inverseLevel = this.groupings.length - level;
34
+
35
+ if (inverseLevel == 0) {
36
+ for (let i = 0; i < records.length; i++) {
37
+ records[i].store.setStore(parentStore);
38
+ result.push(records[i]);
39
+ }
40
+ return;
41
+ }
42
+
43
+ let grouping = this.groupings[level];
44
+ let { grouper } = grouping;
45
+ grouper.reset();
46
+ grouper.processAll(records);
47
+ let results = grouper.getResults();
48
+ if (grouping.comparer) results.sort(grouping.comparer);
49
+
50
+ results.forEach((gr) => {
51
+ keys.push(gr.key);
52
+
53
+ let key = keys.map(serializeKey).join("|");
54
+
55
+ let $group = {
56
+ ...gr.key,
57
+ ...gr.aggregates,
58
+ $name: gr.name,
59
+ $level: inverseLevel,
60
+ $records: gr.records || [],
61
+ $key: key,
62
+ };
63
+
64
+ let data = {
65
+ [this.recordName]: gr.records.length > 0 ? gr.records[0].data : null,
66
+ [this.groupName]: $group,
67
+ };
68
+
69
+ let groupStore = new ReadOnlyDataView({
70
+ store: parentStore,
71
+ data,
72
+ immutable: this.immutable,
73
+ });
74
+
75
+ let group = {
76
+ key,
77
+ data,
78
+ group: $group,
79
+ grouping,
80
+ store: groupStore,
81
+ level: inverseLevel,
82
+ };
83
+
84
+ if (grouping.includeHeader !== false)
85
+ result.push({
86
+ ...group,
87
+ type: "group-header",
88
+ key: "header:" + group.key,
89
+ });
90
+
91
+ this.processLevel(keys, gr.records, result, groupStore);
92
+
93
+ if (grouping.includeFooter !== false)
94
+ result.push({
95
+ ...group,
96
+ type: "group-footer",
97
+ key: "footer:" + group.key,
98
+ });
99
+
100
+ keys.pop();
101
+ });
102
+ }
103
+
104
+ groupBy(groupings) {
105
+ if (!groupings) this.groupings = null;
106
+ else if (isArray(groupings)) {
107
+ this.groupings = groupings;
108
+ this.groupings.forEach((g) => {
109
+ let groupSorters = [];
110
+ let key = {};
111
+ for (let name in g.key) {
112
+ if (!g.key[name] || !isDefined(g.key[name].direction) || !isDefined(g.key[name].value))
113
+ g.key[name] = { value: g.key[name], direction: "ASC" };
114
+ key[name] = g.key[name].value;
115
+ groupSorters.push({
116
+ field: name,
117
+ direction: g.key[name].direction,
118
+ });
119
+ }
120
+ g.grouper = new Grouper(key, { ...this.aggregates, ...g.aggregates }, (r) => r.store.getData(), g.text);
121
+ g.comparer = null;
122
+ if (groupSorters.length > 0)
123
+ g.comparer = getComparer(
124
+ groupSorters,
125
+ (x) => x.key,
126
+ this.sortOptions ? Culture.getComparer(this.sortOptions) : null,
127
+ );
128
+ });
129
+ } else throw new Error("Invalid grouping provided.");
130
+ }
131
+ }
132
+
133
+ GroupAdapter.prototype.groupName = "$group";
134
+
135
+ function serializeKey(data) {
136
+ if (isObject(data))
137
+ return Object.keys(data)
138
+ .map((k) => serializeKey(data[k]))
139
+ .join(":");
140
+ return data?.toString() ?? "";
141
+ }
@@ -43,6 +43,7 @@ import { unfocusElement } from "../../ui/FocusManager";
43
43
  import { tooltipMouseMove, tooltipMouseLeave } from "../overlay/tooltip-ops";
44
44
  import { Container } from "../../ui/Container";
45
45
  import { findFirstChild } from "../../util/DOM";
46
+ import { Binding } from "../../data/Binding";
46
47
 
47
48
  export class Grid extends Container {
48
49
  declareData(...args) {
@@ -910,9 +911,9 @@ export class Grid extends Container {
910
911
  }
911
912
 
912
913
  if (colSpan > 1) skip = colSpan - 1;
913
- } else if (c.aggregate && c.aggregateAlias && c.caption !== false) {
914
+ } else if (c.aggregate && c.aggregateAliasGetter && c.caption !== false) {
914
915
  empty = false;
915
- v = group[c.aggregateAlias];
916
+ v = c.aggregateAliasGetter(group);
916
917
  if (isString(ci.data.format)) v = Format.value(v, ci.data.format);
917
918
  }
918
919
 
@@ -993,9 +994,9 @@ export class Grid extends Container {
993
994
  }
994
995
 
995
996
  if (colSpan > 1) skip = colSpan - 1;
996
- } else if (c.aggregate && c.aggregateAlias && c.footer !== false) {
997
+ } else if (c.aggregate && c.aggregateAliasGetter && c.footer !== false) {
997
998
  empty = false;
998
- v = group[c.aggregateAlias];
999
+ v = c.aggregateAliasGetter(group);
999
1000
  if (isString(ci.data.format)) v = Format.value(v, ci.data.format);
1000
1001
  }
1001
1002
 
@@ -1594,19 +1595,25 @@ class GridComponent extends VDOM.Component {
1594
1595
  </tbody>
1595
1596
  );
1596
1597
 
1598
+ let dataRecordClass = CSS.element(baseClass, "data");
1599
+
1600
+ let isDataRecord = widget.buffered
1601
+ ? (item) => item?.props?.instance?.data?.class == dataRecordClass
1602
+ : (item) => item?.props?.record?.type;
1603
+
1597
1604
  let index = 0;
1598
- while (index < children.length && children[index]?.props?.record?.type != "data") index++;
1605
+ while (index < children.length && !isDataRecord(children[index])) index++;
1599
1606
 
1600
1607
  let count = 0;
1601
1608
  while (index < children.length && count < this.state.dropInsertionIndex) {
1602
- if (children[index]?.props?.record?.type == "data") count++;
1609
+ if (isDataRecord(children[index])) count++;
1603
1610
  index++;
1604
1611
  }
1605
1612
 
1606
1613
  let savedIndexPos = index;
1607
1614
 
1608
1615
  if (!this.state.dropNextToTheRowAbove)
1609
- while (index < children.length && children[index]?.props?.record?.type != "data") index++;
1616
+ while (index < children.length && !isDataRecord(children[index])) index++;
1610
1617
 
1611
1618
  // do not allow insertion after the last group footer
1612
1619
  if (savedIndexPos < index && index == children.length) index = savedIndexPos;
@@ -2002,15 +2009,15 @@ class GridComponent extends VDOM.Component {
2002
2009
  if (dropTarget == "grid" && widget.onDrop && dropInsertionIndex != null) {
2003
2010
  e.target = {
2004
2011
  insertionIndex: start + dropInsertionIndex,
2005
- recordBefore: this.getRecordAt(start + dropInsertionIndex - 1),
2006
- recordAfter: this.getRecordAt(start + dropInsertionIndex),
2012
+ recordBefore: this.getDataRecordAt(start + dropInsertionIndex - 1),
2013
+ recordAfter: this.getDataRecordAt(start + dropInsertionIndex),
2007
2014
  dropNextToTheRowAbove,
2008
2015
  };
2009
2016
  instance.invoke("onDrop", e, instance);
2010
2017
  } else if (dropTarget == "row") {
2011
2018
  e.target = {
2012
2019
  index: start + dropInsertionIndex,
2013
- record: this.getRecordAt(start + dropInsertionIndex),
2020
+ record: this.getDataRecordAt(start + dropInsertionIndex),
2014
2021
  };
2015
2022
  instance.invoke("onRowDrop", e, instance);
2016
2023
  } else if (dropTarget == "column" && widget.onColumnDrop) {
@@ -2730,6 +2737,13 @@ class GridComponent extends VDOM.Component {
2730
2737
  widget.selection.selectMultiple(instance.store, selection, indexes, options);
2731
2738
  }
2732
2739
 
2740
+ getDataRecordAt(index) {
2741
+ let { records } = this.props.instance;
2742
+ if (!records) return this.getRecordAt(index);
2743
+ let dataRecords = records.filter((r) => r.type == "data");
2744
+ return dataRecords[index];
2745
+ }
2746
+
2733
2747
  getRecordAt(cursor) {
2734
2748
  let { instance, data } = this.props;
2735
2749
  let { records, widget } = instance;
@@ -3097,6 +3111,7 @@ class GridColumnHeader extends Widget {
3097
3111
  if (!this.aggregateField && this.field) this.aggregateField = this.field;
3098
3112
 
3099
3113
  if (!this.aggregateAlias) this.aggregateAlias = this.aggregateField;
3114
+ if (this.aggregateAlias) this.aggregateAliasGetter = Binding.get(this.aggregateAlias).value;
3100
3115
 
3101
3116
  if (this.footer && isSelector(this.footer))
3102
3117
  this.footer = {