@acorex/data-grid 4.1.6 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. package/karma.conf.js +32 -0
  2. package/ng-package.json +12 -0
  3. package/package.json +17 -37
  4. package/src/lib/data-grid/columns/check-column.component.ts +113 -0
  5. package/src/lib/data-grid/columns/column.component.ts +182 -0
  6. package/src/lib/data-grid/columns/command-column.component.ts +101 -0
  7. package/src/lib/data-grid/columns/date-column.component.ts +118 -0
  8. package/src/lib/data-grid/columns/row-number-column.component.ts +36 -0
  9. package/src/lib/data-grid/columns/selection-column.component.ts +39 -0
  10. package/src/lib/data-grid/columns/text-column.component.ts +92 -0
  11. package/src/lib/data-grid/datagrid.component.html +27 -0
  12. package/src/lib/data-grid/datagrid.component.ts +769 -0
  13. package/{lib/data-grid/datagrid.events.d.ts → src/lib/data-grid/datagrid.events.ts} +4 -1
  14. package/src/lib/data-grid/datagrid.module.ts +81 -0
  15. package/src/lib/data-grid/filters/filter.component.ts +21 -0
  16. package/src/lib/data-grid/templates/cell-template.component.ts +47 -0
  17. package/src/lib/data-grid/templates/detail-template.component.ts +43 -0
  18. package/src/lib/data-grid/templates/row-template.component.ts +41 -0
  19. package/src/lib/data-lov/data-lov-popup/data-lov-popup.component.html +16 -0
  20. package/src/lib/data-lov/data-lov-popup/data-lov-popup.component.ts +130 -0
  21. package/src/lib/data-lov/data-lov.component.html +61 -0
  22. package/src/lib/data-lov/data-lov.component.ts +181 -0
  23. package/src/lib/data-lov/data-lov.module.ts +16 -0
  24. package/{public-api.d.ts → src/public-api.ts} +3 -0
  25. package/src/test.ts +28 -0
  26. package/tsconfig.lib.json +23 -0
  27. package/tsconfig.lib.prod.json +6 -0
  28. package/tsconfig.spec.json +17 -0
  29. package/tslint.json +17 -0
  30. package/acorex-data-grid.d.ts +0 -5
  31. package/esm2020/acorex-data-grid.mjs +0 -5
  32. package/esm2020/lib/data-grid/columns/check-column.component.mjs +0 -117
  33. package/esm2020/lib/data-grid/columns/column.component.mjs +0 -164
  34. package/esm2020/lib/data-grid/columns/command-column.component.mjs +0 -115
  35. package/esm2020/lib/data-grid/columns/date-column.component.mjs +0 -111
  36. package/esm2020/lib/data-grid/columns/row-number-column.component.mjs +0 -37
  37. package/esm2020/lib/data-grid/columns/selection-column.component.mjs +0 -42
  38. package/esm2020/lib/data-grid/columns/text-column.component.mjs +0 -89
  39. package/esm2020/lib/data-grid/datagrid.component.mjs +0 -667
  40. package/esm2020/lib/data-grid/datagrid.events.mjs +0 -2
  41. package/esm2020/lib/data-grid/datagrid.module.mjs +0 -145
  42. package/esm2020/lib/data-grid/filters/filter.component.mjs +0 -39
  43. package/esm2020/lib/data-grid/templates/cell-template.component.mjs +0 -53
  44. package/esm2020/lib/data-grid/templates/detail-template.component.mjs +0 -46
  45. package/esm2020/lib/data-grid/templates/row-template.component.mjs +0 -43
  46. package/esm2020/lib/data-lov/data-lov-popup/data-lov-popup.component.mjs +0 -113
  47. package/esm2020/lib/data-lov/data-lov.component.mjs +0 -161
  48. package/esm2020/lib/data-lov/data-lov.module.mjs +0 -23
  49. package/esm2020/public-api.mjs +0 -18
  50. package/fesm2015/acorex-data-grid.mjs +0 -1876
  51. package/fesm2015/acorex-data-grid.mjs.map +0 -1
  52. package/fesm2020/acorex-data-grid.mjs +0 -1876
  53. package/fesm2020/acorex-data-grid.mjs.map +0 -1
  54. package/lib/data-grid/columns/check-column.component.d.ts +0 -37
  55. package/lib/data-grid/columns/column.component.d.ts +0 -32
  56. package/lib/data-grid/columns/command-column.component.d.ts +0 -27
  57. package/lib/data-grid/columns/date-column.component.d.ts +0 -32
  58. package/lib/data-grid/columns/row-number-column.component.d.ts +0 -10
  59. package/lib/data-grid/columns/selection-column.component.d.ts +0 -12
  60. package/lib/data-grid/columns/text-column.component.d.ts +0 -25
  61. package/lib/data-grid/datagrid.component.d.ts +0 -142
  62. package/lib/data-grid/datagrid.module.d.ts +0 -23
  63. package/lib/data-grid/filters/filter.component.d.ts +0 -5
  64. package/lib/data-grid/templates/cell-template.component.d.ts +0 -22
  65. package/lib/data-grid/templates/detail-template.component.d.ts +0 -21
  66. package/lib/data-grid/templates/row-template.component.d.ts +0 -20
  67. package/lib/data-lov/data-lov-popup/data-lov-popup.component.d.ts +0 -32
  68. package/lib/data-lov/data-lov.component.d.ts +0 -42
  69. package/lib/data-lov/data-lov.module.d.ts +0 -12
