Skip to content

Commit

Permalink
Do not override custom widths when rebuilding columns
Browse files Browse the repository at this point in the history
  • Loading branch information
mage-eag committed Jul 28, 2015
1 parent a8f7831 commit 966c4d9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
2 changes: 2 additions & 0 deletions src/features/resize-columns/js/ui-grid-column-resizer.js
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
57 changes: 30 additions & 27 deletions src/js/core/factories/GridColumn.js
Expand Up @@ -417,39 +417,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;
Expand Down

0 comments on commit 966c4d9

Please sign in to comment.