Skip to content

Commit

Permalink
fix(hgrid): add setter for child grid row data (#13497)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddaribo authored Sep 28, 2023
1 parent aff057d commit 6475d85
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 @@ -104,7 +104,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 @@ -171,6 +181,8 @@ export class IgxChildGridRowComponent implements AfterViewInit, OnInit {
*/
public expanded = false;

private _data: any;

constructor(
@Inject(IGX_GRID_SERVICE_BASE) public readonly gridAPI: IgxHierarchicalGridAPIService,
public element: ElementRef<HTMLElement>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,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 6475d85

Please sign in to comment.