0

I'm referring to this solution to refresh a datatable. I obtained the newly refreshed JSON data through an ajax call. But I'm not sure how to use it. In particular, how do convert it to be compatible with the datatable aaData attribute?

success:
  function (json){

    var data = json;
    table =$(#mytable).dataTable();
    oSettings = table.fnSettings();
    table.fnClearTable(this);

    $.each(json, function (i, item) {
      table.oApi._fnAddData(oSettings, json[i]);
    });


    oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
    table.fnDraw();
  }

For now, I'm trying to directly use json[i] and that is giving me errors in datatable. Also , the returned data is an array of json objects.

Community
  • 1
  • 1
NeuralLynx
  • 197
  • 1
  • 2
  • 14
  • Refresh the datatable using ajax [Refer to this link](http://stackoverflow.com/questions/20141432/refresh-jquery-datatable-table) – Harish Gupta Apr 25 '17 at 05:22
  • Possible duplicate of [Refresh jQuery datatable table](http://stackoverflow.com/questions/20141432/refresh-jquery-datatable-table) – Samuil Petrov Apr 25 '17 at 11:32

1 Answers1

0

i have different method from you but try it, it will always works for me with datatable

when you receive the success then execute this

$("#example1").load(location.href + " #example1"); //give your table id

this will only refresh the table.

Astound
  • 192
  • 12