Skip to content

Commit 56d9ee8

Browse files
authored
Merge pull request #5226 from IgniteUI/mkirova/fix-5102
fix(igxHierarchicalGrid): Hierarchical Grid should update its childre…
2 parents 3a40e25 + bb82916 commit 56d9ee8

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="igx-grid__hierarchical-indent" [ngClass]="{'igx-grid__hierarchical-indent--scroll': parentHasScroll}">
2-
<igx-hierarchical-grid #hgrid></igx-hierarchical-grid>
2+
<igx-hierarchical-grid #hgrid [data]='rowData.childGridsData[layout.key]'></igx-hierarchical-grid>
33
</div>

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
@@ -141,9 +141,6 @@ export class IgxChildGridRowComponent implements AfterViewInit, OnInit {
141141
* @hidden
142142
*/
143143
ngOnInit() {
144-
// setting child data only once on init
145-
// due to context change issues when moving cached views containing hierarchical child grids
146-
this.hGrid.data = this.rowData.childGridsData[this.layout.key];
147144
this.layout.onLayoutChange.subscribe((ch) => {
148145
this._handleLayoutChanges(ch);
149146
});

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,53 @@ describe('Basic IgxHierarchicalGrid', () => {
269269
expect(childGrid.displayDensity).toBe(DisplayDensity.compact);
270270
}));
271271

272+
it('should update child grid data when root grid data is changed.', () => {
273+
const newData1 = [
274+
{
275+
ID: 0, ChildLevels: 0, ProductName: 'Product: A', childData: [ { ID: 1, ProductName: 'Product: Child A' } ]
276+
},
277+
{
278+
ID: 1, ChildLevels: 0, ProductName: 'Product: A1', childData: [ { ID: 2, ProductName: 'Product: Child A' } ]
279+
},
280+
{
281+
ID: 2, ChildLevels: 0, ProductName: 'Product: A2', childData: [ { ID: 3, ProductName: 'Product: Child A' } ]
282+
}
283+
];
284+
fixture.componentInstance.data = newData1;
285+
fixture.detectChanges();
286+
let row = hierarchicalGrid.getRowByIndex(0) as IgxHierarchicalRowComponent;
287+
UIInteractions.clickElement(row.expander);
288+
fixture.detectChanges();
289+
let childGrids = fixture.debugElement.queryAll(By.css('igx-child-grid-row'));
290+
let childGrid = childGrids[0].query(By.css('igx-hierarchical-grid')).componentInstance;
291+
292+
expect(childGrid.data).toBe(newData1[0].childData);
293+
294+
const newData2 = [
295+
{
296+
ID: 0, ChildLevels: 0, ProductName: 'Product: A', childData: [ { ID: 10, ProductName: 'Product: New Child A' } ]
297+
},
298+
{
299+
ID: 1, ChildLevels: 0, ProductName: 'Product: A1', childData: [ { ID: 20, ProductName: 'Product: New Child A' } ]
300+
},
301+
{
302+
ID: 2, ChildLevels: 0, ProductName: 'Product: A2', childData: [ { ID: 30, ProductName: 'Product: New Child A' } ]
303+
}
304+
];
305+
fixture.componentInstance.data = newData2;
306+
fixture.detectChanges();
307+
308+
row = hierarchicalGrid.getRowByIndex(0) as IgxHierarchicalRowComponent;
309+
UIInteractions.clickElement(row.expander);
310+
fixture.detectChanges();
311+
312+
childGrids = fixture.debugElement.queryAll(By.css('igx-child-grid-row'));
313+
childGrid = childGrids[0].query(By.css('igx-hierarchical-grid')).componentInstance;
314+
315+
expect(childGrid.data).toBe(newData2[0].childData);
316+
317+
});
318+
272319
it('when child width is in percents its width should be update if parent width changes while parent row is collapsed. ', async () => {
273320
const row = hierarchicalGrid.getRowByIndex(0) as IgxHierarchicalRowComponent;
274321
UIInteractions.clickElement(row.expander);

0 commit comments

Comments
 (0)