Wall3-8e
Wall3-8e

Reputation: 23

Reload datatable after ajax

I use JQuery dataTable version 1.9. I need to reload a datatable after ajax success because I filter the elements after my query so the pagination shows all elements and not just the "real" ones filtered after the query. I know it is wrong to do this but I can only check after the query

Here it seems that there are no elements

enter image description here

But when scrolling through the pagination the elements are there

enter image description here

Upvotes: 0

Views: 374

Answers (3)

VinhNT
VinhNT

Reputation: 1101

If you are going to reload datatable after ajax call, then, you should have the data as a list of object. Let's say it is stored in data Then, reload table by

function reloadDataTable(tableObject, data) {
    tableObject.clear().rows.add(data).draw();
};

Upvotes: 0

Ahmed Elgammudi
Ahmed Elgammudi

Reputation: 746

you can use setInterval for reloading the datatable after ajax reuqest

setInterval(function(){
    $('#tableid').DataTable({
 });
}, 300);

Upvotes: 1

user14325562
user14325562

Reputation:

Please test this solution

function refreshTable() {
  $('.dataTable').each(function() {
      dt = $(this).dataTable();
      dt.fnDraw();
  })
}

Upvotes: 0

Related Questions