Skip to content

Commit 9a22f3b

Browse files
MKirovaMayaKirova
authored andcommitted
chore(*): Move child grid column initialization on grid ContentInit.
1 parent b997422 commit 9a22f3b

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ private resolver;
161161
*/
162162
ngAfterViewInit() {
163163
this.hGrid.childLayoutList = this.layout.children;
164-
if (this.layout.childColumns.length > 0 && !this.hGrid.autoGenerate) {
165-
this.hGrid.createColumnsList(this.layout.childColumns.toArray());
166-
}
167164
const layouts = this.hGrid.childLayoutList.toArray();
168165
layouts.forEach((l) => this.hGrid.hgridAPI.registerChildRowIsland(l));
169166
this.parentGrid.hgridAPI.registerChildGrid(this.rowData.rowID, this.layout.key, this.hGrid);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,14 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
414414
}
415415
}
416416

417+
418+
protected setupColumns() {
419+
if (this.parentIsland && this.parentIsland.childColumns.length > 0 && !this.autoGenerate) {
420+
this.createColumnsList(this.parentIsland.childColumns.toArray());
421+
}
422+
super.setupColumns();
423+
}
424+
417425
protected onColumnsChanged(change: QueryList<IgxColumnComponent>) {
418426
Promise.resolve().then(() => {
419427
this.updateColumnList();

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ describe('IgxHierarchicalGrid Template Changing Scenarios #hGrid', () => {
988988
expect(child2Headers[2].nativeElement.innerText).toEqual('Col1');
989989
});
990990

991-
it('should render correct columns when setting columns for parent and child post init using ngFor', () => {
991+
it('should render correct columns when setting columns for parent and child post init using ngFor', fakeAsync(() => {
992992
const row = hierarchicalGrid.getRowByIndex(0) as IgxHierarchicalRowComponent;
993993
UIInteractions.simulateClickAndSelectEvent(row.expander);
994994
fixture.detectChanges();
@@ -999,6 +999,8 @@ describe('IgxHierarchicalGrid Template Changing Scenarios #hGrid', () => {
999999
fixture.componentInstance.parentCols = ['Col1', 'Col2'];
10001000
fixture.componentInstance.islandCols1 = ['ID', 'ProductName', 'Col1'];
10011001
fixture.detectChanges();
1002+
tick();
1003+
fixture.detectChanges();
10021004
// check parent cols
10031005
expect(hierarchicalGrid.columns.length).toBe(4);
10041006
expect(hierarchicalGrid.columns[0].field).toBe('ID');
@@ -1010,9 +1012,9 @@ describe('IgxHierarchicalGrid Template Changing Scenarios #hGrid', () => {
10101012
expect(hierarchicalGrid.columns[0].field).toBe('ID');
10111013
expect(hierarchicalGrid.columns[1].field).toBe('ProductName');
10121014
expect(hierarchicalGrid.columns[2].field).toBe('Col1');
1013-
});
1015+
}));
10141016

1015-
it('should update columns for expanded child when adding column to row island', () => {
1017+
it('should update columns for expanded child when adding column to row island', fakeAsync(() => {
10161018
const row = hierarchicalGrid.getRowByIndex(0) as IgxHierarchicalRowComponent;
10171019
UIInteractions.simulateClickAndSelectEvent(row.expander);
10181020
fixture.detectChanges();
@@ -1035,6 +1037,8 @@ describe('IgxHierarchicalGrid Template Changing Scenarios #hGrid', () => {
10351037

10361038
fixture.componentInstance.islandCols2.push('Col2');
10371039
fixture.detectChanges();
1040+
tick();
1041+
fixture.detectChanges();
10381042

10391043
child2Headers = child2Grid.queryAll(By.css('igx-grid-header'));
10401044
expect(child2Headers.length).toEqual(4);
@@ -1056,9 +1060,9 @@ describe('IgxHierarchicalGrid Template Changing Scenarios #hGrid', () => {
10561060
expect(colHeaders.length).toEqual(2);
10571061
expect(colHeaders[0].nativeElement.innerText).toEqual('ID');
10581062
expect(colHeaders[1].nativeElement.innerText).toEqual('ProductName');
1059-
});
1063+
}));
10601064

1061-
it('should update columns for rendered child that is collapsed when adding column to row island', () => {
1065+
it('should update columns for rendered child that is collapsed when adding column to row island', fakeAsync(() => {
10621066
const row = hierarchicalGrid.getRowByIndex(0) as IgxHierarchicalRowComponent;
10631067
UIInteractions.simulateClickAndSelectEvent(row.expander);
10641068
fixture.detectChanges();
@@ -1084,6 +1088,8 @@ describe('IgxHierarchicalGrid Template Changing Scenarios #hGrid', () => {
10841088

10851089
fixture.componentInstance.islandCols2.push('Col2');
10861090
fixture.detectChanges();
1091+
tick();
1092+
fixture.detectChanges();
10871093

10881094
UIInteractions.simulateClickAndSelectEvent(row1.expander);
10891095
fixture.detectChanges();
@@ -1094,7 +1100,7 @@ describe('IgxHierarchicalGrid Template Changing Scenarios #hGrid', () => {
10941100
expect(child2Headers[1].nativeElement.innerText).toEqual('ProductName');
10951101
expect(child2Headers[2].nativeElement.innerText).toEqual('Col1');
10961102
expect(child2Headers[3].nativeElement.innerText).toEqual('Col2');
1097-
});
1103+
}));
10981104
});
10991105

11001106
describe('IgxHierarchicalGrid Runtime Row Island change Scenarios #hGrid', () => {
@@ -1117,8 +1123,8 @@ describe('IgxHierarchicalGrid Runtime Row Island change Scenarios #hGrid', () =>
11171123
hierarchicalGrid = fixture.componentInstance.hgrid;
11181124
}));
11191125

1120-
it('should allow changing row islands runtime in root grid.', () => {
1121-
const row = hierarchicalGrid.getRowByIndex(0) as IgxHierarchicalRowComponent;
1126+
it('should allow changing row islands runtime in root grid.', fakeAsync(() => {
1127+
let row = hierarchicalGrid.getRowByIndex(0) as IgxHierarchicalRowComponent;
11221128
UIInteractions.simulateClickAndSelectEvent(row.expander);
11231129
fixture.detectChanges();
11241130

@@ -1130,6 +1136,8 @@ describe('IgxHierarchicalGrid Runtime Row Island change Scenarios #hGrid', () =>
11301136

11311137
fixture.componentInstance.toggleRI = false;
11321138
fixture.detectChanges();
1139+
tick();
1140+
fixture.detectChanges();
11331141

11341142
hGrids = fixture.debugElement.queryAll(By.css('igx-hierarchical-grid'));
11351143
childGrids = hierarchicalGrid.hgridAPI.getChildGrids();
@@ -1139,13 +1147,16 @@ describe('IgxHierarchicalGrid Runtime Row Island change Scenarios #hGrid', () =>
11391147

11401148
fixture.componentInstance.toggleRI = true;
11411149
fixture.detectChanges();
1150+
tick();
1151+
fixture.detectChanges();
11421152

11431153
hGrids = fixture.debugElement.queryAll(By.css('igx-hierarchical-grid'));
11441154
childGrids = hierarchicalGrid.hgridAPI.getChildGrids();
1155+
row = hierarchicalGrid.getRowByIndex(0) as IgxHierarchicalRowComponent;
11451156
expect(childGrids.length).toBe(1);
11461157
expect(hGrids.length).toBe(2);
11471158
expect(row.expander).not.toBe(undefined);
1148-
});
1159+
}));
11491160

11501161
it('should allow changing row islands runtime in child grid.', () => {
11511162
const row = hierarchicalGrid.getRowByIndex(0) as IgxHierarchicalRowComponent;

0 commit comments

Comments
 (0)