Skip to content

Commit 2257b3c

Browse files
committed
chore(*): Make sure elements specific events re-emit for row island.
1 parent 1ca0231 commit 2257b3c

3 files changed

Lines changed: 85 additions & 4 deletions

File tree

projects/igniteui-angular-elements/src/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ <h3 class="ig-typography__h6">Flat Grid (MRL column layout)</h3>
527527
</igc-grid-toolbar-actions>
528528
</igc-grid-toolbar>
529529
`;
530+
virtualMachinesRowIsland.addEventListener('columnsAutogenerated', (e) => {
531+
console.log('columns autogenerated for VirtualMachinesRowIsland', e);
532+
});
530533
</script>
531534

532535
<igc-grid auto-generate="false" id="mergedGrid" cell-merge-mode="always" width="100%" height="570px">

projects/igniteui-angular-elements/src/lib/grids/hierarchical-grid.component.ts

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

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';
33
import { NgClass, NgTemplateOutlet, NgStyle } from '@angular/common';
44

55
import { IgxHierarchicalGridAPIService } from 'igniteui-angular/grids/hierarchical-grid/src/hierarchical-grid-api.service';
@@ -29,10 +29,82 @@ import { IgxSnackbarComponent } from 'igniteui-angular/snackbar';
2929
import { IgxIconComponent } from 'igniteui-angular/icon';
3030
import { IgxActionStripToken, IgxOverlayOutletDirective } from 'igniteui-angular/core';
3131
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';
3333
import { IgxRowIslandComponent } from './row-island.component';
3434
import { IColumnsAutoGeneratedEventArgs } from './events';
3535

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+
36108
/* blazorAdditionalDependency: Column */
37109
/* blazorAdditionalDependency: ColumnGroup */
38110
/* blazorAdditionalDependency: ColumnLayout */
@@ -123,6 +195,12 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGrid {
123195
});
124196
}
125197

198+
/**
199+
* @hidden
200+
*/
201+
@ViewChildren(IgxChildGridRowComponent)
202+
public override hierarchicalRows: QueryList<IgxChildGridRowComponent>;
203+
126204
/**
127205
* @hidden
128206
* @internal

projects/igniteui-angular/grids/hierarchical-grid/src/hierarchical-grid.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export class IgxChildGridRowComponent implements AfterViewInit, OnInit {
211211
this.hGrid.cdr.detectChanges();
212212
}
213213

214-
private setupEventEmitters() {
214+
protected setupEventEmitters() {
215215
const destructor = takeUntil(this.hGrid.destroy$);
216216

217217
const mirror = reflectComponentType(IgxGridComponent);
@@ -237,7 +237,7 @@ export class IgxChildGridRowComponent implements AfterViewInit, OnInit {
237237
}
238238

239239

240-
private _handleLayoutChanges(changes: SimpleChanges) {
240+
protected _handleLayoutChanges(changes: SimpleChanges) {
241241
for (const change in changes) {
242242
if (changes.hasOwnProperty(change)) {
243243
this.hGrid[change] = changes[change].currentValue;

0 commit comments

Comments
 (0)