Skip to content

Commit b3f1c55

Browse files
authored
Merge pull request #13499 from IgniteUI/bpachilova/fix-13495-15.1.x
fix(hierarchical-grid): add setter for child grid row data - 15.1.x
2 parents 410cfc9 + 9998fe6 commit b3f1c55

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,17 @@ export class IgxChildGridRowComponent implements AfterViewInit, OnInit {
8383
* ```
8484
*/
8585
@Input()
86-
public data: any = [];
86+
public get data(): any {
87+
return this._data || [];
88+
}
89+
90+
public set data(value: any) {
91+
this._data = value;
92+
if (this.hGrid) {
93+
this.hGrid.data = this._data.childGridsData[this.layout.key];
94+
}
95+
}
96+
8797
/**
8898
* The index of the row.
8999
*
@@ -150,6 +160,8 @@ export class IgxChildGridRowComponent implements AfterViewInit, OnInit {
150160
*/
151161
public expanded = false;
152162

163+
private _data: any;
164+
153165
constructor(
154166
@Inject(IGX_GRID_SERVICE_BASE) public gridAPI: IgxHierarchicalGridAPIService,
155167
public element: ElementRef<HTMLElement>,

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

+22
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,28 @@ describe('Basic IgxHierarchicalGrid #hGrid', () => {
449449
expect(childGrid.data).toBe(newData2[0].childData);
450450
});
451451

452+
it('should update already created child grid with new records added to the root data', () => {
453+
let row = hierarchicalGrid.gridAPI.get_row_by_index(0) as IgxHierarchicalRowComponent;
454+
UIInteractions.simulateClickAndSelectEvent(row.expander);
455+
fixture.detectChanges();
456+
457+
let childGrids = fixture.debugElement.queryAll(By.css('igx-child-grid-row'));
458+
let childGrid = childGrids[0].query(By.css('igx-hierarchical-grid')).componentInstance;
459+
460+
fixture.componentInstance.data[0].childData = [...hierarchicalGrid.data[0].childData ?? [], { ID: 10, ProductName: 'New child' }];
461+
fixture.componentInstance.data = [...fixture.componentInstance.data];
462+
fixture.detectChanges();
463+
464+
childGrids = fixture.debugElement.queryAll(By.css('igx-child-grid-row'));
465+
childGrid = childGrids[0].query(By.css('igx-hierarchical-grid')).componentInstance;
466+
467+
const length = fixture.componentInstance.data[0].childData.length;
468+
const newRow = childGrid.gridAPI.get_row_by_index(length - 1) as IgxHierarchicalRowComponent;
469+
470+
expect(newRow).not.toBeUndefined();
471+
expect(childGrid.data).toBe(fixture.componentInstance.data[0].childData);
472+
});
473+
452474
it('when child width is in percents its width should be update if parent width changes while parent row is collapsed. ', async () => {
453475
const row = hierarchicalGrid.gridAPI.get_row_by_index(0) as IgxHierarchicalRowComponent;
454476
UIInteractions.simulateClickAndSelectEvent(row.expander);

0 commit comments

Comments
 (0)