| 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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742 | 1×
1×
1×
1×
298×
298×
298×
298×
298×
1×
5×
1×
1075×
1075×
1075×
1075×
1075×
1077×
289×
786×
786×
1×
6845×
6845×
14×
6831×
6831×
6831×
1225×
1×
22×
35×
22×
1×
71×
40×
1×
444×
444×
444×
3008×
3008×
6487×
5930×
3008×
1×
446×
446×
446×
446×
446×
446×
446×
580×
279×
446×
446×
2674×
446×
446×
446×
208×
446×
446×
446×
446×
446×
446×
446×
446×
446×
446×
446×
446×
446×
446×
446×
11×
53×
9×
446×
446×
446×
446×
446×
446×
446×
446×
1×
446×
183×
183×
183×
183×
446×
1×
1×
1×
1×
1×
1×
445×
445×
445×
445×
445×
445×
445×
888×
53×
445×
445×
21×
21×
21×
445×
445×
29×
445×
445×
445×
445×
5×
5×
1×
4×
4×
4×
4×
1×
6×
26×
7×
7×
8×
7×
1×
7×
25×
7×
7×
7×
7×
2×
2×
2×
2×
25×
5×
25×
6×
18×
445×
17×
4×
4×
6419×
6419×
6419×
14653×
557×
5862×
5862×
17×
17×
16×
1×
894×
889×
5×
5×
1×
32×
31×
31×
31×
54×
53×
53×
33×
376×
376×
376×
376×
376×
376×
751×
1×
376×
1×
376×
13×
376×
74×
74×
376×
42×
74×
42×
26×
8×
18×
18×
376×
376×
376×
376×
376×
376×
26×
26×
26×
376×
368×
445×
445×
445×
445×
445×
445×
445×
1×
318×
318×
364×
318×
318×
318×
3×
318×
1×
446×
446×
269×
269×
269×
208×
269×
446×
446×
446×
1×
24×
24×
24×
24×
24×
24×
24×
1×
23×
23×
1×
17×
17×
2×
2×
15×
4×
4×
4×
4×
19×
6×
8×
21×
4×
8×
11×
2×
2×
2×
2×
2×
2×
2×
2×
9×
1×
1×
1×
1×
1×
1×
1×
8×
1×
1×
7×
1×
18×
18×
18×
18×
17×
17×
17×
8×
8×
9×
9×
43×
43×
9×
34×
9×
9×
9×
9×
1×
1×
1×
445×
445×
445×
37×
37×
20×
17×
17×
37×
445×
445×
465×
445×
445×
445×
1×
6×
6×
6×
6×
12×
6×
6×
6×
6×
6×
6×
9×
9×
9×
5×
10×
5×
6×
6×
6×
4×
4×
4×
4×
4×
4×
2×
1×
445×
445×
445×
445×
2595×
2595×
2176×
2176×
9×
2167×
2167×
430×
1737×
857×
880×
24×
856×
1×
50×
26×
8×
18×
3×
3×
15×
15×
1×
1×
3×
3×
1×
1×
3×
3×
15×
8×
8×
5×
3×
17×
8×
8×
8×
1×
3×
3×
7×
3×
3×
3×
3×
3×
1×
7×
7×
7×
24×
12×
8×
7×
33×
15×
8×
7×
1×
1×
6×
6×
1×
11×
11×
11×
11×
11×
11×
25×
1×
445×
445×
445×
445×
109×
83×
14×
82×
82×
82×
82×
445×
1×
445×
445×
445×
445×
445×
109×
83×
445×
1×
376×
376×
295×
81×
81×
81×
22×
731×
1×
285×
269×
269×
285×
285×
285×
285×
285×
285×
285×
285×
285×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-grids", "@syncfusion/ej2-base", "../../common/base/flat-util", "@syncfusion/ej2-data"], function (require, exports, ej2_grids_1, ej2_base_1, flat_util_1, ej2_data_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var FlatGrid = (function () {
function FlatGrid(parent) {
this.pending = false;
this.pinningSuspended = false;
this.renderedOrdinals = [];
this.columnAction = false;
this.parent = parent;
}
Object.defineProperty(FlatGrid.prototype, "columnActionPending", {
get: function () { return this.columnAction; },
enumerable: true,
configurable: true
});
FlatGrid.prototype.viewportWidth = function () {
var available = this.parent.element.clientWidth;
var width = String(this.parent.width);
var percentage = width.endsWith('%');
var numeric = percentage ? width.slice(0, -1) : width.endsWith('px') ? width.slice(0, -2) : width;
var parts = numeric.split('.');
if (parts.length > 2 || parts.some(function (part) { return !/^\d+$/.test(part); })) {
return available;
}
var value = parseFloat(numeric);
return percentage ? available * value / 100 : Math.min(available || Infinity, value);
};
FlatGrid.prototype.field = function (encoded) {
var index = /^flat\d+$/.test(encoded || '') ? Number(encoded.slice(4)) : -1;
if (index < 0 || index >= this.columns.length) {
return undefined;
}
var descriptor = Object.getOwnPropertyDescriptor(this.columns, String(index));
var column = descriptor && descriptor.value;
return column && column.field;
};
FlatGrid.prototype.encoded = function (field) { return 'flat' + this.columns.findIndex(function (column) { return column.field === field; }); };
FlatGrid.prototype.physicalColumn = function (column) {
var field = this.field(column.field);
var descriptor = this.columns.filter(function (entry) { return entry.field === field; })[0];
return new ej2_grids_1.Column(Object.assign({}, flat_util_1.cloneFlat(descriptor), { field: field }));
};
FlatGrid.prototype.can = function (field, flag) {
var column = this.columns.filter(function (entry) { return entry.field === field; })[0];
return flat_util_1.isFlatColumnActionEnabled(this.settings, column, flag);
};
FlatGrid.prototype.frame = function (skip, take) {
var _this = this;
var flat = this.parent.flatLayoutModule;
return flat.project(skip, take).map(function (record, offset) {
var row = { flatOrdinal: skip + offset };
_this.columns.forEach(function (column, index) {
if (column.visible !== false) {
row['flat' + index] = record[column.field];
}
});
return row;
});
};
FlatGrid.prototype.render = function (notify) {
var _this = this;
if (notify === void 0) { notify = true; }
var parent = this.parent;
var flat = parent.flatLayoutModule;
var prior = parent.grid;
var pageSettings = parent.flatSettings.pageSettings;
var fields = function (columns) {
return JSON.stringify(columns.map(function (column) { return [column.field, column.visible !== false]; })
.sort(function (left, right) { return String(left[0]).localeCompare(String(right[0])); }));
};
var ordinals = flat.query.ordinals.values();
var retain = prior && !prior.isDestroyed && this.renderedStore === flat.store && this.settings &&
fields(this.settings.columns) === fields(parent.flatSettings.columns) &&
this.settings.pageSettings.currentPage === pageSettings.currentPage &&
this.settings.pageSettings.pageSize === pageSettings.pageSize &&
this.renderedOrdinals.length === flat.query.ordinals.length &&
this.renderedOrdinals.every(function (ordinal) { return ordinal === ordinals.next().value; });
var columnSelection = retain && this.columnAction ? this.columnSelection : undefined;
var selected = columnSelection ? columnSelection.rows : retain ? prior.getSelectedRowIndexes().slice() : [];
var previousFields = columnSelection ? columnSelection.fields : retain ?
prior.getColumns().map(function (column) { return _this.field(column.field); }) : [];
var cells = columnSelection ? columnSelection.cells : retain ? flat_util_1.cloneFlat(prior.getSelectedRowCellIndexes()) : [];
this.columnSelection = undefined;
this.columnAction = false;
var content = retain ? prior.getContent().querySelector('.e-content') : undefined;
var top = content ? content.scrollTop : 0;
var left = content ? content.scrollLeft : 0;
var focused = parent.element.ownerDocument.activeElement;
var focusInfo = retain && prior.element.contains(focused) && focused.closest('.e-rowcell') ?
prior.getRowInfo(focused) : undefined;
var focusRow = columnSelection && columnSelection.focus ? columnSelection.focus.row :
focusInfo ? focusInfo.rowIndex : undefined;
var focusField = columnSelection && columnSelection.focus ? columnSelection.focus.field :
focusInfo ? this.field(focusInfo.column.field) : undefined;
this.generation = flat.renderGeneration;
var generation = this.generation;
this.settings = flat_util_1.cloneFlat(parent.flatSettings);
this.columns = flat_util_1.cloneFlat(this.settings.columns || []);
if (this.settings.showColumnChooser) {
flat.store.fields.forEach(function (field) {
if (!_this.columns.some(function (column) { return column.field === field; })) {
_this.columns.push({ field: field, visible: false });
}
});
}
this.renderedStore = flat.store;
this.renderedOrdinals = flat.query.ordinals;
this.pinningSuspended = !flat_util_1.flatPinsFit(this.settings, this.viewportWidth());
this.watchWidth();
this.pending = false;
this.removeTotal();
var previousEmpty = parent.element.querySelector('.e-pivot-flat-empty');
if (previousEmpty) {
ej2_base_1.remove(previousEmpty);
}
if (parent.grid && !parent.grid.isDestroyed) {
var previous = parent.grid.element;
parent.grid.destroy();
Eif (previous.parentElement) {
ej2_base_1.remove(previous);
}
}
if (!flat.columns.length && !this.settings.showColumnChooser && !(this.settings.toolbar || []).length) {
parent.grid = undefined;
var empty_1 = parent.createElement('div', { className: 'e-pivot-flat-empty', attrs: { role: 'status' } });
empty_1.textContent = parent.localeObj.getConstant('flatNoFields');
parent.element.appendChild(empty_1);
flat.dataBound();
return;
}
ej2_grids_1.Grid.Inject(ej2_grids_1.Selection, ej2_grids_1.Sort, ej2_grids_1.Filter, ej2_grids_1.Page, ej2_grids_1.VirtualScroll, ej2_grids_1.Resize, ej2_grids_1.Reorder, ej2_grids_1.Freeze, ej2_grids_1.ColumnMenu, ej2_grids_1.AdvancedFilter, ej2_grids_1.Clipboard, ej2_grids_1.Aggregate, ej2_grids_1.Toolbar, ej2_grids_1.ColumnChooser, ej2_grids_1.ExcelExport, ej2_grids_1.PdfExport);
var pageSize = this.settings.pageSettings && this.settings.pageSettings.pageSize || 12;
var page = this.settings.allowPaging ? Math.min(this.settings.pageSettings.currentPage || 1, Math.max(1, Math.ceil(flat.query.ordinals.length / pageSize))) : 1;
parent.setProperties({ flatSettings: { pageSettings: { currentPage: page } } }, true);
var virtual = this.settings.enableVirtualization && (!this.settings.allowPaging || pageSize > 40);
var count = flat.query.ordinals.length;
var take = this.settings.allowPaging ? pageSize : virtual ? Math.max(40, pageSize) : count;
var columns = this.columns.map(function (column, index) { return ({
field: 'flat' + index, headerText: column.headerText || column.field, visible: column.visible,
width: column.width || 200, type: column.type || (flat.store.types[column.field] === 'mixed' ? undefined :
flat.store.types[column.field]),
format: column.format, textAlign: column.textAlign, disableHtmlEncode: true,
allowSorting: column.allowSorting !== false, allowFiltering: column.allowFiltering !== false,
allowResizing: column.allowResizing !== false, allowReordering: column.allowReordering !== false,
allowSearching: column.allowSearching !== false, showColumnMenu: column.showColumnMenu !== false,
filter: column.filter || {}, freeze: _this.pinningSuspended ? 'None' : _this.settings.frozenColumns &&
_this.columns.slice(0, index + 1).filter(function (entry) { return entry.visible !== false; }).length <=
_this.settings.frozenColumns && column.visible !== false ? 'Left' : column.freeze,
isFrozen: !_this.pinningSuspended && column.isFrozen
}); });
var filters = flat_util_1.cloneFlat(this.settings.filterSettings || {});
filters.columns = (filters.columns || []).map(function (entry) {
var predicate = Object.assign({}, entry, { field: _this.encoded(entry.field) });
delete predicate.uid;
return predicate;
});
var sort = flat_util_1.cloneFlat(this.settings.sortSettings || {});
sort.columns = (sort.columns || []).map(function (entry) {
return Object.assign({}, entry, { field: _this.encoded(entry.field) });
});
var completed = false;
var empty = parent.createElement('div', { className: 'e-pivot-flat-empty', attrs: { role: 'status' } });
empty.textContent = parent.localeObj.getConstant('flatNoFields');
parent.grid = new ej2_grids_1.Grid({
dataSource: { result: flat.columns.length ? this.frame((page - 1) * pageSize, take) : [],
count: flat.columns.length ? count : 0, aggregates: this.aggregateValues() }, columns: columns,
emptyRecordTemplate: flat.columns.length ? undefined : empty.outerHTML,
width: parent.width, height: parent.height === 'auto' ? virtual ? 400 : 'auto' : parent.height,
locale: parent.locale, enableRtl: parent.enableRtl, cssClass: parent.cssClass,
enableHtmlSanitizer: parent.enableHtmlSanitizer,
allowSelection: this.settings.allowSelection, selectionSettings: this.settings.selectionSettings,
allowSorting: this.settings.allowSorting, allowMultiSorting: this.settings.allowMultiSorting, sortSettings: sort,
allowFiltering: this.settings.allowFiltering, filterSettings: filters,
allowAdvancedFiltering: this.settings.allowAdvancedFiltering,
toolbar: (this.settings.toolbar || []).length ? this.settings.toolbar : undefined,
showColumnChooser: this.settings.showColumnChooser,
allowExcelExport: this.settings.allowExcelExport, allowPdfExport: this.settings.allowPdfExport,
toolbarClick: function (args) {
parent.trigger('toolbarClick', args);
if (args.cancel) {
return;
}
var command = args.item.id.slice(parent.grid.element.id.length + 1);
Eif (['excelexport', 'csvexport', 'pdfexport'].indexOf(command) !== -1) {
args.cancel = true;
flat.output.export(command === 'pdfexport' ? 'PDF' : command === 'csvexport' ? 'CSV' : 'Excel')
.catch(function () { return undefined; });
}
},
columnChooserSettings: this.settings.columnChooserSettings,
searchSettings: Object.assign({}, this.settings.searchSettings, { fields: [] }),
advancedFilterSettings: this.mapAdvanced(),
advancedFilterBegin: function (args) { return _this.advanced(args); },
allowPaging: this.settings.allowPaging, pageSettings: Object.assign({}, this.settings.pageSettings, { pageSize: virtual ? Math.max(40, pageSize) : pageSize, currentPage: page }),
enableVirtualization: virtual, enableColumnVirtualization: this.settings.enableColumnVirtualization,
frozenColumns: 0, showColumnMenu: this.settings.showColumnMenu,
columnMenuItems: this.menuItems(),
aggregates: this.nativeSummaries(),
columnMenuClick: function (args) { return _this.menu(args.item.id, _this.field(args.column.field)); },
columnMenuOpen: function (args) {
var field = _this.field(args.column.field);
var available = _this.columns.some(function (column) {
return column.field === field && column.showColumnMenu !== false;
});
if (!available) {
args.cancel = true;
}
args.items.forEach(function (item) {
if (item.id === parent.grid.element.id + '_colmenu_Filter') {
item.hide = !_this.can(field, 'allowFiltering');
var items = _this.settings.columnMenuItems || [];
var metadata = items.filter(function (entry) { return typeof entry === 'object' && entry.id === 'Filter'; })[0];
if (metadata) {
Eif (metadata.text) {
item.text = metadata.text;
}
Eif (metadata.iconCss) {
item.iconCss = metadata.iconCss;
}
}
}
if (item.id === 'FlatAutoFit') {
item.hide = !_this.can(field, 'allowResizing');
}
if (item.id === 'FlatAutoFitAll') {
item.hide = !_this.columns.some(function (column) { return _this.can(column.field, 'allowResizing'); });
}
});
},
allowResizing: this.settings.allowResizing, allowReordering: this.settings.allowReordering,
allowTextWrap: this.settings.allowTextWrap, textWrapSettings: this.settings.textWrapSettings,
rowHeight: this.settings.rowHeight, gridLines: this.settings.gridLines, clipMode: this.settings.clipMode,
dataStateChange: function (state) { return _this.dataState(state); },
created: function () { return parent.grid.on('beforeCheckboxRenderer', function (args) {
args.executeQuery = false;
}, _this); },
actionBegin: function (args) { return _this.action(args); },
resizeStart: function () { return _this.captureColumnSelection(); },
resizeStop: function () { return _this.persistColumns(false); },
columnDragStart: function () { return _this.captureColumnSelection(); },
columnDrop: function () { return Promise.resolve().then(function () { return _this.persistColumns(true); }); },
queryCellInfo: function (args) {
Iif (generation !== flat.renderGeneration) {
return;
}
var index = ej2_base_1.getValue('flatOrdinal', args.data);
var field = _this.field(args.column.field);
if (_this.columns.some(function (column) { return column.field === field && column.visible === false; })) {
return;
}
try {
if (_this.settings.queryCellInfo) {
var detached = Object.assign({}, args, {
data: flat.project(index, 1)[0], column: _this.physicalColumn(args.column)
});
_this.settings.queryCellInfo.call(parent, detached);
Iif (detached.rowSpan > 1 || detached.colSpan > 1) {
throw new Error('Flat layout does not support cell spanning.');
}
}
}
catch (error) {
flat.failRender(error instanceof Error ? error : new Error('Flat layout settings contain an invalid value.'));
}
},
headerCellInfo: function (args) {
if (generation !== flat.renderGeneration || !_this.settings.headerCellInfo ||
!args.cell || !args.cell.column || args.cell.column.visible === false) {
return;
}
try {
_this.settings.headerCellInfo.call(parent, Object.assign({}, args, {
cell: Object.assign({}, args.cell, { column: _this.physicalColumn(args.cell.column) })
}));
}
catch (error) {
flat.failRender(error instanceof Error ? error : new Error('Flat header rendering failed.'));
}
},
rowSelecting: function (args) { return _this.selection('rowSelecting', args); },
rowDeselecting: function (args) { return _this.selection('rowDeselecting', args); },
rowSelected: function (args) { return _this.selection('rowSelected', args); },
rowDeselected: function (args) { return _this.selection('rowDeselected', args); },
cellSelecting: function (args) { return _this.selection('cellSelecting', args); },
cellSelected: function (args) { return _this.selection('cellSelected', args); },
cellDeselecting: function (args) { return _this.selection('cellDeselecting', args); },
cellDeselected: function (args) { return _this.selection('cellDeselected', args); },
dataBound: function () {
Iif (generation !== flat.renderGeneration) {
return;
}
parent.grid.element.setAttribute('aria-readonly', 'true');
_this.renderTotal();
Eif (!completed) {
completed = true;
var fitted = _this.columns.filter(function (column) {
return column.visible !== false && column.autoFit === true;
}).map(function (column) { return _this.encoded(column.field); });
if (fitted.length) {
parent.grid.autoFitColumns(fitted, 1, 200);
}
if (selected.length) {
parent.grid.selectRows(selected);
}
var nextIndex_1 = function (index) {
var descriptor = Object.getOwnPropertyDescriptor(previousFields, String(index));
return descriptor ? parent.grid.getColumnIndexByField(_this.encoded(descriptor.value)) : -1;
};
if (cells.length) {
var restoredCells = cells.map(function (entry) { return ({ rowIndex: entry.rowIndex,
cellIndexes: entry.cellIndexes.map(nextIndex_1).filter(function (index) { return index !== -1; })
.sort(function (a, b) { return a - b; }) }); }).filter(function (entry) { return entry.cellIndexes.length > 0; });
if (restoredCells.length && parent.grid.selectionSettings.type === 'Single') {
parent.grid.selectCell({ rowIndex: restoredCells[0].rowIndex, cellIndex: restoredCells[0].cellIndexes[0] });
}
else Eif (restoredCells.length) {
parent.grid.selectCells(restoredCells);
}
}
var viewport = parent.grid.getContent().querySelector('.e-content');
Eif (viewport) {
viewport.scrollLeft = left;
viewport.scrollTop = top;
}
var focusColumn = parent.grid.getColumnIndexByField(_this.encoded(focusField));
if (focusRow !== undefined && focusColumn !== -1) {
var cell = parent.grid.getCellFromIndex(focusRow, focusColumn);
Eif (cell) {
cell.focus();
}
}
if (notify) {
flat.dataBound();
}
}
}
});
parent.grid.createElement = parent.createElement;
parent.grid.print = function () { return flat.output.print(); };
var element = parent.createElement('div', { id: parent.element.id + '_grid' });
parent.element.appendChild(element);
parent.notEmpty = true;
parent.isEmptyGrid = false;
parent.grid.appendTo(element);
};
FlatGrid.prototype.selection = function (name, args) {
var _this = this;
var project = function (record) {
return _this.parent.flatLayoutModule.project(ej2_base_1.getValue('flatOrdinal', record), 1)[0];
};
var detached = Object.assign({}, args, {
data: Array.isArray(args.data) ? args.data.map(project) : args.data ? project(args.data) : undefined
});
var callback = ej2_base_1.getValue(name, this.settings);
if (callback) {
callback.call(this.parent, detached);
}
args.cancel = detached.cancel;
};
FlatGrid.prototype.watchWidth = function () {
var _this = this;
if (!this.observer) {
var Observer = ej2_base_1.getValue('ResizeObserver', this.parent.element.ownerDocument.defaultView);
Eif (Observer) {
this.observer = new Observer(function () {
Iif (!_this.parent.isDestroyed && _this.parent.flatLayoutModule.active && _this.parent.grid &&
_this.pinningSuspended === flat_util_1.flatPinsFit(_this.settings, _this.viewportWidth())) {
_this.render(false);
}
});
this.observer.observe(this.parent.element);
}
}
Iif (this.pinNotice && this.pinNotice.parentElement) {
ej2_base_1.remove(this.pinNotice);
}
this.pinNotice = undefined;
Iif (this.pinningSuspended) {
this.pinNotice = this.parent.createElement('div', { className: 'e-pivot-flat-pin-notice', attrs: { role: 'status' } });
this.pinNotice.textContent = this.parent.localeObj.getConstant('flatPinningSuspended');
this.parent.element.appendChild(this.pinNotice);
}
};
FlatGrid.prototype.schedule = function (settings) {
var _this = this;
Iif (this.pending) {
return;
}
this.pending = true;
var generation = this.generation;
Promise.resolve().then(function () {
_this.pending = false;
if (_this.parent.isDestroyed || _this.parent.flatLayoutModule.renderGeneration !== generation) {
return;
}
_this.parent.setProperties({ flatSettings: settings }, false);
_this.parent.dataBind();
});
};
FlatGrid.prototype.action = function (args) {
var _this = this;
if (args.requestType === 'searching') {
args.cancel = true;
this.schedule({ searchSettings: Object.assign({}, this.settings.searchSettings, { key: this.parent.grid.searchSettings.key }) });
}
else if (args.requestType === 'columnstate') {
args.cancel = true;
this.captureColumnSelection();
var current_1 = this.parent.grid.getColumns();
var columns = this.columns.filter(function (column) {
return current_1.some(function (entry) { return _this.field(entry.field) === column.field && entry.visible !== false; }) ||
_this.settings.columns.some(function (entry) { return entry.field === column.field; });
})
.map(function (column) { return Object.assign({}, column, {
visible: current_1.filter(function (entry) { return _this.field(entry.field) === column.field; })[0].visible !== false
}); });
this.columnAction = true;
this.schedule({ columns: columns, frozenColumns: Math.min(this.settings.frozenColumns || 0, columns.filter(function (column) { return column.visible !== false; }).length) });
}
else if (args.requestType === 'sorting') {
args.cancel = true;
var field = this.field(args.columnName);
Iif (field && !this.can(field, 'allowSorting')) {
return;
}
var sort_1 = flat_util_1.cloneFlat(this.parent.grid.sortSettings);
sort_1.columns = (sort_1.columns || []).map(function (entry) {
return ({ field: _this.field(entry.field), direction: entry.direction });
});
Eif (!field && (this.settings.sortSettings.columns || []).some(function (entry) {
return !_this.can(entry.field, 'allowSorting') && !sort_1.columns.some(function (candidate) {
return candidate.field === entry.field && candidate.direction === entry.direction;
});
})) {
return;
}
this.schedule({ sortSettings: sort_1 });
}
else if (args.requestType === 'filtering') {
var field = this.field(args.currentFilteringColumn);
Iif (args.action !== 'clear-filter' && field && !this.can(field, 'allowFiltering')) {
args.cancel = true;
return;
}
var columns = (args.columns || this.parent.grid.filterSettings.columns || [])
.map(function (entry) {
var predicate = Object.assign({}, flat_util_1.cloneFlat(entry), { field: _this.field(entry.field) });
delete predicate.uid;
return predicate;
});
this.schedule({ filterSettings: Object.assign({}, this.settings.filterSettings, { columns: columns }) });
}
else if (args.requestType === 'paging') {
args.cancel = true;
this.schedule({ pageSettings: Object.assign({}, this.settings.pageSettings, {
currentPage: Number(args.currentPage), pageSize: this.parent.grid.pageSettings.pageSize
}) });
}
else Iif (args.requestType === 'refresh' && this.pending) {
args.cancel = true;
}
};
FlatGrid.prototype.dataState = function (state) {
var _this = this;
var flat = this.parent.flatLayoutModule;
Iif (this.parent.isDestroyed || this.generation !== flat.renderGeneration) {
return;
}
if (state.dataSource) {
var encoded_1 = ej2_base_1.getValue('action.filterModel.options.field', state);
var field = this.field(encoded_1);
if (!field) {
state.dataSource([]);
return;
}
var search = ej2_base_1.getValue('action.filterModel.sInput.value', state) || '';
var normalize_1 = function (value) {
var text = _this.settings.filterSettings.ignoreAccent ? ej2_data_1.DataUtil.ignoreDiacritics(value) : value;
return _this.settings.filterSettings.enableCaseSensitivity ? text : text.toLocaleLowerCase.call(text, _this.parent.locale);
};
var key_1 = normalize_1(search);
var values = flat.query.facet(field).filter(function (value) { return !key_1 ||
normalize_1(value === null ? '' : value instanceof Date ? value.toLocaleDateString(_this.parent.locale) : String(value))
.indexOf(key_1) !== -1; }).map(function (value) {
var _a;
return (_a = {}, _a[encoded_1] = value, _a);
});
state.dataSource(this.settings.filterSettings.enableInfiniteScrolling ? {
result: values.slice(state.skip || 0, (state.skip || 0) + (state.take || values.length)), count: values.length
} : values);
return;
}
Eif (this.pending) {
return;
}
this.parent.grid.dataSource = {
result: flat.columns.length ? this.frame(state.skip || 0, state.take || flat.query.ordinals.length) : [],
count: flat.columns.length ? flat.query.ordinals.length : 0, aggregates: this.aggregateValues()
};
};
FlatGrid.prototype.mapAdvanced = function () {
var _this = this;
var settings = flat_util_1.cloneFlat(this.settings.advancedFilterSettings || {});
var map = function (rule) {
Iif (!rule) {
return rule;
}
if (rule.rules) {
rule.rules = rule.rules.map(map);
}
else Eif (rule.field) {
rule.field = _this.encoded(rule.field);
}
return rule;
};
settings.queryBuilderSettings = settings.queryBuilderSettings || {};
var hasCondition = function (rule) {
return !!rule && (!!rule.not || (rule.rules ? rule.rules.some(hasCondition) : !!rule.field));
};
var rule = settings.queryBuilderSettings.rule;
settings.queryBuilderSettings.rule = hasCondition(rule) ? map(rule) : undefined;
return settings;
};
FlatGrid.prototype.advanced = function (args) {
var _this = this;
args.cancel = true;
var rule = flat_util_1.cloneFlat(args.rule || { condition: 'and', rules: [] });
var map = function (entry) {
if (entry.rules) {
entry.rules.forEach(map);
}
else Eif (entry.field) {
entry.field = _this.field(entry.field);
}
};
map(rule);
var previous = this.settings.advancedFilterSettings.queryBuilderSettings.rule;
var protectedRules = function (entry, parents) {
if (parents === void 0) { parents = []; }
Iif (!entry) {
return [];
}
if (entry.rules) {
return entry.rules.reduce(function (all, child) { return all.concat(protectedRules(child, parents.concat(String(entry.condition) + ':' + !!entry.not))); }, []);
}
var column = _this.columns.filter(function (item) { return item.field === entry.field; })[0];
return column && column.allowFiltering === false ? [JSON.stringify([parents, entry])] : [];
};
var clearing = rule.rules && rule.rules.length === 0;
var permitted = this.settings.allowAdvancedFiltering && (clearing ||
JSON.stringify(protectedRules(previous).sort()) === JSON.stringify(protectedRules(rule).sort()));
if (!permitted) {
this.pending = true;
Promise.resolve().then(function () {
Iif (_this.parent.isDestroyed) {
return;
}
_this.render(false);
_this.parent.actionFailureMethod(new Error(_this.parent.localeObj.getConstant('flatFilteringDisabled')));
});
return;
}
this.schedule({ advancedFilterSettings: Object.assign({}, this.settings.advancedFilterSettings, {
queryBuilderSettings: Object.assign({}, this.settings.advancedFilterSettings.queryBuilderSettings, { rule: rule })
}) });
};
FlatGrid.prototype.menuItems = function () {
var _this = this;
var defaults = ['SortAscending', 'SortDescending', 'Filter', 'AutoFit', 'AutoFitAll', 'ColumnChooser'];
var items = this.settings.columnMenuItems || defaults;
return items.filter(function (item) {
var id = typeof item === 'string' ? item : item.id;
return id !== 'ColumnChooser' || _this.settings.showColumnChooser;
}).map(function (item) {
var id = typeof item === 'string' ? item : item.id;
if (id === 'ColumnChooser') {
return item;
}
var metadata = typeof item === 'object' ? flat_util_1.cloneFlat(item) : {};
if (id === 'Filter') {
return 'Filter';
}
if (['AutoFit', 'AutoFitAll'].indexOf(id) !== -1) {
return Object.assign(metadata, { id: 'Flat' + id, text: metadata.text ||
_this.parent.localeObj.getConstant('flat' + id) });
}
if (id.indexOf('FlatFreeze') === 0 || id === 'FlatUnfreeze') {
return Object.assign(metadata, { id: id, text: metadata.text ||
_this.parent.localeObj.getConstant(id.charAt(0).toLowerCase() + id.slice(1)) });
}
return typeof item === 'string' ? item : Object.assign({}, item, { id: _this.parent.element.id + '_grid_colmenu_' + id });
});
};
FlatGrid.prototype.menu = function (id, field) {
var descriptor = this.settings.columns.filter(function (column) { return column.field === field; })[0];
if (!this.settings.showColumnMenu || !descriptor || descriptor.showColumnMenu === false) {
return;
}
if (id === 'FlatAutoFit' || id === 'FlatAutoFitAll') {
this.autoFit(id === 'FlatAutoFit' ? field : undefined);
return;
}
var direction;
switch (id) {
case 'FlatFreezeLeft':
direction = 'Left';
break;
case 'FlatFreezeRight':
direction = 'Right';
break;
case 'FlatFreezeFixed':
direction = 'Fixed';
break;
case 'FlatUnfreeze':
direction = 'None';
break;
}
if (direction) {
var columns = flat_util_1.cloneFlat(this.settings.columns);
if (this.settings.frozenColumns) {
columns.filter(function (column) { return column.visible !== false; }).slice(0, this.settings.frozenColumns)
.forEach(function (column) { column.freeze = 'Left'; });
}
var column = columns.filter(function (entry) { return entry.field === field; })[0];
column.freeze = direction;
column.isFrozen = false;
this.schedule({ columns: columns, frozenColumns: 0 });
}
};
FlatGrid.prototype.autoFit = function (field) {
var _this = this;
var grid = this.parent.grid;
var fields = this.columns.filter(function (column) { return column.visible !== false &&
(!field || field === column.field) && _this.can(column.field, 'allowResizing'); })
.map(function (column) { return _this.encoded(column.field); });
Iif (!fields.length) {
return;
}
this.captureColumnSelection();
grid.autoFitColumns(fields, 1, 200);
this.persistColumns(false);
};
FlatGrid.prototype.persistColumns = function (reorder) {
var _this = this;
var current = this.parent.grid.getColumns();
var selected = this.columns.filter(function (column) {
return _this.settings.columns.some(function (entry) { return entry.field === column.field; });
});
var columns = reorder ? current.filter(function (column) { return selected.some(function (entry) { return entry.field === _this.field(column.field); }); }).map(function (column) {
return flat_util_1.cloneFlat(_this.columns[Number(column.field.slice(4))]);
}) : flat_util_1.cloneFlat(selected);
columns.forEach(function (column) {
var native = current.filter(function (entry) { return _this.field(entry.field) === column.field; })[0];
if (native && _this.can(column.field, 'allowResizing')) {
column.width = typeof native.width === 'string' && native.width.trim().endsWith('px') ?
parseFloat(native.width) : native.width;
}
});
if (JSON.stringify(columns) === JSON.stringify(this.settings.columns)) {
this.columnSelection = undefined;
return;
}
this.columnAction = true;
this.schedule({ columns: columns });
};
FlatGrid.prototype.captureColumnSelection = function () {
var _this = this;
var grid = this.parent.grid;
var focused = this.parent.element.ownerDocument.activeElement;
var info = grid.element.contains(focused) && focused.closest('.e-rowcell') ? grid.getRowInfo(focused) : undefined;
var column = info && info.column;
this.columnSelection = { rows: grid.allowSelection ? grid.getSelectedRowIndexes().slice() : [],
cells: grid.allowSelection ? flat_util_1.cloneFlat(grid.getSelectedRowCellIndexes()) : [],
fields: grid.getColumns().map(function (entry) { return _this.field(entry.field); }),
focus: column ? { row: info.rowIndex, field: this.field(column.field) } : undefined };
};
FlatGrid.prototype.nativeSummaries = function () {
var _this = this;
var values = this.parent.flatLayoutModule.summaries.values;
var aggregates = this.settings.aggregates && this.settings.aggregates[0] &&
this.settings.aggregates[0].columns || [];
var columns = aggregates.filter(function (aggregate) {
return Object.prototype.hasOwnProperty.call(values, aggregate.field);
}).map(function (aggregate) { return ({
field: _this.encoded(aggregate.field), type: aggregate.type, format: aggregate.format,
customAggregate: aggregate.type === 'Custom' ? function () { return values[aggregate.field]; } : undefined,
footerTemplate: function (data) {
var span = _this.parent.createElement('span');
var value = data[aggregate.type];
span.textContent = value === undefined || value === null ? '' : String(value);
return [span];
}
}); });
return columns.length ? [{ columns: columns }] : [];
};
FlatGrid.prototype.aggregateValues = function () {
var _this = this;
var values = this.parent.flatLayoutModule.summaries.values;
var result = Object.create(null);
var row = this.settings.aggregates && this.settings.aggregates[0];
(row && row.columns || []).forEach(function (column) {
if (Object.prototype.hasOwnProperty.call(values, column.field)) {
result[_this.encoded(column.field) + ' - ' + column.type.toLowerCase()] = values[column.field];
}
});
return result;
};
FlatGrid.prototype.renderTotal = function () {
this.total = this.parent.grid.element.querySelector('.e-gridfooter');
if (!this.total) {
return;
}
this.total.classList.add('e-pivot-flat-totals');
this.total.setAttribute('aria-label', this.parent.localeObj.getConstant('total'));
if (this.settings.totalsPosition === 'Top') {
this.parent.grid.element.insertBefore(this.total, this.parent.grid.getContent());
}
};
FlatGrid.prototype.removeTotal = function () { this.total = undefined; };
FlatGrid.prototype.destroy = function () {
if (this.observer) {
this.observer.disconnect();
this.observer = undefined;
}
Iif (this.pinNotice && this.pinNotice.parentElement) {
ej2_base_1.remove(this.pinNotice);
}
this.pinNotice = undefined;
this.renderedStore = undefined;
this.renderedOrdinals = [];
this.columnSelection = undefined;
this.columnAction = false;
this.removeTotal();
this.columns = [];
this.settings = undefined;
};
return FlatGrid;
}());
exports.FlatGrid = FlatGrid;
});
|