| 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 | 1×
1×
1×
1×
26×
26×
26×
26×
26×
1×
14647×
1×
26×
26×
26×
26×
26×
1×
25×
1×
25×
25×
1×
4830×
1×
9×
9×
9×
9×
9×
9×
9×
4×
9×
4×
4×
1×
1×
8×
8×
8×
8×
3×
3×
3×
3×
3×
3×
8×
8×
8×
8×
8×
2×
8×
6×
6×
1×
5×
6×
1×
3×
3×
1×
9×
9×
9×
7×
7×
1×
1×
1×
1×
1×
1×
1×
1×
7×
7×
1×
7×
2×
2×
2×
7×
7×
7×
7×
2×
7×
1×
1×
1×
1×
1×
7×
7×
7×
2×
7×
1×
4422×
1385×
1385×
1385×
1385×
1385×
1385×
4422×
4422×
1×
8×
1×
1456×
1385×
1385×
1385×
1385×
1385×
1300×
1300×
1300×
1300×
1300×
85×
85×
1×
7×
7×
7×
1×
41×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-grids", "@syncfusion/ej2-grids", "../utils", "@syncfusion/ej2-base", "@syncfusion/ej2-data", "../base/constant"], function (require, exports, ej2_grids_1, ej2_grids_2, utils_1, ej2_base_1, ej2_data_1, event) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ExcelExport = (function () {
function ExcelExport(parent) {
this.isCollapsedStatePersist = false;
ej2_grids_1.Grid.Inject(ej2_grids_1.ExcelExport);
this.parent = parent;
this.dataResults = {};
this.addEventListener();
}
ExcelExport.prototype.getModuleName = function () {
return 'ExcelExport';
};
ExcelExport.prototype.addEventListener = function () {
this.parent.on('updateResults', this.updateExcelResultModel, this);
this.parent.on('excelCellInfo', this.excelQueryCellInfo, this);
this.parent.grid.on('export-RowDataBound', this.exportRowDataBound, this);
this.parent.on('excelAggregateCellInfo', this.excelAggregateCellInfo, this);
this.parent.grid.on('finalPageSetup', this.finalPageSetup, this);
};
ExcelExport.prototype.destroy = function () {
this.removeEventListener();
};
ExcelExport.prototype.removeEventListener = function () {
Eif (this.parent.isDestroyed) {
return;
}
this.parent.off('updateResults', this.updateExcelResultModel);
this.parent.off('excelCellInfo', this.excelQueryCellInfo);
this.parent.grid.off('export-RowDataBound', this.exportRowDataBound);
this.parent.off('excelAggregateCellInfo', this.excelAggregateCellInfo);
this.parent.grid.off('finalPageSetup', this.finalPageSetup);
};
ExcelExport.prototype.updateExcelResultModel = function (returnResult) {
this.dataResults = returnResult;
};
ExcelExport.prototype.Map = function (excelExportProperties, isMultipleExport, workbook, isBlob, isCsv) {
var _this = this;
var dataSource = this.parent.dataSource;
var data = new ej2_grids_2.Data(this.parent.grid);
var property = Object();
ej2_base_1.setValue('isCsv', isCsv, property);
ej2_base_1.setValue('cancel', false, property);
if (!ej2_base_1.isNullOrUndefined(excelExportProperties)) {
this.isCollapsedStatePersist = excelExportProperties.isCollapsedStatePersist;
}
if (!ej2_base_1.isNullOrUndefined(excelExportProperties)) {
Iif (!this.isLocal() && !ej2_base_1.isNullOrUndefined(excelExportProperties.dataSource) && !excelExportProperties.dataSource['dataSource']) {
return this.parent.grid.excelExportModule.Map(this.parent.grid, excelExportProperties, isMultipleExport, workbook, isCsv, isBlob);
}
if (excelExportProperties.exportType === 'CurrentPage') {
excelExportProperties.dataSource = this.parent.getCurrentViewRecords();
return this.parent.grid.excelExportModule.Map(this.parent.grid, excelExportProperties, isMultipleExport, workbook, isCsv, isBlob);
}
}
return new Promise(function (resolve) {
var dm = _this.isLocal() && !(dataSource instanceof ej2_data_1.DataManager) ? new ej2_data_1.DataManager(dataSource)
: _this.parent.dataSource;
var query = new ej2_data_1.Query();
if (!_this.isLocal()) {
query = _this.generateQuery(query);
var hasFilter = _this.parent.grid.filterSettings &&
Array.isArray(_this.parent.grid.filterSettings.columns) &&
_this.parent.grid.filterSettings.columns.length > 0;
var hasSearch = _this.parent.grid.searchSettings &&
typeof _this.parent.grid.searchSettings.key === 'string' &&
_this.parent.grid.searchSettings.key.trim().length > 0;
var hasSorting = _this.parent.grid.sortSettings &&
Array.isArray(_this.parent.grid.sortSettings.columns) &&
_this.parent.grid.sortSettings.columns.length > 0;
Iif (hasFilter || hasSearch || hasSorting) {
query.queries = _this.parent.grid.getDataModule().generateQuery().queries;
query = ej2_grids_1.ExportHelper.getQuery(_this.parent.grid, data);
if (ej2_base_1.isNullOrUndefined(_this.parent.filterModule)) {
query.queries = query.queries.slice(1, 2);
query.params = query.params.slice(0, 0);
}
}
ej2_base_1.setValue('query', query, property);
}
_this.parent.trigger(event.beforeExcelExport, ej2_base_1.extend(property, excelExportProperties));
Iif (ej2_grids_1.getObject('cancel', property)) {
return null;
}
dm.executeQuery(query).then(function (e) {
var customData = null;
if (!ej2_base_1.isNullOrUndefined(excelExportProperties) && !ej2_base_1.isNullOrUndefined(excelExportProperties.dataSource)) {
customData = excelExportProperties.dataSource;
}
excelExportProperties = _this.manipulateExportProperties(excelExportProperties, dataSource, e);
return _this.parent.grid.excelExportModule.Map(_this.parent.grid, excelExportProperties, isMultipleExport, workbook, isCsv, isBlob).then(function (book) {
if (customData != null) {
excelExportProperties.dataSource = customData;
}
else {
delete excelExportProperties.dataSource;
}
resolve(book);
});
});
});
};
ExcelExport.prototype.generateQuery = function (query, property) {
Iif (!ej2_base_1.isNullOrUndefined(property) && property.exportType === 'CurrentPage'
&& this.parent.allowPaging) {
property.exportType = 'AllPages';
query.addParams('ExportType', 'CurrentPage');
query.where(this.parent.parentIdMapping, 'equal', null);
query = ej2_grids_1.getObject('grid.renderModule.data.pageQuery', this.parent)(query);
}
return query;
};
ExcelExport.prototype.manipulateExportProperties = function (property, dtSrc, queryResult) {
var _this = this;
var args = Object();
Eif (!ej2_base_1.isNullOrUndefined(this.parent.grid.getDataModule())) {
ej2_base_1.setValue('query', this.parent.grid.getDataModule().generateQuery(true), args);
}
if (!this.isLocal() && !ej2_base_1.isNullOrUndefined(property) &&
!ej2_base_1.isNullOrUndefined(property.isCollapsedStatePersist) &&
property.isCollapsedStatePersist === false) {
Eif (args.query && args.query.queries && args.query.queries.length) {
args.query.queries = args.query.queries.filter(function (q) {
Eif (q.fn === 'onWhere' && q.e) {
var preds = q.e;
Eif (preds && preds.field === _this.parent.parentIdMapping && (preds.value === null || preds.value === 'null')) {
return false;
}
}
return true;
});
}
Eif (args.query && args.query.params && args.query.params.length) {
args.query.params = args.query.params.filter(function (param) { return param.key !== 'IdMapping'; });
}
}
ej2_base_1.setValue('isExport', true, args);
if (!ej2_base_1.isNullOrUndefined(property) && !ej2_base_1.isNullOrUndefined(property.exportType)) {
ej2_base_1.setValue('exportType', property.exportType, args);
}
if (!this.isLocal()) {
this.parent.parentData = [];
this.parent.dataModule.convertToFlatData(ej2_grids_1.getObject('result', queryResult));
ej2_base_1.setValue('expresults', this.parent.flatData, args);
}
this.parent.notify('dataProcessor', args);
args = this.dataResults;
dtSrc = ej2_base_1.isNullOrUndefined(args.result) ? this.parent.flatData.slice(0) : args.result;
if (!this.isLocal()) {
this.parent.flatData = [];
}
if (property && property.dataSource) {
var flatsData = this.parent.flatData;
var dataSrc = property.dataSource instanceof ej2_data_1.DataManager ? property.dataSource.dataSource.json : property.dataSource;
this.parent.dataModule.convertToFlatData(dataSrc);
dtSrc = this.parent.flatData;
this.parent.flatData = flatsData;
}
property = ej2_base_1.isNullOrUndefined(property) ? Object() : property;
property.dataSource = new ej2_data_1.DataManager({ json: dtSrc });
if (this.parent.aggregates.length > 0) {
property.query = args['query'];
}
return property;
};
ExcelExport.prototype.excelQueryCellInfo = function (args) {
if (this.parent.grid.getColumnIndexByUid(args.column.uid) === this.parent.treeColumnIndex) {
var style = {};
var data = args.data;
var ispadfilter = ej2_base_1.isNullOrUndefined(data.filterLevel);
var pad = ispadfilter ? data.level : data.filterLevel;
style.indent = pad;
args.style = style;
}
this.parent.notify('updateResults', args);
this.parent.trigger('excelQueryCellInfo', args);
};
ExcelExport.prototype.excelAggregateCellInfo = function (args) {
this.parent.trigger('excelAggregateQueryCellInfo', args);
};
ExcelExport.prototype.exportRowDataBound = function (excelRow) {
if (excelRow.type === 'excel') {
var excelrowobj = excelRow.rowObj.data;
var filtercolumnlength = this.parent.grid.filterSettings.columns.length;
var rowlength = excelRow.excelRows.length;
var rowlevel = excelrowobj.level;
if (excelrowobj.parentItem && utils_1.getParentData(this.parent, excelrowobj.parentItem.uniqueID, Boolean(filtercolumnlength))) {
var expandedStatus = false;
var sublevelState = false;
var state = utils_1.getExpandStatus(this.parent, excelrowobj, this.parent.parentData);
Iif (this.isCollapsedStatePersist && (!state || !this.parent.isLocalData)) {
expandedStatus = true;
sublevelState = excelrowobj.expanded ? false : true;
}
excelRow.excelRows[rowlength - 1].grouping = { outlineLevel: rowlevel, isCollapsed: sublevelState,
isHidden: expandedStatus };
}
else Eif (excelrowobj.hasChildRecords && ej2_base_1.isNullOrUndefined(excelrowobj.parentItem)) {
excelRow.excelRows[rowlength - 1].grouping = { outlineLevel: rowlevel };
}
}
};
ExcelExport.prototype.finalPageSetup = function (workbook) {
for (var i = 0; i < workbook.worksheets.length; i++) {
Eif (workbook.worksheets[parseInt(i.toString(), 10)].rows) {
workbook.worksheets[parseInt(i.toString(), 10)].pageSetup = { isSummaryRowBelow: false };
}
}
};
ExcelExport.prototype.isLocal = function () {
return !utils_1.isRemoteData(this.parent) && utils_1.isOffline(this.parent);
};
return ExcelExport;
}());
exports.ExcelExport = ExcelExport;
});
|