Skip to content

Commit f655438

Browse files
Use allowFloatWidth property to allow float calculations for widths
1 parent 355559a commit f655438

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

packages/core/src/js/factories/GridColumn.js

+12
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,18 @@ angular.module('ui.grid')
258258
*
259259
*/
260260

261+
/**
262+
* @ngdoc property
263+
* @name allowFloatWidth
264+
* @propertyOf ui.grid.class:GridOptions.columnDef
265+
* @description Allows float number in column width calculation
266+
* @example
267+
* <pre> $scope.gridOptions.columnDefs = [ { field: 'field1', width: 50.5, allowFloatWidth: true},
268+
* { field: 'field2', width: '20%', allowFloatWidth: true},
269+
* { field: 'field3', width: '*', allowFloatWidth: true }]; </pre>
270+
*
271+
*/
272+
261273
/**
262274
* @ngdoc property
263275
* @name minWidth

packages/core/src/js/factories/GridRenderContainer.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,12 @@ angular.module('ui.grid')
606606

607607
if (angular.isNumber(column.width)) {
608608
// pixel width, set to this value
609-
width = parseInt(column.width, 10);
609+
if(column.colDef.allowFloatWidth) {
610+
width = parseFloat(column.width);
611+
} else {
612+
width = parseInt(column.width, 10);
613+
}
614+
610615
usedWidthSum = usedWidthSum + width;
611616
column.drawnWidth = width;
612617

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

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

660+
if(column.colDef.allowFloatWidth) {
661+
width = parseFloat(column.width.length * asteriskVal);
662+
}
663+
664+
650665
if (width > column.maxWidth) {
651666
width = column.maxWidth;
652667
}

0 commit comments

Comments
 (0)