Modifying TD contents on data change

Modifying TD contents on data change

AlexHeneveldAlexHeneveld Posts: 2Questions: 0Answers: 0
edited January 2014 in DataTables 1.9
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

Replies

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    Not using DataTables 1.9-, but 1.10 has a new invalidate() method which will cause it to re-read the original data and use that.

    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
  • AlexHeneveldAlexHeneveld Posts: 2Questions: 0Answers: 0
    @Allan Thanks - but that doesn't sound like it addresses this issue.

    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.
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    Interesting - thanks for the feedback. I'll look at improving this aspect.

    Allan
This discussion has been closed.