Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

540
Views
Headers on a DataTables table collapses until a redraw of some sort occurs. Is there a way to force the headers to be redrawn or something similar?

My table is being initialized in this way:

distributorsDistributionAreasTable = $('#id').DataTable({
        pageLength: 10,
        lengthMenu: [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
        scrollY: '160px',
        scrollCollapse: true,
        searching: true,
    });

The table is in a modal dialog. When the dialog loads, the columns collapse to the left. But if I resize the window or click a column, they fix themselves. See the gif. Any ideas what's going on here or how to fix it?

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is a responsiveness issue with DataTables.

I would recommend the following to resolve the issue:

1.) Add these scripts/stylesheets into your HTML

<script src ="https://cdn.datatables.net/responsive/2.2.9/css/responsive.dataTables.min.css"></script>
<script src="https://cdn.datatables.net/responsive/2.2.9/js/dataTables.responsive.min.js"></script>

After you have linked those, in your table initialization, add the following: responsive: true, anywhere above your scrollY option.

Per the DataTables site, If you are using vertical scrolling (scrollY) and not horizontal scrolling (scrollX), enable the horizontal scrolling option so the table has space to scroll into. scrollX: true,

After you enable the scrollX option, add the following to your CSS stylesheet:

table.dataTable tbody th,
table.dataTable tbody td {
    white-space: nowrap;
}

If that doesn't completely solve the issue, after the table is drawn, you can call this to readjust the column(header) sizes.

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

All in all, it should look something like this:

distributorsDistributionAreasTable = $('#id').DataTable({
        responsive: true,
        pageLength: 10,
        lengthMenu: [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
        scrollY: '160px',
        scrollX: true,
        scrollCollapse: true,
        scroller: true,
        searching: true,
    });
distributorsDistributionAreasTable.columns.adjust().draw();
    });
table.dataTable tbody th,
table.dataTable tbody td {
    white-space: nowrap;
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!