| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140 | 1×
1×
1×
1×
484×
484×
1×
408×
408×
408×
408×
408×
408×
408×
184×
1787×
184×
184×
192×
168×
184×
184×
184×
184×
1339×
408×
408×
166×
8×
158×
408×
8×
7×
8×
5×
408×
1×
1×
1×
408×
121×
408×
245×
245×
245×
245×
10×
408×
44×
44×
44×
408×
17×
408×
1×
18×
1×
37×
1×
19×
1×
19×
1×
94×
1×
18×
1×
74×
74×
18×
18×
18×
18×
18×
18×
18×
17×
137×
137×
17×
17×
17×
74×
1×
19×
8004×
18×
7986×
19×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-base", "../base/util", "../base/enum"], function (require, exports, ej2_base_1, util_1, enum_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var CellMergeRender = (function () {
function CellMergeRender(serviceLocator, parent) {
this.serviceLocator = serviceLocator;
this.parent = parent;
}
CellMergeRender.prototype.render = function (cellArgs, row, i, td) {
var cellRendererFact = this.serviceLocator.getService('cellRendererFactory');
var cellRenderer = cellRendererFact.getCellRenderer(row.cells[parseInt(i.toString(), 10)].cellType
|| enum_1.CellType.Data);
var colSpan = row.cells[parseInt(i.toString(), 10)].cellSpan ? row.cells[parseInt(i.toString(), 10)].cellSpan :
cellArgs.colSpan ? (cellArgs.colSpan + i) <= row.cells.length ? cellArgs.colSpan : row.cells.length - i : 1;
var rowSpan = cellArgs.rowSpan;
var visible = 0;
var spannedCell;
if (row.index > this.parent.pinnedTopRecords.length) {
var index = row.index - this.parent.pinnedTopRecords.length;
var rowsObject = this.parent.getRowsObject().filter(function (row) { return row.isDataRow; });
var prevRow = void 0;
if (this.parent.enableDomVirtualization) {
prevRow = rowsObject.filter(function (r) { return r.index === row.index - 1; })[0];
}
else {
prevRow = rowsObject[parseInt(index.toString(), 10) - 1];
}
Eif (prevRow) {
var cells = this.parent.groupSettings.columns.length > 0
&& !prevRow.isDataRow
? (rowsObject[this.parent.enableDomVirtualization
? rowsObject.indexOf(prevRow) + 1 : parseInt(index.toString(), 10)]
? rowsObject[this.parent.enableDomVirtualization
? rowsObject.indexOf(prevRow) + 1 : parseInt(index.toString(), 10)].cells
: prevRow.cells)
: prevRow.cells;
var targetCell_1 = row.cells[parseInt(i.toString(), 10)];
var uid_1 = 'uid';
spannedCell = cells.filter(function (cell) { return cell.column.uid === targetCell_1.column["" + uid_1]; })[0];
}
}
var colSpanLen = spannedCell && spannedCell.colSpanRange > 1 && spannedCell.rowSpanRange > 1 ?
spannedCell.colSpanRange : colSpan;
for (var j = i + 1; j < i + colSpanLen && j < row.cells.length; j++) {
if (row.cells[parseInt(j.toString(), 10)].visible === false) {
visible++;
}
else {
row.cells[parseInt(j.toString(), 10)].isSpanned = true;
}
}
if (visible > 0) {
for (var j = i + colSpan; j < i + colSpan + visible && j < row.cells.length; j++) {
row.cells[parseInt(j.toString(), 10)].isSpanned = true;
}
if (i + colSpan + visible >= row.cells.length) {
colSpan -= (i + colSpan + visible) - row.cells.length;
}
}
if (row.cells[parseInt(i.toString(), 10)].cellSpan) {
row.data[cellArgs.column.field] = row.cells[parseInt(i.toString(), 10)].spanText;
var index = row.index - this.parent.pinnedTopRecords.length;
td = cellRenderer.render(row.cells[parseInt(i.toString(), 10)], row.data, { 'index': !ej2_base_1.isNullOrUndefined(index) ? index.toString() : '' });
}
if (colSpan > 1) {
ej2_base_1.attributes(td, { 'colSpan': colSpan.toString(), 'aria-colSpan': colSpan.toString() });
}
if (rowSpan > 1) {
ej2_base_1.attributes(td, { 'rowspan': rowSpan.toString(), 'aria-rowspan': rowSpan.toString() });
row.cells[parseInt(i.toString(), 10)].isRowSpanned = true;
row.cells[parseInt(i.toString(), 10)].rowSpanRange = Number(rowSpan);
if (colSpan > 1) {
row.cells[parseInt(i.toString(), 10)].colSpanRange = Number(colSpan);
}
}
if (row.index > this.parent.pinnedTopRecords.length && spannedCell && (spannedCell.rowSpanRange > 1)) {
row.cells[parseInt(i.toString(), 10)].isSpanned = true;
row.cells[parseInt(i.toString(), 10)].rowSpanRange = Number(spannedCell.rowSpanRange - 1);
row.cells[parseInt(i.toString(), 10)].colSpanRange = spannedCell.rowSpanRange > 0 ? spannedCell.colSpanRange : 1;
}
if (this.parent.enableColumnVirtualization && !row.cells[parseInt(i.toString(), 10)].cellSpan &&
!this.containsKey(cellArgs.column.field, cellArgs.data[cellArgs.column.field])) {
this.backupMergeCells(cellArgs.column.field, cellArgs.data[cellArgs.column.field], cellArgs.colSpan);
}
return td;
};
CellMergeRender.prototype.backupMergeCells = function (fName, data, span) {
this.setMergeCells(this.generteKey(fName, data), span);
};
CellMergeRender.prototype.generteKey = function (fname, data) {
return fname + '__' + data.toString();
};
CellMergeRender.prototype.splitKey = function (key) {
return key.split('__');
};
CellMergeRender.prototype.containsKey = function (fname, data) {
return this.getMergeCells().hasOwnProperty(this.generteKey(fname, data));
};
CellMergeRender.prototype.getMergeCells = function () {
return this.parent.mergeCells;
};
CellMergeRender.prototype.setMergeCells = function (key, span) {
this.parent.mergeCells["" + key] = span;
};
CellMergeRender.prototype.updateVirtualCells = function (rows) {
var mCells = this.getMergeCells();
for (var _i = 0, _a = Object.keys(mCells); _i < _a.length; _i++) {
var key = _a[_i];
var value = mCells["" + key];
var merge = this.splitKey(key);
var columnIndex = this.getIndexFromAllColumns(merge[0]);
var vColumnIndices = this.parent.getColumnIndexesInView();
var span = value - (vColumnIndices[0] - columnIndex);
if (columnIndex < vColumnIndices[0] && span > 1) {
for (var _b = 0, rows_1 = rows; _b < rows_1.length; _b++) {
var row = rows_1[_b];
if (row.data[merge[0]].toString() === merge[1].toString()) {
row.cells[0].cellSpan = span;
row.cells[0].spanText = merge[1];
break;
}
}
}
}
return rows;
};
CellMergeRender.prototype.getIndexFromAllColumns = function (field) {
var index = util_1.iterateArrayOrObject(this.parent.getVisibleColumns(), function (item, index) {
if (item.field === field) {
return index;
}
return undefined;
})[0];
return index;
};
return CellMergeRender;
}());
exports.CellMergeRender = CellMergeRender;
});
|