| 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 | 1×
1×
1×
1×
818×
818×
818×
818×
818×
818×
818×
1×
14670×
1×
800×
1×
818×
818×
1×
800×
799×
1×
1×
1×
203×
203×
203×
203×
203×
203×
203×
17602×
17602×
17602×
122×
17602×
17602×
3561×
17602×
17602×
14356×
14356×
14356×
1070×
203×
29×
203×
18260×
18260×
14545×
14545×
6049480×
14545×
14471×
74×
203×
203×
18260×
203×
1×
1959×
1959×
1959×
1953×
1959×
889×
1×
33832×
33832×
33832×
43×
20×
13×
5×
5×
5×
13×
23×
23×
16×
14×
14×
7×
4×
4×
33789×
16283×
16283×
93×
17×
16190×
33789×
15700×
15700×
1×
4062×
4062×
4062×
16105×
16105×
16105×
2555×
2555×
2537×
2537×
2537×
16105×
46×
8×
8×
16097×
501×
16097×
8155×
4062×
1×
29×
29×
29×
221×
221×
221×
133×
133×
88×
88×
1×
621×
621×
621×
620×
620×
70947×
70947×
70947×
343×
343×
620×
620×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-grids", "@syncfusion/ej2-base", "../utils", "../utils"], function (require, exports, ej2_grids_1, ej2_base_1, utils_1, utils_2) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Filter = (function () {
function Filter(parent) {
ej2_grids_1.Grid.Inject(ej2_grids_1.Filter);
this.parent = parent;
this.isHierarchyFilter = false;
this.filteredResult = [];
this.flatFilteredData = [];
this.filteredParentRecs = [];
this.addEventListener();
}
Filter.prototype.getModuleName = function () {
return 'filter';
};
Filter.prototype.destroy = function () {
this.removeEventListener();
};
Filter.prototype.addEventListener = function () {
this.parent.on('updateFilterRecs', this.updatedFilteredRecord, this);
this.parent.on('clearFilters', this.clearFilterLevel, this);
};
Filter.prototype.removeEventListener = function () {
if (this.parent.isDestroyed) {
return;
}
this.parent.off('updateFilterRecs', this.updatedFilteredRecord);
this.parent.off('clearFilters', this.clearFilterLevel);
};
Filter.prototype.updatedFilteredRecord = function (dataDetails) {
ej2_base_1.setValue('uniqueIDFilterCollection', {}, this.parent);
this.flatFilteredData = dataDetails.data;
this.filteredParentRecs = [];
this.filteredResult = [];
this.isHierarchyFilter = false;
var hierarchyMode = this.parent.grid.searchSettings.key === '' ? this.parent.filterSettings.hierarchyMode
: this.parent.searchSettings.hierarchyMode;
for (var f = 0; f < this.flatFilteredData.length; f++) {
var rec = this.flatFilteredData[parseInt(f.toString(), 10)];
this.addParentRecord(rec);
if (((hierarchyMode === 'Child' || hierarchyMode === 'None') &&
(this.parent.grid.filterSettings.columns.length !== 0 || this.parent.grid.searchSettings.key !== ''))) {
this.isHierarchyFilter = true;
}
var ischild = ej2_grids_1.getObject('childRecords', rec);
if (!ej2_base_1.isNullOrUndefined(ischild) && ischild.length) {
ej2_base_1.setValue('hasFilteredChildRecords', this.checkChildExsist(rec), rec);
}
var parent_1 = ej2_grids_1.getObject('parentItem', rec);
if (!ej2_base_1.isNullOrUndefined(parent_1)) {
var parRecord = utils_2.getParentData(this.parent, rec.parentItem.uniqueID, true);
ej2_base_1.setValue('hasFilteredChildRecords', true, parRecord);
if (parRecord && parRecord.parentItem) {
this.updateParentFilteredRecord(parRecord);
}
}
}
if (this.flatFilteredData.length > 0 && this.isHierarchyFilter) {
this.updateFilterLevel();
}
var _loop_1 = function (i) {
var record = this_1.filteredResult[parseInt(i.toString(), 10)];
if (!ej2_base_1.isNullOrUndefined(record.parentItem)) {
var parentUID_1 = record.parentItem.uniqueID;
var parentPresent = this_1.filteredResult.some(function (r) {
return !ej2_base_1.isNullOrUndefined(r.uniqueID) && r.uniqueID === parentUID_1;
});
if (parentPresent) {
record.isCollapsedChild = !utils_1.getExpandStatus(this_1.parent, record, this_1.parent.parentData);
}
else {
record.isCollapsedChild = false;
}
}
};
var this_1 = this;
for (var i = 0; i < this.filteredResult.length; i++) {
_loop_1(i);
}
this.parent.notify('updateAction', { result: this.filteredResult });
};
Filter.prototype.updateParentFilteredRecord = function (record) {
var parRecord = utils_2.getParentData(this.parent, record.parentItem.uniqueID, true);
var uniqueIDValue = ej2_base_1.getValue('uniqueIDFilterCollection', this.parent);
if (parRecord && Object.prototype.hasOwnProperty.call(uniqueIDValue, parRecord.uniqueID)) {
ej2_base_1.setValue('hasFilteredChildRecords', true, parRecord);
}
if (parRecord && parRecord.parentItem) {
this.updateParentFilteredRecord(parRecord);
}
};
Filter.prototype.addParentRecord = function (record) {
var parent = utils_2.getParentData(this.parent, record.parentUniqueID);
var hierarchyMode = this.parent.grid.searchSettings.key === '' ? this.parent.filterSettings.hierarchyMode
: this.parent.searchSettings.hierarchyMode;
if (hierarchyMode === 'None' && (this.parent.grid.filterSettings.columns.length !== 0
|| this.parent.grid.searchSettings.key !== '')) {
if (ej2_base_1.isNullOrUndefined(parent)) {
if (this.flatFilteredData.indexOf(record) !== -1) {
if (this.filteredResult.indexOf(record) === -1) {
this.filteredResult.push(record);
ej2_base_1.setValue('uniqueIDFilterCollection.' + record.uniqueID, record, this.parent);
record.hasFilteredChildRecords = true;
}
return;
}
}
else {
this.addParentRecord(parent);
if (this.flatFilteredData.indexOf(parent) !== -1 || this.filteredResult.indexOf(parent) !== -1) {
if (this.filteredResult.indexOf(record) === -1) {
this.filteredResult.push(record);
ej2_base_1.setValue('uniqueIDFilterCollection.' + record.uniqueID, record, this.parent);
}
}
else {
if (this.filteredResult.indexOf(record) === -1 && this.flatFilteredData.indexOf(record) !== -1) {
this.filteredResult.push(record);
ej2_base_1.setValue('uniqueIDFilterCollection.' + record.uniqueID, record, this.parent);
}
}
}
}
else {
if (!ej2_base_1.isNullOrUndefined(parent)) {
var hierarchyMode_1 = this.parent.grid.searchSettings.key === '' ?
this.parent.filterSettings.hierarchyMode : this.parent.searchSettings.hierarchyMode;
if (hierarchyMode_1 === 'Child' && (this.parent.grid.filterSettings.columns.length !== 0
|| this.parent.grid.searchSettings.key !== '')) {
if (this.flatFilteredData.indexOf(parent) !== -1) {
this.addParentRecord(parent);
}
}
else {
this.addParentRecord(parent);
}
}
if (this.filteredResult.indexOf(record) === -1) {
this.filteredResult.push(record);
ej2_base_1.setValue('uniqueIDFilterCollection.' + record.uniqueID, record, this.parent);
}
}
};
Filter.prototype.checkChildExsist = function (records) {
var childRec = ej2_grids_1.getObject('childRecords', records);
var isExist = false;
for (var count = 0; count < childRec.length; count++) {
var ischild = childRec[parseInt(count.toString(), 10)].childRecords;
var hierarchyMode = this.parent.grid.searchSettings.key === '' ?
this.parent.filterSettings.hierarchyMode : this.parent.searchSettings.hierarchyMode;
if (((hierarchyMode === 'Child' || hierarchyMode === 'Both') && (this.parent.grid.filterSettings.columns.length !== 0
|| this.parent.grid.searchSettings.key !== ''))) {
var uniqueIDValue = ej2_base_1.getValue('uniqueIDFilterCollection', this.parent);
if (!Object.prototype.hasOwnProperty.call(uniqueIDValue, childRec[parseInt(count.toString(), 10)].uniqueID)) {
this.filteredResult.push(childRec[parseInt(count.toString(), 10)]);
ej2_base_1.setValue('uniqueIDFilterCollection.' + childRec[parseInt(count.toString(), 10)].uniqueID, childRec[parseInt(count.toString(), 10)], this.parent);
isExist = true;
}
}
if ((hierarchyMode === 'None')
&& (this.parent.grid.filterSettings.columns.length !== 0 || this.parent.grid.searchSettings.key !== '')) {
if (this.flatFilteredData.indexOf(childRec[parseInt(count.toString(), 10)]) !== -1) {
isExist = true;
break;
}
}
if (!ej2_base_1.isNullOrUndefined(ischild) && ischild.length) {
isExist = this.checkChildExsist(childRec[parseInt(count.toString(), 10)]);
}
if ((hierarchyMode === 'Child' || hierarchyMode === 'Both') && childRec.length) {
isExist = true;
}
}
return isExist;
};
Filter.prototype.updateFilterLevel = function () {
var record = this.filteredResult;
var len = this.filteredResult.length;
for (var c = 0; c < len; c++) {
var parent_2 = utils_2.getParentData(this.parent, record[parseInt(c.toString(), 10)].parentUniqueID);
var isPrst = record.indexOf(parent_2) !== -1;
if (isPrst) {
var parent_3 = utils_2.getParentData(this.parent, record[parseInt(c.toString(), 10)].parentUniqueID, true);
record[parseInt(c.toString(), 10)].filterLevel = parent_3.filterLevel + 1;
}
else {
record[parseInt(c.toString(), 10)].filterLevel = 0;
this.filteredParentRecs.push(record[parseInt(c.toString(), 10)]);
}
}
};
Filter.prototype.clearFilterLevel = function (data) {
var count = 0;
var flatData = data.flatData;
var len = flatData.length;
var currentRecord;
for (count; count < len; count++) {
currentRecord = flatData[parseInt(count.toString(), 10)];
var fLevel = currentRecord.filterLevel;
if (fLevel || fLevel === 0 || !ej2_base_1.isNullOrUndefined(currentRecord.hasFilteredChildRecords)) {
currentRecord.hasFilteredChildRecords = null;
currentRecord.filterLevel = null;
}
}
this.filteredResult = [];
this.parent.notify('updateResults', { result: flatData, count: flatData.length });
};
return Filter;
}());
exports.Filter = Filter;
});
|