@@ -989,6 +989,32 @@ describe('Basic IgxHierarchicalGrid #hGrid', () => {
989989 expect ( childGrid1 . data [ 0 ] . ID ) . toBe ( 11 ) ;
990990 expect ( childGrid2 . data [ 0 ] . ID ) . toBe ( 21 ) ;
991991 } ) ;
992+
993+ it ( 'should expose the (child) grid instance as context of the empty grid template' , ( ) => {
994+ fixture = TestBed . createComponent ( IgxHierarchicalGridEmptyTemplateComponent ) ;
995+ fixture . detectChanges ( ) ;
996+ hierarchicalGrid = fixture . componentInstance . hgrid ;
997+ expect ( fixture . componentInstance . childGridRef ) . toBe ( null ) ;
998+
999+ const firstDataItem = fixture . componentInstance . data [ 0 ] ;
1000+ firstDataItem . childData = [ ] ;
1001+ fixture . componentInstance . data [ 0 ] = firstDataItem ;
1002+ fixture . detectChanges ( ) ;
1003+
1004+ hierarchicalGrid . expandRow ( fixture . componentInstance . data [ 0 ] ) ;
1005+ fixture . detectChanges ( ) ;
1006+
1007+ const child1Grids = fixture . debugElement . queryAll ( By . css ( 'igx-child-grid-row' ) ) ;
1008+ const child1Grid = child1Grids [ 0 ] . query ( By . css ( 'igx-hierarchical-grid' ) ) ;
1009+ const gridBody = child1Grid . query ( By . css ( '.igx-grid__tbody' ) ) ;
1010+ expect ( gridBody . nativeElement . innerText ) . toBe ( 'Get child grid ref' ) ; //text from custom template button
1011+
1012+ const button = gridBody . nativeElement . querySelector ( 'button' ) ;
1013+ button . click ( ) ;
1014+ fixture . detectChanges ( ) ;
1015+
1016+ expect ( fixture . componentInstance . childGridRef . elementRef . nativeElement ) . toEqual ( child1Grid . nativeElement ) ;
1017+ } ) ;
9921018 } ) ;
9931019
9941020 describe ( 'IgxHierarchicalGrid Children Sizing #hGrid' , ( ) => {
@@ -2289,3 +2315,36 @@ export class IgxHierarchicalGridMCHComponent {
22892315 this . pinnedArgs = args ;
22902316 }
22912317}
2318+
2319+ @Component ( {
2320+ template : `
2321+ <igx-hierarchical-grid #grid1 [data]="data" [autoGenerate]="false" [height]="'400px'" [width]="'500px'" #hierarchicalGrid
2322+ [emptyGridTemplate]="emptyTemplate">
2323+ <igx-column field="ID"></igx-column>
2324+ <igx-column field="ProductName"></igx-column>
2325+ <igx-row-island [key]="'childData'" [autoGenerate]="false" [emptyGridTemplate]="emptyTemplate">
2326+ <igx-column field="ID"></igx-column>
2327+ <igx-column field="ProductName"></igx-column>
2328+ <ng-template #emptyTemplate let-grid>
2329+ <button (click)="getChildGridRef(grid)">
2330+ Get child grid ref
2331+ </button>
2332+ </ng-template>
2333+ </igx-row-island>
2334+ </igx-hierarchical-grid>` ,
2335+ standalone : true ,
2336+ imports : [ IgxHierarchicalGridComponent , IgxColumnComponent , IgxRowIslandComponent ]
2337+ } )
2338+ export class IgxHierarchicalGridEmptyTemplateComponent extends IgxHierarchicalGridTestBaseComponent {
2339+ public childGridRef : IgxHierarchicalGridComponent = null ;
2340+ constructor ( ) {
2341+ super ( ) ;
2342+ const firstDataItem = this . data [ 0 ] ;
2343+ firstDataItem . childData = [ ] ;
2344+ this . data [ 0 ] = firstDataItem ;
2345+ }
2346+
2347+ public getChildGridRef ( grid : IgxHierarchicalGridComponent ) {
2348+ this . childGridRef = grid ;
2349+ }
2350+ }
0 commit comments