0

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

3 Answers 3

1

you can use setInterval for reloading the datatable after ajax reuqest

setInterval(function(){
    $('#tableid').DataTable({
 });
}, 300);
Sign up to request clarification or add additional context in comments.

5 Comments

i'm using your code in fnDrwCallback.... but i have this alert: DataTables warning (table id = 'pro'): Cannot reinitialise DataTable. To retrieve the DataTables object for this table, pass no arguments or see the docs for bRetrieve and bDestroy
this problem happen when you make many then one call $().DataTable({})
i think you need to add "retrieve: true"
i try to insert setInterval(function(){ $('#mydatatable').dataTable({bRetrieve: true}); }, 300); but in this case don't have errors but my datatable always remains the same
0

Please test this solution

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

1 Comment

I have too many row.... Uncaught RangeError: Maximum call stack size exceeded
0

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();
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.