Skip to content

Commit bb28024

Browse files
authored
fix(grid): allowing for grids in grids for master-detail - 20.0 (#15876)
1 parent 4979d5e commit bb28024

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6739,7 +6739,7 @@ export abstract class IgxGridBaseDirective implements GridType,
67396739
}
67406740

67416741
protected getColumnList() {
6742-
return this.columnList.toArray();
6742+
return this.columnList.toArray().filter((col) => col.grid === this);
67436743
}
67446744

67456745
/**
@@ -6797,6 +6797,9 @@ export abstract class IgxGridBaseDirective implements GridType,
67976797
let removed = false;
67986798
let pinning = false;
67996799
diff.forEachAddedItem((record: IterableChangeRecord<IgxColumnComponent>) => {
6800+
if (record.item.grid !== this) {
6801+
return;
6802+
}
68006803
added = true;
68016804
if (record.item.pinned) {
68026805
this._pinnedColumns.push(record.item);
@@ -6806,12 +6809,15 @@ export abstract class IgxGridBaseDirective implements GridType,
68066809
}
68076810
});
68086811

6809-
this.initColumns(this.columnList.toArray(), (col: IgxColumnComponent) => this.columnInit.emit(col));
6812+
this.initColumns(this.getColumnList(), (col: IgxColumnComponent) => this.columnInit.emit(col));
68106813
if (pinning) {
68116814
this.initPinning();
68126815
}
68136816

68146817
diff.forEachRemovedItem((record: IterableChangeRecord<IgxColumnComponent | IgxColumnGroupComponent>) => {
6818+
if (record.item.grid !== this) {
6819+
return;
6820+
}
68156821
const isColumnGroup = record.item instanceof IgxColumnGroupComponent;
68166822
if (!isColumnGroup) {
68176823
// Clear Grouping

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ViewChild, OnInit, DebugElement, QueryList, TemplateRef } from '@angular/core';
1+
import { Component, ViewChild, OnInit, DebugElement, QueryList, TemplateRef, ContentChild, ViewChildren } from '@angular/core';
22
import { TestBed, ComponentFixture, fakeAsync, tick, waitForAsync } from '@angular/core/testing';
33
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
44
import { By } from '@angular/platform-browser';
@@ -358,6 +358,16 @@ describe('IgxGrid Master Detail #grid', () => {
358358
const firstDetail = GridFunctions.getMasterRowDetail(gridRows[0]);
359359
expect(firstDetail.textContent.trim()).toBe('NEW TEMPLATE');
360360
});
361+
362+
it('should allow grids in details view without breaking the column collection of the master grid', () => {
363+
grid = fix.componentInstance.grid;
364+
grid.detailTemplate = fix.componentInstance.gridTemplate;
365+
fix.detectChanges();
366+
grid.toggleRow(fix.componentInstance.data[0].ID);
367+
fix.detectChanges();
368+
expect(grid.unpinnedColumns.map(c => c.field)).toEqual(['ContactName', 'CompanyName']);
369+
expect(fix.componentInstance.childGrid.first.unpinnedColumns.map(c => c.field)).toEqual(['ColA', 'ColB']);
370+
});
361371
});
362372

363373
describe('Keyboard Navigation ', () => {
@@ -1282,6 +1292,12 @@ describe('IgxGrid Master Detail #grid', () => {
12821292
NEW TEMPLATE
12831293
</div>
12841294
</ng-template>
1295+
<ng-template igxGridDetail #gridTemplate>
1296+
<igx-grid #childGrid>
1297+
<igx-column [field]="'ColA'" [width]="'400px'"></igx-column>
1298+
<igx-column [field]="'ColB'" [width]="'400px'"></igx-column>
1299+
</igx-grid>
1300+
</ng-template>
12851301
`,
12861302
imports: [IgxGridComponent, IgxColumnComponent, IgxGridDetailTemplateDirective, IgxCheckboxComponent, IgxPaginatorComponent, IgxInputGroupComponent, IgxInputDirective]
12871303
})
@@ -1292,6 +1308,12 @@ export class DefaultGridMasterDetailComponent {
12921308
@ViewChild('detailTemplate', { read: TemplateRef, static: true })
12931309
public detailTemplate: TemplateRef<any>;
12941310

1311+
@ViewChild('gridTemplate', { read: TemplateRef, static: true })
1312+
public gridTemplate: TemplateRef<any>;
1313+
1314+
@ViewChildren('childGrid', { read: IgxGridComponent })
1315+
public childGrid: IgxGridComponent;
1316+
12951317
public width = '800px';
12961318
public height = '500px';
12971319
public data = SampleTestData.contactInfoDataFull();

0 commit comments

Comments
 (0)