Modifying TD contents on data change
Modifying TD contents on data change
AlexHeneveld
Posts: 2Questions: 0Answers: 0
Is there a way to provide a function to modify a cell's HTML directly when the data changes ?
That is, rather than recompute and reset the TD's innerHTML (which is what happens if I do mRender) I'd like to be able to provide some function e.g. mRenderUpdateCell which is passed the TD and performs jquery-style manipulation on the DOM. (Thinking is that if this is supplied, then any mRender(type=display) call is suppressed and routed to mRenderUpdateCell instead.)
The reason for this is that I have popup menus in the TD with changing data, and when the data updates if innerHTML changes the popup goes AWOL. (It will also be more efficient than recreating the entire cell HTML when typically there is just a small change to a fragment of the TD.)
I know that fnCreatedCell has been suggested for DOM modifications, but it only works for styling the TD. Any changes it makes to the *contents* of the TD are wiped on the next mRender call (ie when the data is next updated).
If there's a better approach I should follow, I'd welcome suggestions for that also!
Thanks
Alex
That is, rather than recompute and reset the TD's innerHTML (which is what happens if I do mRender) I'd like to be able to provide some function e.g. mRenderUpdateCell which is passed the TD and performs jquery-style manipulation on the DOM. (Thinking is that if this is supplied, then any mRender(type=display) call is suppressed and routed to mRenderUpdateCell instead.)
The reason for this is that I have popup menus in the TD with changing data, and when the data updates if innerHTML changes the popup goes AWOL. (It will also be more efficient than recreating the entire cell HTML when typically there is just a small change to a fragment of the TD.)
I know that fnCreatedCell has been suggested for DOM modifications, but it only works for styling the TD. Any changes it makes to the *contents* of the TD are wiped on the next mRender call (ie when the data is next updated).
If there's a better approach I should follow, I'd welcome suggestions for that also!
Thanks
Alex
This discussion has been closed.
Replies
The docs for this aren't public yet as 1.10 isn't in beta yet, but I'll send you a PM in just a minute...
Allan
However I've found a simple solution.
In mRender if the cell exists with the right contents, then I use jquery to get $cell, make the mods there, then return $cell.html() . This causes browsers (Chrome at least) not to make any changes to the DOM when fnUpdate does its own $cell.innerHTML=. (If the cell doesn't exist or have my contents yet, then I create it as normal in mRender.)
Hope this helps anyone else with popup menus inside dynamic tables. And @Allan, thanks for all your great work on this library.
Allan