Skip to content

Commit 0e9d584

Browse files
committed
fix(hGrid): emit events for child grids with mch
1 parent 840f9b7 commit 0e9d584

File tree

2 files changed

+158
-4
lines changed

2 files changed

+158
-4
lines changed

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
NgZone,
1414
Optional,
1515
Output,
16+
QueryList,
1617
reflectComponentType,
1718
ViewContainerRef
1819
} from '@angular/core';
@@ -27,7 +28,7 @@ import { IgxHierarchicalGridNavigationService } from './hierarchical-grid-naviga
2728
import { IgxGridSummaryService } from '../summaries/grid-summary.service';
2829
import { IgxGridSelectionService } from '../selection/selection.service';
2930
import { IgxColumnResizingService } from '../resizing/resizing.service';
30-
import { GridType, IGX_GRID_SERVICE_BASE, IPathSegment } from '../common/grid.interface';
31+
import { ColumnType, GridType, IGX_GRID_SERVICE_BASE, IPathSegment } from '../common/grid.interface';
3132
import { IgxColumnGroupComponent } from '../columns/column-group.component';
3233
import { IgxColumnComponent } from '../columns/column.component';
3334
import { IForOfState } from '../../directives/for-of/for_of.directive';
@@ -210,7 +211,7 @@ export abstract class IgxHierarchicalGridBaseDirective extends IgxGridBaseDirect
210211
this.columns.forEach(column => {
211212
if (column[output.propName]) {
212213
column[output.propName].pipe(takeUntil(column.destroy$)).subscribe((args) => {
213-
const rowIslandColumn = this.parentIsland.childColumns.find(col => col.field === column.field);
214+
const rowIslandColumn = this.getRowIslandColumn(column, this.parentIsland.childColumns);
214215
rowIslandColumn[output.propName].emit({ args, owner: this });
215216
});
216217
}
@@ -274,6 +275,32 @@ export abstract class IgxHierarchicalGridBaseDirective extends IgxGridBaseDirect
274275
}
275276
return this.gridAPI.getChildGrid(path);
276277
}
278+
279+
private getRowIslandColumn(
280+
target: ColumnType,
281+
columns: QueryList<ColumnType>
282+
): ColumnType {
283+
const targetField = target.field ?? target.header;
284+
let result;
285+
286+
for (const col of columns) {
287+
const colField = col.field ?? col.header;
288+
289+
if (colField === targetField) {
290+
result = col;
291+
break;
292+
} else if (col.children) {
293+
const column = this.getRowIslandColumn(target, col.children);
294+
295+
if (column) {
296+
result = column;
297+
break;
298+
}
299+
}
300+
}
301+
302+
return result;
303+
}
277304
}
278305

279306
const flatten = (arr: any[]) => {

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

Lines changed: 129 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { IgxExcelStyleHeaderComponent } from '../filtering/excel-style/excel-sty
2121
import { IgxExcelStyleSortingComponent } from '../filtering/excel-style/excel-style-sorting.component';
2222
import { IgxExcelStyleSearchComponent } from '../filtering/excel-style/excel-style-search.component';
2323
import { IgxCellHeaderTemplateDirective } from '../columns/templates.directive';
24-
import { CellType, ColumnType, IGridCellEventArgs, IgxColumnComponent, IgxRowEditActionsDirective, IgxRowEditTextDirective } from '../public_api';
24+
import { CellType, ColumnType, IGridCellEventArgs, IgxColumnComponent, IgxColumnGroupComponent, IgxRowEditActionsDirective, IgxRowEditTextDirective } from '../public_api';
2525
import { getComponentSize } from '../../core/utils';
2626

2727
describe('Basic IgxHierarchicalGrid #hGrid', () => {
@@ -42,7 +42,8 @@ describe('Basic IgxHierarchicalGrid #hGrid', () => {
4242
IgxHierarchicalGridAutoSizeColumnsComponent,
4343
IgxHierarchicalGridCustomTemplateComponent,
4444
IgxHierarchicalGridCustomFilteringTemplateComponent,
45-
IgxHierarchicalGridToggleRIAndColsComponent
45+
IgxHierarchicalGridToggleRIAndColsComponent,
46+
IgxHierarchicalGridMCHComponent
4647
]
4748
}).compileComponents();
4849
}))
@@ -1713,6 +1714,42 @@ describe('Basic IgxHierarchicalGrid #hGrid', () => {
17131714
}));
17141715
});
17151716

