diff --git a/src/features/resize-columns/js/ui-grid-column-resizer.js b/src/features/resize-columns/js/ui-grid-column-resizer.js index 0e9d1b51b9..1c2c27759d 100644 --- a/src/features/resize-columns/js/ui-grid-column-resizer.js +++ b/src/features/resize-columns/js/ui-grid-column-resizer.js @@ -430,6 +430,7 @@ // check we're not outside the allowable bounds for this column col.width = constrainWidth(col, newWidth); + col.hasCustomWidth = true; refreshCanvas(xDiff); @@ -542,6 +543,7 @@ // check we're not outside the allowable bounds for this column col.width = constrainWidth(col, maxWidth); + col.hasCustomWidth = true; refreshCanvas(xDiff); diff --git a/src/js/core/factories/GridColumn.js b/src/js/core/factories/GridColumn.js index e01565eb9f..608fd37f71 100644 --- a/src/js/core/factories/GridColumn.js +++ b/src/js/core/factories/GridColumn.js @@ -427,39 +427,42 @@ angular.module('ui.grid') self.displayName = (colDef.displayName === undefined) ? gridUtil.readableColumnName(colDef.name) : colDef.displayName; - var colDefWidth = colDef.width; - var parseErrorMsg = "Cannot parse column width '" + colDefWidth + "' for column named '" + colDef.name + "'"; - - if (!angular.isString(colDefWidth) && !angular.isNumber(colDefWidth)) { - self.width = '*'; - } else if (angular.isString(colDefWidth)) { - // See if it ends with a percent - if (gridUtil.endsWith(colDefWidth, '%')) { - // If so we should be able to parse the non-percent-sign part to a number - var percentStr = colDefWidth.replace(/%/g, ''); - var percent = parseInt(percentStr, 10); - if (isNaN(percent)) { + if (!angular.isNumber(self.width) || !self.hasCustomWidth || colDef.allowCustomWidthOverride) { + var colDefWidth = colDef.width; + var parseErrorMsg = "Cannot parse column width '" + colDefWidth + "' for column named '" + colDef.name + "'"; + self.hasCustomWidth = false; + + if (!angular.isString(colDefWidth) && !angular.isNumber(colDefWidth)) { + self.width = '*'; + } else if (angular.isString(colDefWidth)) { + // See if it ends with a percent + if (gridUtil.endsWith(colDefWidth, '%')) { + // If so we should be able to parse the non-percent-sign part to a number + var percentStr = colDefWidth.replace(/%/g, ''); + var percent = parseInt(percentStr, 10); + if (isNaN(percent)) { + throw new Error(parseErrorMsg); + } + self.width = colDefWidth; + } + // And see if it's a number string + else if (colDefWidth.match(/^(\d+)$/)) { + self.width = parseInt(colDefWidth.match(/^(\d+)$/)[1], 10); + } + // Otherwise it should be a string of asterisks + else if (colDefWidth.match(/^\*+$/)) { + self.width = colDefWidth; + } + // No idea, throw an Error + else { throw new Error(parseErrorMsg); } - self.width = colDefWidth; - } - // And see if it's a number string - else if (colDefWidth.match(/^(\d+)$/)) { - self.width = parseInt(colDefWidth.match(/^(\d+)$/)[1], 10); } - // Otherwise it should be a string of asterisks - else if (colDefWidth.match(/^\*+$/)) { - self.width = colDefWidth; - } - // No idea, throw an Error + // Is a number, use it as the width else { - throw new Error(parseErrorMsg); + self.width = colDefWidth; } } - // Is a number, use it as the width - else { - self.width = colDefWidth; - } self.minWidth = !colDef.minWidth ? 30 : colDef.minWidth; self.maxWidth = !colDef.maxWidth ? 9000 : colDef.maxWidth;