tags:

views:

299

answers:

1

Hi,

i have a big table and need to set CSS-classes on it etc. So i clone the table into a documentFragment to prevent the browsers reflow for each touched DOM-property etc. The Problem is, i set much of $.data and have $.live events appended to the tables TD's. So the question is, how can i preserve the $.data of the table for the new table?

+1  A: 

How about making the table temporarily non-visible (eg. display: none) whilst you make the changes, then putting it back when finished? Only two reflows and you don't have the clone overhead.

Whilst it would theoretically be possible to fool jQuery by using a DOM cloneNode instead of clone to create full copies of the table elements, keeping the magic expando property that jQuery uses to identify nodes, this seems pretty ugly and fragile to me.

bobince
Yes, i'm gone so far that i can temporary save and reapply the data:var oData = $.cache[$.data($BeforeClone[0])];and after inserting the cloned, processed table:$.cache[$.data($AfterClone[0])] = oData;That does the trick. But the problem is that i have to refresh jQuery objects wich still refer to the old Table, out of the data.I think i'll give your solution a try.
abp
Hiding and showing the table again, after the processing is faster and i don't have to bother with the data. So i'll go with this solution. Thanks :)
abp