Skip to content

Commit 140981f

Browse files
Merge pull request #14746 from IgniteUI/bpachilova/fix-col-group-hidden-initially-17.2.x
fix(igx-grid): hide igx-column-group when hidden=true is set in the template initially - 17.2.x
2 parents c314ed8 + 74fbbe1 commit 140981f

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
285285
if (this.pinned) {
286286
child.pinned = this.pinned;
287287
}
288+
if (this._hidden) {
289+
child.hidden = this._hidden;
290+
}
288291
});
289292
if (this.collapsible) {
290293
this.setExpandCollapseState();

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import { OneGroupOneColGridComponent, OneGroupThreeColsGridComponent,
1818
NestedColGroupsGridComponent, StegosaurusGridComponent,
1919
OneColPerGroupGridComponent, NestedColumnGroupsGridComponent,
2020
DynamicGridComponent, NestedColGroupsWithTemplatesGridComponent,
21-
DynamicColGroupsGridComponent } from '../../test-utils/grid-mch-sample.spec';
21+
DynamicColGroupsGridComponent,
22+
ColumnGroupHiddenInTemplateComponent} from '../../test-utils/grid-mch-sample.spec';
2223
import { CellType } from '../common/grid.interface';
2324

2425
const GRID_COL_THEAD_TITLE_CLASS = 'igx-grid-th__title';
@@ -47,7 +48,8 @@ describe('IgxGrid - multi-column headers #grid', () => {
4748
NestedColumnGroupsGridComponent,
4849
DynamicGridComponent,
4950
NestedColGroupsWithTemplatesGridComponent,
50-
DynamicColGroupsGridComponent
51+
DynamicColGroupsGridComponent,
52+
ColumnGroupHiddenInTemplateComponent
5153
]
5254
})
5355
.compileComponents();
@@ -392,6 +394,20 @@ describe('IgxGrid - multi-column headers #grid', () => {
392394
expect(generalHeader.nativeElement.firstElementChild.title).toBe('General Information Title');
393395
expect(addressHeader.nativeElement.firstElementChild.title).toBe('Address Information');
394396
});
397+
398+
it('should hide column group when hidden property is set to true in the template - parent and child level', () => {
399+
fixture = TestBed.createComponent(ColumnGroupHiddenInTemplateComponent);
400+
fixture.detectChanges();
401+
402+
grid = fixture.componentInstance.grid;
403+
const generalGroup = grid.columnList.find(c => c.header === 'General Information');
404+
const locationGroup = grid.columnList.find(c => c.header === 'Location');
405+
expect(generalGroup.hidden).toBe(true);
406+
expect(locationGroup.hidden).toBe(true);
407+
408+
expect(GridFunctions.getColumnHeaders(fixture).length).toEqual(6);
409+
expect(GridFunctions.getColumnGroupHeaders(fixture).length).toEqual(2);
410+
});
395411
});
396412

397413
describe('Columns widths tests (1 group 1 column) ', () => {

projects/igniteui-angular/src/lib/test-utils/grid-mch-sample.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,3 +660,36 @@ export class NestedColGroupsWithTemplatesGridComponent {
660660

661661
public data = SampleTestData.contactInfoDataFull();
662662
}
663+
664+
@Component({
665+
template: `
666+
<igx-grid #grid [data]="data" height="500px" >
667+
<igx-column field="ID"></igx-column>
668+
<igx-column-group header="General Information" [hidden]="true">
669+
<igx-column [filterable]="true" [sortable]="true" [resizable]="true" field="CompanyName"></igx-column>
670+
<igx-column-group header="Person Details">
671+
<igx-column [filterable]="true" [sortable]="true" [resizable]="true" field="ContactName"></igx-column>
672+
<igx-column [filterable]="true" [sortable]="true" [resizable]="true" field="ContactTitle"></igx-column>
673+
</igx-column-group>
674+
</igx-column-group>
675+
<igx-column-group header="Address Information">
676+
<igx-column-group header="Location" [hidden]="true">
677+
<igx-column [filterable]="true" [sortable]="true" [resizable]="true" field="Country"></igx-column>
678+
<igx-column [filterable]="true" [sortable]="true" [resizable]="true" field="Region"></igx-column>
679+
</igx-column-group>
680+
<igx-column [filterable]="true" [sortable]="true" [resizable]="true" field="City"></igx-column>
681+
<igx-column [filterable]="true" [sortable]="true" [resizable]="true" field="Address"></igx-column>
682+
<igx-column-group header="Contact Information">
683+
<igx-column [filterable]="true" [sortable]="true" [resizable]="true" field="Phone"></igx-column>
684+
<igx-column [filterable]="true" [sortable]="true" [resizable]="true" field="Fax"></igx-column>
685+
<igx-column [filterable]="true" [sortable]="true" [resizable]="true" field="PostalCode"></igx-column>
686+
</igx-column-group>
687+
</igx-column-group>
688+
<igx-column-group #emptyColGroup header="Empty Header">
689+
</igx-column-group>
690+
</igx-grid>
691+
`,
692+
standalone: true,
693+
imports: [IgxGridComponent, IgxColumnGroupComponent, IgxColumnComponent]
694+
})
695+
export class ColumnGroupHiddenInTemplateComponent extends ColumnGroupTestComponent { }

0 commit comments

Comments
 (0)