| 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 | 1×
1×
1×
1×
1918×
1918×
1918×
2714×
2714×
1918×
2720×
1918×
1504×
1403×
101×
101×
101×
101×
10×
101×
9×
92×
1918×
211×
211×
2×
209×
184×
184×
184×
184×
184×
3×
184×
25×
24×
1×
1918×
1918×
1918×
1918×
1918×
1×
45971×
1×
29×
1×
1918×
1918×
1918×
33×
33×
1918×
1918×
44×
44×
44×
1×
33×
33×
16×
17×
17×
27×
17×
17×
15×
15×
15×
15×
1×
44×
44×
40×
4×
4×
4×
4×
8×
4×
2×
2×
2×
2×
8×
8×
8×
8×
8×
5×
5×
5×
2×
1×
44×
44×
248×
44×
42×
2×
1×
8×
8×
2×
6×
6×
1×
1919×
1×
1918×
1918×
1918×
1918×
1918×
1918×
1×
3793×
1975×
1818×
1818×
1818×
1818×
1×
93×
93×
93×
35×
58×
58×
58×
72×
5×
5×
5×
5×
1×
19×
19×
1×
18×
18×
18×
18×
1×
1×
17×
17×
17×
17×
6×
6×
11×
11×
11×
11×
11×
13×
11×
1×
17×
17×
17×
20×
20×
14×
6×
3×
3×
1×
2×
1×
20×
19×
17×
1×
1×
1×
1×
1×
1×
1×
194×
194×
194×
1×
193×
1×
3791×
3791×
3791×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-base", "../services/highlight-service", "../base/constant", "../base/util", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1, highlight_service_1, events, util_1, ej2_base_2) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Highlight = (function () {
function Highlight(parent, serviceLocator) {
var _this = this;
this.evtHandlers = [];
this.onContentReady = function () {
_this.highlightService.initialize();
_this.highlightService.reapplyDetached();
};
this.onDataBound = function () {
_this.highlightService.initialize();
};
this.onActionComplete = function (args) {
if (!args || args.requestType !== 'save' || args.action === 'add' || !args.data) {
return;
}
var settings = _this.parent.highlightSettings;
Iif (ej2_base_1.isNullOrUndefined(settings)) {
return;
}
var rowIndex = _this.parent.getPrimaryKeyFieldNames()[0] ? _this.parent.getRowIndexByPrimaryKey(args.data) : -1;
if (ej2_base_1.isNullOrUndefined(rowIndex) || rowIndex < 0) {
rowIndex = args.index;
}
if (ej2_base_1.isNullOrUndefined(rowIndex) || rowIndex < 0) {
return;
}
_this.highlightChangedCells(rowIndex, args.data, settings);
};
this.onCellSaved = function (args) {
var settings = _this.parent.highlightSettings;
if (ej2_base_1.isNullOrUndefined(settings) || args.cancel) {
return;
}
if (args.cell && args.columnName) {
var tr = args.cell.parentElement;
var colIndex = _this.parent.getColumnIndexByField(args.columnName);
var rowIndex = tr ? parseInt(tr.getAttribute('aria-rowindex'), 10) - 1 : -1;
var changed = (!ej2_base_1.isNullOrUndefined(args.previousValue) && !ej2_base_1.isNullOrUndefined(args.value)) ?
args.previousValue.toString() !== args.value.toString() : args.previousValue !== args.value;
if (changed && colIndex >= 0 && rowIndex >= 0 && args.cell instanceof HTMLElement
&& _this.shouldHighlightColumn(colIndex)) {
_this.highlightService.highlightCell(args.cell, rowIndex, colIndex, settings);
}
return;
}
if (!args.data) {
return;
}
_this.highlightChangedCells(args.rowIndex, args.data, settings);
};
ej2_base_2.initializeTelemetryFeature('Highlight', 'DataGrid');
this.parent = parent;
this.serviceLocator = serviceLocator;
this.highlightService = new highlight_service_1.HighlightService(this.parent);
this.addEventListener();
}
Highlight.prototype.getModuleName = function () {
return 'highlight';
};
Highlight.prototype.getService = function () {
return this.highlightService;
};
Highlight.prototype.wrapGridMethods = function () {
var _this = this;
var originalSetCellValue = this.parent.setCellValue.bind(this.parent);
this.parent.setCellValue = function (key, field, value) {
originalSetCellValue(key, field, value);
_this.onProgrammaticCellUpdate(key, field, value);
};
var originalSetRowData = this.parent.setRowData.bind(this.parent);
this.parent.setRowData = function (key, rowData) {
var previousData = _this.getPreviousRowData(key);
originalSetRowData(key, rowData);
_this.onProgrammaticRowUpdate(key, rowData, previousData);
};
};
Highlight.prototype.onProgrammaticCellUpdate = function (key, field, value) {
var settings = this.parent.highlightSettings;
if (ej2_base_1.isNullOrUndefined(settings) || !this.shouldHighlightColumn(this.parent.getColumnIndexByField(field))) {
return;
}
var pkName = this.parent.getPrimaryKeyFieldNames()[0];
var rows = this.parent.contentModule.getRows();
var findRow = function (r) { return r && r.data && r.data[pkName] === key; };
var selectedRow = rows.find(findRow);
if (selectedRow) {
var colIndex = this.parent.getColumnIndexByField(field);
var cellElement = this.parent.getCellFromIndex(selectedRow.index, colIndex);
Eif (cellElement && cellElement instanceof HTMLElement) {
this.highlightService.highlightCell(cellElement, selectedRow.index, colIndex, settings);
}
}
};
Highlight.prototype.onProgrammaticRowUpdate = function (key, rowData, previousData) {
var _this = this;
if (!this.parent.enableHighlightOnDataChange || !rowData) {
return;
}
var settings = this.parent.highlightSettings;
Iif (ej2_base_1.isNullOrUndefined(settings)) {
return;
}
var pkName = this.parent.getPrimaryKeyFieldNames()[0];
var rows = this.parent.contentModule.getRows();
var selectedRow = rows.find(function (r) { return r.data && r.data[pkName] === key; });
if (selectedRow) {
var rowElement = this.parent.getRowByIndex(selectedRow.index);
Eif (rowElement && rowElement instanceof HTMLElement) {
var columns = this.parent.getVisibleColumns();
var onUpdateCell = function (col, colIndex) {
Iif (!col.field) {
return;
}
var fieldKey = col.field;
var newValue = rowData[fieldKey];
var oldValue = previousData ? previousData[fieldKey] : undefined;
if (!_this.valuesEqual(newValue, oldValue)) {
var cellElement = _this.parent.getCellFromIndex(selectedRow.index, colIndex);
Eif (cellElement && cellElement instanceof HTMLElement) {
_this.highlightService.highlightCell(cellElement, selectedRow.index, colIndex, settings);
}
}
};
columns.forEach(onUpdateCell);
}
}
};
Highlight.prototype.getPreviousRowData = function (key) {
var pkName = this.parent.getPrimaryKeyFieldNames()[0];
var rows = this.parent.contentModule.getRows();
var selectedRow = rows.find(function (r) { return r.data && r.data[pkName] === key; });
if (selectedRow && selectedRow.data) {
return Object.assign({}, selectedRow.data);
}
return null;
};
Highlight.prototype.valuesEqual = function (val1, val2) {
Iif (ej2_base_1.isNullOrUndefined(val1) && ej2_base_1.isNullOrUndefined(val2)) {
return true;
}
if (ej2_base_1.isNullOrUndefined(val1) || ej2_base_1.isNullOrUndefined(val2)) {
return false;
}
Iif (val1 instanceof Date && val2 instanceof Date) {
return val1.getTime() === val2.getTime();
}
return val1 === val2;
};
Highlight.prototype.addEventListener = function () {
if (this.parent.isDestroyed) {
return;
}
this.evtHandlers = [
{ event: events.contentReady, handler: this.onContentReady },
{ event: events.destroy, handler: this.destroy }
];
util_1.addRemoveEventListener(this.parent, this.evtHandlers, true, this);
this.parent.addEventListener(events.cellSaved, this.onCellSaved);
this.parent.addEventListener(events.dataBound, this.onDataBound);
this.parent.addEventListener(events.actionComplete, this.onActionComplete);
this.wrapGridMethods();
};
Highlight.prototype.removeEventListener = function () {
if (this.parent.isDestroyed) {
return;
}
util_1.addRemoveEventListener(this.parent, this.evtHandlers, false);
this.parent.removeEventListener(events.cellSaved, this.onCellSaved);
this.parent.removeEventListener(events.dataBound, this.onDataBound);
this.parent.removeEventListener(events.actionComplete, this.onActionComplete);
};
Highlight.prototype.highlightChangedCells = function (rowIndex, data, settings) {
var _this = this;
var changedColumns = this.highlightService.compareRow(rowIndex, data);
if (!changedColumns || changedColumns.length === 0) {
return;
}
var pkName = this.parent.getPrimaryKeyFieldNames()[0];
var pkValue = pkName ? ej2_base_1.getValue(pkName, data) : undefined;
changedColumns.forEach(function (colIndex) {
if (_this.shouldHighlightColumn(colIndex)) {
var located = ej2_base_1.isNullOrUndefined(pkValue) ? null
: _this.highlightService.findRenderedCell(pkValue, colIndex);
var cellElement = located ? located.cell : _this.parent.getCellFromIndex(rowIndex, colIndex);
Eif (cellElement && cellElement instanceof HTMLElement) {
_this.highlightService.highlightCell(cellElement, located ? located.rowIndex : rowIndex, colIndex, settings);
}
}
});
};
Highlight.prototype.flash = function (options) {
var _this = this;
if (!this.highlightService || !options) {
return;
}
var overrides = Array.isArray(options) ? null : options.highlightSettings;
var gridSettings = this.parent.highlightSettings.properties || this.parent.highlightSettings;
var settings = ej2_base_1.extend({}, gridSettings, overrides, true);
if (Array.isArray(options)) {
this.highlightService.highlightCells(options, settings);
return;
}
var rowIndexes = this.resolveRowIndexes(options.rowNodes);
var hasRows = !ej2_base_1.isNullOrUndefined(options.rowNodes);
var fields = options.columns;
if (!fields || !fields.length) {
this.highlightService.highlightRows(rowIndexes, settings);
return;
}
var rows = hasRows ? rowIndexes : this.parent.getRows().map(function (r, i) { return i; });
var cells = [];
fields.forEach(function (field) {
var colIndex = _this.parent.getColumnIndexByField(field);
if (colIndex >= 0) {
rows.forEach(function (rowIndex) { return cells.push({ rowIndex: rowIndex, colIndex: colIndex }); });
}
});
this.highlightService.highlightCells(cells, settings);
};
Highlight.prototype.resolveRowIndexes = function (rowNodes) {
var _this = this;
var result = [];
(rowNodes || []).forEach(function (node) {
var index = -1;
if (typeof node === 'number') {
index = node;
}
else if (node instanceof HTMLElement) {
index = parseInt(node.getAttribute('aria-rowindex'), 10) - 1;
}
else if (node && typeof node.index === 'number') {
index = node.index;
}
else if (node && _this.parent.getPrimaryKeyFieldNames()[0]) {
index = _this.parent.getRowIndexByPrimaryKey(node);
}
if (index >= 0) {
result.push(index);
}
});
return result;
};
Highlight.prototype.highlightCells = function (cells) {
Eif (this.highlightService) {
this.highlightService.highlightCells(cells, this.parent.highlightSettings);
}
};
Highlight.prototype.highlightRows = function (rows) {
Eif (this.highlightService) {
this.highlightService.highlightRows(rows, this.parent.highlightSettings);
}
};
Highlight.prototype.shouldHighlightColumn = function (colIndex) {
var column = this.parent.getColumnByIndex(colIndex);
Iif (!column) {
return this.parent.enableHighlightOnDataChange;
}
if (column.enableHighlightOnDataChange !== null && column.enableHighlightOnDataChange !== undefined) {
return column.enableHighlightOnDataChange;
}
return this.parent.enableHighlightOnDataChange;
};
Highlight.prototype.destroy = function () {
this.removeEventListener();
Eif (this.highlightService) {
this.highlightService.destroy();
}
};
return Highlight;
}());
exports.Highlight = Highlight;
});
|