|
1 | 1 |
|
2 | | -import { ChangeDetectionStrategy, Component, ContentChildren, CUSTOM_ELEMENTS_SCHEMA, EventEmitter, Output, QueryList } from '@angular/core'; |
| 2 | +import { ChangeDetectionStrategy, Component, ContentChildren, CUSTOM_ELEMENTS_SCHEMA, EventEmitter, Output, QueryList, reflectComponentType, ViewChildren } from '@angular/core'; |
3 | 3 | import { NgClass, NgTemplateOutlet, NgStyle } from '@angular/common'; |
4 | 4 |
|
5 | 5 | import { IgxHierarchicalGridAPIService } from 'igniteui-angular/grids/hierarchical-grid/src/hierarchical-grid-api.service'; |
@@ -29,10 +29,82 @@ import { IgxSnackbarComponent } from 'igniteui-angular/snackbar'; |
29 | 29 | import { IgxIconComponent } from 'igniteui-angular/icon'; |
30 | 30 | import { IgxActionStripToken, IgxOverlayOutletDirective } from 'igniteui-angular/core'; |
31 | 31 | import { IgxGridCellMergePipe, IgxGridFilteringPipe, IgxGridSortingPipe, IgxGridUnmergeActivePipe } from 'igniteui-angular/grids/grid'; |
32 | | -import { IgxChildGridRowComponent, IgxHierarchicalGridComponent as IgxHierarchicalGrid } from 'igniteui-angular/grids/hierarchical-grid/src/hierarchical-grid.component'; |
| 32 | +import { IgxChildGridRowComponent as IgxChildGridRow, IgxHierarchicalGridComponent as IgxHierarchicalGrid } from 'igniteui-angular/grids/hierarchical-grid/src/hierarchical-grid.component'; |
33 | 33 | import { IgxRowIslandComponent } from './row-island.component'; |
34 | 34 | import { IColumnsAutoGeneratedEventArgs } from './events'; |
35 | 35 |
|
| 36 | + |
| 37 | +/** |
| 38 | + * @hidden @internal |
| 39 | + */ |
| 40 | +@Component({ |
| 41 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 42 | + selector: 'igx-child-grid-row', |
| 43 | + templateUrl: '../../../../igniteui-angular/grids/hierarchical-grid/src/child-grid-row.component.html', |
| 44 | + imports: [NgClass] |
| 45 | +}) |
| 46 | +export class IgxChildGridRowComponent extends IgxChildGridRow { |
| 47 | + |
| 48 | + /** |
| 49 | + * @hidden |
| 50 | + */ |
| 51 | + public override hGrid: IgxHierarchicalGridComponent; |
| 52 | + |
| 53 | + /** |
| 54 | + * @hidden |
| 55 | + */ |
| 56 | + public override ngOnInit() { |
| 57 | + const ref = this.container.createComponent(IgxHierarchicalGridComponent, { injector: this.container.injector }); |
| 58 | + this.hGrid = ref.instance; |
| 59 | + this.hGrid.setDataInternal(this.data.childGridsData[this.layout.key]); |
| 60 | + this.hGrid.nativeElement["__componentRef"] = ref; |
| 61 | + this.layout.layoutChange.subscribe((ch) => { |
| 62 | + this._handleLayoutChanges(ch); |
| 63 | + }); |
| 64 | + const changes = this.layout.initialChanges; |
| 65 | + changes.forEach(change => { |
| 66 | + this._handleLayoutChanges(change); |
| 67 | + }); |
| 68 | + this.hGrid.parent = this.parentGrid; |
| 69 | + this.hGrid.parentIsland = this.layout; |
| 70 | + this.hGrid.childRow = this; |
| 71 | + // handler logic that re-emits hgrid events on the row island |
| 72 | + this.setupEventEmitters(); |
| 73 | + this.layout.gridCreated.emit({ |
| 74 | + owner: this.layout, |
| 75 | + parentID: this.data.rowID, |
| 76 | + grid: this.hGrid, |
| 77 | + parentRowData: this.data.parentRowData, |
| 78 | + }); |
| 79 | + } |
| 80 | + |
| 81 | + protected override setupEventEmitters() { |
| 82 | + const destructor = takeUntil(this.hGrid.destroy$); |
| 83 | + // use wc type so that it includes elements specific events: childrenResolved, columnsAutogenerated, etc. |
| 84 | + const mirror = reflectComponentType(IgxHierarchicalGridComponent); |
| 85 | + // exclude outputs related to two-way binding functionality |
| 86 | + const inputNames = mirror.inputs.map(input => input.propName); |
| 87 | + const outputs = mirror.outputs.filter(o => { |
| 88 | + const matchingInputPropName = o.propName.slice(0, o.propName.indexOf('Change')); |
| 89 | + return inputNames.indexOf(matchingInputPropName) === -1; |
| 90 | + }); |
| 91 | + |
| 92 | + // TODO: Skip the `rendered` output. Rendered should be called once per grid. |
| 93 | + outputs.filter(o => o.propName !== 'rendered').forEach(output => { |
| 94 | + if (this.hGrid[output.propName]) { |
| 95 | + this.hGrid[output.propName].pipe(destructor).subscribe((args) => { |
| 96 | + if (!args) { |
| 97 | + args = {}; |
| 98 | + } |
| 99 | + args.owner = this.hGrid; |
| 100 | + this.layout[output.propName].emit(args); |
| 101 | + }); |
| 102 | + } |
| 103 | + }); |
| 104 | + } |
| 105 | + |
| 106 | +} |
| 107 | + |
36 | 108 | /* blazorAdditionalDependency: Column */ |
37 | 109 | /* blazorAdditionalDependency: ColumnGroup */ |
38 | 110 | /* blazorAdditionalDependency: ColumnLayout */ |
@@ -123,6 +195,12 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGrid { |
123 | 195 | }); |
124 | 196 | } |
125 | 197 |
|
| 198 | + /** |
| 199 | + * @hidden |
| 200 | + */ |
| 201 | + @ViewChildren(IgxChildGridRowComponent) |
| 202 | + public override hierarchicalRows: QueryList<IgxChildGridRowComponent>; |
| 203 | + |
126 | 204 | /** |
127 | 205 | * @hidden |
128 | 206 | * @internal |
|
0 commit comments