Skip to content

Commit 1e3aac5

Browse files
Copilotivanvpetrov
andcommitted
fix(grid): prevent header/cell misalignment with collapsible column groups (#17042)
Co-authored-by: ivanvpetrov <110455887+ivanvpetrov@users.noreply.github.com> Agent-Logs-Url: https://github.com/IgniteUI/igniteui-angular/sessions/2868c645-079b-41e4-8b5f-299bfac230a2
1 parent 57175e4 commit 1e3aac5

4 files changed

Lines changed: 65 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ All notable changes for each version of this project will be documented in this
99
- `IgxCombo`, `IgxSimpleCombo`
1010
- Introduced the `selectionChanged` event for both components. The event is not cancelable and is emitted after the selection is committed and the component state is updated.
1111

12+
### General
13+
14+
- `IgxGrid`
15+
- Fixed an issue where headers and cells became misaligned when collapsible column groups were present and columns inside the collapsed group had explicit width values, causing standalone columns to misalign with their headers when scrolled horizontally (#17042).
16+
1217
## 21.1.3
1318

1419
### Security Fixes

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5654,7 +5654,7 @@ export abstract class IgxGridBaseDirective implements GridType,
56545654

56555655
const columnsWithSetWidths = this.hasColumnLayouts ?
56565656
visibleCols.filter(c => c.widthSetByUser) :
5657-
visibleChildColumns.filter(c => (c.widthSetByUser || c.widthConstrained) && c.width !== 'fit-content');
5657+
visibleChildColumns.filter(c => (c.widthSetByUser || (c.widthConstrained && !isNaN(c.calcPixelWidth))) && c.width !== 'fit-content');
56585658

56595659
const columnsToSize = this.hasColumnLayouts ?
56605660
combinedBlocksSize - columnsWithSetWidths.length :

projects/igniteui-angular/grids/grid/src/grid-collapsible-columns.spec.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
44
import {
55
CollapsibleColumnGroupTestComponent,
66
CollapsibleGroupsTemplatesTestComponent,
7-
CollapsibleGroupsDynamicColComponent
7+
CollapsibleGroupsDynamicColComponent,
8+
CollapsibleGroupWithExplicitWidthsTestComponent
89
} from '../../../test-utils/grid-samples.spec';
910
import { GridFunctions } from '../../../test-utils/grid-functions.spec';
1011
import { UIInteractions, wait } from '../../../test-utils/ui-interactions.spec';
@@ -28,7 +29,8 @@ describe('IgxGrid - multi-column headers #grid', () => {
2829
NoopAnimationsModule,
2930
CollapsibleColumnGroupTestComponent,
3031
CollapsibleGroupsTemplatesTestComponent,
31-
CollapsibleGroupsDynamicColComponent
32+
CollapsibleGroupsDynamicColComponent,
33+
CollapsibleGroupWithExplicitWidthsTestComponent
3234
]
3335
}).compileComponents();
3436
}));
@@ -636,4 +638,40 @@ describe('IgxGrid - multi-column headers #grid', () => {
636638
GridFunctions.verifyColumnIsHidden(countryCol, true, 12);
637639
});
638640
});
641+
642+
describe('Column width after collapse', () => {
643+
let fixture;
644+
let grid: IgxGridComponent;
645+
646+
beforeEach(fakeAsync(() => {
647+
fixture = TestBed.createComponent(CollapsibleGroupWithExplicitWidthsTestComponent);
648+
fixture.detectChanges();
649+
tick(16);
650+
fixture.detectChanges();
651+
grid = fixture.componentInstance.grid;
652+
}));
653+
654+
it('standalone auto-sized columns with minWidth should not use stale widthConstrained after group collapse', fakeAsync(() => {
655+
// In expanded state, standalone columns (minWidth=150px) fill (700 - 400) / 2 = 150px each,
656+
// which equals minWidth, causing widthConstrained=true.
657+
const standaloneContactName = grid.getColumnByName('ContactName');
658+
const standaloneContactTitle = grid.getColumnByName('ContactTitle');
659+
660+
// Confirm group is initially expanded and standalone columns are constrained at minWidth
661+
const groupA = GridFunctions.getColGroup(grid, 'Group A');
662+
expect(groupA.expanded).toBe(true);
663+
expect(standaloneContactName.calcPixelWidth).toBeLessThanOrEqual(150);
664+
665+
// Collapse the group — grouped columns (ID, CompanyName) become hidden
666+
groupA.expanded = false;
667+
tick(16);
668+
fixture.detectChanges();
669+
670+
// After collapse only the 2 standalone auto-sized columns remain visible.
671+
// Expected width per standalone ≈ 700 / 2 = 350px (no explicit-width columns remain visible).
672+
// Bug: stale widthConstrained=true causes columnsToSize=0 → columnWidth=Infinity → wrong calcPixelWidth.
673+
expect(standaloneContactName.calcPixelWidth).toBeGreaterThan(200);
674+
expect(standaloneContactTitle.calcPixelWidth).toBeGreaterThan(200);
675+
}));
676+
});
639677
});

projects/igniteui-angular/test-utils/grid-samples.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,6 +2009,25 @@ export class CollapsibleGroupsDynamicColComponent {
20092009
}
20102010
}
20112011

2012+
@Component({
2013+
template: `
2014+
<igx-grid #grid [data]="data" height="500px" width="700px">
2015+
<igx-column-group header="Group A" [collapsible]="true">
2016+
<igx-column field="ID" width="200px" [visibleWhenCollapsed]="false"></igx-column>
2017+
<igx-column field="CompanyName" width="200px" [visibleWhenCollapsed]="false"></igx-column>
2018+
</igx-column-group>
2019+
<igx-column field="ContactName" minWidth="150px"></igx-column>
2020+
<igx-column field="ContactTitle" minWidth="150px"></igx-column>
2021+
</igx-grid>
2022+
`,
2023+
imports: [IgxGridComponent, IgxColumnComponent, IgxColumnGroupComponent]
2024+
})
2025+
export class CollapsibleGroupWithExplicitWidthsTestComponent {
2026+
@ViewChild(IgxGridComponent, { read: IgxGridComponent, static: true })
2027+
public grid: IgxGridComponent;
2028+
public data = SampleTestData.contactInfoDataFull();
2029+
}
2030+
20122031
@Component({
20132032
template: `
20142033
<igx-grid #grid [data]="data" height="500px" width="1300px" columnWidth="100px">

0 commit comments

Comments
 (0)