Skip to content

Commit d38f068

Browse files
committed
feat(hierarchical-grid): add parentRowData to IGridCreatedEventArgs
1 parent bad2dea commit d38f068

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export interface IGridCreatedEventArgs extends IBaseEventArgs {
77
owner: IgxRowIslandComponent;
88
parentID: any;
99
grid: IgxHierarchicalGridComponent;
10+
parentRowData?: any;
1011
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,9 @@ export class IgxChildGridRowComponent implements AfterViewInit, OnInit {
196196
*/
197197
public ngOnInit() {
198198
const ref = this.container.createComponent(IgxHierarchicalGridComponent, { injector: this.container.injector });
199+
const childGridData = this.data.childGridsData[this.layout.key];
199200
this.hGrid = ref.instance;
200-
this.hGrid.setDataInternal(this.data.childGridsData[this.layout.key]);
201+
this.hGrid.setDataInternal(childGridData);
201202
this.hGrid.nativeElement["__componentRef"] = ref;
202203
this.layout.layoutChange.subscribe((ch) => {
203204
this._handleLayoutChanges(ch);
@@ -214,7 +215,8 @@ export class IgxChildGridRowComponent implements AfterViewInit, OnInit {
214215
this.layout.gridCreated.emit({
215216
owner: this.layout,
216217
parentID: this.data.rowID,
217-
grid: this.hGrid
218+
grid: this.hGrid,
219+
parentRowData: !childGridData?.length ? this.data.parentRowData : undefined,
218220
});
219221
}
220222

@@ -231,7 +233,8 @@ export class IgxChildGridRowComponent implements AfterViewInit, OnInit {
231233
this.layout.gridInitialized.emit({
232234
owner: this.layout,
233235
parentID: this.data.rowID,
234-
grid: this.hGrid
236+
grid: this.hGrid,
237+
parentRowData: !this.hGrid.data.length ? this.data.parentRowData : undefined,
235238
});
236239

237240
this.hGrid.cdr.detectChanges();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class IgxGridHierarchicalPipe implements PipeTransform {
4949
childGridsData[childKey] = childData;
5050
});
5151
if (grid.gridAPI.get_row_expansion_state(v)) {
52-
result.push({ rowID: primaryKey ? v[primaryKey] : v, childGridsData });
52+
result.push({ rowID: primaryKey ? v[primaryKey] : v, childGridsData, parentRowData: v });
5353
}
5454
});
5555
return result;

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

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,12 +686,14 @@ describe('Basic IgxHierarchicalGrid #hGrid', () => {
686686
fixture.detectChanges();
687687
const childGrids = hierarchicalGrid.gridAPI.getChildGrids(false);
688688
const childRows = fixture.debugElement.queryAll(By.directive(IgxChildGridRowComponent));
689-
expect(childGrids.length).toBe(2);
690-
expect(childRows.length).toBe(2);
689+
expect(childGrids.length).toBe(3);
690+
expect(childRows.length).toBe(3);
691691
const ri1 = fixture.componentInstance.rowIsland1;
692692
const ri2 = fixture.componentInstance.rowIsland2;
693+
const ri3 = fixture.componentInstance.rowIsland3;
693694
expect(childRows[0].componentInstance.layout).toBe(ri1);
694695
expect(childRows[1].componentInstance.layout).toBe(ri2);
696+
expect(childRows[2].componentInstance.layout).toBe(ri3);
695697
});
696698

697699
it('should display correct data for sibling row islands', () => {
@@ -865,18 +867,21 @@ describe('Basic IgxHierarchicalGrid #hGrid', () => {
865867
fixture.detectChanges();
866868

867869
const children = hierarchicalGrid.gridAPI.getChildGrids(true);
868-
expect(children.length).toBe(2);
870+
expect(children.length).toBe(3);
869871
const child1 = children[0] as IgxHierarchicalGridComponent;
870872
const child2 = children[1] as IgxHierarchicalGridComponent;
873+
const child3 = children[2] as IgxHierarchicalGridComponent;
871874
expect(child1._destroyed).toBeFalsy();
872875
expect(child2._destroyed).toBeFalsy();
876+
expect(child3._destroyed).toBeFalsy();
873877
hierarchicalGrid.verticalScrollContainer.scrollTo(hierarchicalGrid.dataView.length - 1);
874878
await wait();
875879
fixture.detectChanges();
876880

877881
// check that we have child is not destroyed
878882
expect(child1._destroyed).toBeFalsy();
879883
expect(child2._destroyed).toBeFalsy();
884+
expect(child3._destroyed).toBeFalsy();
880885

881886
// destroy hgrid
882887
fixture.destroy();
@@ -1119,6 +1124,32 @@ describe('Basic IgxHierarchicalGrid #hGrid', () => {
11191124
expect(getterSpy).toHaveBeenCalledTimes(7);
11201125
expect(summaryCell.textContent.trim()).toEqual('');
11211126
}));
1127+
1128+
it('should verify gridCreated and gridInitialized events emit correct parentRowData for grids with and without data.', () => {
1129+
const row = hierarchicalGrid.gridAPI.get_row_by_index(0) as IgxHierarchicalRowComponent;
1130+
const ri1 = fixture.componentInstance.rowIsland1;
1131+
const ri3 = fixture.componentInstance.rowIsland3;
1132+
1133+
spyOn(ri1.gridCreated, 'emit').and.callThrough();
1134+
spyOn(ri1.gridInitialized, 'emit').and.callThrough();
1135+
spyOn(ri3.gridCreated, 'emit').and.callThrough();
1136+
spyOn(ri3.gridInitialized, 'emit').and.callThrough();
1137+
1138+
UIInteractions.simulateClickAndSelectEvent(row.expander);
1139+
fixture.detectChanges();
1140+
1141+
// Verify parentRowData is undefined for grids with existing data
1142+
expect(ri1.gridCreated.emit).toHaveBeenCalledTimes(1);
1143+
expect(ri1.gridCreated.emit).toHaveBeenCalledWith(jasmine.objectContaining({ parentRowData: undefined }));
1144+
expect(ri1.gridInitialized.emit).toHaveBeenCalledTimes(1);
1145+
expect(ri1.gridInitialized.emit).toHaveBeenCalledWith(jasmine.objectContaining({ parentRowData: undefined }));
1146+
1147+
// Verify parentRowData is defined for grids without data
1148+
expect(ri3.gridCreated.emit).toHaveBeenCalledTimes(1);
1149+
expect(ri3.gridCreated.emit).toHaveBeenCalledWith(jasmine.objectContaining({ parentRowData: row.data }));
1150+
expect(ri3.gridInitialized.emit).toHaveBeenCalledTimes(1);
1151+
expect(ri3.gridInitialized.emit).toHaveBeenCalledWith(jasmine.objectContaining({ parentRowData: row.data }));
1152+
});
11221153
});
11231154

11241155
describe('IgxHierarchicalGrid Children Sizing #hGrid', () => {
@@ -1984,12 +2015,14 @@ export class IgxHierarchicalGridTestBaseComponent {
19842015
<igx-column field="Col2"></igx-column>
19852016
<igx-column field="Col3"></igx-column>
19862017
</igx-row-island>
2018+
<igx-row-island [key]="'noData'" #rowIsland3></igx-row-island>
19872019
</igx-hierarchical-grid>`,
19882020
imports: [IgxHierarchicalGridComponent, IgxColumnComponent, IgxRowIslandComponent]
19892021
})
19902022
export class IgxHierarchicalGridMultiLayoutComponent extends IgxHierarchicalGridTestBaseComponent {
19912023
@ViewChild('rowIsland1', { read: IgxRowIslandComponent, static: true }) public rowIsland1: IgxRowIslandComponent;
19922024
@ViewChild('rowIsland2', { read: IgxRowIslandComponent, static: true }) public override rowIsland2: IgxRowIslandComponent;
2025+
@ViewChild('rowIsland3', { read: IgxRowIslandComponent, static: true }) public rowIsland3: IgxRowIslandComponent;
19932026
public height = '100px';
19942027
public toggleColumns = true;
19952028
}

0 commit comments

Comments
 (0)