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

后端 未结 10 1094
猫巷女王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:21

    You can use Following code in your CSS:

    div.dataTables_scrollHeadInner table { margin-bottom: 0px !important; }
    
    0 讨论(0)
  • 2021-02-06 00:22

    Good explanation by Sairam. Better way would be to use just a CSS

    div.dataTables_scrollBody thead {           
        display: none;
    }
    
    0 讨论(0)
  • 2021-02-06 00:24

    Solution 1 :

    To Resolve This Please Use "scrollXInner": true Avoid to Using "scrollX": true"

    var tableI = $('#table_data').DataTable({
        "bLengthChange": false,
        "scrollX": true, //Do Not Use This (Remove This Line)
        "scrollXInner": true //Use This (Add This Line)
         "dom": 'frtp'
    });
    

    Solution 2 :

    OR You Can Add This CSS

    .dataTables_scrollBody thead tr[role="row"]{
        visibility: collapse !important;
    }
    
    0 讨论(0)
  • 2021-02-06 00:30

    I had the same issue with firefox & firefox developer edition. The root cause is, when we set scrollX:true, datatable adds an additional div with a table and a header inside, apart from the table & header already constructed. This is to get the scrolling within table effect.

    Datatable, tries to set the height to 0px, to hide it. Some browsers don't interpret this properly.

    <tr style="height: 0px;" role="row"> 
    

    To hide it, changing the style to this row to 'hidden' will break the structure of the table. The working solution would be, to have visibility:'collapse'

    Sample datatable configuration:

    tableElement.DataTable({
        "scrollX": true,
        "initComplete": function(settings, json) {
            $('.dataTables_scrollBody thead tr').css({visibility:'collapse'});
        }
        //other datatable configurations...  
    });
    

    since it's a table, we need to have visibility:'collapse' and not visibility:'hidden' - more info on visibility css property

    0 讨论(0)
  • 2021-02-06 00:33

    Try something like this:

    "scrollX": '100%',

    "scrollXInner": '125%',

    0 讨论(0)
  • 2021-02-06 00:35

    This worked for me:

    $('#DataTables_Table_0').on( 'draw.dt' function() {
        $('.dataTables_scrollBody thead tr').addClass('hidden')
    }
    

    Reference: geam's March 2015 answer on datatables.net forum

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