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

Overwrite columnDefs requires new UID to be handled #1948

Closed
OrenHasbani opened this issue Oct 28, 2014 · 10 comments
Closed

Overwrite columnDefs requires new UID to be handled #1948

OrenHasbani opened this issue Oct 28, 2014 · 10 comments
Assignees
Milestone

Comments

@OrenHasbani
Copy link

i want to change columns position dynamically, so i changed the position of the first column to be the last, but noting happen. i tried to use the api grid.refresh() after the reordering (and also inside $timeout like in 'ui.grid.moveColumns' feature) without success either.
i edit your "all features" plunker and made one that demonstrates my problem.
http://plnkr.co/edit/7qvlbMhL5b24ugeUf8j4?p=preview

To solve the problem i made a work-around:
instead of:
$scope.moveFirstCellToBeTheLast = function () {
var temp = $scope.cols[0];
$scope.cols.splice(0,1);
$scope.cols.push(temp);
}

i wrote:
$scope.moveFirstCellToBeTheLastWorkArround = function () {
var temp = $scope.col1[0];
$scope.col1.splice(0,1);
$timeout(function () { $scope.col1.push(temp); });
}
so the grid "think" that the columns was removed (so it refreshed itself once) and than i add another column so it refreshed itself again.

BUT, all the grid flickered twice, and this work around won't satisfied all the possible situations of programmatically columns reordering.

I want to know if there is a better way to do it (by api for example) or right now this action is not supported?

Thanks a lot,
Oren.

@zuk38
Copy link

zuk38 commented Oct 29, 2014

Hello.
I have this problem in my app.
I traied to update columnDefs (width, position, visible), but when I do "$scope.columnDefs = new_ColDef" nothing happend..
I traied call gridApi.refresh() after update...

What I can do this in new ui-grid?

@OrenHasbani
Copy link
Author

anyone?

@PaulL1
Copy link
Contributor

PaulL1 commented Nov 4, 2014

I believe we now support column moving, and that our column order now follows the order in the columnDefs. Are you using the latest code from github, or the version from bower?

@PaulL1 PaulL1 added this to the 3.0 milestone Nov 4, 2014
@rvignacio
Copy link

I have the same problem using bower version "3.0.0-rc.14". Even when assigning a new columnDefs array, if it contains the same columns names in different order the grid doesn't update.
Every time I'm passing a new columnDefs array of new objects (created by array.map).

I was able to temporally fix it by clearing the columns and adding a $timeout call to set the new array:

``` javascript`
// Clear current columns.
$scope.grid.options.columnDefs = [];
$timeout(function(){
// And now add them all again.
$scope.grid.options.columnDefs = newColumnsArray;
return;
});

@OrenHasbani
Copy link
Author

It doesn't work and I use the latest version.
By the way column-moving isn't supported in IE and FF (you can verify it in the tutorial page: http://ui-grid.info/docs/#/tutorial/310_column_moving).

@PaulL1
Copy link
Contributor

PaulL1 commented Nov 7, 2014

@jpuri: were you aware of column moving issues on IE and FF?

@jpuri
Copy link
Contributor

jpuri commented Nov 7, 2014

Hey Paul,

I got to know about this issue yesterday only by looking at comment in issue #1815. I have already fixed it for FF. I guess it will now work well on IE also but I need to test that, I need a different machine for that, but I will be able to do that today.

Thanks a lot for your help with these issue,

@PaulL1
Copy link
Contributor

PaulL1 commented Nov 7, 2014

Excellent, thanks for being on top of this @jpuri

@c0bra c0bra changed the title change position of columns in columnDefs doesn't affect the grid Change position of columns in columnDefs doesn't affect the grid Dec 8, 2014
@c0bra
Copy link
Contributor

c0bra commented Dec 8, 2014

Update: I've tried updating column defs here: http://plnkr.co/edit/DzIdSjTMQ5Rcv5EAG82X?p=preview and there indeed does appear to be a bug.

When you overwrite the columnDefs completely, new column UIDs get generated but there isn't any handling within the header-cell/regular-cell directives for altering their classes that are based on those UIDs. The updateClass handler should probably swap out the UID-based class if the UID changes.

@c0bra c0bra changed the title Change position of columns in columnDefs doesn't affect the grid Change position of columns in columnDefs doesn't affect the grid/has bug Dec 8, 2014
@PaulL1 PaulL1 changed the title Change position of columns in columnDefs doesn't affect the grid/has bug Overwrite columnDefs requires new UID to be handled Jan 16, 2015
@c0bra
Copy link
Contributor

c0bra commented Jan 26, 2015

Update: this is going to be a more difficult solve than initially thought.

  1. The grid fires the uiGridConstants.dataChange.COLUMN callbacks before the grid definition actually changes, so when I check the UIDs in the callback handler they haven't changed yet.
  2. The grid only changes the column UIDs on the initial swap. On the 2nd-Nth swap the UIDs are no longer altered. A more robust rewrite of columnDef changing will be needed, most likely.

@c0bra c0bra closed this as completed in 865573c Jan 29, 2015
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