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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348 | 1×
1×
1×
1×
626×
626×
626×
626×
1×
28821×
28821×
28821×
28821×
20552×
20552×
587×
587×
587×
17123×
28821×
245×
245×
8070×
243×
17×
17×
28819×
28819×
158×
28819×
28819×
6374×
22445×
2582×
28819×
623×
430×
28819×
28819×
28819×
859×
859×
859×
31×
28819×
72×
72×
72×
72×
28747×
1×
152781×
10×
152771×
152771×
152771×
152771×
152771×
152771×
152771×
152771×
152771×
152771×
152771×
115761×
37010×
152771×
152771×
152771×
152771×
152771×
28895×
28895×
28895×
43467×
43467×
28895×
28895×
8822×
8822×
28895×
9065×
9065×
9065×
9065×
9065×
6134×
2931×
9065×
9065×
9065×
9065×
9065×
9065×
19830×
19774×
19774×
19774×
28895×
28895×
96×
28895×
28895×
28895×
28895×
123876×
237×
152771×
152771×
135623×
135623×
135623×
17148×
17148×
17148×
17148×
673×
16475×
2517×
13958×
2551×
152771×
1734×
1734×
12×
12×
12×
12×
12×
12×
12×
152771×
795×
795×
795×
795×
158×
637×
9×
628×
152771×
152771×
152771×
152771×
152584×
187×
36×
36×
36×
36×
1×
28895×
28895×
28895×
28895×
28895×
175×
28895×
1058×
1058×
1058×
28895×
28895×
28895×
1058×
1058×
1058×
1058×
1058×
1058×
1058×
1058×
1058×
1058×
1058×
1058×
27837×
27837×
1×
1×
237×
1×
1×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-grids", "@syncfusion/ej2-grids", "@syncfusion/ej2-base", "../base/constant", "../utils"], function (require, exports, ej2_grids_1, ej2_grids_2, ej2_base_1, events, utils_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Render = (function () {
function Render(parent) {
this.parent = parent;
this.templateResult = null;
this.parent.grid.on('template-result', this.columnTemplateResult, this);
this.parent.grid.on('reactTemplateRender', this.reactTemplateRender, this);
}
Render.prototype.RowModifier = function (args) {
Iif (!args.data) {
return;
}
var data = args.data;
var parentData = data.parentItem;
if (!ej2_base_1.isNullOrUndefined(data.parentItem) && !utils_1.isFilterChildHierarchy(this.parent) &&
(!(this.parent.allowPaging && !(this.parent.pageSettings.pageSizeMode === 'Root')) ||
(utils_1.isRemoteData(this.parent) && !utils_1.isOffline(this.parent)))) {
var collapsed = (this.parent.initialRender && (!(ej2_base_1.isNullOrUndefined(parentData[this.parent.expandStateMapping]) ||
parentData[this.parent.expandStateMapping]) || this.parent.enableCollapseAll)) ||
!utils_1.getExpandStatus(this.parent, args.data, this.parent.grid.getCurrentViewRecords());
if (collapsed && !ej2_base_1.isNullOrUndefined(args.row)) {
this.parent['toggleRowVisibility'](args.row, 'e-childrow-hidden');
var rowsObj = this.parent.grid.getRowsObject();
Eif (!this.parent.grid.isFrozenGrid() && !ej2_base_1.isNullOrUndefined(args.row.getAttribute('data-uid'))) {
rowsObj.filter(function (e) { return e.uid === args.row.getAttribute('data-uid'); })[0].visible = false;
}
}
}
if (utils_1.isRemoteData(this.parent) && !utils_1.isOffline(this.parent)) {
var proxy_1 = this.parent;
var parentrec = this.parent.getCurrentViewRecords().filter(function (rec) {
return ej2_base_1.getValue(proxy_1.idMapping, rec) === ej2_base_1.getValue(proxy_1.parentIdMapping, data);
});
if (parentrec.length > 0 && !parentrec[0].isSummaryRow && !ej2_base_1.isNullOrUndefined(args.row)) {
var display = parentrec[0].expanded ? 'e-childrow-visible' : 'e-childrow-hidden';
this.parent['toggleRowVisibility'](args.row, display);
}
}
var summaryRow = ej2_grids_1.getObject('isSummaryRow', args.data);
if (summaryRow) {
ej2_base_1.addClass([args.row], 'e-summaryrow');
}
Eif (!ej2_base_1.isNullOrUndefined(args.row)) {
if (args.row.querySelector('.e-treegridexpand')) {
args.row.setAttribute('aria-expanded', 'true');
}
else if (args.row.querySelector('.e-treegridcollapse')) {
args.row.setAttribute('aria-expanded', 'false');
}
if (this.parent.enableCollapseAll && this.parent.initialRender) {
if (!ej2_base_1.isNullOrUndefined(data.parentItem)) {
this.parent['toggleRowVisibility'](args.row, 'e-childrow-hidden');
}
}
}
var dragStartData = 'dragStartData';
var draggedRecord = 'draggedRecord';
if (this.parent.rowDragAndDropModule && this.parent.grid.rowDragAndDropModule && (this.parent.grid.rowDragAndDropModule["" + dragStartData] ||
this.parent.rowDragAndDropModule["" + draggedRecord]) && this.parent.getContentTable().scrollHeight <= this.parent.getContent().clientHeight) {
var lastRowBorder = 'lastRowBorder';
var lastVisualData = this.parent.getVisibleRecords()[this.parent.getVisibleRecords().length - 1];
if (lastVisualData.uniqueID === args.data.uniqueID && !ej2_base_1.isNullOrUndefined(args.row) && !args.row.cells[0].classList.contains('e-lastrowcell')) {
this.parent["" + lastRowBorder](args.row, true);
}
}
if (this.parent.isReact) {
var renderReactTemplates = 'renderReactTemplates';
var thisRef_1 = this;
thisRef_1.parent["" + renderReactTemplates](function () {
thisRef_1.parent.trigger(events.rowDataBound, args);
});
}
else {
this.parent.trigger(events.rowDataBound, args);
}
};
Render.prototype.cellRender = function (args) {
if (!args.data) {
return;
}
var grid = this.parent.grid;
var data = args.data;
var index;
var ispadfilter = ej2_base_1.isNullOrUndefined(data.filterLevel);
var pad = ispadfilter ? data.level : data.filterLevel;
var totalIconsWidth = 0;
var cellElement;
var column = this.parent.getColumnByUid(args.column.uid);
var summaryRow = data.isSummaryRow;
var frozenColumns = this.parent.getFrozenColumns();
if (!ej2_base_1.isNullOrUndefined(data.parentItem)) {
index = data.parentItem.index;
}
else {
index = data.index;
}
var columnIndex;
var getVirtualColIndexByUid = 'getVirtualColIndexByUid';
Iif (this.parent.enableColumnVirtualization && !this.parent.initialRender) {
columnIndex = this.parent["" + getVirtualColIndexByUid](args.column.uid);
}
else {
columnIndex = grid.getColumnIndexByUid(args.column.uid);
}
if (columnIndex === this.parent.treeColumnIndex && (args.requestType === 'add' || args.requestType
=== 'rowDragAndDrop' || args.requestType === 'delete' || ej2_base_1.isNullOrUndefined(args.cell.querySelector('.e-treecell')))) {
var container = ej2_base_1.createElement('div', { className: 'e-treecolumn-container' });
var emptyExpandIcon = ej2_base_1.createElement('span', {
className: 'e-icons e-none',
styles: 'width: 10px; display: inline-block'
});
for (var n = 0; n < pad; n++) {
totalIconsWidth += 10;
container.appendChild(emptyExpandIcon.cloneNode());
}
var iconRequired = !ej2_base_1.isNullOrUndefined(data.hasFilteredChildRecords)
? data.hasFilteredChildRecords : data.hasChildRecords;
if (iconRequired && !ej2_base_1.isNullOrUndefined(data.childRecords)) {
Iif (this.parent['isFromGantt'] && this.parent.loadChildOnDemand) {
iconRequired = data.hasChildRecords;
}
else {
iconRequired = !(data.childRecords.length === 0);
}
}
if (iconRequired) {
ej2_base_1.addClass([args.cell], 'e-treerowcell');
args.cell.setAttribute('aria-expanded', data.expanded ? 'true' : 'false');
var expandIcon = ej2_base_1.createElement('span', { className: 'e-icons' });
var expand = void 0;
if (this.parent.initialRender) {
expand = data.expanded &&
(ej2_base_1.isNullOrUndefined(data[this.parent.expandStateMapping]) || data[this.parent.expandStateMapping]) &&
!this.parent.enableCollapseAll;
}
else {
expand = !(!data.expanded || !utils_1.getExpandStatus(this.parent, data, this.parent.grid.getCurrentViewRecords()));
}
ej2_base_1.addClass([expandIcon], (expand) ? 'e-treegridexpand' : 'e-treegridcollapse');
totalIconsWidth += 18;
container.appendChild(expandIcon);
emptyExpandIcon.style.width = '4px';
totalIconsWidth += 7;
container.appendChild(emptyExpandIcon.cloneNode());
}
else if (pad || !pad && !data.level) {
totalIconsWidth += 20;
container.appendChild(emptyExpandIcon.cloneNode());
container.appendChild(emptyExpandIcon.cloneNode());
}
cellElement = ej2_base_1.createElement('span', { className: 'e-treecell' });
if (this.parent.allowTextWrap) {
cellElement.style.width = 'Calc(100% - ' + totalIconsWidth + 'px)';
}
ej2_base_1.addClass([args.cell], 'e-gridrowindex' + index + 'level' + data.level);
this.updateTreeCell(args, cellElement);
container.appendChild(cellElement);
args.cell.appendChild(container);
}
else if (this.templateResult) {
this.templateResult = null;
}
var freeze = (grid.getFrozenLeftColumnsCount() > 0 || grid.getFrozenRightColumnsCount() > 0) ? true : false;
if (!freeze) {
Iif (frozenColumns > this.parent.treeColumnIndex && frozenColumns > 0 &&
grid.getColumnIndexByUid(args.column.uid) === frozenColumns) {
ej2_base_1.addClass([args.cell], 'e-gridrowindex' + index + 'level' + data.level);
}
else Iif (frozenColumns < this.parent.treeColumnIndex && frozenColumns > 0 &&
(grid.getColumnIndexByUid(args.column.uid) === frozenColumns
|| grid.getColumnIndexByUid(args.column.uid) === frozenColumns - 1)) {
ej2_base_1.addClass([args.cell], 'e-gridrowindex' + index + 'level' + data.level);
}
else Iif (frozenColumns === this.parent.treeColumnIndex && frozenColumns > 0 &&
grid.getColumnIndexByUid(args.column.uid) === this.parent.treeColumnIndex - 1) {
ej2_base_1.addClass([args.cell], 'e-gridrowindex' + index + 'level' + data.level);
}
}
else {
var freezerightColumns = grid.getFrozenRightColumns();
var freezeLeftColumns = grid.getFrozenLeftColumns();
var movableColumns = grid.getMovableColumns();
if ((freezerightColumns.length > 0) && freezerightColumns[0].field === args.column.field) {
ej2_base_1.addClass([args.cell], 'e-gridrowindex' + index + 'level' + data.level);
}
else if ((freezeLeftColumns.length > 0) && freezeLeftColumns[0].field === args.column.field) {
ej2_base_1.addClass([args.cell], 'e-gridrowindex' + index + 'level' + data.level);
}
else if ((movableColumns.length > 0) && movableColumns[0].field === args.column.field) {
ej2_base_1.addClass([args.cell], 'e-gridrowindex' + index + 'level' + data.level);
}
}
if (!ej2_base_1.isNullOrUndefined(column) && column.showCheckbox) {
this.parent.notify('columnCheckbox', args);
if (this.parent.allowTextWrap) {
var checkboxElement = args.cell.querySelectorAll('.e-frame')[0];
var width = parseInt(checkboxElement.style.width, 16);
totalIconsWidth += width;
totalIconsWidth += 10;
Eif (grid.getColumnIndexByUid(args.column.uid) === this.parent.treeColumnIndex) {
cellElement = args.cell.querySelector('.e-treecell');
}
else {
cellElement = args.cell.querySelector('.e-treecheckbox');
}
cellElement.style.width = 'Calc(100% - ' + totalIconsWidth + 'px)';
}
}
if (summaryRow) {
ej2_base_1.addClass([args.cell], 'e-summarycell');
var summaryData = ej2_grids_1.getObject(args.column.field, args.data);
summaryData = ej2_base_1.isNullOrUndefined(summaryData) ? null : summaryData;
if (args.cell.querySelector('.e-treecell') != null) {
args.cell.querySelector('.e-treecell').innerHTML = summaryData;
}
else {
if (args.column.template) {
args.cell.innerHTML = null;
}
else {
args.cell.innerHTML = summaryData;
}
}
}
this.parent['args'] = args;
var columnModel = ej2_base_1.getValue('columnModel', this.parent);
var treeColumn = columnModel[this.parent.treeColumnIndex];
if ((ej2_base_1.isNullOrUndefined(this.parent.rowTemplate) && !(this.parent.isReact))
|| ((this.parent.isReact) &&
!args.column['template'])) {
this.parent.trigger(events.queryCellInfo, args);
}
else if (((this.parent.isReact) &&
treeColumn.field !== args.column.field)) {
var renderReactTemplates = 'renderReactTemplates';
var thisRef_2 = this;
thisRef_2.parent["" + renderReactTemplates](function () {
thisRef_2.parent.trigger(events.queryCellInfo, args);
});
}
};
Render.prototype.updateTreeCell = function (args, cellElement) {
var columnModel = ej2_base_1.getValue('columnModel', this.parent);
var treeColumn = columnModel[this.parent.treeColumnIndex];
var templateFn = 'templateFn';
var colindex = args.column.index;
if (ej2_base_1.isNullOrUndefined(treeColumn.field)) {
args.cell.setAttribute('data-colindex', colindex + '');
}
if (treeColumn.field === args.column.field && !ej2_base_1.isNullOrUndefined(treeColumn.template)) {
args.column.template = treeColumn.template;
args.column["" + templateFn] = ej2_grids_2.templateCompiler(args.column.template);
args.cell.classList.add('e-templatecell');
}
var textContent = args.cell.querySelector('.e-treecell') != null ?
args.cell.querySelector('.e-treecell').innerHTML : args.cell.innerHTML;
Iif (typeof (args.column.template) === 'object' && this.templateResult) {
ej2_grids_1.appendChildren(cellElement, this.templateResult);
this.templateResult = null;
args.cell.innerHTML = '';
}
else if (args.cell.classList.contains('e-templatecell')) {
var len = args.cell.children.length;
var tempID = this.parent.element.id + args.column.uid;
Eif (treeColumn.field === args.column.field && !ej2_base_1.isNullOrUndefined(treeColumn.template)) {
var portals = 'portals';
var renderReactTemplates = 'renderReactTemplates';
Iif (this.parent.isReact && typeof (args.column.template) !== 'string') {
args.column["" + templateFn](args.data, this.parent, 'columnTemplate', tempID, null, null, cellElement);
if (ej2_base_1.isNullOrUndefined(this.parent.grid["" + portals])) {
this.parent.grid["" + portals] = this.parent["" + portals];
}
this.parent.notify('renderReactTemplate', this.parent["" + portals]);
var thisRef_3 = this;
thisRef_3.parent["" + renderReactTemplates](function () {
thisRef_3.parent.trigger(events.queryCellInfo, args);
});
}
else {
var str = 'isStringTemplate';
var result = args.column["" + templateFn](ej2_grids_2.extend({ 'index': '' }, args.data), this.parent, 'template', tempID, this.parent["" + str]);
ej2_grids_1.appendChildren(cellElement, result);
}
delete args.column.template;
delete args.column["" + templateFn];
args.cell.innerHTML = '';
}
else {
for (var i = 0; i < len; len = args.cell.children.length) {
cellElement.appendChild(args.cell.children[parseInt(i.toString(), 10)]);
}
}
}
else {
cellElement.innerHTML = textContent;
args.cell.innerHTML = '';
}
};
Render.prototype.refreshReactColumnTemplateByUid = function (columnUid) {
var _this = this;
if (this.parent.isReact) {
this.parent.clearTemplate(['columnTemplate'], undefined, function () {
var cells = 'cells';
var rowIdx = 'index';
var rowsObj = _this.parent.grid.getRowsObject();
var rows = _this.parent.getDataRows();
var indent = _this.parent.grid.getIndentCount();
var cellIndex = _this.parent.grid.getNormalizedColumnIndex(columnUid);
if (rows.length !== 0) {
for (var j = 0; j < rowsObj.length; j++) {
if (rowsObj[parseInt(j.toString(), 10)].isDataRow
&& !ej2_base_1.isNullOrUndefined(rowsObj[parseInt(j.toString(), 10)].index)) {
var cell = rowsObj[parseInt(j.toString(), 10)]["" + cells][parseInt(cellIndex.toString(), 10)];
var cellRenderer = new ej2_grids_2.CellRenderer(_this.parent.grid, _this.parent.grid.serviceLocator);
var td = rows.length >= rowsObj.length
? _this.parent.getCellFromIndex(rowsObj[parseInt(j.toString(), 10)].index, cellIndex - indent)
: rows[rowsObj[parseInt(j.toString(), 10)].index].querySelector('.e-templatecell');
cellRenderer.refreshTD(td, cell, rowsObj[parseInt(j.toString(), 10)].data, { index: rowsObj[parseInt(j.toString(), 10)]["" + rowIdx] });
var treecell = _this.parent.getRows()[parseInt(j.toString(), 10)]
.cells[parseInt(cellIndex.toString(), 10)];
_this.cellRender({ data: rowsObj[parseInt(j.toString(), 10)].data, cell: treecell, column: cell.column });
}
}
}
});
}
};
Render.prototype.columnTemplateResult = function (args) {
this.templateResult = args.template;
};
Render.prototype.reactTemplateRender = function (args, callBack) {
var renderReactTemplates = 'renderReactTemplates';
var portals = 'portals';
this.parent["" + portals] = args;
this.parent.notify('renderReactTemplate', this.parent["" + portals]);
this.parent["" + renderReactTemplates](callBack);
};
Render.prototype.destroy = function () {
this.parent.grid.off('template-result', this.columnTemplateResult);
this.parent.grid.off('reactTemplateRender', this.reactTemplateRender);
};
return Render;
}());
exports.Render = Render;
});
|