-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Column width reset when updating grid.data #4005
Comments
So I understand that this behavior is by design, though I don't get why anyone would want the column widths to reset to the coded values anytime the filter is changed, or the grid.data is changed. I don't know how to file an "enhancement request" here, so I will write here what feature I would appreciate. Essentially the behavior of the grid as in RC 21. Could there be an option on the grid level not to fire the updateColumnWidths method every time the filter or the data changes? The grid worked great in RC 21, and it made it possible to allow users to save the state of the grid, so that the column widths were as they wanted. Now I can still restore the saved state, but it is lost once the filter is used, or data.grid updated. Thanks |
So this PR did it: #3897 For now I changed my own version of ui-grid-unstable.js: In GridColumn.prototype.updateColumnDef : GridColumn.prototype.updateColumnDef = function(colDef, isNew) {
var self = this;
self.colDef = colDef;
if (colDef.name === undefined) {
throw new Error('colDef.name is required for column at index ' + self.grid.options.columnDefs.indexOf(colDef));
}
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.isNumber(self.width)){ //this line I added
if (!angular.isString(colDefWidth) && !angular.isNumber(colDefWidth)) {
self.width = '*';
} else if (angular.isString(colDefWidth)) {
// See if it ends with a percent
... I added the condition if (!angular.isNumber(self.width)), and for me that works out fine. |
I think this PR probably shouldn't have been merged as it is - I'd also have a problem with this behaviour if I'd gotten around to upgrading. I'd be happy to look at a PR that made this switchable, and that had the default behaviour as it was before. |
Because we have faced the same problem, here is what we are currently using to get around it : mage-eag@966c4d9. Still need to find a solution to allow overriding the width only once when a column definition is changed (see #3880, which was the original issue) - do you think a flag set on the column definition and reset after the first call to |
That should work. If the flag is set to true, updateColumnDef works like in @mage-eag 's code or in mine. If the flag is not yet set (to true), updateColumnDef works like in the current version, and sets the flag on the column definition to true. I think this would solve both the problem in #3880 and the problem of not persisting column widths when filtering or updating grid.data. |
Anyone have a PR ready to submit to fix this? |
Previously, if a user resized a column and the data were reset, the column size would also be reset. Instead, disable this behavior by default and add a flag (`allowCustomWidthOverride`) to allow it. Code originally taken from mage-eag@966c4d9 Fixes angular-ui#4005
@mage-eag I've created a PR using your code (referenced above). Hope that's ok by you. |
Sorry, went on vacation for a couple of weeks, thanks @SomeKittens for the PR :) |
Back from vacation. Many thanks @SomeKittens , works fine. |
In Version 3.01, I have the following problem:
When you manually change column widths, and then reset grid.data, the column widths reset to the values defined in code.
I didn't have this problem in v3.0.0-rc.21.
See the following plunker: http://plnkr.co/edit/R2JWg0YO75RKBklwU9vN?p=preview
Change a column width, and then click on the "Set data a" button, and the column width resets to the default values.
What am i missing?
EDIT:
The same issue can be seen in the tutorial 401: http://ui-grid.info/docs/#/tutorial/401_AllFeatures
Change a column width and click on "Refresh Data": the column width resets.
The text was updated successfully, but these errors were encountered: