Skip to content

fix(hierarchical-grid): add setter for child grid row data - 15.1.x #13499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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