ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

generating unique uids when column object is cached

Open MeMea66 opened this issue 11 years ago • 9 comments

This is an odd but fairly serious bug that occurs when the user swaps out the columndefs array entirely but there are elements in this new array that share the same attribute as the previous columndefs array -- see this plunkr: http://plnkr.co/edit/LUFGq2Ri35xlewpPXqYW?p=preview

simply click swap, and watch the table disintegrate

In the above, the two schemes that the user swaps between both share the 'name' column. Due to the fact that the default uses 'track by col.colDef.name' the column isnt recompiled and subsequently the class isnt refreshed to reflect the new uid given to the column. What is refreshed to reflect the uid is the customStyles used to compile the inline css.

MeMea66 avatar Dec 16 '14 21:12 MeMea66

I see. If you supply the name property rather than the field property it works as expected. Is that an option?

c0bra avatar Dec 19 '14 19:12 c0bra

oh, thats interesting, thats certainly a better workaround than I am using (I just removed the track by).

The col class stays the same as well, meaning that setting the field col causes a new uid generation (presumably due to some cache lookup somewhere?) whereas name doesn't?

MeMea66 avatar Dec 20 '14 18:12 MeMea66

@c0bra: would this be related to #1948?

PaulL1 avatar Jan 16 '15 06:01 PaulL1

I've tried the plunker again and it's no longer exhibiting any bad behavior. I just fixed #1948 but the patch hasn't been released into unstable yet so the fix must have come from somewhere else!

@MeMea66 can you confirm that you haven't altered the plunker and it appears to be fixed? Thanks!

c0bra avatar Jan 29 '15 16:01 c0bra

it still seems broken to me, it works as is because it is using the name property, if you switch the name property back to field it is still broken on the latest unstable

MeMea66 avatar Jan 29 '15 19:01 MeMea66

Is it because you're using the same field name twice without giving them unique names?

c0bra avatar Jan 29 '15 20:01 c0bra

right, The issue I think is that the ngrepeat tracks by the name field so the same column object is used, but a unique uid is generated for the column. This creates a mismatch in the css where the column object expects a css class for the old uid but it no longer exists

MeMea66 avatar Jan 29 '15 23:01 MeMea66

So what should we do if you supply { field: 'name' }, { field: 'name' }? Use an incrementing naming system like 'Name', 'Name2' for uniqueness?

c0bra avatar Jan 30 '15 20:01 c0bra

That's what I went ahead and did.

c0bra avatar Jan 30 '15 21:01 c0bra