1717+
describe('IgxHierarchicalGrid Multi-Column Headers', () => {
1718+
let fixture: ComponentFixture<IgxHierarchicalGridMCHComponent>;
1719+
let hierarchicalGrid: IgxHierarchicalGridComponent;
1720+
1721+
beforeEach(() => {
1722+
fixture = TestBed.createComponent(IgxHierarchicalGridMCHComponent);
1723+
fixture.detectChanges();
1724+
hierarchicalGrid = fixture.componentInstance.hGrid;
1725+
});
1726+
1727+
it('should fire expandedChange, hiddenChange and pinnedChange events for child grid.', () => {
1728+
const childGrid = hierarchicalGrid.gridAPI.getChildGrids(false)[0];
1729+
const columnGroup2 = childGrid.columns[4] as IgxColumnGroupComponent;
1730+
const columnGroup2Header = GridFunctions.getColumnGroupHeaders(fixture)[3];
1731+
const expandIcon = columnGroup2Header.queryAll(By.css('.igx-icon'))[0];
1732+
const pinIcon = columnGroup2Header.queryAll(By.css('.igx-icon'))[1];
1733+
1734+
expect(columnGroup2.expanded).toBeFalsy();
1735+
expect(columnGroup2.pinned).toBeFalsy();
1736+
1737+
UIInteractions.simulateClickEvent(expandIcon.nativeElement);
1738+
fixture.detectChanges();
1739+
1740+
expect(columnGroup2.expanded).toBeTruthy();
1741+
1742+
expect(fixture.componentInstance.expandedArgs).toBeDefined();
1743+
expect(fixture.componentInstance.expandedArgs).not.toBe(false);
1744+
expect(fixture.componentInstance.hiddenArgs).toBeDefined();
1745+
1746+
UIInteractions.simulateClickEvent(pinIcon.nativeElement);
1747+
fixture.detectChanges();
1748+
1749+
expect(columnGroup2.pinned).toBeTruthy();
1750+
expect(fixture.componentInstance.pinnedArgs).toBeDefined();
1751+
});
1752+
});
17161753
});
17171754

