ngx-axis-appforge 0.0.84 → 0.0.85
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.
- package/axis-components/table/index.d.ts +1 -0
- package/axis-components/table-helper/index.d.ts +26 -2
- package/fesm2022/ngx-axis-appforge-axis-components-table-design.mjs +7 -2
- package/fesm2022/ngx-axis-appforge-axis-components-table-design.mjs.map +1 -1
- package/fesm2022/ngx-axis-appforge-axis-components-table-helper.mjs +152 -25
- package/fesm2022/ngx-axis-appforge-axis-components-table-helper.mjs.map +1 -1
- package/fesm2022/ngx-axis-appforge-axis-components-table.mjs +12 -8
- package/fesm2022/ngx-axis-appforge-axis-components-table.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -29,7 +29,7 @@ class TableFieldDisplayService {
|
|
|
29
29
|
if (!this.fieldDisplayCache.has(field.field())) {
|
|
30
30
|
this.fieldDisplayCache.set(field.field(), new Map());
|
|
31
31
|
}
|
|
32
|
-
if (!this.fieldDisplayCache.get(field.field()).has(row[field.field()])) {
|
|
32
|
+
if (row[field.field()] === undefined || !this.fieldDisplayCache.get(field.field()).has(row[field.field()])) {
|
|
33
33
|
const child = this.scope?.snapshotOptions(field.child(), { row, loopRow });
|
|
34
34
|
let text;
|
|
35
35
|
switch (child.component) {
|
|
@@ -61,6 +61,9 @@ class TableFieldDisplayService {
|
|
|
61
61
|
text = child.text;
|
|
62
62
|
break;
|
|
63
63
|
}
|
|
64
|
+
if (row[field.field()] === undefined) {
|
|
65
|
+
return text;
|
|
66
|
+
}
|
|
64
67
|
this.fieldDisplayCache.get(field.field()).set(row[field.field()], text);
|
|
65
68
|
}
|
|
66
69
|
return this.fieldDisplayCache.get(field.field()).get(row[field.field()]);
|
|
@@ -117,6 +120,7 @@ class TableService {
|
|
|
117
120
|
}
|
|
118
121
|
ready = signal(false, ...(ngDevMode ? [{ debugName: "ready" }] : []));
|
|
119
122
|
data;
|
|
123
|
+
customExportData;
|
|
120
124
|
options;
|
|
121
125
|
fields;
|
|
122
126
|
getRow;
|
|
@@ -126,7 +130,13 @@ class TableService {
|
|
|
126
130
|
fields.sort((a, b) => (a.groupLevel() ?? 0) - (b.groupLevel() ?? 0));
|
|
127
131
|
return fields;
|
|
128
132
|
}, ...(ngDevMode ? [{ debugName: "groupAbleFields" }] : []));
|
|
133
|
+
groupAbleFieldsForExport = computed(() => {
|
|
134
|
+
const fields = this.fields().filter(f => f.groupAble() && f.export?.());
|
|
135
|
+
fields.sort((a, b) => (a.groupLevel() ?? 0) - (b.groupLevel() ?? 0));
|
|
136
|
+
return fields;
|
|
137
|
+
}, ...(ngDevMode ? [{ debugName: "groupAbleFieldsForExport" }] : []));
|
|
129
138
|
rowsGroupMap = computed(() => this.buildRowsGroupMap(), ...(ngDevMode ? [{ debugName: "rowsGroupMap" }] : []));
|
|
139
|
+
rowsGroupMapForExport = computed(() => this.buildRowsGroupMapForExport(), ...(ngDevMode ? [{ debugName: "rowsGroupMapForExport" }] : []));
|
|
130
140
|
useBackEndPaging = computed(() => this.options.showPagination() && this.options.useBackEndPaging(), ...(ngDevMode ? [{ debugName: "useBackEndPaging" }] : []));
|
|
131
141
|
rows = computed(() => this.useBackEndPaging() ? this.data()?.rows : this.data(), ...(ngDevMode ? [{ debugName: "rows" }] : []));
|
|
132
142
|
pageIndex = signal(1, ...(ngDevMode ? [{ debugName: "pageIndex" }] : []));
|
|
@@ -139,6 +149,7 @@ class TableService {
|
|
|
139
149
|
return this.fields().filter(f => f.inuse());
|
|
140
150
|
}, ...(ngDevMode ? [{ debugName: "displayFields" }] : []));
|
|
141
151
|
fieldsControlsMap = signal({}, ...(ngDevMode ? [{ debugName: "fieldsControlsMap" }] : []));
|
|
152
|
+
tableDataForExport = computed(() => this.buildTableDataForExport(), ...(ngDevMode ? [{ debugName: "tableDataForExport" }] : []));
|
|
142
153
|
tableData = signal([], ...(ngDevMode ? [{ debugName: "tableData" }] : []));
|
|
143
154
|
fieldsFilterValueMap = new Map();
|
|
144
155
|
filedsFilterItemsCache = new Map();
|
|
@@ -148,6 +159,7 @@ class TableService {
|
|
|
148
159
|
pageCursorMarkIndexs = [];
|
|
149
160
|
init(opts) {
|
|
150
161
|
this.data = opts.data;
|
|
162
|
+
this.customExportData = opts.customExportData;
|
|
151
163
|
this.options = opts.options;
|
|
152
164
|
this.fields = opts.fields;
|
|
153
165
|
this.getRow = opts.getRow;
|
|
@@ -155,6 +167,58 @@ class TableService {
|
|
|
155
167
|
this.ready.set(true);
|
|
156
168
|
this.refreshTableData();
|
|
157
169
|
}
|
|
170
|
+
buildTableDataForExport() {
|
|
171
|
+
const data = [...(this.customExportData?.() ?? this.tableData())];
|
|
172
|
+
const sortFields = this.fields().filter(f => f.export?.() && this.fieldSortAble(f) && f.sortOrder() != null);
|
|
173
|
+
if (sortFields.length) {
|
|
174
|
+
sortFields.sort((a, b) => {
|
|
175
|
+
let ap = this.fieldSortPriority(a, this.groupAbleFieldsForExport());
|
|
176
|
+
let bp = this.fieldSortPriority(b, this.groupAbleFieldsForExport());
|
|
177
|
+
if (ap === bp) {
|
|
178
|
+
return 0;
|
|
179
|
+
}
|
|
180
|
+
if (ap === false) {
|
|
181
|
+
return 1;
|
|
182
|
+
}
|
|
183
|
+
else if (bp === false) {
|
|
184
|
+
return -1;
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
return bp - ap;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
data.sort((a, b) => {
|
|
191
|
+
for (const f of sortFields) {
|
|
192
|
+
let sortFn = this.fieldsControlsMap()[f.field()]?.sortFn;
|
|
193
|
+
if (typeof sortFn != "function") {
|
|
194
|
+
sortFn = (a, b) => {
|
|
195
|
+
const va = a[f.field()];
|
|
196
|
+
const vb = b[f.field()];
|
|
197
|
+
const ta = typeof va;
|
|
198
|
+
const tb = typeof vb;
|
|
199
|
+
if (ta == tb) {
|
|
200
|
+
if (ta == "number") {
|
|
201
|
+
return va - vb;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
return va.localeCompare(vb);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else if (ta == "number") {
|
|
208
|
+
return -1;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
const res = sortFn(a, b);
|
|
213
|
+
if (res != 0) {
|
|
214
|
+
return res * (f.sortOrder() == "descend" ? -1 : 1);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return 0;
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
return data;
|
|
221
|
+
}
|
|
158
222
|
refreshTableData() {
|
|
159
223
|
let data = [...(this.rows() ?? [])];
|
|
160
224
|
if (!this.useBackEndPaging()) {
|
|
@@ -210,13 +274,20 @@ class TableService {
|
|
|
210
274
|
this.tableData.set(data);
|
|
211
275
|
}
|
|
212
276
|
buildRowsGroupMap() {
|
|
277
|
+
return this._buildRowsGroupMap(this.tableData(), this.useBackEndPaging());
|
|
278
|
+
}
|
|
279
|
+
buildRowsGroupMapForExport() {
|
|
280
|
+
return this._buildRowsGroupMap(this.tableDataForExport(), false, this.groupAbleFieldsForExport());
|
|
281
|
+
}
|
|
282
|
+
_buildRowsGroupMap(data, useBackEndPaging = false, groupAbleFields) {
|
|
213
283
|
const rowsGroupMap = new Map();
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
284
|
+
groupAbleFields ??= this.groupAbleFields();
|
|
285
|
+
if (!useBackEndPaging) {
|
|
286
|
+
if (groupAbleFields.length > 0) {
|
|
287
|
+
for (let i = 0; i < data.length; i++) {
|
|
217
288
|
let valuePerfix = "";
|
|
218
|
-
const row =
|
|
219
|
-
for (const field of
|
|
289
|
+
const row = data[i];
|
|
290
|
+
for (const field of groupAbleFields) {
|
|
220
291
|
if (!rowsGroupMap.has(field.field())) {
|
|
221
292
|
rowsGroupMap.set(field.field(), new Map());
|
|
222
293
|
}
|
|
@@ -234,6 +305,15 @@ class TableService {
|
|
|
234
305
|
}
|
|
235
306
|
}
|
|
236
307
|
}
|
|
308
|
+
else {
|
|
309
|
+
for (const field in data.group_result ?? {}) {
|
|
310
|
+
const groups = new Map();
|
|
311
|
+
for (const value in data.group_result[field]) {
|
|
312
|
+
groups.set(value, data.group_result[field][value]);
|
|
313
|
+
}
|
|
314
|
+
rowsGroupMap.set(field, groups);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
237
317
|
return rowsGroupMap;
|
|
238
318
|
}
|
|
239
319
|
fieldSortAble(f) {
|
|
@@ -242,14 +322,15 @@ class TableService {
|
|
|
242
322
|
fieldSortDirections(f) {
|
|
243
323
|
return f.groupAble() ? ['ascend', 'descend'] : ['ascend', 'descend', null];
|
|
244
324
|
}
|
|
245
|
-
fieldSortPriority(f) {
|
|
325
|
+
fieldSortPriority(f, groupAbleFields) {
|
|
246
326
|
if (f.groupAble()) {
|
|
247
327
|
return (f.groupLevel() ?? 0) * -1;
|
|
248
328
|
}
|
|
329
|
+
groupAbleFields ??= this.groupAbleFields();
|
|
249
330
|
if (f.sortAble()) {
|
|
250
331
|
let p = 0;
|
|
251
|
-
if (
|
|
252
|
-
p =
|
|
332
|
+
if (groupAbleFields.length) {
|
|
333
|
+
p = groupAbleFields[groupAbleFields.length - 1].groupLevel() ?? 0;
|
|
253
334
|
p *= -1;
|
|
254
335
|
}
|
|
255
336
|
return (p - 1 + (f.sortPriority() ?? 0));
|
|
@@ -259,6 +340,9 @@ class TableService {
|
|
|
259
340
|
getGroupValue(row) {
|
|
260
341
|
return row[this.groupAbleFields()[0].field()];
|
|
261
342
|
}
|
|
343
|
+
getGroupValueForExport(row) {
|
|
344
|
+
return row[this.groupAbleFieldsForExport()[0].field()];
|
|
345
|
+
}
|
|
262
346
|
isGroupEnd(index, row) {
|
|
263
347
|
const topGroupField = this.groupAbleFields()[0];
|
|
264
348
|
if (!topGroupField) {
|
|
@@ -270,6 +354,17 @@ class TableService {
|
|
|
270
354
|
}
|
|
271
355
|
return false;
|
|
272
356
|
}
|
|
357
|
+
isGroupEndForExport(index, row) {
|
|
358
|
+
const topGroupField = this.groupAbleFieldsForExport()[0];
|
|
359
|
+
if (!topGroupField) {
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
const indexs = this.rowsGroupMapForExport().get(topGroupField.field())?.get(row[topGroupField.field()]?.toString());
|
|
363
|
+
if (indexs) {
|
|
364
|
+
return indexs[indexs.length - 1] == index;
|
|
365
|
+
}
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
273
368
|
rowspan(f, index, pageIndex, pageSize, row) {
|
|
274
369
|
if (f.groupAble()) {
|
|
275
370
|
const value = this.groupAbleFields().slice(0, this.groupAbleFields().findIndex(_f => _f.field() == f.field()) + 1).map(_f => row[_f.field()]).join("@");
|
|
@@ -455,13 +550,16 @@ class TableService {
|
|
|
455
550
|
this.pageCursorMarks.clear();
|
|
456
551
|
}
|
|
457
552
|
get backEndPageParams() {
|
|
553
|
+
const sortFields = this.displayFields().filter(f => this.fieldSortAble(f) && f.sortOrder() != null);
|
|
554
|
+
sortFields.sort((a, b) => this.fieldSortPriority(b) - this.fieldSortPriority(a));
|
|
458
555
|
return {
|
|
459
556
|
use_page: true,
|
|
460
557
|
page_index: this.pageIndex() - 1,
|
|
461
558
|
page_size: this.options.pageSize(),
|
|
462
559
|
query_total: !this.hasTotal,
|
|
463
560
|
cursor_mark: this.getNearestCursorMark(),
|
|
464
|
-
|
|
561
|
+
group_fields: this.groupAbleFields().map(f => f.field()),
|
|
562
|
+
order_by: sortFields.map(f => ({
|
|
465
563
|
column: f.field(),
|
|
466
564
|
desc_order: f.sortOrder() == "descend"
|
|
467
565
|
}))
|
|
@@ -752,9 +850,12 @@ class StatisticService {
|
|
|
752
850
|
fields;
|
|
753
851
|
getRow;
|
|
754
852
|
tableSvc;
|
|
853
|
+
useBackEndPaging = computed(() => this.options.showPagination() && this.options.useBackEndPaging(), ...(ngDevMode ? [{ debugName: "useBackEndPaging" }] : []));
|
|
755
854
|
hasStatistic = false;
|
|
756
855
|
statisticMap = computed(() => this.buildStatisticMap(), ...(ngDevMode ? [{ debugName: "statisticMap" }] : []));
|
|
856
|
+
statisticMapForExport = computed(() => this.buildStatisticMapForExport(), ...(ngDevMode ? [{ debugName: "statisticMapForExport" }] : []));
|
|
757
857
|
statisticGroupMap = computed(() => this.buildStatisticGroupMap(), ...(ngDevMode ? [{ debugName: "statisticGroupMap" }] : []));
|
|
858
|
+
statisticGroupMapForExport = computed(() => this.buildStatisticGroupMapForExport(), ...(ngDevMode ? [{ debugName: "statisticGroupMapForExport" }] : []));
|
|
758
859
|
init(opts) {
|
|
759
860
|
this.options = opts.options;
|
|
760
861
|
this.data = opts.data;
|
|
@@ -764,36 +865,62 @@ class StatisticService {
|
|
|
764
865
|
this.ready.set(true);
|
|
765
866
|
}
|
|
766
867
|
buildStatisticMap() {
|
|
868
|
+
return this._buildStatisticMap(this.data());
|
|
869
|
+
}
|
|
870
|
+
buildStatisticMapForExport() {
|
|
871
|
+
return this._buildStatisticMap(this.tableSvc?.customExportData?.() ?? this.data());
|
|
872
|
+
}
|
|
873
|
+
_buildStatisticMap(data) {
|
|
767
874
|
if (!this.ready()) {
|
|
768
875
|
return {};
|
|
769
876
|
}
|
|
770
877
|
let res = {};
|
|
771
|
-
if (this.options.showStatistic() &&
|
|
772
|
-
if (this.
|
|
773
|
-
res =
|
|
878
|
+
if (this.options.showStatistic() && data) {
|
|
879
|
+
if (this.useBackEndPaging()) {
|
|
880
|
+
res = data.statistic_result;
|
|
774
881
|
}
|
|
775
882
|
else {
|
|
776
|
-
res = this.statisticCompute(
|
|
883
|
+
res = this.statisticCompute(data);
|
|
777
884
|
}
|
|
778
885
|
}
|
|
779
|
-
return res;
|
|
886
|
+
return res ?? {};
|
|
780
887
|
}
|
|
781
888
|
buildStatisticGroupMap() {
|
|
889
|
+
if (!this.ready() || !this.tableSvc) {
|
|
890
|
+
return {};
|
|
891
|
+
}
|
|
892
|
+
return this._buildStatisticGroupMap(this.tableSvc.tableData(), this.useBackEndPaging());
|
|
893
|
+
}
|
|
894
|
+
buildStatisticGroupMapForExport() {
|
|
895
|
+
if (!this.ready() || !this.tableSvc) {
|
|
896
|
+
return {};
|
|
897
|
+
}
|
|
898
|
+
return this._buildStatisticGroupMap(this.tableSvc.tableDataForExport(), false, this.tableSvc.groupAbleFieldsForExport(), this.tableSvc.rowsGroupMapForExport());
|
|
899
|
+
}
|
|
900
|
+
_buildStatisticGroupMap(data, useBackEndPaging = false, groupAbleFields, rowsGroupMap) {
|
|
782
901
|
if (!this.ready() || !this.tableSvc) {
|
|
783
902
|
return {};
|
|
784
903
|
}
|
|
785
904
|
let res = {};
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
res = this.data().statistic_result;
|
|
905
|
+
if (useBackEndPaging) {
|
|
906
|
+
if (data?.query_statistic_group) {
|
|
907
|
+
res = data.statistic_group_result ?? {};
|
|
790
908
|
}
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
909
|
+
}
|
|
910
|
+
else {
|
|
911
|
+
groupAbleFields ??= this.tableSvc.groupAbleFields();
|
|
912
|
+
const groupField = groupAbleFields[0];
|
|
913
|
+
if (this.options.showStatistic() && groupField) {
|
|
914
|
+
if (useBackEndPaging) {
|
|
915
|
+
res = data.statistic_result;
|
|
916
|
+
}
|
|
917
|
+
else {
|
|
918
|
+
rowsGroupMap ??= this.tableSvc.rowsGroupMap();
|
|
919
|
+
const group = rowsGroupMap.get(groupField.field());
|
|
920
|
+
if (group) {
|
|
921
|
+
for (const [value, indexs] of group) {
|
|
922
|
+
res[value] = this.statisticCompute(indexs.map(index => data[index]));
|
|
923
|
+
}
|
|
797
924
|
}
|
|
798
925
|
}
|
|
799
926
|
}
|