Skip to content

Commit f56fbb3

Browse files
authored
fix(igxGrid): Fix when grid and cols have % width in hidden container. (#15211)
1 parent 3bc6364 commit f56fbb3

File tree

5 files changed

+49
-10
lines changed

5 files changed

+49
-10
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
14371437
}
14381438
const unpinnedColumns = this.grid.unpinnedColumns.filter(c => !c.columnGroup);
14391439
const pinnedColumns = this.grid.pinnedColumns.filter(c => !c.columnGroup);
1440-
1440+
14411441
let col = this;
14421442
let vIndex = -1;
14431443

@@ -2326,10 +2326,10 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
23262326
columns = columns.filter(c => c.level >= this.level && c !== this && c.parent !== this &&
23272327
c.topLevelParent === this.topLevelParent);
23282328
}
2329-
2329+
23302330
// If isPreceding, find a target such that when the current column is placed after it, current colummn will receive a visibleIndex === index. This takes into account visible children of the columns.
23312331
// If !isPreceding, finds a column of the same level and visible index that equals the passed index agument (c.visibleIndex === index). No need to consider the children here.
2332-
2332+
23332333
if (isPreceding) {
23342334
columns = columns.filter(c => c.visibleIndex > this.visibleIndex);
23352335
target = columns.find(c => c.level === this.level && c.visibleIndex + (c as any).calcChildren() - this.calcChildren() === index);
@@ -2558,7 +2558,9 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
25582558
const colWidth = this.width;
25592559
const isPercentageWidth = colWidth && typeof colWidth === 'string' && colWidth.indexOf('%') !== -1;
25602560
const isAutoWidth = colWidth && typeof colWidth === 'string' && colWidth === 'fit-content';
2561-
if (isPercentageWidth) {
2561+
if (isPercentageWidth && this.grid.isColumnWidthSum) {
2562+
this._calcWidth = this.grid.minColumnWidth;
2563+
} else if (isPercentageWidth) {
25622564
this._calcWidth = parseFloat(colWidth) / 100 * this.grid.calcWidth;
25632565
} else if (!colWidth || isAutoWidth && !this.autoSize) {
25642566
// no width

projects/igniteui-angular/src/lib/grids/common/grid.interface.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,10 @@ export interface GridType extends IGridDataBindable {
719719
isLoading: boolean;
720720
/** @hidden @internal */
721721
gridSize: Size;
722-
722+
/** @hidden @internal */
723+
isColumnWidthSum: boolean;
724+
/** @hidden @internal */
725+
minColumnWidth: number;
723726
/** Strategy, used for cloning the provided data. The type has one method, that takes any type of data */
724727
dataCloneStrategy: IDataCloneStrategy;
725728

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3007,6 +3007,12 @@ export abstract class IgxGridBaseDirective implements GridType,
30073007
* @hidden @internal
30083008
*/
30093009
public filteringPipeTrigger = 0;
3010+
3011+
/**
3012+
* @hidden @internal
3013+
*/
3014+
public isColumnWidthSum = false;
3015+
30103016
/**
30113017
* @hidden @internal
30123018
*/
@@ -3208,7 +3214,7 @@ export abstract class IgxGridBaseDirective implements GridType,
32083214
private _columnSelectionMode: GridSelectionMode = GridSelectionMode.none;
32093215

32103216
private lastAddedRowIndex;
3211-
protected isColumnWidthSum = false;
3217+
32123218
private _currencyPositionLeft: boolean;
32133219

32143220
private rowEditPositioningStrategy = new RowEditPositionStrategy({
@@ -3241,7 +3247,7 @@ export abstract class IgxGridBaseDirective implements GridType,
32413247
/**
32423248
* @hidden @internal
32433249
*/
3244-
protected get minColumnWidth() {
3250+
public get minColumnWidth() {
32453251
return MINIMUM_COLUMN_WIDTH;
32463252
}
32473253

@@ -4930,7 +4936,7 @@ export abstract class IgxGridBaseDirective implements GridType,
49304936
* @param value
49314937
* @param condition
49324938
* @param ignoreCase
4933-
* @deprecated in version 19.0.0.
4939+
* @deprecated in version 19.0.0.
49344940
*/
49354941
public filterGlobal(value: any, condition, ignoreCase?) {
49364942
this.filteringService.filterGlobal(value, condition, ignoreCase);
@@ -6496,8 +6502,10 @@ export abstract class IgxGridBaseDirective implements GridType,
64966502

64976503

64986504
if (this.width === null || !width) {
6499-
width = this.getColumnWidthSum();
65006505
this.isColumnWidthSum = true;
6506+
width = this.getColumnWidthSum();
6507+
} else {
6508+
this.isColumnWidthSum = false;
65016509
}
65026510

65036511
if (this.hasVerticalScroll() && this.width !== null) {

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,21 @@ describe('IgxGrid Component Tests #grid', () => {
19001900
expect(parseInt(grid.hostWidth, 10)).toBe(30 * 136);
19011901
});
19021902

1903+
it('should render grid and columns with correct width when all are in % and inside a hidden container.', () => {
1904+
// in this case since the grid width is 0, the grid will use the sum of the columns
1905+
// those should resolve to 136px, as per the docs
1906+
const fix = TestBed.createComponent(IgxGridColumnHiddenPercentageWidthComponent);
1907+
const grid = fix.componentInstance.grid;
1908+
grid.width = '100%';
1909+
// 4 cols - 10% width
1910+
fix.componentInstance.initColumnsRows(5, 4);
1911+
fix.detectChanges();
1912+
1913+
expect(grid.calcWidth).toBe(136*4);
1914+
expect(grid.columns[0].calcWidth).toBe(136);
1915+
expect(grid.columns[1].calcWidth).toBe(136);
1916+
});
1917+
19031918
it('should retain column with in % after hiding/showing grid with 100% width', () => {
19041919
const fix = TestBed.createComponent(IgxGridColumnPercentageWidthComponent);
19051920
fix.componentInstance.initColumnsRows(5, 3);
@@ -3123,6 +3138,17 @@ export class IgxGridColumnPercentageWidthComponent extends IgxGridDefaultRenderi
31233138
}
31243139
}
31253140

3141+
@Component({
3142+
template: `<igx-grid #grid [hidden]="hidden" [data]="data" [autoGenerate]="false">
3143+
<igx-column *ngFor="let col of columns" [width]="'10%'" [field]="col.key" [header]="col.key" [dataType]="col.dataType">
3144+
</igx-column>
3145+
</igx-grid>`,
3146+
imports: [IgxGridComponent, IgxColumnComponent, NgFor]
3147+
})
3148+
export class IgxGridColumnHiddenPercentageWidthComponent extends IgxGridDefaultRenderingComponent {
3149+
public hidden = true;
3150+
}
3151+
31263152
@Component({
31273153
template: `<div>
31283154
<igx-grid #grid [data]="data" height='300px' [style.--ig-size]="1" [autoGenerate]="true"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
478478
/**
479479
* @hidden @internal
480480
*/
481-
protected override get minColumnWidth() {
481+
public override get minColumnWidth() {
482482
if (this.superCompactMode) {
483483
return MINIMUM_COLUMN_WIDTH_SUPER_COMPACT;
484484
} else {

0 commit comments

Comments
 (0)