Skip to content

Commit 2c61d3f

Browse files
authored
Merge pull request #14367 from IgniteUI/mkirova/hgrid-colInit-17.2.x
fix(igxHierarchicalGrid): Make sure columnInit is called on column's …
2 parents 4dcaf00 + 1711a5d commit 2c61d3f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
11461146
const colLength = this.columns.length;
11471147
const topCols = this.columnList.filter((item) => colsArray.indexOf(item) === -1);
11481148
if (topCols.length > 0) {
1149-
this.updateColumns(topCols);
1149+
this.initColumns(topCols, (col: IgxColumnComponent) => this.columnInit.emit(col));
11501150
if (recalcColSizes && this.columns.length !== colLength) {
11511151
this.calculateGridSizes(false);
11521152
}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,16 @@ describe('Basic IgxHierarchicalGrid #hGrid', () => {
628628
expect(hierarchicalGrid.tbody.nativeElement.attributes['aria-activedescendant'].value).toEqual(hierarchicalGrid.id);
629629
expect(childGrid.tbody.nativeElement.attributes['aria-activedescendant'].value).toEqual(`${childGrid.id}_0_1`);
630630
});
631+
632+
it('should emit columnInit when a column is added runtime.', async() => {
633+
spyOn(hierarchicalGrid.columnInit, 'emit').and.callThrough();
634+
fixture.detectChanges();
635+
fixture.componentInstance.showAnotherCol = true;
636+
fixture.detectChanges();
637+
await wait(30);
638+
fixture.detectChanges();
639+
expect(hierarchicalGrid.columnInit.emit).toHaveBeenCalled();
640+
});
631641
});
632642

633643
describe('IgxHierarchicalGrid Row Islands #hGrid', () => {
@@ -1827,6 +1837,7 @@ describe('Basic IgxHierarchicalGrid #hGrid', () => {
18271837
<igx-hierarchical-grid #grid1 [data]="data"
18281838
[autoGenerate]="false" [height]="'400px'" [width]="width" #hierarchicalGrid>
18291839
<igx-column field="ID"></igx-column>
1840+
<igx-column field="AnotherColumn" *ngIf="showAnotherCol"></igx-column>
18301841
<igx-column field="ProductName"></igx-column>
18311842
<igx-row-island [key]="'childData'" [autoGenerate]="false" #rowIsland>
18321843
<igx-column field="ID"></igx-column>
@@ -1839,15 +1850,15 @@ describe('Basic IgxHierarchicalGrid #hGrid', () => {
18391850
</igx-row-island>
18401851
</igx-hierarchical-grid>`,
18411852
standalone: true,
1842-
imports: [IgxHierarchicalGridComponent, IgxColumnComponent, IgxRowIslandComponent]
1853+
imports: [IgxHierarchicalGridComponent, IgxColumnComponent, IgxRowIslandComponent, NgIf]
18431854
})
18441855
export class IgxHierarchicalGridTestBaseComponent {
18451856
@ViewChild('hierarchicalGrid', { read: IgxHierarchicalGridComponent, static: true }) public hgrid: IgxHierarchicalGridComponent;
18461857
@ViewChild('rowIsland', { read: IgxRowIslandComponent, static: true }) public rowIsland: IgxRowIslandComponent;
18471858
@ViewChild('rowIsland2', { read: IgxRowIslandComponent, static: true }) public rowIsland2: IgxRowIslandComponent;
18481859
public data;
18491860
public width = '500px';
1850-
1861+
public showAnotherCol = false;
18511862
constructor() {
18521863
// 3 level hierarchy
18531864
this.data = this.generateDataUneven(20, 3);

0 commit comments

Comments
 (0)