canvas-datagrid 0.3.22 → 0.4.0
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/CHANGELOG.md +33 -0
- package/dist/canvas-datagrid.debug.js +2272 -157
- package/dist/canvas-datagrid.debug.map +1 -1
- package/dist/canvas-datagrid.js +1 -1
- package/dist/canvas-datagrid.module.js +1 -1
- package/dist/canvas-datagrid.module.js.map +1 -1
- package/dist/types.d.ts +114 -0
- package/lib/contextMenu.js +283 -0
- package/lib/defaults.js +35 -0
- package/lib/docs.js +18 -0
- package/lib/dom.js +27 -5
- package/lib/draw.js +626 -30
- package/lib/events/index.js +145 -50
- package/lib/events/util.js +6 -5
- package/lib/intf.js +584 -3
- package/lib/publicMethods.js +378 -12
- package/package.json +1 -1
package/lib/intf.js
CHANGED
|
@@ -57,6 +57,20 @@ export default function (self, ctor) {
|
|
|
57
57
|
self.scrollBox = {};
|
|
58
58
|
self.visibleRows = [];
|
|
59
59
|
self.visibleCells = [];
|
|
60
|
+
/**
|
|
61
|
+
* This array stored all groups information with context for drawing,
|
|
62
|
+
* it is generated by drawing functions,
|
|
63
|
+
* and be used for searching groups when users operate on the spreadsheet
|
|
64
|
+
* Each item of this array contains these properties:
|
|
65
|
+
* - `type`: its available values: 'c' and 'r'. indicates the type of this item, 'c' for column group
|
|
66
|
+
* and 'r' for row group.
|
|
67
|
+
* - `x`,`y`: the left-top point of this group's rendering area.
|
|
68
|
+
* - `x2`, `y2`: the right-bottom of this group's rendering area.
|
|
69
|
+
* - `collapsed`: this value indicates the collapsed status of this group.
|
|
70
|
+
* - `from`, `to`: The column index range of this group (We use this value for searching the group)
|
|
71
|
+
* - `row`: The row index for column groups (We use this value for searching the group)
|
|
72
|
+
*/
|
|
73
|
+
self.visibleGroups = [];
|
|
60
74
|
self.sizes = {
|
|
61
75
|
rows: {},
|
|
62
76
|
columns: {},
|
|
@@ -71,6 +85,18 @@ export default function (self, ctor) {
|
|
|
71
85
|
columnIndex: -1,
|
|
72
86
|
rowIndex: -1,
|
|
73
87
|
};
|
|
88
|
+
self.cellTree = {
|
|
89
|
+
rows: [],
|
|
90
|
+
columns: {},
|
|
91
|
+
tempSchema: {},
|
|
92
|
+
rowTreeColIndex: 0,
|
|
93
|
+
columnTreeRowStartIndex: 0,
|
|
94
|
+
columnTreeRowEndIndex: 0,
|
|
95
|
+
origin: {
|
|
96
|
+
rows: [],
|
|
97
|
+
columns: {},
|
|
98
|
+
},
|
|
99
|
+
};
|
|
74
100
|
self.hovers = {};
|
|
75
101
|
self.attributes = {};
|
|
76
102
|
self.style = {};
|
|
@@ -86,6 +112,29 @@ export default function (self, ctor) {
|
|
|
86
112
|
self.scrollPixelLeft = 0;
|
|
87
113
|
self.childGrids = {};
|
|
88
114
|
self.openChildren = {};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Array for grouped columns
|
|
118
|
+
* Each item in this array is an array and it represents some grouping in one row
|
|
119
|
+
* A grouping descriptor has three properties:
|
|
120
|
+
* - `from`: The column index of the first column
|
|
121
|
+
* - `to`: The column index of the last column
|
|
122
|
+
* - `collapsed`: Is this group be collapsed
|
|
123
|
+
* @example [[{ from: 1, to: 2, collapsed: false }]]
|
|
124
|
+
*/
|
|
125
|
+
self.groupedColumns = [];
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Array for grouped rows
|
|
129
|
+
* Each item in this array is an array and it represents some grouping in one column
|
|
130
|
+
* A grouping descriptor has three properties:
|
|
131
|
+
* - `from`: The row index of the first row
|
|
132
|
+
* - `to`: The row index of the last row
|
|
133
|
+
* - `collapsed`: Is this group be collapsed
|
|
134
|
+
* @example [[{ from: 1, to: 2, collapsed: false }]]
|
|
135
|
+
*/
|
|
136
|
+
self.groupedRows = [];
|
|
137
|
+
|
|
89
138
|
self.scrollModes = [
|
|
90
139
|
'vertical-scroll-box',
|
|
91
140
|
'vertical-scroll-top',
|
|
@@ -99,6 +148,7 @@ export default function (self, ctor) {
|
|
|
99
148
|
'afterdraw',
|
|
100
149
|
'afterrendercell',
|
|
101
150
|
'afterrenderfilterbutton',
|
|
151
|
+
'aftercreategroup',
|
|
102
152
|
'attributechanged',
|
|
103
153
|
'beforebeginedit',
|
|
104
154
|
'beforecreatecellgrid',
|
|
@@ -337,6 +387,124 @@ export default function (self, ctor) {
|
|
|
337
387
|
self.getBoundColumnIndexFromViewColumnIndex = function (viewColumnIndex) {
|
|
338
388
|
return self.orders.columns[viewColumnIndex];
|
|
339
389
|
};
|
|
390
|
+
/**
|
|
391
|
+
* Get the height of the area about column groups for rendering and handling events.
|
|
392
|
+
*/
|
|
393
|
+
self.getColumnGroupAreaHeight = function () {
|
|
394
|
+
if (!self.attributes.allowGroupingColumns) {
|
|
395
|
+
return 0;
|
|
396
|
+
}
|
|
397
|
+
const groups = self.groupedColumns.length;
|
|
398
|
+
const base = self.style.columnGroupRowHeight * self.scale;
|
|
399
|
+
return base * groups;
|
|
400
|
+
};
|
|
401
|
+
/**
|
|
402
|
+
* Get the width of the area about row groups for rendering and handling events.
|
|
403
|
+
*/
|
|
404
|
+
self.getRowGroupAreaWidth = function () {
|
|
405
|
+
if (!self.attributes.allowGroupingRows) {
|
|
406
|
+
return 0;
|
|
407
|
+
}
|
|
408
|
+
const groups = self.groupedRows.length;
|
|
409
|
+
const base = self.style.rowGroupColumnWidth * self.scale;
|
|
410
|
+
return base * groups;
|
|
411
|
+
};
|
|
412
|
+
self.getCollapsedColumnGroups = function () {
|
|
413
|
+
const result = [];
|
|
414
|
+
for (let rowIndex = 0; rowIndex < self.groupedColumns.length; rowIndex++) {
|
|
415
|
+
const groups = self.groupedColumns[rowIndex];
|
|
416
|
+
for (let groupIndex = 0; groupIndex < groups.length; groupIndex++) {
|
|
417
|
+
const group = groups[groupIndex];
|
|
418
|
+
if (group.collapsed) result.push(group);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return result;
|
|
422
|
+
};
|
|
423
|
+
self.getCollapsedRowGroups = function () {
|
|
424
|
+
const result = [];
|
|
425
|
+
for (let rowIndex = 0; rowIndex < self.groupedRows.length; rowIndex++) {
|
|
426
|
+
const groups = self.groupedRows[rowIndex];
|
|
427
|
+
for (let groupIndex = 0; groupIndex < groups.length; groupIndex++) {
|
|
428
|
+
const group = groups[groupIndex];
|
|
429
|
+
if (group.collapsed) result.push(group);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return result;
|
|
433
|
+
};
|
|
434
|
+
/**
|
|
435
|
+
* Toggle the collapse status of a group (expanded/collapsed)
|
|
436
|
+
* @param {{type:string,from:number,to:number}} group
|
|
437
|
+
*/
|
|
438
|
+
self.toggleGroup = function (group) {
|
|
439
|
+
if (group.type === 'c') {
|
|
440
|
+
const { from, to } = group;
|
|
441
|
+
/** @type {{from:number,to:number,collapsed:boolean}} */
|
|
442
|
+
let matchedGroup;
|
|
443
|
+
/** @type {Array<Array<{from:number,to:number,collapsed:boolean}>>} */
|
|
444
|
+
const allGroups = self.groupedColumns;
|
|
445
|
+
for (let i = 0; i < allGroups.length; i++) {
|
|
446
|
+
const groups = allGroups[i];
|
|
447
|
+
for (let gi = 0; gi < groups.length; gi++) {
|
|
448
|
+
const group = groups[gi];
|
|
449
|
+
if (group.from === from && group.to === to) {
|
|
450
|
+
matchedGroup = group;
|
|
451
|
+
break;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (matchedGroup) break;
|
|
455
|
+
}
|
|
456
|
+
if (!matchedGroup) return;
|
|
457
|
+
const nextCollapsed = !matchedGroup.collapsed;
|
|
458
|
+
matchedGroup.collapsed = nextCollapsed;
|
|
459
|
+
return true;
|
|
460
|
+
}
|
|
461
|
+
if (group.type === 'r') {
|
|
462
|
+
const { from, to } = group;
|
|
463
|
+
/** @type {{from:number,to:number,collapsed:boolean}} */
|
|
464
|
+
let matchedGroup;
|
|
465
|
+
/** @type {Array<Array<{from:number,to:number,collapsed:boolean}>>} */
|
|
466
|
+
const allGroups = self.groupedRows;
|
|
467
|
+
for (let i = 0; i < allGroups.length; i++) {
|
|
468
|
+
const groups = allGroups[i];
|
|
469
|
+
for (let gi = 0; gi < groups.length; gi++) {
|
|
470
|
+
const group = groups[gi];
|
|
471
|
+
if (group.from === from && group.to === to) {
|
|
472
|
+
matchedGroup = group;
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (matchedGroup) break;
|
|
477
|
+
}
|
|
478
|
+
if (!matchedGroup) return;
|
|
479
|
+
const nextCollapsed = !matchedGroup.collapsed;
|
|
480
|
+
matchedGroup.collapsed = nextCollapsed;
|
|
481
|
+
return true;
|
|
482
|
+
}
|
|
483
|
+
return false;
|
|
484
|
+
};
|
|
485
|
+
self.isNewGroupRangeValid = function (groupsArray, from, to) {
|
|
486
|
+
for (let i = 0; i < groupsArray.length; i++) {
|
|
487
|
+
const groups = groupsArray[i];
|
|
488
|
+
for (let gIndex = 0; gIndex < groups.length; gIndex++) {
|
|
489
|
+
const group = groups[gIndex];
|
|
490
|
+
if (from === group.to + 1) return false;
|
|
491
|
+
if (from > group.to) continue;
|
|
492
|
+
|
|
493
|
+
if (from === group.from) {
|
|
494
|
+
if (to === group.to) return false;
|
|
495
|
+
if (to > group.to) return true;
|
|
496
|
+
break; // check smaller range
|
|
497
|
+
}
|
|
498
|
+
if (from > group.from) {
|
|
499
|
+
if (to > group.to) return false;
|
|
500
|
+
break; // check smaller range
|
|
501
|
+
}
|
|
502
|
+
if (to < group.to) return false;
|
|
503
|
+
return true;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return true;
|
|
507
|
+
};
|
|
340
508
|
self.getColumnHeaderCellHeight = function () {
|
|
341
509
|
if (!self.attributes.showColumnHeaders) {
|
|
342
510
|
return 0;
|
|
@@ -396,15 +564,24 @@ export default function (self, ctor) {
|
|
|
396
564
|
self.createRowOrders = function () {
|
|
397
565
|
self.orders.rows = fillArray(0, self.originalData.length - 1);
|
|
398
566
|
};
|
|
399
|
-
self.fitSelectedColumns = function () {
|
|
567
|
+
self.fitSelectedColumns = function (width) {
|
|
400
568
|
const selectedColumns = self.selections[0];
|
|
401
569
|
const schema = self.getSchema();
|
|
402
570
|
|
|
403
571
|
for (const selectedColumn of selectedColumns) {
|
|
404
572
|
// Make sure the column is not the row header and that the whole column has in fact been selected.
|
|
405
573
|
if (selectedColumn >= 0 && self.isColumnSelected(selectedColumn)) {
|
|
406
|
-
|
|
407
|
-
|
|
574
|
+
if (isNaN(width)) {
|
|
575
|
+
const column = schema[self.orders.columns[selectedColumn]];
|
|
576
|
+
self.fitColumnToValues(column.name);
|
|
577
|
+
} else {
|
|
578
|
+
self.sizes.columns[selectedColumn] = width;
|
|
579
|
+
self.dispatchEvent('resizecolumn', {
|
|
580
|
+
x: width,
|
|
581
|
+
y: self.resizingStartingHeight,
|
|
582
|
+
draggingItem: self.currentCell,
|
|
583
|
+
});
|
|
584
|
+
}
|
|
408
585
|
}
|
|
409
586
|
}
|
|
410
587
|
};
|
|
@@ -455,6 +632,16 @@ export default function (self, ctor) {
|
|
|
455
632
|
self.hasActiveFilters = function () {
|
|
456
633
|
return self.columnFilters && Object.keys(self.columnFilters).length > 0;
|
|
457
634
|
};
|
|
635
|
+
self.hasCollapsedRowGroup = function () {
|
|
636
|
+
for (let i = 0; i < self.groupedRows.length; i++) {
|
|
637
|
+
const groups = self.groupedRows[i];
|
|
638
|
+
for (let j = 0; j < groups.length; j++) {
|
|
639
|
+
const g = groups[j];
|
|
640
|
+
if (g.collapsed) return true;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
return false;
|
|
644
|
+
};
|
|
458
645
|
self.getFilteredAndSortedViewData = function (originalData) {
|
|
459
646
|
// We make a copy of originalData here in order be able to
|
|
460
647
|
// filter and sort rows without modifying the original array.
|
|
@@ -490,6 +677,59 @@ export default function (self, ctor) {
|
|
|
490
677
|
});
|
|
491
678
|
}
|
|
492
679
|
|
|
680
|
+
//#region Hide rows from collapsed group
|
|
681
|
+
/** @type {number[][]} */
|
|
682
|
+
let collapsedGroups = [];
|
|
683
|
+
for (let i = 0; i < self.groupedRows.length; i++) {
|
|
684
|
+
const rows = self.groupedRows[i];
|
|
685
|
+
for (let j = 0; j < rows.length; j++) {
|
|
686
|
+
const r = rows[j];
|
|
687
|
+
if (!r.collapsed) continue;
|
|
688
|
+
collapsedGroups.push([r.from, r.to]);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
if (collapsedGroups.length > 0) {
|
|
692
|
+
//#region merge groups
|
|
693
|
+
collapsedGroups.sort((a, b) => a[0] - b[0]);
|
|
694
|
+
let newLen = 0;
|
|
695
|
+
const len = collapsedGroups.length;
|
|
696
|
+
for (let i = 0; i < len; i++) {
|
|
697
|
+
const r = collapsedGroups[i];
|
|
698
|
+
if (i === len - 1) {
|
|
699
|
+
collapsedGroups[newLen++] = r;
|
|
700
|
+
break;
|
|
701
|
+
}
|
|
702
|
+
const to = r[1];
|
|
703
|
+
const [from2, to2] = collapsedGroups[i + 1];
|
|
704
|
+
if (from2 > to + 1) {
|
|
705
|
+
collapsedGroups[newLen++] = r;
|
|
706
|
+
continue;
|
|
707
|
+
}
|
|
708
|
+
collapsedGroups[i + 1] = r;
|
|
709
|
+
if (to2 > to) collapsedGroups[i + 1][1] = to2;
|
|
710
|
+
}
|
|
711
|
+
collapsedGroups = collapsedGroups.slice(0, newLen);
|
|
712
|
+
//#endregion merge groups
|
|
713
|
+
|
|
714
|
+
//#region omit rows by groups
|
|
715
|
+
let g = collapsedGroups.shift();
|
|
716
|
+
for (let start = 0; start < newViewData.length; start++) {
|
|
717
|
+
const it = newViewData[start][1];
|
|
718
|
+
if (it < g[0]) continue;
|
|
719
|
+
let end = start + 1;
|
|
720
|
+
for (; end < newViewData.length; end++) {
|
|
721
|
+
const it2 = newViewData[end][1];
|
|
722
|
+
if (it2 > g[1]) break;
|
|
723
|
+
}
|
|
724
|
+
newViewData.splice(start, end - start);
|
|
725
|
+
g = collapsedGroups.shift();
|
|
726
|
+
if (!g) break;
|
|
727
|
+
start--;
|
|
728
|
+
}
|
|
729
|
+
//#endregion omit rows by groups
|
|
730
|
+
}
|
|
731
|
+
//#endregion Hide rows from collapsed group
|
|
732
|
+
|
|
493
733
|
// Apply sorting
|
|
494
734
|
for (const column of self.orderings.columns) {
|
|
495
735
|
const sortFn = column.sortFunction(column.orderBy, column.orderDirection);
|
|
@@ -694,6 +934,329 @@ export default function (self, ctor) {
|
|
|
694
934
|
}
|
|
695
935
|
}
|
|
696
936
|
};
|
|
937
|
+
self.toggleCollapseTree = function (rowIndex, columnIndex, type) {
|
|
938
|
+
let tempData = [];
|
|
939
|
+
let collapsedCount = 0;
|
|
940
|
+
if (
|
|
941
|
+
columnIndex == self.cellTree.rowTreeColIndex &&
|
|
942
|
+
(rowIndex > 0 || (rowIndex == 0 && self.cellTree.rows[0].icon))
|
|
943
|
+
) {
|
|
944
|
+
let ctr = self.cellTree.rows;
|
|
945
|
+
switch (type) {
|
|
946
|
+
case 'Expand':
|
|
947
|
+
ctr[rowIndex].expand = true;
|
|
948
|
+
self.cellTree.origin.rows[ctr[rowIndex].index].expand = true;
|
|
949
|
+
break;
|
|
950
|
+
|
|
951
|
+
case 'Collapse':
|
|
952
|
+
ctr[rowIndex].expand = false;
|
|
953
|
+
self.cellTree.origin.rows[ctr[rowIndex].index].expand = false;
|
|
954
|
+
break;
|
|
955
|
+
|
|
956
|
+
default:
|
|
957
|
+
ctr[rowIndex].expand = !ctr[rowIndex].expand;
|
|
958
|
+
self.cellTree.origin.rows[ctr[rowIndex].index].expand =
|
|
959
|
+
ctr[rowIndex].expand;
|
|
960
|
+
}
|
|
961
|
+
for (
|
|
962
|
+
let ri = ctr[rowIndex].index + 1;
|
|
963
|
+
ri <= ctr[rowIndex].lastchild;
|
|
964
|
+
ri++
|
|
965
|
+
) {
|
|
966
|
+
let orTree = self.cellTree.origin.rows[ri];
|
|
967
|
+
if (ctr[rowIndex].expand) {
|
|
968
|
+
orTree.hide = false;
|
|
969
|
+
if (orTree.icon && !orTree.expand) ri = orTree.lastchild;
|
|
970
|
+
} else {
|
|
971
|
+
orTree.hide = true;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
} else if (self.cellTree.columns[rowIndex]) {
|
|
975
|
+
let ctc = self.cellTree.columns[rowIndex];
|
|
976
|
+
|
|
977
|
+
switch (type) {
|
|
978
|
+
case 'Expand':
|
|
979
|
+
ctc[columnIndex].expand = true;
|
|
980
|
+
break;
|
|
981
|
+
|
|
982
|
+
case 'Collapse':
|
|
983
|
+
ctc[columnIndex].expand = false;
|
|
984
|
+
break;
|
|
985
|
+
|
|
986
|
+
default:
|
|
987
|
+
ctc[columnIndex].expand = !ctc[columnIndex].expand;
|
|
988
|
+
}
|
|
989
|
+
for (
|
|
990
|
+
let ci = ctc[columnIndex].index + 1;
|
|
991
|
+
ci <= ctc[columnIndex].lastchild;
|
|
992
|
+
ci++
|
|
993
|
+
) {
|
|
994
|
+
if (ctc[columnIndex].expand)
|
|
995
|
+
self.cellTree.tempSchema[ci].hidden = false;
|
|
996
|
+
else self.cellTree.tempSchema[ci].hidden = true;
|
|
997
|
+
}
|
|
998
|
+
let rc = 0,
|
|
999
|
+
_ri;
|
|
1000
|
+
|
|
1001
|
+
if (ctc[columnIndex].expand) {
|
|
1002
|
+
while (rc < ctc[columnIndex].child) {
|
|
1003
|
+
_ri = rowIndex + rc + 1;
|
|
1004
|
+
|
|
1005
|
+
for (
|
|
1006
|
+
let _ci = ctc[columnIndex].index;
|
|
1007
|
+
_ci <= ctc[columnIndex].lastchild;
|
|
1008
|
+
_ci++
|
|
1009
|
+
) {
|
|
1010
|
+
if (
|
|
1011
|
+
self.cellTree.origin.columns[_ri] &&
|
|
1012
|
+
self.cellTree.origin.columns[_ri][_ci].icon &&
|
|
1013
|
+
!self.cellTree.origin.columns[_ri][_ci].expand
|
|
1014
|
+
) {
|
|
1015
|
+
for (
|
|
1016
|
+
let si = _ci + 1;
|
|
1017
|
+
si <= self.cellTree.origin.columns[_ri][_ci].lastchild;
|
|
1018
|
+
si++
|
|
1019
|
+
) {
|
|
1020
|
+
self.cellTree.tempSchema[si].hidden = true;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
rc++;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
let otherData = {};
|
|
1030
|
+
let collapsed = [];
|
|
1031
|
+
self.cellTree.rows = [];
|
|
1032
|
+
self.cellTree.columns = {};
|
|
1033
|
+
for (let k in self.cellTree.origin.rows) {
|
|
1034
|
+
let tempRow = [];
|
|
1035
|
+
let tree = self.cellTree.origin.rows[k];
|
|
1036
|
+
if (!tree.hide) {
|
|
1037
|
+
let colTrees = [];
|
|
1038
|
+
let collapsedColCount = 0;
|
|
1039
|
+
if (k < self.cellTree.columnTreeRowStartIndex) {
|
|
1040
|
+
tempData.push(self.originalData[k]);
|
|
1041
|
+
} else {
|
|
1042
|
+
if (k > self.cellTree.columnTreeRowEndIndex) {
|
|
1043
|
+
otherData[k] = self.viewData[k];
|
|
1044
|
+
collapsedCount++;
|
|
1045
|
+
} else {
|
|
1046
|
+
for (let l = 0; l < self.originalData[k].length; l++) {
|
|
1047
|
+
if (!self.cellTree.tempSchema[l].hidden) {
|
|
1048
|
+
if (l < self.cellTree.rowTreeColIndex) {
|
|
1049
|
+
if (!Object.prototype.hasOwnProperty.call(otherData, k))
|
|
1050
|
+
otherData[k] = [];
|
|
1051
|
+
otherData[k].push(self.viewData[k][l]);
|
|
1052
|
+
}
|
|
1053
|
+
tempRow.push(self.originalData[k][l]);
|
|
1054
|
+
if (
|
|
1055
|
+
Object.prototype.hasOwnProperty.call(
|
|
1056
|
+
self.cellTree.origin.columns,
|
|
1057
|
+
k,
|
|
1058
|
+
)
|
|
1059
|
+
)
|
|
1060
|
+
colTrees.push(self.cellTree.origin.columns[k][l]);
|
|
1061
|
+
} else collapsedColCount++;
|
|
1062
|
+
}
|
|
1063
|
+
tempRow.push(
|
|
1064
|
+
...Array(collapsedColCount)
|
|
1065
|
+
.fill()
|
|
1066
|
+
.map(function () {
|
|
1067
|
+
return '';
|
|
1068
|
+
}),
|
|
1069
|
+
);
|
|
1070
|
+
if (colTrees.length) {
|
|
1071
|
+
colTrees.push(
|
|
1072
|
+
...Array(collapsedColCount)
|
|
1073
|
+
.fill()
|
|
1074
|
+
.map(() => {
|
|
1075
|
+
return {};
|
|
1076
|
+
}),
|
|
1077
|
+
);
|
|
1078
|
+
self.cellTree.columns[k] = colTrees;
|
|
1079
|
+
}
|
|
1080
|
+
tempData.push(tempRow);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
self.cellTree.rows.push(tree);
|
|
1084
|
+
} else {
|
|
1085
|
+
for (let l = 0; l < self.cellTree.rowTreeColIndex; l++) {
|
|
1086
|
+
tempRow.push(self.viewData[k][l]);
|
|
1087
|
+
}
|
|
1088
|
+
otherData[k] = tempRow;
|
|
1089
|
+
collapsed.push(
|
|
1090
|
+
Array(self.viewData[0].length)
|
|
1091
|
+
.fill()
|
|
1092
|
+
.map(function () {
|
|
1093
|
+
return '';
|
|
1094
|
+
}),
|
|
1095
|
+
);
|
|
1096
|
+
collapsedCount++;
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
if (collapsedCount) {
|
|
1100
|
+
self.cellTree.rows.push(
|
|
1101
|
+
...Array(collapsedCount)
|
|
1102
|
+
.fill()
|
|
1103
|
+
.map((u, index) => {
|
|
1104
|
+
return { index: self.cellTree.rows.length + index };
|
|
1105
|
+
}),
|
|
1106
|
+
);
|
|
1107
|
+
tempData.push(...collapsed);
|
|
1108
|
+
}
|
|
1109
|
+
for (let k in otherData) {
|
|
1110
|
+
if (k > self.cellTree.columnTreeRowEndIndex) tempData[k] = otherData[k];
|
|
1111
|
+
else
|
|
1112
|
+
for (let l in otherData[k]) {
|
|
1113
|
+
tempData[k][l] = otherData[k][l];
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
self.viewData = tempData;
|
|
1117
|
+
};
|
|
1118
|
+
self.cellTreeExpandCollapse = function (rowIndex, columnIndex, type) {
|
|
1119
|
+
if (
|
|
1120
|
+
columnIndex == self.cellTree.rowTreeColIndex &&
|
|
1121
|
+
(rowIndex > 0 || (rowIndex == 0 && self.cellTree.rows[0].icon))
|
|
1122
|
+
) {
|
|
1123
|
+
const ctr = self.cellTree.rows;
|
|
1124
|
+
switch (type) {
|
|
1125
|
+
case 'Expand':
|
|
1126
|
+
ctr[rowIndex].expand = true;
|
|
1127
|
+
break;
|
|
1128
|
+
case 'Collapse':
|
|
1129
|
+
ctr[rowIndex].expand = false;
|
|
1130
|
+
break;
|
|
1131
|
+
default:
|
|
1132
|
+
ctr[rowIndex].expand = !ctr[rowIndex].expand;
|
|
1133
|
+
}
|
|
1134
|
+
for (let ri = rowIndex + 1; ri <= ctr[rowIndex].lastchild; ri++) {
|
|
1135
|
+
if (ctr[rowIndex].expand) {
|
|
1136
|
+
ctr[ri].hide = false;
|
|
1137
|
+
if (ctr[ri].icon && !ctr[ri].expand) ri = ctr[ri].lastchild;
|
|
1138
|
+
} else {
|
|
1139
|
+
ctr[ri].hide = true;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
} else if (self.cellTree.columns[rowIndex]) {
|
|
1143
|
+
const ctc = self.cellTree.columns[rowIndex];
|
|
1144
|
+
switch (type) {
|
|
1145
|
+
case 'Expand':
|
|
1146
|
+
ctc[columnIndex].expand = true;
|
|
1147
|
+
break;
|
|
1148
|
+
case 'Collapse':
|
|
1149
|
+
ctc[columnIndex].expand = false;
|
|
1150
|
+
break;
|
|
1151
|
+
default:
|
|
1152
|
+
ctc[columnIndex].expand = !ctc[columnIndex].expand;
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
for (let ci = columnIndex + 1; ci <= ctc[columnIndex].lastchild; ci++) {
|
|
1156
|
+
if (ctc[columnIndex].expand) self.tempSchema[ci].hidden = false;
|
|
1157
|
+
else self.tempSchema[ci].hidden = true;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
let rc = 0,
|
|
1161
|
+
ri;
|
|
1162
|
+
if (ctc[columnIndex].expand) {
|
|
1163
|
+
while (rc < ctc[columnIndex].child) {
|
|
1164
|
+
ri = rowIndex + rc + 1;
|
|
1165
|
+
for (let ci = columnIndex; ci <= ctc[columnIndex].lastchild; ci++) {
|
|
1166
|
+
if (
|
|
1167
|
+
self.cellTree.columns[ri] &&
|
|
1168
|
+
self.cellTree.columns[ri][ci].icon &&
|
|
1169
|
+
!self.cellTree.columns[ri][ci].expand
|
|
1170
|
+
) {
|
|
1171
|
+
for (
|
|
1172
|
+
let si = ci + 1;
|
|
1173
|
+
si <= self.cellTree.columns[ri][ci].lastchild;
|
|
1174
|
+
si++
|
|
1175
|
+
)
|
|
1176
|
+
self.tempSchema[si].hidden = true;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
rc++;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
};
|
|
1184
|
+
|
|
1185
|
+
self.initCellTreeSettings = function () {
|
|
1186
|
+
if (self.viewData === undefined) return;
|
|
1187
|
+
if (self.attributes.rowTree.length > 0 && self.viewData.length > 0) {
|
|
1188
|
+
self.cellTree.rows = Array(self.viewData.length)
|
|
1189
|
+
.fill()
|
|
1190
|
+
.map((u, index) => ({ index: index }));
|
|
1191
|
+
self.cellTree.rowTreeColIndex = self.attributes.rowTreeColIndex;
|
|
1192
|
+
let invalidRowTree = false;
|
|
1193
|
+
for (let rt of self.attributes.rowTree) {
|
|
1194
|
+
if (self.cellTree.rows.length <= rt.end) {
|
|
1195
|
+
invalidRowTree = true;
|
|
1196
|
+
break;
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
for (let ri = rt.begin; ri <= rt.end; ri++) {
|
|
1200
|
+
if (ri == rt.begin) {
|
|
1201
|
+
self.cellTree.rows[ri].icon = true;
|
|
1202
|
+
self.cellTree.rows[ri].lastchild = rt.end;
|
|
1203
|
+
self.cellTree.rows[ri].expand = true;
|
|
1204
|
+
if (!self.cellTree.rows[ri].parentCount)
|
|
1205
|
+
self.cellTree.rows[ri].parentCount = 0;
|
|
1206
|
+
} else {
|
|
1207
|
+
self.cellTree.rows[ri].hide = false;
|
|
1208
|
+
self.cellTree.rows[ri].parentIndex = rt.begin;
|
|
1209
|
+
if (self.cellTree.rows[ri] && self.cellTree.rows[ri].parentCount)
|
|
1210
|
+
self.cellTree.rows[ri].parentCount += 1;
|
|
1211
|
+
else self.cellTree.rows[ri].parentCount = 1;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
if (invalidRowTree) self.cellTree.rows = {};
|
|
1216
|
+
}
|
|
1217
|
+
if (self.attributes.columnTree.length > 0 && self.viewData.length > 0) {
|
|
1218
|
+
self.cellTree.columnTreeRowStartIndex =
|
|
1219
|
+
self.attributes.columnTreeRowStartIndex;
|
|
1220
|
+
self.cellTree.columnTreeRowEndIndex =
|
|
1221
|
+
self.attributes.columnTreeRowEndIndex;
|
|
1222
|
+
let dataColumnLength = Object.keys(self.viewData[0]).length;
|
|
1223
|
+
let invalidColumnTree = false;
|
|
1224
|
+
for (let ct of self.attributes.columnTree) {
|
|
1225
|
+
if (dataColumnLength <= ct.end) {
|
|
1226
|
+
invalidColumnTree = true;
|
|
1227
|
+
break;
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
if (!self.cellTree.columns[ct.row])
|
|
1231
|
+
self.cellTree.columns[ct.row] = Array(dataColumnLength)
|
|
1232
|
+
.fill()
|
|
1233
|
+
.map((u, index) => ({ index: index }));
|
|
1234
|
+
|
|
1235
|
+
for (let i = ct.begin; i <= ct.end; i++) {
|
|
1236
|
+
const ctc = self.cellTree.columns[ct.row][i];
|
|
1237
|
+
if (i == ct.begin) {
|
|
1238
|
+
ctc.icon = true;
|
|
1239
|
+
ctc.lastchild = ct.end;
|
|
1240
|
+
ctc.length = ct.end - ct.begin;
|
|
1241
|
+
ctc.expand = true;
|
|
1242
|
+
if (ct.child) ctc.child = ct.child;
|
|
1243
|
+
else ctc.child = 0;
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
self.cellTree.tempSchema = Array(dataColumnLength)
|
|
1248
|
+
.fill()
|
|
1249
|
+
.map(function () {
|
|
1250
|
+
return { hidden: false };
|
|
1251
|
+
});
|
|
1252
|
+
if (invalidColumnTree) self.cellTree.columns = {};
|
|
1253
|
+
}
|
|
1254
|
+
self.cellTree.origin = {
|
|
1255
|
+
rows: self.cellTree.rows,
|
|
1256
|
+
columns: self.cellTree.columns,
|
|
1257
|
+
};
|
|
1258
|
+
};
|
|
1259
|
+
|
|
697
1260
|
self.getDomRoot = function () {
|
|
698
1261
|
return self.shadowRoot ? self.shadowRoot.host : self.parentNode;
|
|
699
1262
|
};
|
|
@@ -865,6 +1428,8 @@ export default function (self, ctor) {
|
|
|
865
1428
|
self.intf.gotoCell = self.gotoCell;
|
|
866
1429
|
self.intf.gotoRow = self.gotoRow;
|
|
867
1430
|
self.intf.addButton = self.addButton;
|
|
1431
|
+
self.intf.toggleCellCollapseTree = self.toggleCellCollapseTree;
|
|
1432
|
+
self.intf.expandCollapseCellTree = self.expandCollapseCellTree;
|
|
868
1433
|
self.intf.getHeaderByName = self.getHeaderByName;
|
|
869
1434
|
self.intf.findColumnScrollLeft = self.findColumnScrollLeft;
|
|
870
1435
|
self.intf.findRowScrollTop = self.findRowScrollTop;
|
|
@@ -872,6 +1437,14 @@ export default function (self, ctor) {
|
|
|
872
1437
|
self.intf.findColumnMaxTextLength = self.findColumnMaxTextLength;
|
|
873
1438
|
self.intf.disposeContextMenu = self.disposeContextMenu;
|
|
874
1439
|
self.intf.getCellAt = self.getCellAt;
|
|
1440
|
+
self.intf.groupColumns = self.groupColumns;
|
|
1441
|
+
self.intf.groupRows = self.groupRows;
|
|
1442
|
+
self.intf.removeGroupColumns = self.removeGroupColumns;
|
|
1443
|
+
self.intf.removeGroupRows = self.removeGroupRows;
|
|
1444
|
+
self.intf.toggleGroupColumns = self.toggleGroupColumns;
|
|
1445
|
+
self.intf.toggleGroupRows = self.toggleGroupRows;
|
|
1446
|
+
self.intf.getGroupsColumnBelongsTo = self.getGroupsColumnBelongsTo;
|
|
1447
|
+
self.intf.getGroupsRowBelongsTo = self.getGroupsRowBelongsTo;
|
|
875
1448
|
self.intf.isCellVisible = self.isCellVisible;
|
|
876
1449
|
self.intf.isRowVisible = self.isRowVisible;
|
|
877
1450
|
self.intf.isColumnVisible = self.isColumnVisible;
|
|
@@ -1001,6 +1574,13 @@ export default function (self, ctor) {
|
|
|
1001
1574
|
if (key === 'name') {
|
|
1002
1575
|
self.tryLoadStoredSettings();
|
|
1003
1576
|
}
|
|
1577
|
+
if (
|
|
1578
|
+
key === 'rowTree' ||
|
|
1579
|
+
key === 'columnTree' ||
|
|
1580
|
+
key === 'columnTreeRowEndIndex'
|
|
1581
|
+
) {
|
|
1582
|
+
self.initCellTreeSettings();
|
|
1583
|
+
}
|
|
1004
1584
|
self.draw(true);
|
|
1005
1585
|
self.dispatchEvent('attributechanged', {
|
|
1006
1586
|
name: key,
|
|
@@ -1614,6 +2194,7 @@ export default function (self, ctor) {
|
|
|
1614
2194
|
self.createRowOrders();
|
|
1615
2195
|
self.tryLoadStoredSettings();
|
|
1616
2196
|
self.dispatchEvent('datachanged', { data: self.originalData });
|
|
2197
|
+
self.initCellTreeSettings();
|
|
1617
2198
|
self.resize(true);
|
|
1618
2199
|
});
|
|
1619
2200
|
},
|