Skip to content

Commit b351e86

Browse files
authored
Merge pull request #13623 from IgniteUI/iminchev/fix-header-autosize
fix(igxGrid): autosize hidden empty column headers correctly - master
2 parents c0e1ac2 + 27f9d59 commit b351e86

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7098,13 +7098,13 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
70987098
}
70997099
const cells = this._dataRowList.map(x => x.cells.find(c => c.column === col));
71007100
cells.forEach((cell) => cellsContentWidths.push(cell?.nativeElement?.offsetWidth || 0));
7101+
const header = this.headerCellList.find(x => x.column === col);
7102+
cellsContentWidths.push(header.nativeElement.offsetWidth);
71017103
const max = Math.max(...cellsContentWidths);
71027104
if (max === 0) {
71037105
// cells not in DOM yet...
71047106
continue;
71057107
}
7106-
const header = this.headerCellList.find(x => x.column === col);
7107-
cellsContentWidths.push(header.nativeElement.offsetWidth);
71087108
let maxSize = Math.ceil(Math.max(...cellsContentWidths)) + 1;
71097109
if (col.maxWidth && maxSize > col.maxWidthPx) {
71107110
maxSize = col.maxWidthPx;

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,6 +1864,23 @@ describe('IgxGrid Component Tests #grid', () => {
18641864

18651865
expect(grid.columnList.get(0).width).toBe('50%');
18661866
});
1867+
1868+
it('should correctly autosize column headers when the grid container has no data and is initially hidden and then shown', async () => {
1869+
const fix = TestBed.createComponent(IgxGridColumnHeaderAutoSizeComponent);
1870+
const grid = fix.componentInstance.grid;
1871+
1872+
//waiting for reqeustAnimationFrame to finish
1873+
await wait(17);
1874+
fix.detectChanges();
1875+
1876+
fix.componentInstance.gridContainerHidden = false;
1877+
await wait(17)
1878+
fix.detectChanges()
1879+
1880+
const calcWidth = parseInt(grid.columnList.first.calcWidth, 10)
1881+
1882+
expect(calcWidth).not.toBe(80);
1883+
});
18671884
});
18681885

18691886
describe('IgxGrid - API methods', () => {
@@ -2870,6 +2887,39 @@ export class IgxGridDefaultRenderingComponent {
28702887
}
28712888
}
28722889

2890+
@Component({
2891+
template: `
2892+
<div [hidden]="gridContainerHidden">
2893+
<igx-grid #grid>
2894+
<igx-column
2895+
field="field1"
2896+
header="Field 1 Header"
2897+
width="auto"
2898+
></igx-column>
2899+
<igx-column
2900+
field="field2"
2901+
header="Field 2 Header"
2902+
width="auto"
2903+
></igx-column>
2904+
<igx-column
2905+
field="field3"
2906+
header="Field 3 Header"
2907+
width="auto"
2908+
></igx-column>
2909+
</igx-grid>
2910+
</div>`,
2911+
standalone: true,
2912+
imports: [IgxGridComponent, IgxColumnComponent]
2913+
2914+
})
2915+
export class IgxGridColumnHeaderAutoSizeComponent {
2916+
@ViewChild('grid', { read: IgxGridComponent, static: true })
2917+
public grid: IgxGridComponent;
2918+
2919+
public gridContainerHidden = true;
2920+
2921+
}
2922+
28732923
@Component({
28742924
template: `<igx-grid #grid [data]="data" [width]="'500px'" (columnInit)="initColumns($event)">
28752925
<igx-column *ngFor="let col of columns" [field]="col.key" [header]="col.key" [dataType]="col.dataType">

0 commit comments

Comments
 (0)