Skip to content
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

Closed
Samy-A opened this issue Jul 20, 2015 · 9 comments
Closed

Column width reset when updating grid.data #4005

Samy-A opened this issue Jul 20, 2015 · 9 comments

Comments

@Samy-A
Copy link

Samy-A commented Jul 20, 2015

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.

@Samy-A
Copy link
Author

Samy-A commented Jul 24, 2015

@c0bra

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.
Likewise, when users manually resize a column (a very desirable feature), that is lost the moment they use a filter.

Thanks

@Samy-A
Copy link
Author

Samy-A commented Jul 24, 2015

So this PR did it: #3897
While I can see the problem it solved, losing the ability to persist column widths when filtering or changing the data is also a problem.

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.

@PaulL1
Copy link
Contributor

PaulL1 commented Jul 24, 2015

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.

@mage-eag
Copy link
Contributor

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 updateColumnDef could be a proper solution ?

@Samy-A
Copy link
Author

Samy-A commented Jul 29, 2015

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.

@swalters
Copy link
Contributor

swalters commented Aug 4, 2015

Anyone have a PR ready to submit to fix this?

SomeKittens added a commit to SomeKittens/ui-grid that referenced this issue Aug 15, 2015
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
@SomeKittens
Copy link
Contributor

@mage-eag I've created a PR using your code (referenced above). Hope that's ok by you.

@mage-eag
Copy link
Contributor

Sorry, went on vacation for a couple of weeks, thanks @SomeKittens for the PR :)

@Samy-A
Copy link
Author

Samy-A commented Aug 24, 2015

Back from vacation.

Many thanks @SomeKittens , works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants