Possible to re-load data table content from the HTML?

Possible to re-load data table content from the HTML?

M__M__ Posts: 5Questions: 0Answers: 0
edited June 2013 in General
Thanks for this brilliant plugin. I have a question about updating the data in a data table. Using MVC, I populate the table, and data table reads the data from HTML the first time. I have a need to sometimes change the data in the table, and would prefer to do that with MVC as well (@Ajax.BeginForm and partial view for the table body). This would make the code more consistent (and would help with e.g date formatting).

I’ve found out that I can refresh the data through ajax in the following manner:

$.ajax({

}).success(function (data, textStatus, jqXHR) {
oTable = $('#example-table).dataTable();
oTable.fnClearTable();
data.forEach(function(entry) {
oTable.fnAddData([”content of first column”, ”content of second column”, ….]);
}
});

It would still be great if there were a function to make a clean start-over from the DOM with the new data, but I haven't found one. Is there any such function?

Replies

  • allanallan Posts: 63,237Questions: 1Answers: 10,418 Site admin
    Currently no. However, v1.10 is going to introduce an invalidate function which will add this ability. Make what changes you want to the DOM and then invalidate the rows you want DataTables to re-read.

    At the moment, the only way to reread from the DOM is to destroy the table, create your new table and initialise DataTables again.

    Allan
  • M__M__ Posts: 5Questions: 0Answers: 0
    Thank you for a quick answer. I look forward to v 1.10 :) Keep up the good work.
This discussion has been closed.