Skip to content

Commit 3ac3c5b

Browse files
dkamburov3phaseChronosSF
authored
fix(grid): Consider min/max width when setting defaultWidth property (#9217)
* fix(grid): Consider min/max width when setting defaultWidth property Fix columnWidth as number scenario, adjust unit test scenarios Co-authored-by: Pepo <[email protected]> Co-authored-by: Stamen Stoychev <[email protected]>
1 parent b473229 commit 3ac3c5b

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
@@ -6081,13 +6081,42 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
60816081
const columnWidthCombined = parseInt(this._columnWidth, 10) * (column.colEnd ? column.colEnd - column.colStart : 1);
60826082
column.defaultWidth = columnWidthCombined + 'px';
60836083
} else {
6084-
column.defaultWidth = this._columnWidth;
6084+
// D.K. March 29th, 2021 #9145 Consider min/max width when setting defaultWidth property
6085+
column.defaultWidth = this.getExtremumBasedColWidth(column);
60856086
column.resetCaches();
60866087
}
60876088
});
60886089
this.resetCachedWidths();
60896090
}
60906091

6092+
/**
6093+
* @hidden
6094+
* @internal
6095+
*/
6096+
protected getExtremumBasedColWidth(column: IgxColumnComponent): string {
6097+
let width = this._columnWidth;
6098+
if (width && typeof width !== 'string') {
6099+
width = String(width);
6100+
}
6101+
const minWidth = width.indexOf('%') === -1 ? column.minWidthPx : column.minWidthPercent;
6102+
const maxWidth = width.indexOf('%') === -1 ? column.maxWidthPx : column.maxWidthPercent;
6103+
if (column.hidden) {
6104+
return width;
6105+
}
6106+
6107+
if (minWidth > parseFloat(width)) {
6108+
width = String(column.minWidth);
6109+
} else if (maxWidth < parseFloat(width)) {
6110+
width = String(column.maxWidth);
6111+
}
6112+
6113+
// if no px or % are defined in maxWidth/minWidth consider it px
6114+
if (width.indexOf('%') === -1 && width.indexOf('px') === -1) {
6115+
width += 'px';
6116+
}
6117+
return width;
6118+
}
6119+
60916120
protected resetNotifyChanges() {
60926121
this._cdrRequestRepaint = false;
60936122
this._cdrRequests = false;

0 commit comments

Comments
 (0)