2

When my server-side processing datatable is loaded the header is broken. To resolve this, I added table.columns.adjust().draw() to my initComplete function:

var table = $('.table').DataTable({
   "serverSide": true,
   /// more code...
   "initComplete": function(settings, json) {
       table.columns.adjust().draw();
   }
});

This works, but it affected the pagination. The correct page is not displayed anymore. It is set back to to first page. How can I prevent this?

3
  • What DataTables version are you using? Commented Apr 16, 2020 at 13:55
  • DataTables 1.10.19 Commented Apr 16, 2020 at 14:00
  • and DataTables Bootstrap 3 integration Commented Apr 16, 2020 at 14:00

1 Answer 1

2

For DataTables version > 1.10.x, you can simply pass false to draw() api which will redraw the table but maintaining current paging position like:

table.columns.adjust().draw( false );

As mentioned in the docs:

  • paging false
    • the ordering and search will be recalculated and the rows redrawn in their new positions. The paging will not be reset - i.e. the current page will still be shown.
Sign up to request clarification or add additional context in comments.

2 Comments

Oh thank you so great! I was searching so mucg for a solution, how did you know that?
I have been using datatable for past few years :) I have also added docs links.

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.