Duplicate empty header occur in datatable when enabling scrollX or scrollY when using Google Chrome

后端 未结 10 1095
猫巷女王i
猫巷女王i 2021-02-06 00:09

I have a datatable in my program. And I want it to be scrollable horizontally so what I did was like this:

var tableI = $(\'#table_data\').DataTable({
    \"bLe         


        
相关标签:
10条回答
  • 2021-02-06 00:39

    I had the same issue on Google Chrome. This was the fix:

    .dataTable(
    {
      "processing": false,
      "serverSide": false,
      "autoWidth": true,
      "columnDefs": [
        {"orderable": false, "targets": [5, 6]}
      ],
      "order": [1, 'asc'],
      "dom": 'l<"toolbar">frtip',
      drawCallback: function () { // this gets rid of duplicate headers
          $('.dataTables_scrollBody thead tr').css({ display: 'none' }); 
      },
      scrollY: '65vh',
      scrollCollapse: true,
      paging: false
    });
    
    0 讨论(0)
  • 2021-02-06 00:41

    The solution was simple in my case. Just include this on your css:

    /* Override sorting header --> DataTable Bug */
    .dataTables_scrollBody > table > thead > tr {
        visibility: collapse;
        height: 0px !important;
    }
    
    0 讨论(0)
  • 2021-02-06 00:41

    This hides the second header and removes the white space between the header and body.

    <style>
         .dataTables_scrollBody thead tr {
             visibility: collapse;
         }
    
         .dataTables_scrollBody {
             margin-top: -10px;
          }
    </style>
    
    0 讨论(0)
  • 2021-02-06 00:42

    The best way is to use

    dataTable.columns.adjust();
    

    on init/draw callback

    0 讨论(0)
提交回复
热议问题