I need to load whole table into div with $.ajax, but after that, Datatables won't work. Can i do something about it?
3 Answers
Probably, the liveQuery plugin could help in that case.
Live Query utilizes the power of jQuery selectors by binding events or firing callbacks for matched elements auto-magically, even after the page has been loaded and the DOM updated.
3 Comments
Nik Chankov
I believe that this could be dont with .live() instead, isnt' it?
Sarfraz
@Nik: The
live() doesn't support plugins' cutom events/methods.Bob0101
Hei. I figured it out. It was much simpler. I just had to put datatables code after filling result div like that: $.post(url, posts, function(data){ $("#results").empty().append(data); $('.datatables').dataTable(); });
The Datatable jQuery call needs to be made after the table exists - if you have it in document ready, the table won't exist yet, until the AJAX call is made - so put the data table initialisation in your AJAX function and you're home and hosed.
$.ajax({
type: "POST",
url: "page.php",
data: { variable: variable },
success: function(data) {
$("#your_div").html(data);
$('#yourtable').DataTable({
"iDisplayLength": 10,
dom: 'Bfrtip',
etc...
});
}
});