Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2527,7 +2527,9 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy, ColumnTy
const colWidth = this.width;
const isPercentageWidth = colWidth && typeof colWidth === 'string' && colWidth.indexOf('%') !== -1;
const isAutoWidth = colWidth && typeof colWidth === 'string' && colWidth === 'fit-content';
if (isPercentageWidth) {
if (isPercentageWidth && this.grid.isColumnWidthSum) {
this._calcWidth = this.grid.minColumnWidth;
} else if (isPercentageWidth ) {
this._calcWidth = Math.floor(parseFloat(colWidth) / 100 * this.grid.calcWidth);
} else if (!colWidth || isAutoWidth && !this.autoSize) {
// no width
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,10 @@ export interface GridType extends IGridDataBindable {
isLoading: boolean;
/** @hidden @internal */
gridSize: Size;

/** @hidden @internal */
isColumnWidthSum: boolean;
/** @hidden @internal */
minColumnWidth: number;
/** Strategy, used for cloning the provided data. The type has one method, that takes any type of data */
dataCloneStrategy: IDataCloneStrategy;

Expand Down
14 changes: 11 additions & 3 deletions projects/igniteui-angular/src/lib/grids/grid-base.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3001,6 +3001,12 @@ export abstract class IgxGridBaseDirective implements GridType,
* @hidden @internal
*/
public filteringPipeTrigger = 0;

/**
* @hidden @internal
*/
public isColumnWidthSum = false;

/**
* @hidden @internal
*/
Expand Down Expand Up @@ -3201,7 +3207,7 @@ export abstract class IgxGridBaseDirective implements GridType,
private _columnSelectionMode: GridSelectionMode = GridSelectionMode.none;

private lastAddedRowIndex;
protected isColumnWidthSum = false;

private _currencyPositionLeft: boolean;

private rowEditPositioningStrategy = new RowEditPositionStrategy({
Expand Down Expand Up @@ -3234,7 +3240,7 @@ export abstract class IgxGridBaseDirective implements GridType,
/**
* @hidden @internal
*/
protected get minColumnWidth() {
public get minColumnWidth() {
return MINIMUM_COLUMN_WIDTH;
}

Expand Down Expand Up @@ -6488,8 +6494,10 @@ export abstract class IgxGridBaseDirective implements GridType,


if (this.width === null || !width) {
width = this.getColumnWidthSum();
this.isColumnWidthSum = true;
width = this.getColumnWidthSum();
} else {
this.isColumnWidthSum = false;
}

if (this.hasVerticalScroll() && this.width !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,21 @@ describe('IgxGrid Component Tests #grid', () => {
expect(parseInt(grid.hostWidth, 10)).toBe(30 * 136);
});

it('should render grid and columns with correct width when all are in % and inside a hidden container.', () => {
// in this case since the grid width is 0, the grid will use the sum of the columns
// those should resolve to 136px, as per the docs
const fix = TestBed.createComponent(IgxGridColumnHiddenPercentageWidthComponent);
const grid = fix.componentInstance.grid;
grid.width = '100%';
// 4 cols - 10% width
fix.componentInstance.initColumnsRows(5, 4);
fix.detectChanges();

expect(grid.calcWidth).toBe(136*4);
expect(grid.columns[0].calcWidth).toBe(136);
expect(grid.columns[1].calcWidth).toBe(136);
});

it('should retain column with in % after hiding/showing grid with 100% width', () => {
const fix = TestBed.createComponent(IgxGridColumnPercentageWidthComponent);
fix.componentInstance.initColumnsRows(5, 3);
Expand Down Expand Up @@ -3100,6 +3115,18 @@ export class IgxGridColumnPercentageWidthComponent extends IgxGridDefaultRenderi
}
}

@Component({
template: `<igx-grid #grid [hidden]="hidden" [data]="data" [autoGenerate]="false">
<igx-column *ngFor="let col of columns" [width]="'10%'" [field]="col.key" [header]="col.key" [dataType]="col.dataType">
</igx-column>
</igx-grid>`,
standalone: true,
imports: [IgxGridComponent, IgxColumnComponent, NgFor]
})
export class IgxGridColumnHiddenPercentageWidthComponent extends IgxGridDefaultRenderingComponent {
public hidden = true;
}

@Component({
template: `<div>
<igx-grid #grid [data]="data" height='300px' [style.--ig-size]="1" [autoGenerate]="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
/**
* @hidden @internal
*/
protected override get minColumnWidth() {
public override get minColumnWidth() {
if (this.superCompactMode) {
return MINIMUM_COLUMN_WIDTH_SUPER_COMPACT;
} else {
Expand Down
Loading