Loading from ajax again and again?

Loading from ajax again and again?

jaycsjaycs Posts: 14Questions: 0Answers: 0
edited December 2011 in General
I've got a number of DataTables configured to load from an ajax call and they work great, i.e.

[code]
"bProcessing": true,
"sAjaxSource": '/rpc/getdata',
"bDeferRender": true,
"fnServerData": function (sSource, aoData, fnCallback) {
$.getJSON(sSource, aoData, function (json) {
fnCallback(json);
FormatCyclePrepTable();
})
},
[/code]

But I have a case where I need the table to reload from a different url on demand and am struggling to get this going. I don't want to have to destroy the table and re-create it using the configuration above. I was hoping I could just give it a new [code]sAjaxSource[/code] value and it would go off and update, and then execute the [code]fnServerData[/code] function again for my post-processing.

I've tried making a manual getJSON call and then use the API to add data, but this isn't going too well, and isn't very clean. Is there a way to get the table to load new data on demand?

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Use the fnReloadAjax plug-in: http://datatables.net/plug-ins/api#fnReloadAjax :-)

    Allan
  • jaycsjaycs Posts: 14Questions: 0Answers: 0
    That works a treat, thanks Allan :)
This discussion has been closed.