DataTable refresh after Edit the record.

DataTable refresh after Edit the record.

SiddiqSiddiq Posts: 6Questions: 3Answers: 0
edited July 2016 in Free community support

Hi.,
I am trying real hard for the past two days to refresh the tabledata after editing it.,

One of my column has a link which open a bootstrap modal , there you can edit the data and hit submit which will do the Ajax call and the DB is getting updated I want to refresh the data in Ajax success.

If I use the below code it gives me this error -- https://datatables.net/manual/tech-notes/4
table.ajax.url( 'ajaxurllink' ).load();
table.draw();

===
If I use lot of other techniques but not successful the various error are

Cannot read property 'aoData' of null

used this function

function RefreshTable(tableId, urlData)
 {
   $.getJSON(urlData, null, function( json )
   {
     table = $(tableId).dataTable();
     oSettings = table.fnSettings();
     table.fnClearTable(this);
     for (var i=0; i<json.data.length; i++)
     {         
       table.oApi._fnAddData(oSettings, json.data[i]);
     }
  
     oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
     table.fnDraw();
   });
 }

My json is well formed too as show below:

{
  "data": [
    [
      "Tiger Nixon",
      "System Architect",
      "Edinburgh",
      "5421",
      "2011/04/25",
      "$320,800"
    ],
    [
      "Garrett Winters",
      "Accountant",
      "Tokyo",
      "8422",
      "2011/07/25",
      "$170,750"
    ]
]
}

Please help !!

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 62,315Questions: 1Answers: 10,225 Site admin
    Answer ✓

    Why are you using the private API methods? If you must add new rows use rows.add(), not internal methods which are not documented! :smile:

    Having said that, ajax.reload() should work. If it isn't, I'd be happy to look at a test case if you post a link.

    Allan

  • SiddiqSiddiq Posts: 6Questions: 3Answers: 0

    Thanks Allan ... It worked as soon as I posted this :)

    I did this table.ajax.reload(null,false); and it refreshed.

    Could it be the order of the js loading ?

  • allanallan Posts: 62,315Questions: 1Answers: 10,225 Site admin

    Its possible. Without being able to see the error it is impossible to say for sure.

    Allan

This discussion has been closed.