| 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 | 1×
1×
1×
1×
4405×
1×
2456×
126×
2330×
2330×
2330×
2330×
7×
2330×
9×
2330×
40695×
2330×
1×
126×
30×
126×
126×
126×
126×
126×
9×
9×
9×
450×
9×
9×
9×
117×
1919×
1919×
1919×
265×
1654×
1654×
1654×
1654×
126×
1×
10×
10×
10×
25×
25×
2×
2×
10×
1×
25×
25×
25×
25×
1×
52384×
52384×
907×
907×
907×
52384×
515×
52384×
1×
52384×
52384×
52384×
52384×
52384×
52384×
52384×
52384×
52384×
52384×
52384×
10014×
52384×
368×
14×
354×
2×
52384×
52384×
52384×
52384×
52384×
52384×
52384×
52384×
25×
52384×
52384×
52384×
1×
53075×
53075×
1005×
1×
53158×
53158×
53158×
252418×
53158×
1×
287922×
287919×
266445×
287919×
1×
27×
691×
691×
27×
1×
139×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-base", "../models/row", "../base/enum", "../models/cell", "../base/util", "../../grid/base/util", "../base/constant"], function (require, exports, ej2_base_1, row_1, enum_1, cell_1, util_1, util_2, events) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var RowModelGenerator = (function () {
function RowModelGenerator(parent) {
this.parent = parent;
}
RowModelGenerator.prototype.generateRows = function (data, args) {
if (this.parent.isRowDomVirtualization() && args) {
return this.generateDomVirtualRows(data, args);
}
var rows = [];
var startIndex = this.parent.enableVirtualization && args
? args.startIndex : 0;
startIndex = this.parent.enableInfiniteScrolling && args ? this.getInfiniteIndex(args) : startIndex;
if (this.parent.enableImmutableMode && args && args.startIndex) {
startIndex = args.startIndex;
}
if (!this.parent.enableVirtualization && this.parent.pinnedTopRowModels.length && args && args.requestType !== 'infiniteScroll') {
startIndex = this.parent.pinnedTopRowModels.length;
}
for (var i = 0, len = Object.keys(data).length; i < len; i++, startIndex++) {
rows[parseInt(i.toString(), 10)] = this.generateRow(data[parseInt(i.toString(), 10)], startIndex);
}
return rows;
};
RowModelGenerator.prototype.generateDomVirtualRows = function (data, args) {
if (args.requestType && this.parent.domVirtualClearActions.indexOf(args.requestType) !== -1) {
this.parent.clearDomVirtualRowCache();
}
var rows = [];
var dataLength = Object.keys(data).length;
var startIndex = args.startIndex || 0;
var endIndex = args.endIndex !== undefined ? args.endIndex : dataLength;
if (this.parent.enableVirtualization) {
var pageSize = this.parent.pageSettings.pageSize;
var pageOffset = (this.parent.pageSettings.currentPage - 1) * pageSize;
for (var r = pageOffset; r < pageOffset + dataLength; r++) {
this.parent.domRowObj.delete(r);
}
var loopStart = Math.max(startIndex, pageOffset);
var loopEnd = Math.min(endIndex, pageOffset + dataLength);
for (var i = loopStart; i < loopEnd; i++) {
var dataItem = data[parseInt((i - pageOffset).toString(), 10)];
var row = this.generateRow(dataItem, i);
this.parent.notify(events.applyDomVirtualRowHeight, { row: row });
this.parent.domRowObj.set(i, row);
rows.push(row);
}
}
else {
for (var i = startIndex; i < Math.min(endIndex, dataLength); i++) {
var dataItem = data[parseInt(i.toString(), 10)];
var cached = this.parent.domRowObj.get(i);
if (cached) {
rows.push(cached);
}
else {
var row = this.generateRow(dataItem, i);
this.parent.notify(events.applyDomVirtualRowHeight, { row: row });
this.parent.domRowObj.set(i, row);
rows.push(row);
}
}
}
return rows;
};
RowModelGenerator.prototype.generatePinnedTopRows = function (data) {
var rows = [];
var startIndex = 0;
for (var i = 0, len = Object.keys(data).length; i < len; i++, startIndex++) {
rows[parseInt(i.toString(), 10)] = this.generateRow(data[parseInt(i.toString(), 10)], startIndex);
for (var j = 0; j < this.parent.groupSettings.columns.length; j++) {
Iif (this.parent.enableColumnVirtualization) {
continue;
}
else {
rows[parseInt(i.toString(), 10)].cells.unshift(this.generateCell({}, null, enum_1.CellType.HeaderIndent));
}
}
}
return rows;
};
RowModelGenerator.prototype.ensurePinnedColumns = function () {
var cols = [];
Iif (this.parent.detailTemplate || this.parent.childGrid) {
cols.push(this.generateCell({}, null, enum_1.CellType.HeaderIndent));
}
Iif (this.parent.isRowDragable()) {
cols.push(this.generateCell({}, null, enum_1.CellType.HeaderIndent));
}
return cols;
};
RowModelGenerator.prototype.ensureColumns = function () {
var cols = [];
if (this.parent.detailTemplate || this.parent.childGrid) {
var args = {};
this.parent.notify(events.detailIndentCellInfo, args);
cols.push(this.generateCell(args, null, enum_1.CellType.DetailExpand));
}
if (this.parent.isRowDragable()) {
cols.push(this.generateCell({}, null, enum_1.CellType.RowDragIcon));
}
return cols;
};
RowModelGenerator.prototype.generateRow = function (data, index, cssClass, indent, pid, tIndex, parentUid, groupDataIndex) {
var options = {};
options.foreignKeyData = {};
options.uid = util_1.getUid('grid-row');
options.data = data;
options.index = index;
options.indent = indent;
options.tIndex = tIndex;
options.isDataRow = true;
options.parentGid = pid;
options.parentUid = parentUid;
if (this.parent.allowGrouping && this.parent.groupSettings.columns.length) {
options.groupDataIndex = groupDataIndex;
}
if (this.parent.isPrinting) {
if (this.parent.hierarchyPrintMode === 'All') {
options.isExpand = true;
}
else if (this.parent.hierarchyPrintMode === 'Expanded' && this.parent.expandedRows && this.parent.expandedRows[parseInt(index.toString(), 10)]) {
options.isExpand = this.parent.expandedRows[parseInt(index.toString(), 10)].isExpand;
}
}
options.cssClass = cssClass;
options.isAltRow = this.parent.enableAltRow ? index % 2 !== 0 : false;
options.isAltRow = this.parent.enableAltRow ? index % 2 !== 0 : false;
var primaryKey = this.parent.getPrimaryKeyFieldNames()[0];
options.isSelected = this.parent.isPersistSelection && this.parent.groupSettings.columns.length &&
this.parent.groupSettings.enableLazyLoading ?
!ej2_base_1.isNullOrUndefined(this.parent.selectionModule.selectedRowState[data["" + primaryKey]]) :
this.parent.getSelectedRowIndexes().indexOf(index) > -1;
this.refreshForeignKeyRow(options);
var cells = this.ensureColumns();
if (this.parent.pinnedTopRecords.length && index < this.parent.pinnedTopRecords.length) {
cells = this.ensurePinnedColumns();
}
var row = new row_1.Row(options, this.parent);
row.cells = this.parent.getFrozenMode() === 'Right' ? this.generateCells(options).concat(cells)
: cells.concat(this.generateCells(options));
return row;
};
RowModelGenerator.prototype.refreshForeignKeyRow = function (options) {
var foreignKeyColumns = this.parent.getForeignKeyColumns();
for (var i = 0; i < foreignKeyColumns.length; i++) {
ej2_base_1.setValue(foreignKeyColumns[parseInt(i.toString(), 10)].field, util_2.getForeignData(foreignKeyColumns[parseInt(i.toString(), 10)], options.data), options.foreignKeyData);
}
};
RowModelGenerator.prototype.generateCells = function (options) {
var dummies = this.parent.getColumns();
var tmp = [];
for (var i = 0; i < dummies.length; i++) {
tmp.push(this.generateCell(dummies[parseInt(i.toString(), 10)], options.uid, ej2_base_1.isNullOrUndefined(dummies[parseInt(i.toString(), 10)].commands) ? undefined : enum_1.CellType.CommandColumn, null, i, options.foreignKeyData));
}
return tmp;
};
RowModelGenerator.prototype.generateCell = function (column, rowId, cellType, colSpan, oIndex, foreignKeyData) {
var opt = {
'visible': column.visible,
'isDataCell': !ej2_base_1.isNullOrUndefined(column.field || column.template),
'isTemplate': !ej2_base_1.isNullOrUndefined(column.template),
'rowID': rowId,
'column': column,
'cellType': !ej2_base_1.isNullOrUndefined(cellType) ? cellType : enum_1.CellType.Data,
'colSpan': colSpan,
'commands': column.commands,
'isForeignKey': column.isForeignColumn && column.isForeignColumn(),
'foreignKeyData': column.isForeignColumn && column.isForeignColumn() && ej2_base_1.getValue(column.field, foreignKeyData)
};
if (opt.isDataCell || opt.column.type === 'checkbox' || opt.commands) {
opt.index = oIndex;
}
return new cell_1.Cell(opt);
};
RowModelGenerator.prototype.refreshRows = function (input) {
for (var i = 0; i < input.length; i++) {
this.refreshForeignKeyRow(input[parseInt(i.toString(), 10)]);
input[parseInt(i.toString(), 10)].cells = this.generateCells(input[parseInt(i.toString(), 10)]);
}
return input;
};
RowModelGenerator.prototype.getInfiniteIndex = function (args) {
return args.requestType === 'infiniteScroll' || args.requestType === 'delete' || args.action === 'add'
? (ej2_base_1.isNullOrUndefined(args.startIndex) ? args['index'] : args.startIndex) : 0;
};
return RowModelGenerator;
}());
exports.RowModelGenerator = RowModelGenerator;
});
|