17181755
@Component({
@@ -2131,3 +2168,93 @@ export class IgxHierarchicalGridCustomRowEditOverlayComponent extends IgxHierarc
21312168
imports: [IgxHierarchicalGridComponent, IgxColumnComponent, IgxRowIslandComponent, IgxRowEditTextDirective, IgxRowEditActionsDirective]
21322169
})
21332170
export class IgxHierarchicalGridAutoSizeColumnsComponent extends IgxHierarchicalGridTestBaseComponent {}
2171+
2172+
@Component({
2173+
template: `
2174+
<ng-template #headerTemplate igxHeader let-col>
2175+
<span >{{ col.header ? col.header : col.field}}</span>
2176+
<igx-icon (click)="pinColumn(col)">push_pin</igx-icon>
2177+
</ng-template>
2178+
<igx-hierarchical-grid #hGrid [data]="data" [height]="'400px'" [width]="'800px'" [expandChildren]="true">
2179+
<igx-column field="CustomerID"></igx-column>
2180+
<igx-column-group header="General Information" [collapsible]="true" [expanded]="false">
2181+
<igx-column field="CompanyName" [visibleWhenCollapsed]="true"></igx-column>
2182+
<igx-column field="ContactName" [visibleWhenCollapsed]="false"></igx-column>
2183+
<igx-column field="ContactTitle" [visibleWhenCollapsed]="false"></igx-column>
2184+
</igx-column-group>
2185+
<igx-column-group header="Address Information" [collapsible]="true" [expanded]="false">
2186+
<igx-column field="Location" [visibleWhenCollapsed]="true"></igx-column>
2187+
<igx-column field="Address" [visibleWhenCollapsed]="false"></igx-column>
2188+
<igx-column field="City" [visibleWhenCollapsed]="false"></igx-column>
2189+
<igx-column field="Country" [visibleWhenCollapsed]="false"></igx-column>
2190+
<igx-column field="PostalCode" [visibleWhenCollapsed]="false"></igx-column>
2191+
</igx-column-group>
2192+
<igx-row-island [height]="null" [key]="'Orders'" [autoGenerate]="false">
2193+
<igx-column-group header="Order Details" [collapsible]="true" [expanded]="false">
2194+
<igx-column field="OrderID" [visibleWhenCollapsed]="true"></igx-column>
2195+
<igx-column field="OrderDate" [dataType]="'date'" [visibleWhenCollapsed]="false"></igx-column>
2196+
<igx-column field="RequiredDate" [dataType]="'date'" [visibleWhenCollapsed]="false"></igx-column>
2197+
</igx-column-group>
2198+
<igx-column-group header="General Shipping Information" [collapsible]="true" [expanded]="false"
2199+
[headerTemplate]="headerTemplate" (expandedChange)="expandedChange($event)">
2200+
<igx-column field="ShippedDate" [dataType]="'date'" [visibleWhenCollapsed]="true"
2201+
(hiddenChange)="hiddenChange($event)" (pinnedChange)="pinnedChange($event)"></igx-column>
2202+
<igx-column field="ShipVia" [visibleWhenCollapsed]="false" ></igx-column>
2203+
<igx-column field="Freight" [visibleWhenCollapsed]="false"></igx-column>
2204+
<igx-column field="ShipName" [visibleWhenCollapsed]="false"></igx-column>
2205+
</igx-column-group>
2206+
</igx-row-island>
2207+
</igx-hierarchical-grid>
2208+
`,
2209+
standalone: true,
2210+
imports: [IgxHierarchicalGridComponent, IgxRowIslandComponent, IgxColumnComponent, IgxColumnGroupComponent, IgxIconComponent, IgxCellHeaderTemplateDirective]
2211+
})
2212+
export class IgxHierarchicalGridMCHComponent {
2213+
@ViewChild('hGrid', { read: IgxHierarchicalGridComponent, static: true })
2214+
public hGrid: IgxHierarchicalGridComponent;
2215+
2216+
public expandedArgs: any;
2217+
public hiddenArgs: any;
2218+
public pinnedArgs: any;
2219+
2220+
public data = [
2221+
{
2222+
CustomerID: "VINET",
2223+
CompanyName: "Vins et alcools Chevalier",
2224+
ContactName: "Paul Henriot",
2225+
ContactTitle: "Accounting Manager",
2226+
Location: "59 rue de l'Abbaye, Reims, France",
2227+
Address: "59 rue de l'Abbaye",
2228+
City: "Reims",
2229+
Country: "France",
2230+
PostalCode: "51100",
2231+
Orders: [
2232+
{
2233+
OrderID: 10248,
2234+
OrderDate: new Date("1996-07-04T00:00:00"),
2235+
RequiredDate: new Date("1996-08-01T00:00:00"),
2236+
ShippedDate: new Date("1996-07-16T00:00:00"),
2237+
ShipVia: 3,
2238+
Freight: 32.38,
2239+
ShipName: "Vins et alcools Chevalier",
2240+
},
2241+
],
2242+
},
2243+
];
2244+
2245+
public pinColumn(col: ColumnType) {
2246+
col.pinned ? col.unpin() : col.pin();
2247+
}
2248+
2249+
public expandedChange(args: any) {
2250+
this.expandedArgs = args;
2251+
}
2252+
2253+
public hiddenChange(args: any) {
2254+
this.hiddenArgs = args;
2255+
}
2256+
2257+
public pinnedChange(args: any) {
2258+
this.pinnedArgs = args;
2259+
}
2260+
}

0 commit comments

Comments
 (0)