From e1aea99db09ca4f18137beecf58aa4eed2067a16 Mon Sep 17 00:00:00 2001 From: MKirova Date: Wed, 12 Aug 2026 15:30:24 +0300 Subject: [PATCH] fix(hierarchicalGrid): Ensure col instances created from ri cols are destroyed. --- .../src/hierarchical-grid-base.directive.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/projects/igniteui-angular/grids/hierarchical-grid/src/hierarchical-grid-base.directive.ts b/projects/igniteui-angular/grids/hierarchical-grid/src/hierarchical-grid-base.directive.ts index 5d5c189cb2d..f1d4e4ed295 100644 --- a/projects/igniteui-angular/grids/hierarchical-grid/src/hierarchical-grid-base.directive.ts +++ b/projects/igniteui-angular/grids/hierarchical-grid/src/hierarchical-grid-base.directive.ts @@ -1,5 +1,6 @@ import { booleanAttribute, + ComponentRef, createComponent, Directive, EventEmitter, @@ -132,6 +133,8 @@ export abstract class IgxHierarchicalGridBaseDirective extends IgxGridBaseDirect /* blazorSuppress */ public abstract expandChildren: boolean; + protected _rowIslandColumnRefs: ComponentRef[] = []; + /** * @hidden */ @@ -141,6 +144,7 @@ export abstract class IgxHierarchicalGridBaseDirective extends IgxGridBaseDirect topLevelCols.forEach((col) => { col.grid = this; const ref = this._createColumn(col); + this._rowIslandColumnRefs.push(ref); ref.changeDetectorRef.detectChanges(); columns.push(ref.instance); }); @@ -189,7 +193,9 @@ export abstract class IgxHierarchicalGridBaseDirective extends IgxGridBaseDirect if (col.children.length > 0) { const newChildren = []; col.children.forEach(child => { - const newCol = this._createColumn(child).instance; + const childRef = this._createColumn(child); + this._rowIslandColumnRefs.push(childRef); + const newCol = childRef.instance; newCol.parent = ref.instance; newChildren.push(newCol); }); @@ -214,6 +220,16 @@ export abstract class IgxHierarchicalGridBaseDirective extends IgxGridBaseDirect return ref; } + public override ngOnDestroy() { + this.destroyRowIslandColumnRefs(); + super.ngOnDestroy(); + } + + protected destroyRowIslandColumnRefs() { + this._rowIslandColumnRefs.forEach(ref => ref.destroy()); + this._rowIslandColumnRefs = []; + } + protected getGridsForIsland(rowIslandID: string) { return this.gridAPI.getChildGridsForRowIsland(rowIslandID); }