Skip to content

Commit 14e1e2e

Browse files
committed
fix(grid): update group children when add/delete a column #5837
1 parent 66420c8 commit 14e1e2e

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

projects/igniteui-angular/src/lib/grids/column.component.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
Input,
99
QueryList,
1010
TemplateRef,
11-
forwardRef
11+
forwardRef,
12+
OnDestroy
1213
} from '@angular/core';
1314
import { DataType } from '../data-operations/data-util';
1415
import { GridBaseAPIService } from './api.service';
@@ -33,6 +34,8 @@ import { DeprecateProperty } from '../core/deprecateDecorators';
3334
import { MRLColumnSizeInfo, MRLResizeColumnInfo } from '../data-operations/multi-row-layout.interfaces';
3435
import { DisplayDensity } from '../core/displayDensity';
3536
import { notifyChanges } from './watch-changes';
37+
import { Subject } from 'rxjs';
38+
import { takeUntil } from 'rxjs/operators';
3639
import {
3740
IgxCellTemplateDirective,
3841
IgxCellHeaderTemplateDirective,
@@ -1646,7 +1649,8 @@ export class IgxColumnComponent implements AfterContentInit {
16461649
selector: 'igx-column-group',
16471650
template: ``
16481651
})
1649-
export class IgxColumnGroupComponent extends IgxColumnComponent implements AfterContentInit {
1652+
export class IgxColumnGroupComponent extends IgxColumnComponent implements AfterContentInit, OnDestroy {
1653+
private destroy$ = new Subject<boolean>();
16501654

16511655
@ContentChildren(IgxColumnComponent, { read: IgxColumnComponent })
16521656
children = new QueryList<IgxColumnComponent>();
@@ -1774,11 +1778,22 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
17741778
if (this.headTemplate && this.headTemplate.length) {
17751779
this._headerTemplate = this.headTemplate.toArray()[0].template;
17761780
}
1777-
this.children.reset(this.children.toArray().slice(1));
1778-
this.children.forEach(child => {
1779-
child.parent = this;
1781+
this.updateChildren();
1782+
this.children.changes.pipe(takeUntil(this.destroy$))
1783+
.subscribe(() => {
1784+
this.updateChildren();
17801785
});
17811786
}
1787+
1788+
protected updateChildren() {
1789+
if (this.children && this.children.toArray().length > 0 && this.children.toArray()[0] === this) {
1790+
this.children.reset(this.children.toArray().slice(1));
1791+
this.children.forEach(child => {
1792+
child.parent = this;
1793+
});
1794+
}
1795+
}
1796+
17821797
/**
17831798
* Returns the children columns collection.
17841799
* ```typescript
@@ -1836,6 +1851,14 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
18361851
// D.P. constructor duplication due to es6 compilation, might be obsolete in the future
18371852
super(gridAPI, cdr);
18381853
}
1854+
1855+
/**
1856+
* @hidden
1857+
*/
1858+
public ngOnDestroy() {
1859+
this.destroy$.next(true);
1860+
this.destroy$.complete();
1861+
}
18391862
}
18401863

18411864
@Component({
@@ -1980,5 +2003,4 @@ export class IgxColumnLayoutComponent extends IgxColumnGroupComponent implements
19802003
this.childrenVisibleIndexes.push({column: child, index: vIndex});
19812004
});
19822005
}
1983-
19842006
}

0 commit comments

Comments
 (0)