Want fnRender to run after changing a value

Want fnRender to run after changing a value

doctorjwdoctorjw Posts: 12Questions: 0Answers: 0
edited March 2012 in General
I'm using datatables 1.9; my data is via an ajax source, so all the data ends up being on the client side. I'm using fnRender to display a true/false value as a checkbox, and I wrap that in a div with a class to indicate whether a change was made from the initial value (to highlight the changed cell). I'm using a hidden column to track the initial value of the data, and so my fnRender adds the appropriate class after comparing values.

After saving any changed values, I want to clear that changed state ... which means changing the value in the hidden column. The issue becomes how to get fnRender to fire for the visible column? It's value has only changed implicitly (just the rendering; the underlying value via fnGetData(row, column) will not indicate a change).

RIght now, I have a rather hacky fix, doing an:

oTable.fnUpdate( data[row][column], row, column+1); // set changed column to same as data
oTable.fnUpdate( data[row][column], row, column); // to dirty the cell

This does force the fnRender to fire for the visible column, but ... not ideal.

Thoughts?

john

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Currently that's the only "built-in" way to do it - there isn't an exposed API call to that that. What I would suggest is that you could write an API plug-in that would do the fnRender call (details on how to write an API plug-in here: http://datatables.net/blog/Creating_feature_plug-ins ).

    One thing to watch with your current method is that it incurs two draws of the table - fine if its a small table, might be a problem if it is a bigger table or server-side processing. fnUpdate as a 'no redraw' option (fourth parameter I think).

    Regards,
    Allan
  • doctorjwdoctorjw Posts: 12Questions: 0Answers: 0
    Yeah, I saw that double-draw hit; in my case, passing the 4th & 5th parameters as false (so no pre-draw activities or a table redraw) works out just fine. This was an issue when doing a bulk update of values, so I just do an fnStandingRedraw at the end (one of the plugins).

    Might be interesting to do this as a plugin; we'll have to see if this is the only place I run into this.

    Many thanks!

    john
This discussion has been closed.