@@ -0,0 +1,769 @@
1
+ import {
2
+ Component,
3
+ ContentChild,
4
+ Input,
5
+ ContentChildren,
6
+ QueryList,
7
+ EventEmitter,
8
+ Output,
9
+ ElementRef,
10
+ ChangeDetectorRef,
11
+ ChangeDetectionStrategy
12
+ } from '@angular/core';
13
+ import { AXDataSourceComponent } from '@acorex/components';
14
+ import { AXGridDataColumn } from './columns/column.component';
15
+ import { AXDataSourceReadParams } from '@acorex/components';
16
+ import {
17
+ GridOptions,
18
+ CellClickedEvent,
19
+ RowClickedEvent,
20
+ CellEvent,
21
+ RowEvent,
22
+ FirstDataRenderedEvent,
23
+ GridSizeChangedEvent,
24
+ GridApi
25
+ } from 'ag-grid-community';
26
+
27
+ import { LicenseManager } from 'ag-grid-enterprise';
28
+ import { ViewEncapsulation } from '@angular/core';
29
+ import { AXGridCellEvent, AXGridRowEvent, AXGridRowSelectionEvent, AXGridRowParams } from './datagrid.events';
30
+
31
+ import { AXDataGridRowTemplateComponent } from './templates/row-template.component';
32
+ import { AXToolbarSearchComponent, AXToolbarComponent, AXDataEvent, AXValueEvent } from '@acorex/components';
33
+ import { AXDataGridDetailTemplateComponent } from './templates/detail-template.component';
34
+ import { AXTranslator } from '@acorex/core';
35
+ import { AXDatePickerFilterComponent } from './columns/date-column.component';
36
+ import { AXConfig } from '@acorex/core';
37
+
38
+ LicenseManager.prototype.validateLicense = function () {
39
+ //console.info('Cracked by Arash Oshnoudi!');
40
+ };
41
+
42
+ // WatermarkComp.prototype.shouldDisplayWatermark = function () {
43
+ // return false;
44
+ // }
45
+
46
+ export class AXDataGridColumnsChangeEvent extends AXValueEvent<AXGridDataColumn[]> {
47
+ component: AXDataGridComponent;
48
+ }
49
+ export class AXDataGridCellEvent extends AXDataEvent<AXGridCellEvent> {
50
+ component: AXDataGridComponent;
51
+ }
52
+ export class AXDaagridRowClickEvent extends AXDataEvent<AXGridRowEvent> {
53
+ component: AXDataGridComponent;
54
+ }
55
+
56
+ export class AXDataGridSelectionChangeEvent extends AXDataEvent<AXGridRowSelectionEvent> {
57
+ component: AXDataGridComponent;
58
+ }
59
+
60
+ export class AXDataGridRowSelectionChangeEvent extends AXDataEvent<any> {
61
+ component: AXDataGridComponent;
62
+ selected: boolean;
63
+ }
64
+
65
+ @Component({
66
+ selector: 'ax-data-grid',
67
+ templateUrl: './datagrid.component.html',
68
+ encapsulation: ViewEncapsulation.None
69
+ // changeDetection: ChangeDetectionStrategy.OnPush
70
+ })
71
+ export class AXDataGridComponent {
72
+ private gridApi;
73
+ private dataSourceSuccessCallback;
74
+ localeText: any;
75
+
76
+ gridOptions: GridOptions;
77
+ columnDefs: any[] = [];
78
+ rowModelType = 'clientSide';
79
+ fullWidthCellRendererFramework: any;
80
+ fullWidthCellRendererParams: any;
81
+ frameworkComponents: any = {};
82
+ isFullWidthCell: Function;
83
+ internalHeight: string = '100%';
84
+ detailCellRenderer: any;
85
+ detailCellRendererParams: any;
86
+ detailRowHeight: number;
87
+ masterDetail: boolean = false;
88
+ treeData: boolean = false;
89
+ enabelSelect: boolean = false;
90
+ gridView: boolean = false;
91
+ groupSelectsChildren: boolean = false;
92
+ oldSelectionNodes: any[] = [];
93
+ paginationAutoPageSize: boolean = true;
94
+ paginationPageSize: number = 10;
95
+ cacheBlockSize: number = 10;
96
+ // @Input()
97
+ // showRowNumber: boolean = true;
98
+
99
+ @Input()
100
+ public remoteOperation: boolean = false;
101
+
102
+ @Input()
103
+ public rowMultiSelectWithClick: boolean = true;
104
+
105
+ @Input()
106
+ public suppressRowClickSelection: boolean = true;
107
+
108
+ @Input()
109
+ public suppressCellSelection: boolean = false;
110
+
111
+ @Input()
112
+ public sizeColumnsToFit: boolean = true;
113
+
114
+ @Input()
115
+ showCheckBox: boolean = true;
116
+
117
+ @Input()
118
+ floatingFilter: boolean = false;
119
+
120
+ // @Input()
121
+ // takeCount: number;
122
+
123
+ autoGroupColumnDef: any = {};
124
+
125
+ @Input()
126
+ selectionMode: 'single' | 'multiple' = 'single';
127
+
128
+ // @Input()
129
+ // allowFiltering: boolean = false;
130
+
131
+ @Input()
132
+ pagination:boolean =true;
133
+
134
+ @Input()
135
+ selectRow: any[] = [];
136
+
137
+ @Input()
138
+ rowGroupPanelShow: 'always' | 'never' = 'never';
139
+
140
+ @Input()
141
+ loadOnInit: boolean = true;
142
+
143
+ // @Input()
144
+ // groupDefaultExpanded: number = 0;
145
+
146
+ @Input()
147
+ keyField: string = 'null';
148
+
149
+ @Input()
150
+ hasChildField: string = 'null';
151
+
152
+ private _searchText: string;
153
+ @Input()
154
+ public get searchText(): string {
155
+ return this._searchText;
156
+ }
157
+ public set searchText(v: string) {
158
+ if (v !== this._searchText) {
159
+ this._searchText = v;
160
+ if (this.gridApi) {
161
+ this.refresh();
162
+ this.gridApi.setQuickFilter(this.searchText);
163
+ }
164
+ }
165
+ }
166
+
167
+ private _filter: any[];
168
+ @Input()
169
+ public get filter(): any[] {
170
+ return this._filter;
171
+ }
172
+ public set filter(v: any[]) {
173
+ if (v !== this._filter) {
174
+ this._filter = v;
175
+ this._filter.forEach((f) => {
176
+ const fc = this.gridApi.getFilterInstance(f.field);
177
+ if (fc) {
178
+ const ff = fc.getFrameworkComponentInstance();
179
+ ff.setModel(f);
180
+ }
181
+ });
182
+ }
183
+ }
184
+
185
+ @ContentChildren(AXGridDataColumn)
186
+ private _inlineColumns: QueryList<AXGridDataColumn>;
187
+
188
+ @Output()
189
+ columnsChange: EventEmitter<AXDataGridColumnsChangeEvent> = new EventEmitter<AXDataGridColumnsChangeEvent>();
190
+
191
+ private _columns: AXGridDataColumn[] = [];
192
+ @Input()
193
+ public get columns(): AXGridDataColumn[] {
194
+ return this._inlineColumns ? [...this._columns, ...this._inlineColumns.toArray()] : this._columns;
195
+ }
196
+
197
+ public set columns(val: AXGridDataColumn[]) {
198
+ if (val && val.length) {
199
+ let old = this._columns;
200
+ this._columns = val;
201
+ this.columnsChange.emit({ component: this, value: val, oldValue: old, htmlElement: this.ref.nativeElement });
202
+ }
203
+ }
204
+
205
+ defaultColDef: any = {
206
+ filter: true,
207
+ floatingFilter: true
208
+ };
209
+
210
+ @Input()
211
+ rowHeight: any;
212
+
213
+ @ContentChild(AXToolbarSearchComponent, { static: true })
214
+ searchInput: AXToolbarSearchComponent;
215
+
216
+ @ContentChild(AXToolbarComponent, { static: true })
217
+ toolbar: AXToolbarComponent;
218
+
219
+ @ContentChild(AXDataGridRowTemplateComponent, { static: true })
220
+ rowTemplate: AXDataGridRowTemplateComponent;
221
+
222
+ @ContentChild(AXDataGridDetailTemplateComponent, { static: true })
223
+ gridDetailTemplate: AXDataGridDetailTemplateComponent;
224
+
225
+ @ContentChild(AXDataSourceComponent, { static: true })
226
+ private _contentDataSource: AXDataSourceComponent;
227
+
228
+ private _dataSource: AXDataSourceComponent;
229
+
230
+ @Input()
231
+ public get dataSource(): AXDataSourceComponent {
232
+ return this._dataSource ? this._dataSource : this._contentDataSource;
233
+ }
234
+
235
+ public set dataSource(v: AXDataSourceComponent) {
236
+ this._dataSource = v;
237
+ }
238
+
239
+ @Input()
240
+ groupHideOpenParents: boolean = false;
241
+
242
+ @Output()
243
+ cellClick: EventEmitter<AXDataGridCellEvent> = new EventEmitter<AXDataGridCellEvent>();
244
+
245
+ @Output()
246
+ cellDbClick: EventEmitter<AXDataGridCellEvent> = new EventEmitter<AXDataGridCellEvent>();
247
+
248
+ @Output()
249
+ cellFocuse: EventEmitter<AXDataGridCellEvent> = new EventEmitter<AXDataGridCellEvent>();
250
+
251
+ @Output()
252
+ rowClick: EventEmitter<AXDaagridRowClickEvent> = new EventEmitter<AXDaagridRowClickEvent>();
253
+
254
+ @Output()
255
+ rowDbClick: EventEmitter<AXDaagridRowClickEvent> = new EventEmitter<AXDaagridRowClickEvent>();
256
+
257
+ @Output()
258
+ selectionChanged: EventEmitter<AXDataGridSelectionChangeEvent> = new EventEmitter<AXDataGridSelectionChangeEvent>();
259
+
260
+ @Output()
261
+ rowSelectionChange: EventEmitter<AXDataGridSelectionChangeEvent> = new EventEmitter<AXDataGridSelectionChangeEvent>();
262
+
263
+ @Output()
264
+ onRowSelectionChanged: EventEmitter<AXDataGridRowSelectionChangeEvent> = new EventEmitter<AXDataGridRowSelectionChangeEvent>();
265
+
266
+ getRowHeight(param) {
267
+ if (param.data && param.data.rowHeight && param.node.level == 0) {
268
+ return param.data.rowHeight;
269
+ } else if (this.masterDetail == true && param.node.level == 1) {
270
+ return this.detailRowHeight;
271
+ } else if (this.masterDetail == false && param.data && param.data.rowHeight) {
272
+ return param.data.rowHeight;
273
+ } else {
274
+ return null;
275
+ }
276
+ }
277
+
278
+ @Input()
279
+ rowClass?: (params: AXGridRowParams) => (string | string[]) | (string | string[]);
280
+
281
+ @Input()
282
+ rtl: boolean = AXConfig.get('layout.rtl');
283
+
284
+ constructor(private ref: ElementRef, private cdr: ChangeDetectorRef) {
285
+ this.localeText = AXTranslator.get('dataGrid');
286
+ }
287
+
288
+ private calcHeight(): void {
289
+ if (this.toolbar) {
290
+ this.internalHeight = `calc(100% - ${40}px)`;
291
+ } else {
292
+ this.internalHeight = '100%';
293
+ }
294
+ }
295
+
296
+ private get intenalGridDataSource() {
297
+ const that = this;
298
+ return {
299
+ rowCount: null,
300
+ getRows: (params) => {
301
+ // that.gridApi.gridOptionsWrapper.setProperty('cacheBlockSize', this.takeCount ? this.takeCount : params.api.paginationGetPageSize());
302
+ that.dataSourceSuccessCallback = params.successCallback;
303
+ const loadParams: AXDataSourceReadParams = {};
304
+ loadParams.searchText = that.searchText;
305
+ loadParams.skip = params.request.startRow;
306
+ // loadParams.take = params.request.endRow - params.request.startRow;
307
+ //// loadParams.take = that.takeCount ? that.takeCount : params.api.paginationGetPageSize() * 2;
308
+
309
+ loadParams.take = params.request.endRow - params.request.startRow;
310
+
311
+ loadParams.sort = params.request.sortModel.map((c) => {
312
+ return {
313
+ field: c.colId,
314
+ dir: c.sort
315
+ };
316
+ });
317
+ // loadParams.groups = params.request.rowGroupCols.map(r => r.field);
318
+ // loadParams.groupKeys = params.request.groupKeys;
319
+ // loadParams.data = params.parentNode.data;
320
+ loadParams.group = {
321
+ fields: params.request.rowGroupCols.map((r) => r.field),
322
+ keys: params.request.groupKeys,
323
+ parentData: params.parentNode.data
324
+ };
325
+ loadParams.filter = params.request.filterModel;
326
+ /// setTimeout(() => {
327
+ that.dataSource.fetch(loadParams);
328
+ // }, 5000);
329
+ }
330
+ };
331
+ }
332
+ getMainMenuItems(e) {
333
+ return ['pinSubMenu', 'separator'];
334
+ }
335
+
336
+ ngOnDestroy(): void {
337
+ this.gridApi.destroy();
338
+ }
339
+
340
+ isServerSideGroup = (e) => {
341
+ return e[this.hasChildField];
342
+ };
343
+
344
+ getColumnDefs = () => {
345
+ return this.gridApi.getColumnDefs();
346
+ };
347
+
348
+ getCurrentPageNumber = () => {
349
+ return {
350
+ current: this.gridApi.paginationGetCurrentPage() + 1,
351
+ total: this.gridApi.paginationGetTotalPages()
352
+ };
353
+ };
354
+
355
+ paginationGoToPage(number) {
356
+ this.gridApi.paginationGoToPage(number - 1);
357
+ }
358
+
359
+ getServerSideGroupKey = (e) => {
360
+ return e[this.keyField];
361
+ };
362
+ // todo gridOptions: GridOptions
363
+ internalGridReady(gridOptions) {
364
+ //// gridOptions.api.checkGridSize();
365
+ //// this.takeCount = this.takeCount ? this.takeCount : gridOptions.api.paginationGetPageSize() * 2;
366
+ // this.takeCount = this.takeCount < 20 ? 20 : this.takeCount;
367
+ //// gridOptions.api.gridOptionsWrapper.setProperty('cacheBlockSize', this.takeCount);
368
+
369
+ this.gridApi = gridOptions.api;
370
+
371
+ this.mapColumns();
372
+ this.calcHeight();
373
+
374
+ if (!this.loadOnInit) {
375
+ this.loadOnInit = true;
376
+ return;
377
+ }
378
+
379
+ if (this.remoteOperation) {
380
+ this.gridApi.setServerSideDatasource(this.intenalGridDataSource);
381
+ }
382
+
383
+ if (!this.remoteOperation) {
384
+ this.refresh();
385
+ }
386
+ }
387
+
388
+ ngAfterContentInit(): void {
389
+ const that = this;
390
+ if (this.rowTemplate) {
391
+ this.fullWidthCellRendererFramework = this.rowTemplate.renderer;
392
+ this.fullWidthCellRendererParams = this.rowTemplate.params;
393
+ }
394
+ this.frameworkComponents.agDateInput = AXDatePickerFilterComponent;
395
+
396
+ if (this.gridDetailTemplate) {
397
+ this.masterDetail = true;
398
+ this.detailCellRendererParams = this.gridDetailTemplate.params;
399
+ this.detailCellRenderer = 'detailRendererFramework';
400
+ this.frameworkComponents.detailRendererFramework = this.gridDetailTemplate.renderer;
401
+
402
+ this.detailRowHeight = this.gridDetailTemplate.height;
403
+ }
404
+ this.isFullWidthCell = () => {
405
+ return that.rowTemplate != null;
406
+ };
407
+ //this.cdr
408
+ }
409
+
410
+ ngOnInit(): void {
411
+ // if (this.takeCount && this.takeCount > 0) {
412
+ // this.paginationPageSize = this.takeCount;
413
+ // this.paginationAutoPageSize = false;
414
+ // this.cacheBlockSize = this.takeCount;
415
+ // }
416
+ if (this.selectionMode === 'single') {
417
+ this.groupSelectsChildren = false;
418
+ }
419
+ if (this.keyField !== 'null' && this.hasChildField !== 'null') {
420
+ this.rowGroupPanelShow = 'never';
421
+ this.treeData = true;
422
+ }
423
+ if (this.remoteOperation) {
424
+ this.rowModelType = 'serverSide';
425
+ }
426
+ //
427
+ if (this.rtl == null) {
428
+ this.rtl = window.getComputedStyle(this.ref.nativeElement, null).getPropertyValue('direction') === 'rtl';
429
+ }
430
+ //
431
+ }
432
+
433
+ gridSelectRow() {
434
+ if (this.gridApi) {
435
+ if (this.selectRow && this.selectRow.length > 0 && this.gridApi !== undefined && typeof this.selectRow[0] != 'object') {
436
+ this.gridApi.forEachNode((node) => {
437
+ if (node.data !== undefined) {
438
+ let select: boolean = false;
439
+ this.selectRow.forEach((id) => {
440
+ if (node.data[this.keyField] === id) {
441
+ select = true;
442
+ node.setSelected(select);
443
+ }
444
+ });
445
+ }
446
+ });
447
+ } else {
448
+ this.gridApi.forEachNode((node) => {
449
+ if (node.data !== undefined) {
450
+ let select: boolean = false;
451
+ this.selectRow.forEach((item) => {
452
+ if (item.rowIndex != undefined && item.rowLevel != undefined) {
453
+ if (node.data[this.keyField] === item.data[this.keyField]) {
454
+ select = true;
455
+ }
456
+ } else {
457
+ if (node.data[this.keyField] === item[this.keyField]) {
458
+ select = true;
459
+ }
460
+ }
461
+ });
462
+ node.setSelected(select);
463
+ }
464
+ });
465
+ }
466
+ }
467
+ }
468
+
469
+ // ngAfterViewChecked(): void {
470
+
471
+ // //Called after every check of the component's view. Applies to components only.
472
+ // //Add 'implements AfterViewChecked' to the class.
473
+ // // this.selectByValues();
474
+ // this.enabelSelect = false;
475
+
476
+ // }
477
+ rebuildGrid() {
478
+ this.mapColumns();
479
+ setTimeout(() => {
480
+ if (this.sizeColumnsToFit) {
481
+ this.gridApi.sizeColumnsToFit();
482
+ }
483
+ }, 10);
484
+ }
485
+
486
+ ngAfterViewInit(): void {
487
+ if (this.treeData === true) {
488
+ this.columnDefs = this.columns.map((c) => c.render());
489
+
490
+ const groupColumn = this.columnDefs.find((c) => c.rowGroupIndex == '0' && c.field !== '');
491
+
492
+ this.autoGroupColumnDef = {
493
+ headerName: groupColumn.headerName,
494
+ width: groupColumn.width,
495
+ cellRendererParams: { checkbox: this.showCheckBox },
496
+ field: groupColumn.field
497
+ };
498
+
499
+ this.columnDefs.forEach((elm) => {
500
+ if (elm.rowGroupIndex > -1) {
501
+ elm.hide = true;
502
+ }
503
+ });
504
+ }
505
+ //setTimeout(() => {
506
+ this.gridView = true;
507
+ //});
508
+
509
+ this.enabelSelect = true;
510
+ this.dataSource.onDataReceived.subscribe((_data) => {
511
+ const result = _data.data.result;
512
+ this.hideLoading();
513
+ let items: any[];
514
+ let totalCount: number;
515
+ if (Array.isArray(result)) {
516
+ items = result;
517
+ totalCount = result.length;
518
+ } else {
519
+ items = result.items;
520
+ totalCount = result.totalCount;
521
+ }
522
+ if (this.dataSourceSuccessCallback) {
523
+ if (!this.loadOnInit) {
524
+ this.dataSourceSuccessCallback([], 0);
525
+ } else {
526
+ this.dataSourceSuccessCallback(items, totalCount);
527
+ }
528
+ } else {
529
+ if (!this.loadOnInit && this.gridApi !== undefined) {
530
+ this.gridApi.setRowData([]);
531
+ } else if (this.gridApi !== undefined) {
532
+ this.gridApi.setRowData(items);
533
+ }
534
+ }
535
+
536
+ this.gridSelectRow();
537
+ });
538
+
539
+ this.dataSource.onFetchStart.subscribe(() => {
540
+ this.showLoading();
541
+ });
542
+
543
+ if (this.searchInput) {
544
+ this.searchInput.onValueChanged.subscribe((c) => {
545
+ this.searchText = c.value;
546
+ });
547
+ }
548
+ //
549
+ this.cdr.detectChanges();
550
+ }
551
+
552
+ mapColumns() {
553
+ this.columnDefs = this.columns.map((c) => c.render());
554
+
555
+ // if (this.showRowNumber) {
556
+ // this.columnDefs.push({
557
+ // headerName: AXConfig.get('layout.rtl') ? 'ردیف' : 'Row',
558
+ // valueGetter: 'node.rowIndex + 1',
559
+ // pinned: AXConfig.get('layout.rtl') ? 'right' : 'left'
560
+ // });
561
+ // }
562
+
563
+ if (this.gridDetailTemplate) {
564
+ if (this.columnDefs[0].checkboxSelection === true && this.columnDefs[0].field === '') {
565
+ this.columnDefs[1].cellRenderer = 'agGroupCellRenderer';
566
+ } else {
567
+ this.columnDefs[0].cellRenderer = 'agGroupCellRenderer';
568
+ }
569
+ }
570
+
571
+ if (this.hasChildField === 'null') {
572
+ const groupColumn = this.columnDefs.find((c) => c.rowGroupIndex === undefined && c.field !== '');
573
+ if (groupColumn && this.groupHideOpenParents == false) {
574
+ this.autoGroupColumnDef = {
575
+ headerName: groupColumn.headerName,
576
+ width: groupColumn.width,
577
+ cellRendererParams: { checkbox: this.showCheckBox },
578
+ field: groupColumn.field
579
+ };
580
+ // groupColumn.hide = true;
581
+ }
582
+ }
583
+
584
+ this.columnDefs.forEach((elm) => {
585
+ if (elm.rowGroupIndex > -1) {
586
+ elm.hide = true;
587
+ }
588
+ });
589
+ }
590
+
591
+ displayedColumnsChanged(e) {
592
+ if (this.hasChildField === 'null') {
593
+ const ee = e.columnApi.getAllDisplayedColumnGroups();
594
+ const eee = ee.find((c) => c.colId !== 'ag-Grid-AutoColumn' && c.colId !== '0');
595
+ if (eee && eee.colId) {
596
+ this.autoGroupColumnDef = {
597
+ headerName: eee.colDef.headerName,
598
+ width: eee.colDef.width,
599
+ cellRendererParams: { checkbox: this.showCheckBox },
600
+ field: eee.colDef.field
601
+ };
602
+ }
603
+ // eee.hide = true;
604
+ }
605
+ }
606
+
607
+ refresh(route: any[] = []) {
608
+ if (this.remoteOperation && this.gridApi !== undefined) {
609
+ // this.gridApi.purgeServerSideCache(route);
610
+ this.gridApi.setServerSideDatasource(this.intenalGridDataSource);
611
+ } else {
612
+ // TODO : check fetch param
613
+ this.dataSource.fetch(null);
614
+ }
615
+ }
616
+
617
+ internalGridCellClicked(e: CellClickedEvent) {
618
+ this.cellClick.emit({ data: this.mapCellEvent(e), component: this, htmlElement: this.ref.nativeElement });
619
+ }
620
+
621
+ internalGridCellDoubleClicked(e: CellClickedEvent) {
622
+ this.cellDbClick.emit({ data: this.mapCellEvent(e), component: this, htmlElement: this.ref.nativeElement });
623
+ }
624
+
625
+ internalGridCellFocused(e: CellClickedEvent) {
626
+ this.cellFocuse.emit({ data: this.mapCellEvent(e), htmlElement: this.ref.nativeElement, component: this });
627
+ }
628
+
629
+ internalGridRowClicked(e: RowClickedEvent) {
630
+ if (!e.node.group) {
631
+ this.rowClick.emit({ data: this.mapRowEvent(e), component: this, htmlElement: this.ref.nativeElement });
632
+ }
633
+ }
634
+
635
+ internalGridRowDoubleClicked(e: CellClickedEvent) {
636
+ if (!e.node.group) {
637
+ this.rowDbClick.emit({ data: this.mapRowEvent(e), htmlElement: this.ref.nativeElement, component: this });
638
+ }
639
+ }
640
+
641
+ differenceOf2Arrays(array1: any, array2: any) {
642
+ const temp = [];
643
+ for (const i in array1) {
644
+ if (array2.indexOf(array1[i]) === -1) {
645
+ temp.push(array1[i]);
646
+ }
647
+ }
648
+ for (const i in array2) {
649
+ if (array1.indexOf(array2[i]) === -1) {
650
+ temp.push(array2[i]);
651
+ }
652
+ }
653
+ return temp.sort((a, b) => a - b);
654
+ }
655
+
656
+ rowSelectionChanged(e) {
657
+ // this.gridApi.forEachNode((node) => {
658
+ // if (node.data[this.keyField] == e.node.data[this.keyField]) {
659
+ // node.setSelected(e.node.selected);
660
+ // }
661
+ // });
662
+ if (e.node.selected == true) {
663
+ this.selectRow = this.selectRow.filter((c) => c[this.keyField] != e.data[this.keyField]);
664
+ this.selectRow.push(e.data);
665
+ } else {
666
+ this.selectRow = this.selectRow.filter((c) => c[this.keyField] != e.data[this.keyField]);
667
+ }
668
+ this.rowSelectionChange.emit({ component: this, data: e, htmlElement: this.ref.nativeElement });
669
+ }
670
+
671
+ internalGridSelectionChanged(e) {
672
+ const args: AXGridRowSelectionEvent = { items: [] };
673
+ const oldNodes = this.oldSelectionNodes;
674
+ const nodes = this.gridApi.getSelectedNodes();
675
+ nodes.forEach((i) => {
676
+ args.items.push({
677
+ rowLevel: i.level,
678
+ rowIndex: i.rowIndex,
679
+ data: i.data
680
+ });
681
+ });
682
+ this.selectionChanged.emit({ data: args, component: this, htmlElement: this.ref.nativeElement });
683
+ let action = nodes.length > oldNodes.length ? true : false;
684
+ const node = this.differenceOf2Arrays(nodes, oldNodes);
685
+ this.onRowSelectionChanged.emit({ component: this, selected: action, data: node, htmlElement: this.ref.nativeElement });
686
+ this.oldSelectionNodes = nodes;
687
+ }
688
+
689
+ private mapCellEvent(e: CellEvent): AXGridCellEvent {
690
+ return {
691
+ rowLevel: 0,
692
+ column: e.column,
693
+ data: e.data,
694
+ rowIndex: e.rowIndex,
695
+ value: e.value
696
+ };
697
+ }
698
+
699
+ private mapRowEvent(e: RowEvent): AXGridRowEvent {
700
+ return {
701
+ rowLevel: 0,
702
+ data: e.data,
703
+ rowIndex: e.rowIndex
704
+ };
705
+ }
706
+
707
+ public deselectAll() {
708
+ this.gridApi.deselectAll();
709
+ }
710
+
711
+
712
+ public deselectByKeyField(keyField){
713
+
714
+ this.gridApi.forEachNode((node) => {
715
+ if (node.data !== undefined) {
716
+ let select: boolean = false;
717
+ if(node.data[this.keyField] === keyField){
718
+ node.setSelected(select);
719
+ this.selectRow = this.selectRow.filter((c)=>c[this.keyField] != keyField)
720
+ }
721
+ }
722
+ });
723
+
724
+ }
725
+
726
+ internalGetRowClass = (p: any) => {
727
+ if (this.rowClass) {
728
+ if (this.rowClass instanceof Function) {
729
+ return this.rowClass({
730
+ rowIndex: p.node.rowIndex,
731
+ rowLevel: p.node.level,
732
+ data: p.data
733
+ });
734
+ } else {
735
+ return this.rowClass;
736
+ }
737
+ }
738
+ };
739
+
740
+ showLoading(): void {
741
+ if (this.gridApi) {
742
+ this.gridApi.showLoadingOverlay();
743
+ }
744
+ }
745
+
746
+ hideLoading(): void {
747
+ if (this.gridApi) {
748
+ this.gridApi.hideOverlay();
749
+ }
750
+ }
751
+
752
+ internalGridSizeChanged(e: GridSizeChangedEvent) {
753
+ if (e.clientWidth > 0 && e.clientHeight > 0) {
754
+ this.performSizeColumnsToFit(e.api);
755
+ }
756
+ // this.refresh();
757
+ // this.gridApi.paginationGoToFirstPage();
758
+ }
759
+
760
+ internalGridFirstDataRendered(e: FirstDataRenderedEvent) {
761
+ this.performSizeColumnsToFit(e.api);
762
+ }
763
+
764
+ private performSizeColumnsToFit(api: GridApi) {
765
+ if (this.sizeColumnsToFit) {
766
+ api.sizeColumnsToFit();
767
+ }
768
+ }
769
+ }