Skip to content

fix(grid): allowing for grids in grids for master-detail - 19.2 #15834

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 7 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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
10 changes: 8 additions & 2 deletions projects/igniteui-angular/src/lib/grids/grid-base.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6738,7 +6738,7 @@ export abstract class IgxGridBaseDirective implements GridType,
}

protected getColumnList() {
return this.columnList.toArray();
return this.columnList.toArray().filter((col) => col.grid === this);
}

/**
Expand Down Expand Up @@ -6796,6 +6796,9 @@ export abstract class IgxGridBaseDirective implements GridType,
let removed = false;
let pinning = false;
diff.forEachAddedItem((record: IterableChangeRecord<IgxColumnComponent>) => {
if (record.item.grid !== this) {
return;
}
added = true;
if (record.item.pinned) {
this._pinnedColumns.push(record.item);
Expand All @@ -6805,12 +6808,15 @@ export abstract class IgxGridBaseDirective implements GridType,
}
});

this.initColumns(this.columnList.toArray(), (col: IgxColumnComponent) => this.columnInit.emit(col));
this.initColumns(this.getColumnList(), (col: IgxColumnComponent) => this.columnInit.emit(col));
if (pinning) {
this.initPinning();
}

diff.forEachRemovedItem((record: IterableChangeRecord<IgxColumnComponent | IgxColumnGroupComponent>) => {
if (record.item.grid !== this) {
return;
}
const isColumnGroup = record.item instanceof IgxColumnGroupComponent;
if (!isColumnGroup) {
// Clear Grouping
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ViewChild, OnInit, DebugElement, QueryList, TemplateRef } from '@angular/core';
import { Component, ViewChild, OnInit, DebugElement, QueryList, TemplateRef, ContentChild, ViewChildren } from '@angular/core';
import { TestBed, ComponentFixture, fakeAsync, tick, waitForAsync } from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { By } from '@angular/platform-browser';
Expand Down Expand Up @@ -358,6 +358,16 @@ describe('IgxGrid Master Detail #grid', () => {
const firstDetail = GridFunctions.getMasterRowDetail(gridRows[0]);
expect(firstDetail.textContent.trim()).toBe('NEW TEMPLATE');
});

it('should allow grids in details view without breaking the column collection of the master grid', () => {
grid = fix.componentInstance.grid;
grid.detailTemplate = fix.componentInstance.gridTemplate;
fix.detectChanges();
grid.toggleRow(fix.componentInstance.data[0].ID);
fix.detectChanges();
expect(grid.unpinnedColumns.map(c => c.field)).toEqual(['ContactName', 'CompanyName']);
expect(fix.componentInstance.childGrid.first.unpinnedColumns.map(c => c.field)).toEqual(['ColA', 'ColB']);
});
});

describe('Keyboard Navigation ', () => {
Expand Down Expand Up @@ -1282,6 +1292,12 @@ describe('IgxGrid Master Detail #grid', () => {
NEW TEMPLATE
</div>
</ng-template>
<ng-template igxGridDetail #gridTemplate>
<igx-grid #childGrid>
<igx-column [field]="'ColA'" [width]="'400px'"></igx-column>
<igx-column [field]="'ColB'" [width]="'400px'"></igx-column>
</igx-grid>
</ng-template>
`,
imports: [IgxGridComponent, IgxColumnComponent, IgxGridDetailTemplateDirective, IgxCheckboxComponent, IgxPaginatorComponent, IgxInputGroupComponent, IgxInputDirective]
})
Expand All @@ -1292,6 +1308,12 @@ export class DefaultGridMasterDetailComponent {
@ViewChild('detailTemplate', { read: TemplateRef, static: true })
public detailTemplate: TemplateRef<any>;

@ViewChild('gridTemplate', { read: TemplateRef, static: true })
public gridTemplate: TemplateRef<any>;

@ViewChildren('childGrid', { read: IgxGridComponent })
public childGrid: IgxGridComponent;

public width = '800px';
public height = '500px';
public data = SampleTestData.contactInfoDataFull();
Expand Down
Loading