jQuery Datatables Header Misaligned With Vertical Scrolling

前端 未结 20 2330
北海茫月
北海茫月 2020-12-15 05:05

I\'ve posted this in the datatables.net forums, but after a week, still no response. Hopefully I can find help here...

I\'m using datatables version 1.8.1 and am ha

相关标签:
20条回答
  • 2020-12-15 05:20

    I know this is quite old thread, but I landed here when searching for the header alignment issue. Turned out I needed a different solution, so posting here so that someone will find it useful.

    I just added following in my style block and it solved the issue:

    .table {table-layout:auto !important;}
    

    Seems that Datatables adds fixed layout, so adding this line made my headers align correctly with data when scrolling

    0 讨论(0)
  • 2020-12-15 05:21

    I had the problem and it turned out to be a side effect with my CSS. Try to disable all external css and see if the problem persists.

    0 讨论(0)
  • 2020-12-15 05:22
    var table = $("#myTable").DataTable({
                "sScrollY": "150px",
                //"bAutoWidth": false // Disable the auto width calculation 
            });
    
        $(window).resize( function () {
            table.columns.adjust();
        } );
    
    0 讨论(0)
  • 2020-12-15 05:26

    I use bootstrap and I managed with this

    <table id="datatable_patients" class="table table-striped table-bordered table-hover table-responsive" width="100%">
         <thead></thead>
         <tbody></tbody>
    </table>
    
    0 讨论(0)
  • 2020-12-15 05:28

    I had this problem with bootstrap 3 and the problem was related to left and right padding on my th and td elements that I added after the bootstrap styling was applied. Removing my left and right padding fixed the problem in my case.

    0 讨论(0)
  • 2020-12-15 05:29

    if you are using bootstrap:

    .table {
        width: 100%;
        max-width: none; // >= this is very important
    }
    
    0 讨论(0)
提交回复
热议问题