jQuery DataTables: control table width

后端 未结 26 2021
别那么骄傲
别那么骄傲 2020-11-29 16:29

I have a problem controlling the width of a table using the jQuery DataTables plugin. The table is supposed to be 100% of the container width, but ends up being an arbitrar

相关标签:
26条回答
  • 2020-11-29 17:31

    None of the solutions here worked for me. Even the example on the datatables homepage did not work hence to the initialization of the datatable in the show option.

    I found a solution to the problem. The trick is to use the activate option for tabs and to call fnAdjustColumnSizing() on the visible table:

    $(function () {
    
    // INIT TABS WITH DATATABLES
    $("#TabsId").tabs({
        activate: function (event, ui) {
            var oTable = $('div.dataTables_scrollBody>table:visible', ui.panel).dataTable();
            if (oTable.length > 0) {
                oTable.fnAdjustColumnSizing();
            }
        }
    });
    
    // INIT DATATABLES
    // options for datatables
    var optDataTables = {
        "sScrollY": "200px",
        "bScrollCollapse": true,
        "bPaginate": false,
        "bJQueryUI": true,
        "aoColumnDefs": [
            { "sWidth": "10%", "aTargets": [-1] }
        ]
    };
    // initialize data table
    $('table').dataTable(optDataTables);
    
    });
    
    0 讨论(0)
  • 2020-11-29 17:31

    I ran into a similar issue when having a div wrapped around the table.

    Adding position: relative fixed it for me.

    
    #report_container {
     float: right;
     position: relative;
     width: 100%;
    }
    0 讨论(0)
提交回复
热议问题