DataTables reset

DataTables reset

danielcamburdanielcambur Posts: 1Questions: 0Answers: 0
edited February 2011 in General
So i'm obviously not good at using the search function, as i've spent the past two hours seraching and trying different things to solve my issue with no joy... So given up, but i wanted to use DataTables, so before i look for an alternative thought i'd ask here!

I have tables which update via ajax using innerHTML() to change the content of the table's tbody. I now want to add pagination, sorting and keyword filtering using the DataTables plugin.

I don't want to change the ajax to use json, as i was looking for a quick fix, and i would have to re-write too many functions. Is there a way i can get DataTables to re-evaluate the html and do it's magic??

[code]

var dTable ;

$(document).ready(function() {
dTable = $('#maintable').dataTable() ;
});

function updateTable(postdata) {
$.ajax({
type: "POST",
url: "ajax.php",
data: postdata,
success: function(response){
//so i'll clear the current content of the dTable
dTable.fnClearTable(true) ;
//now i will replace the content of the table (html returned by ajax call)
$('table.tablesorter tbody').html(response) ;
//now i want to re-initialise data tables with the new html
dTable.????() ;

}

}
});
}
[/code]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    There sure is - in your success function you want to destroy the current table rather than clearing it (fnDestroy - you'll want to use the 1.7.6 nightly on the downloads page as there is a memory leak in the current release when using fnDestroy). Then just reinitialise the table (after the html has been written). Another option which doesn't involve destroying the table is the fnAddTr plug-in: http://datatables.net/plug-ins/api#fnAddTr

    Allan
This discussion has been closed.