Skip to content

Commit 1774173

Browse files
dkamburovChronosSF
andauthored
fix(grid): Consider min/max width when setting defaultWidth property (#9218)
* fix(grid): Consider min/max width when setting defaultWidth property Fix columnWidth as number scenario, adjust unit test scenarios Co-authored-by: Stamen Stoychev <[email protected]>
1 parent 0f15b30 commit 1774173

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
@@ -6230,13 +6230,42 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
62306230
const columnWidthCombined = parseInt(this._columnWidth, 10) * (column.colEnd ? column.colEnd - column.colStart : 1);
62316231
column.defaultWidth = columnWidthCombined + 'px';
62326232
} else {
6233-
column.defaultWidth = this._columnWidth;
6233+
// D.K. March 29th, 2021 #9145 Consider min/max width when setting defaultWidth property
6234+
column.defaultWidth = this.getExtremumBasedColWidth(column);
62346235
column.resetCaches();
62356236
}
62366237
});
62376238
this.resetCachedWidths();
62386239
}
62396240

6241+
/**
6242+
* @hidden
6243+
* @internal
6244+
*/
6245+
protected getExtremumBasedColWidth(column: IgxColumnComponent): string {
6246+
let width = this._columnWidth;
6247+
if (width && typeof width !== 'string') {
6248+
width = String(width);
6249+
}
6250+
const minWidth = width.indexOf('%') === -1 ? column.minWidthPx : column.minWidthPercent;
6251+
const maxWidth = width.indexOf('%') === -1 ? column.maxWidthPx : column.maxWidthPercent;
6252+
if (column.hidden) {
6253+
return width;
6254+
}
6255+
6256+
if (minWidth > parseFloat(width)) {
6257+
width = String(column.minWidth);
6258+
} else if (maxWidth < parseFloat(width)) {
6259+
width = String(column.maxWidth);
6260+
}
6261+
6262+
// if no px or % are defined in maxWidth/minWidth consider it px
6263+
if (width.indexOf('%') === -1 && width.indexOf('px') === -1) {
6264+
width += 'px';
6265+
}
6266+
return width;
6267+
}
6268+
62406269
protected resetNotifyChanges() {
62416270
this._cdrRequestRepaint = false;
62426271
this._cdrRequests = false;

0 commit comments

Comments
 (0)