Skip to content

Commit aabd769

Browse files
authored
Merge pull request #9219 from IgniteUI/dkamburov/fix-9145-10.2
fix(grid): Consider min/max width when setting defaultWidth property
2 parents 5d28060 + db9fcd7 commit aabd769

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4826,13 +4826,42 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
48264826
const columnWidthCombined = parseInt(this._columnWidth, 10) * (column.colEnd ? column.colEnd - column.colStart : 1);
48274827
column.defaultWidth = columnWidthCombined + 'px';
48284828
} else {
4829-
column.defaultWidth = this._columnWidth;
4829+
// D.K. March 29th, 2021 #9145 Consider min/max width when setting defaultWidth property
4830+
column.defaultWidth = this.getExtremumBasedColWidth(column);
48304831
column.resetCaches();
48314832
}
48324833
});
48334834
this.resetCachedWidths();
48344835
}
48354836

4837+
/**
4838+
* @hidden
4839+
* @internal
4840+
*/
4841+
protected getExtremumBasedColWidth(column: IgxColumnComponent): string {
4842+
let width = this._columnWidth;
4843+
if (width && typeof width !== 'string') {
4844+
width = String(width);
4845+
}
4846+
const minWidth = width.indexOf('%') === -1 ? column.minWidthPx : column.minWidthPercent;
4847+
const maxWidth = width.indexOf('%') === -1 ? column.maxWidthPx : column.maxWidthPercent;
4848+
if (column.hidden) {
4849+
return width;
4850+
}
4851+
4852+
if (minWidth > parseFloat(width)) {
4853+
width = String(column.minWidth);
4854+
} else if (maxWidth < parseFloat(width)) {
4855+
width = String(column.maxWidth);
4856+
}
4857+
4858+
// if no px or % are defined in maxWidth/minWidth consider it px
4859+
if (width.indexOf('%') === -1 && width.indexOf('px') === -1) {
4860+
width += 'px';
4861+
}
4862+
return width;
4863+
}
4864+
48364865
/**
48374866
* @hidden
48384867
*/

0 commit comments

Comments
 (0)