update data without distroy

update data without distroy

davidjpagedavidjpage Posts: 1Questions: 1Answers: 0

Is there a way to update the data in the DataTable without doing a destroy and re-initializing the table? My data is an array I'm getting from a web API call.

Answers

  • ignignoktignignokt Posts: 146Questions: 4Answers: 39
    edited October 2014

    You could add a class to every TD, and a unique id to every TR - server side example of this. Then use jQuery to replace the text of the desired cells.

    You can also add the ID to each TR when initializing your datatable if you would rather do it this way, or if you aren't using server side processing.

    "fnCreatedRow": function( nRow, aData, iDataIndex ) {
        $(nRow).attr('id',aData['0']); //or whichever column you want to use
    }
    
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Also, if your table is Ajax sourced, use the ajax.reload() method. There is also clear() and rows.add() if you have the data already client-side.

    Allan

This discussion has been closed.