DOM manipulation with AJAX source

DOM manipulation with AJAX source

krojewkrojew Posts: 30Questions: 0Answers: 0
edited October 2010 in General
Hello,
Is there a way to alter the node created after AJAX data request? I need to set id based on an id returned by the server for a given row. The server sends additional JSON id array with the data, which should not be displayed in the table, but set as node id. I thought I can use fnRowCallback, but it doesn't get all the data returned by the server. Is there any way to do this?

Replies

  • allanallan Posts: 63,195Questions: 1Answers: 10,412 Site admin
    You can indeed do this with fnRowCallback, but you would need some way to map between the information in the row, and the id you want. Normally that mapping would be the id - so that might not be too helpful. What you can do is put the ID into a hidden column and then use fnRowCallback to assign the id reading the id from the row (and the hidden column).

    Making this easier will be something I want to look at for the next big upgrade of DataTables! While it's not too difficult to do, it does seem a little "extraneous" to need a hidden column...

    Regards,
    Allan
  • krojewkrojew Posts: 30Questions: 0Answers: 0
    Hidden column can indeed solve the problem, but it feels like a not-so-clean hack. Maybe fnRowCallback could get the raw JSON data in server-side processing mode?
  • allanallan Posts: 63,195Questions: 1Answers: 10,412 Site admin
    It's not currently possible without some kind of mapping between the original JSON and the row - and that mapping would normally be the ID... The method I'm thinking about for allowing this would be to attach the json information to the row object and then allow that to be accessed. Probably not hugely difficult to do, but it needs some consideration for how to do it cleanly.

    Allan
  • krojewkrojew Posts: 30Questions: 0Answers: 0
    Any news?
  • allanallan Posts: 63,195Questions: 1Answers: 10,412 Site admin
    No not yet I'm afraid, I'm still working my my through my to-do list. It might take me a little while to get to this one as it will likely be DataTables 1.8 before I start to try this kind of thing.

    Allan
This discussion has been closed.