DataTables fixed headers misaligned with columns in wide tables

前端 未结 21 1585
悲&欢浪女
悲&欢浪女 2020-11-30 19:23

Problem

When using the sScrollX, sScrollXInner and/or sScrollY to achieve a fixed header table with its inner content scroll

21条回答
  •  失恋的感觉
    2020-11-30 20:01

    I just figured out a way to fix the alignment issue. Changing the width of div containing the static header will fix its alignment. The optimal width I found is 98%. Please refer to the code.

    The auto generated div:

    Width here is 100%, change it to 98% on initializing and reloading the data table.

    jQuery('#dashboard').dataTable({
        "sEcho": "1",
    
        "aaSorting": [[aasortvalue, 'desc']],
        "bServerSide": true,
        "sAjaxSource": "NF.do?method=loadData&Table=dashboardReport",
        "bProcessing": true,
        "sPaginationType": "full_numbers",
        "sDom": "lrtip", // Add 'f' to add back in filtering
        "bJQueryUI": false,
        "sScrollX": "100%",
        "sScrollY": "450px",
        "iDisplayLength": '<%=recordCount%>',
        "bScrollCollapse": true,
        "bScrollAutoCss": true,
        "fnInitComplete": function () {
            jQuery('.dataTables_scrollHead').css('width', '98%'); //changing the width
        },
        "fnDrawCallback": function () {
            jQuery('.dataTables_scrollHead').css('width', '98%');//changing the width
        }
    });
    

提交回复
热议问题