Skip to content

Commit

Permalink
Merge pull request #13499 from IgniteUI/bpachilova/fix-13495-15.1.x
Browse files Browse the repository at this point in the history
fix(hierarchical-grid): add setter for child grid row data - 15.1.x
  • Loading branch information
teodosiah committed Sep 28, 2023
2 parents 410cfc9 + 9998fe6 commit b3f1c55
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,17 @@ export class IgxChildGridRowComponent implements AfterViewInit, OnInit {
* ```
*/
@Input()
public data: any = [];
public get data(): any {
return this._data || [];
}

public set data(value: any) {
this._data = value;
if (this.hGrid) {
this.hGrid.data = this._data.childGridsData[this.layout.key];
}
}

/**
* The index of the row.
*
Expand Down Expand Up @@ -150,6 +160,8 @@ export class IgxChildGridRowComponent implements AfterViewInit, OnInit {
*/
public expanded = false;

private _data: any;

constructor(
@Inject(IGX_GRID_SERVICE_BASE) public gridAPI: IgxHierarchicalGridAPIService,
public element: ElementRef<HTMLElement>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,28 @@ describe('Basic IgxHierarchicalGrid #hGrid', () => {
expect(childGrid.data).toBe(newData2[0].childData);
});

it('should update already created child grid with new records added to the root data', () => {
let row = hierarchicalGrid.gridAPI.get_row_by_index(0) as IgxHierarchicalRowComponent;
UIInteractions.simulateClickAndSelectEvent(row.expander);
fixture.detectChanges();

let childGrids = fixture.debugElement.queryAll(By.css('igx-child-grid-row'));
let childGrid = childGrids[0].query(By.css('igx-hierarchical-grid')).componentInstance;

fixture.componentInstance.data[0].childData = [...hierarchicalGrid.data[0].childData ?? [], { ID: 10, ProductName: 'New child' }];
fixture.componentInstance.data = [...fixture.componentInstance.data];
fixture.detectChanges();

childGrids = fixture.debugElement.queryAll(By.css('igx-child-grid-row'));
childGrid = childGrids[0].query(By.css('igx-hierarchical-grid')).componentInstance;

const length = fixture.componentInstance.data[0].childData.length;
const newRow = childGrid.gridAPI.get_row_by_index(length - 1) as IgxHierarchicalRowComponent;

expect(newRow).not.toBeUndefined();
expect(childGrid.data).toBe(fixture.componentInstance.data[0].childData);
});

it('when child width is in percents its width should be update if parent width changes while parent row is collapsed. ', async () => {
const row = hierarchicalGrid.gridAPI.get_row_by_index(0) as IgxHierarchicalRowComponent;
UIInteractions.simulateClickAndSelectEvent(row.expander);
Expand Down

0 comments on commit b3f1c55

Please sign in to comment.