@acorex/data-grid 3.0.22 → 3.0.26

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