Skip to content

Commit

Permalink
fix(core): use allowFloatWidth property to allow float calculations f…
Browse files Browse the repository at this point in the history
…or width
  • Loading branch information
marc-khoury-kronos authored and mportuga committed Jun 9, 2021
1 parent 355559a commit f4d3e22
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/core/src/js/factories/GridColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,18 @@ angular.module('ui.grid')
*
*/

/**
* @ngdoc property
* @name allowFloatWidth
* @propertyOf ui.grid.class:GridOptions.columnDef
* @description Allows float number in column width calculation
* @example
* <pre> $scope.gridOptions.columnDefs = [ { field: 'field1', width: 50.5, allowFloatWidth: true},
* { field: 'field2', width: '20%', allowFloatWidth: true},
* { field: 'field3', width: '*', allowFloatWidth: true }]; </pre>
*
*/

/**
* @ngdoc property
* @name minWidth
Expand Down
19 changes: 17 additions & 2 deletions packages/core/src/js/factories/GridRenderContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,12 @@ angular.module('ui.grid')

if (angular.isNumber(column.width)) {
// pixel width, set to this value
width = parseInt(column.width, 10);
if(column.colDef.allowFloatWidth) {
width = parseFloat(column.width);
} else {
width = parseInt(column.width, 10);
}

usedWidthSum = usedWidthSum + width;
column.drawnWidth = width;

Expand All @@ -615,7 +620,12 @@ angular.module('ui.grid')
// percentage width, set to percentage of the viewport
// round down to int - some browsers don't play nice with float maxWidth
var percentageIntegerValue = parseInt(column.width.replace(/%/g, ''), 10);
width = parseInt(percentageIntegerValue / 100 * availableWidth);
if(column.colDef.allowFloatWidth) {
width = parseFloat(percentageIntegerValue / 100 * availableWidth);
} else {
width = parseInt(percentageIntegerValue / 100 * availableWidth, 10);
}


if (width > column.maxWidth) {
width = column.maxWidth;
Expand Down Expand Up @@ -647,6 +657,11 @@ angular.module('ui.grid')
asterisksArray.forEach(function (column) {
var width = parseInt(column.width.length * asteriskVal, 10);

if(column.colDef.allowFloatWidth) {
width = parseFloat(column.width.length * asteriskVal);
}


if (width > column.maxWidth) {
width = column.maxWidth;
}
Expand Down

0 comments on commit f4d3e22

Please sign in to comment.