From 74544089592152b052b0f8f5482a851ca655d657 Mon Sep 17 00:00:00 2001 From: c0bra Date: Fri, 3 Oct 2014 14:14:38 -0500 Subject: [PATCH] fix(Column Resizing): Don't update widths in colDef column.drawnWidth wasn't being updated after column resizing. This change does two things: 1. Prevent updating column.width in `updateColumnDef` if it already has a value set and the value is a number. If the column has a width that's a number then we're assuming the user has said "I want it to be this wide" and we shouldn't override that. 2. In the column resizer feature, update column.width, not colDef.width. --- .../js/ui-grid-column-resizer.js | 6 +-- src/js/core/factories/GridColumn.js | 50 ++++++++++--------- 2 files changed, 29 insertions(+), 27 deletions(-) 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 7965f4550a..51b1a20a7c 100644 --- a/src/features/resize-columns/js/ui-grid-column-resizer.js +++ b/src/features/resize-columns/js/ui-grid-column-resizer.js @@ -263,7 +263,7 @@ var colDef = column.colDef; if (!colDef.width || (angular.isString(colDef.width) && (colDef.width.indexOf('*') !== -1 || colDef.width.indexOf('%') !== -1))) { - colDef.width = column.drawnWidth; + column.width = column.drawnWidth; } }); } @@ -384,7 +384,7 @@ newWidth = col.colDef.maxWidth; } - col.colDef.width = newWidth; + col.width = newWidth; // All other columns because fixed to their drawn width, if they aren't already resizeAroundColumn(col); @@ -488,7 +488,7 @@ maxWidth = col.colDef.maxWidth; } - col.colDef.width = parseInt(maxWidth, 10); + col.width = parseInt(maxWidth, 10); // All other columns because fixed to their drawn width, if they aren't already resizeAroundColumn(col); diff --git a/src/js/core/factories/GridColumn.js b/src/js/core/factories/GridColumn.js index cc363bd8f9..281b9a54ef 100644 --- a/src/js/core/factories/GridColumn.js +++ b/src/js/core/factories/GridColumn.js @@ -311,35 +311,37 @@ angular.module('ui.grid') var parseErrorMsg = "Cannot parse column width '" + colDef.width + "' for column named '" + colDef.name + "'"; // If width is not defined, set it to a single star - if (gridUtil.isNullOrUndefined(colDef.width)) { - self.width = '*'; - } - else { - // If the width is not a number - if (!angular.isNumber(colDef.width)) { - // See if it ends with a percent - if (gridUtil.endsWith(colDef.width, '%')) { - // If so we should be able to parse the non-percent-sign part to a number - var percentStr = colDef.width.replace(/%/g, ''); - var percent = parseInt(percentStr, 10); - if (isNaN(percent)) { + if (gridUtil.isNullOrUndefined(self.width) || !angular.isNumber(self.width)) { + if (gridUtil.isNullOrUndefined(colDef.width)) { + self.width = '*'; + } + else { + // If the width is not a number + if (!angular.isNumber(colDef.width)) { + // See if it ends with a percent + if (gridUtil.endsWith(colDef.width, '%')) { + // If so we should be able to parse the non-percent-sign part to a number + var percentStr = colDef.width.replace(/%/g, ''); + var percent = parseInt(percentStr, 10); + if (isNaN(percent)) { + throw new Error(parseErrorMsg); + } + self.width = colDef.width; + } + // And see if it's a number string + else if (colDef.width.match(/^(\d+)$/)) { + self.width = parseInt(colDef.width.match(/^(\d+)$/)[1], 10); + } + // Otherwise it should be a string of asterisks + else if (!colDef.width.match(/^\*+$/)) { throw new Error(parseErrorMsg); } - self.width = colDef.width; - } - // And see if it's a number string - else if (colDef.width.match(/^(\d+)$/)) { - self.width = parseInt(colDef.width.match(/^(\d+)$/)[1], 10); } - // Otherwise it should be a string of asterisks - else if (!colDef.width.match(/^\*+$/)) { - throw new Error(parseErrorMsg); + // Is a number, use it as the width + else { + self.width = colDef.width; } } - // Is a number, use it as the width - else { - self.width = colDef.width; - } } // Remove this column from the grid sorting