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 | 1×
1×
1×
1×
11×
11×
11×
1×
11279×
1×
11×
11×
11×
11×
11×
11×
1×
17×
11×
6×
6×
6×
6×
6×
6×
1×
1×
14×
2×
2×
2×
2×
1×
21×
21×
21×
21×
21×
21×
1×
141×
21×
21×
21×
21×
21×
21×
21×
21×
21×
21×
21×
21×
21×
2×
2×
2×
19×
6×
6×
13×
21×
21×
5×
16×
21×
1×
7×
7×
7×
7×
1×
4×
1×
3×
3×
3×
3×
3×
3×
3×
1×
1×
1×
1×
4×
4×
4×
8×
1090×
4×
4×
4×
4×
4×
4×
4×
8×
1×
7×
7×
7×
7×
7×
7×
7×
7×
7×
7×
7×
7×
7×
7×
7×
11×
11×
5×
3×
3×
3×
3×
1×
3×
2×
1×
1×
6×
6×
7×
1×
17×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-grids", "@syncfusion/ej2-grids", "@syncfusion/ej2-base", "../base/constant", "@syncfusion/ej2-data", "../utils"], function (require, exports, ej2_grids_1, ej2_grids_2, ej2_base_1, events, ej2_data_1, utils_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var InfiniteScroll = (function () {
function InfiniteScroll(parent) {
this.parent = parent;
ej2_grids_1.Grid.Inject(ej2_grids_1.InfiniteScroll);
this.addEventListener();
}
InfiniteScroll.prototype.getModuleName = function () {
return 'infiniteScroll';
};
InfiniteScroll.prototype.addEventListener = function () {
this.parent.on(events.pagingActions, this.infinitePageAction, this);
this.parent.on('infinite-remote-expand', this.infiniteRemoteExpand, this);
this.parent.grid.on('delete-complete', this.infiniteDeleteHandler, this);
this.parent.grid.on('infinite-edit-handler', this.infiniteEditHandler, this);
this.parent.grid.on('infinite-crud-cancel', this.createRows, this);
this.parent.grid.on('content-ready', this.contentready, this);
};
InfiniteScroll.prototype.removeEventListener = function () {
if (this.parent.isDestroyed) {
return;
}
this.parent.off('infinite-remote-expand', this.infiniteRemoteExpand);
this.parent.grid.off('delete-complete', this.infiniteDeleteHandler);
this.parent.grid.off('infinite-edit-handler', this.infiniteEditHandler);
this.parent.off(events.pagingActions, this.infinitePageAction);
this.parent.grid.off('infinite-crud-cancel', this.createRows);
this.parent.grid.off('content-ready', this.contentready);
};
InfiniteScroll.prototype.infiniteRemoteExpand = function (args) {
var rowObjects = this.parent.grid.getRowsObject();
var locator = 'serviceLocator';
var generateRows = 'generateRows';
var serviceLocator = this.parent.grid.infiniteScrollModule["" + locator];
var rowRenderer = new ej2_grids_2.RowRenderer(serviceLocator, null, this.parent.grid);
var rows = this.parent.getRows();
var position = args.index === rows.length - 1 ? 'after' : 'before';
var cols = this.parent.grid.getColumns();
var childRowObjects = this.parent.grid.infiniteScrollModule["" + generateRows](args.childData, args);
var childRowElements = [];
for (var i = 0; i < childRowObjects.length; i++) {
childRowElements.push(rowRenderer.render(childRowObjects[parseInt(i.toString(), 10)], cols));
}
rowObjects.splice.apply(rowObjects, [args.index + 1, 0].concat(childRowObjects));
for (var i = 0; i < childRowElements.length; i++) {
if (position === 'after') {
rows[args.index + i]["" + position](childRowElements[parseInt(i.toString(), 10)]);
}
else {
rows[args.index + i + 1]["" + position](childRowElements[parseInt(i.toString(), 10)]);
}
rows.splice(args.index + 1 + i, 0, childRowElements[parseInt(i.toString(), 10)]);
}
ej2_grids_2.resetRowIndex(this.parent.grid, this.parent.grid.getRowsObject(), this.parent.grid.getRows(), 0);
};
InfiniteScroll.prototype.contentready = function () {
if (this.parent.infiniteScrollSettings.enableCache && !ej2_base_1.isNullOrUndefined(this.parent.editModule)) {
var updateIndex = 'updateIndex';
this.parent.editModule["" + updateIndex](this.parent.grid.dataSource, this.parent.getRows(), this.parent.getCurrentViewRecords());
Eif (this.parent.getFrozenColumns()) {
this.parent.editModule["" + updateIndex](this.parent.grid.dataSource, this.parent.getDataRows(), this.parent.getCurrentViewRecords());
}
}
};
InfiniteScroll.prototype.infinitePageAction = function (pageingDetails) {
var dm = new ej2_data_1.DataManager(pageingDetails.result);
var expanded = new ej2_data_1.Predicate('expanded', 'notequal', null).or('expanded', 'notequal', undefined);
var visualData = dm.executeLocal(new ej2_data_1.Query().where(expanded));
var actionArgs = ej2_base_1.getValue('actionArgs', pageingDetails.actionArgs);
var actions = ej2_base_1.getValue('actions', this.parent.grid.infiniteScrollModule);
if (this.parent.grid.infiniteScrollModule['isInitialRender'] && !this.parent.initialRender) {
this.parent.grid.pageSettings.currentPage = 1;
}
var initial = actions.some(function (value) { return value === actionArgs.requestType; });
var initialRender = initial ? true : this.parent.initialRender ? true : false;
this.visualData = visualData;
pageingDetails.count = visualData.length;
Iif (ej2_base_1.getValue('isPrinting', pageingDetails.actionArgs)) {
pageingDetails.result = visualData;
}
else {
var query = new ej2_data_1.Query();
var isCache = this.parent.infiniteScrollSettings.enableCache;
Iif (isCache && this.parent.infiniteScrollSettings.initialBlocks > this.parent.infiniteScrollSettings.maxBlocks) {
this.parent.infiniteScrollSettings.initialBlocks = this.parent.infiniteScrollSettings.maxBlocks;
}
var size = initialRender ?
this.parent.grid.pageSettings.pageSize * this.parent.infiniteScrollSettings.initialBlocks :
this.parent.grid.pageSettings.pageSize;
var current = this.parent.grid.pageSettings.currentPage;
Eif (!ej2_base_1.isNullOrUndefined(actionArgs)) {
var lastIndex = ej2_base_1.getValue('lastIndex', this.parent.grid.infiniteScrollModule);
var firstIndex = ej2_base_1.getValue('firstIndex', this.parent.grid.infiniteScrollModule);
if (!isCache && actionArgs.requestType === 'delete') {
var skip = lastIndex - actionArgs.data.length + 1;
var take = actionArgs.data.length;
query = query.skip(skip).take(take);
}
else if (isCache && actionArgs.requestType === 'delete' ||
(actionArgs.requestType === 'save' && actionArgs.action === 'add')) {
query = query.skip(firstIndex);
query = query.take(this.parent.infiniteScrollSettings.initialBlocks * this.parent.pageSettings.pageSize);
}
else {
query = query.page(current, size);
}
}
else {
query = query.page(current, size);
}
dm.dataSource.json = visualData;
if (!isCache && !ej2_base_1.isNullOrUndefined(actionArgs) && actionArgs.requestType === 'save' && actionArgs.action === 'add') {
pageingDetails.result = [actionArgs.data];
}
else {
pageingDetails.result = dm.executeLocal(query);
}
}
this.parent.notify('updateAction', pageingDetails);
};
InfiniteScroll.prototype.infiniteEditHandler = function (args) {
var infiniteData = 'infiniteCurrentViewData';
var infiniteCurrentViewData = this.parent.grid.infiniteScrollModule["" + infiniteData];
var keys = Object.keys(infiniteCurrentViewData);
if (args.e.requestType === 'delete' && args.result.length > 1) {
for (var i = 1; i < args.result.length; i++) {
infiniteCurrentViewData[keys[keys.length - 1]].push(args.result[parseInt(i.toString(), 10)]);
}
}
};
InfiniteScroll.prototype.infiniteDeleteHandler = function (args) {
Eif (args.requestType === 'delete') {
var rows = this.parent.grid.getRowsObject();
var rowElms = this.parent.getRows();
var data = args.data instanceof Array ? args.data : [args.data];
var keyField = this.parent.grid.getPrimaryKeyFieldNames()[0];
this.removeRows(rowElms, rows, data, keyField, true);
if (this.parent.getFrozenColumns() > 0) {
var mRows = this.parent.grid.getRowsObject();
var mRowElms = this.parent.grid.getRows();
this.removeRows(mRowElms, mRows, data, keyField);
}
}
};
InfiniteScroll.prototype.removeRows = function (rowElms, rows, data, keyField, isFrozen) {
var _this = this;
var resetInfiniteCurrentViewData = 'resetInfiniteCurrentViewData';
var _loop_1 = function (i) {
rows.filter(function (e, index) {
if (e.data["" + keyField] === data[parseInt(i.toString(), 10)]["" + keyField]) {
Eif (isFrozen) {
var page = Math.ceil((index + 1) / _this.parent.grid.pageSettings.pageSize);
_this.parent.grid.infiniteScrollModule["" + resetInfiniteCurrentViewData](page, index);
}
rows.splice(index, 1);
ej2_base_1.remove(rowElms[parseInt(index.toString(), 10)]);
rowElms.splice(index, 1);
}
});
};
for (var i = 0; i < data.length; i++) {
_loop_1(i);
}
};
InfiniteScroll.prototype.createRows = function (eventArgs) {
var locator = 'serviceLocator';
var actionArgs = eventArgs.args.e;
var row = eventArgs.row;
var serviceLocator = this.parent.grid.infiniteScrollModule["" + locator];
var rowRenderer = new ej2_grids_2.RowRenderer(serviceLocator, null, this.parent.grid);
var tbody;
var currentData = this.parent.getCurrentViewRecords();
var currentRows = eventArgs.isMovable ? this.parent.grid.getRows()
: this.parent.grid.getDataRows();
Iif (eventArgs.isFrozenRight) {
tbody = this.parent.element.querySelector('.e-frozen-right-content').querySelector('tbody');
}
else {
tbody = !this.parent.grid.isFrozenGrid() ? this.parent.getContent().querySelector('tbody') : eventArgs.isMovable
? this.parent.grid.getContent().querySelector('tbody')
: this.parent.grid.getContent().querySelector('tbody');
}
Iif (this.parent.frozenRows) {
tbody = eventArgs.isFrozenRows && this.parent.grid.infiniteScrollModule.requestType !== 'add'
|| !eventArgs.isFrozenRows && this.parent.grid.infiniteScrollModule.requestType === 'add'
? !this.parent.grid.isFrozenGrid() ? this.parent.getHeaderContent().querySelector('tbody')
: eventArgs.isMovable ? this.parent.grid.getHeaderContent().querySelector('tbody')
: eventArgs.isFrozenRight ? this.parent.element.querySelector('.e-frozen-right-header').querySelector('tbody')
: this.parent.grid.getHeaderContent().querySelector('tbody') : tbody;
}
var position;
var addRowIndex = 'addRowIndex';
var newRowIndex = this.parent.editModule["" + addRowIndex];
for (var i = 0; i < row.length; i++) {
var newRow = rowRenderer.render(row[parseInt(i.toString(), 10)], this.parent.grid.getColumns());
if (actionArgs.requestType === 'save' && actionArgs.action === 'add') {
if (ej2_base_1.getValue('selectedIndex', this.parent.editModule) !== -1 && this.parent.editSettings.newRowPosition !== 'Top') {
Eif (this.parent.editSettings.newRowPosition === 'Below' || this.parent.editSettings.newRowPosition === 'Child') {
position = 'after';
newRowIndex += utils_1.findChildrenRecords(currentData[parseInt(newRowIndex.toString(), 10)]).length;
if (this.parent.editSettings.newRowPosition === 'Child') {
newRowIndex -= 1;
}
currentRows[parseInt(newRowIndex.toString(), 10)]["" + position](newRow);
}
else if (this.parent.editSettings.newRowPosition === 'Above') {
position = 'before';
currentRows[this.parent.editModule["" + addRowIndex]]["" + position](newRow);
}
}
else if (this.parent.editSettings.newRowPosition === 'Bottom') {
tbody.appendChild(newRow);
}
else {
tbody.insertBefore(newRow, tbody.firstElementChild);
}
}
else Eif (actionArgs.requestType === 'delete') {
tbody.appendChild(newRow);
}
}
eventArgs.cancel = true;
};
InfiniteScroll.prototype.destroy = function () {
this.removeEventListener();
};
return InfiniteScroll;
}());
exports.InfiniteScroll = InfiniteScroll;
});
|