Old column widths are reused on matching column names
A very slight modification to the 112 tutorial (add/delete/swap data) illustrates the problem. In colDefs1 the 'company' field has width:60 and it works fine. colDefs2 has a column defined with the same name but with width:120 . When you swap the data to use colDefs2 it keeps the width of the company column at 60 rather than using the new value of 120.
It looks like there is some internal cache that gets reused when the column name is the same.
http://plnkr.co/edit/kpn77emSbQLb4VbVe0XK?p=preview
Confirmed. Relevant code is most likely here: https://github.com/angular-ui/ng-grid/blob/master/src/js/core/factories/Grid.js#L812
I believe this if-else chain is the problem: https://github.com/angular-ui/ng-grid/blob/master/src/js/core/factories/GridColumn.js#L431
if (gridUtil.isNullOrUndefined(self.width) || !angular.isNumber(self.width)) {
if (gridUtil.isNullOrUndefined(colDef.width)) {
self.width = '*';
}
[....]
// Is a number, use it as the width
else {
self.width = colDef.width;
}
}
}
If width is defined and a number, it isn't updated. Setting widths as percentages makes the demo work.
@mportuga this is closed. Are you planning to reopen since you marked it as "good first issue"?
nope, I re-read it and noticed it has already been addressed in the latest version.