jQuery DataTables: control table width

后端 未结 26 2019
别那么骄傲
别那么骄傲 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条回答
  • Check this solution too. this solved my DataTable column width issue easily

    JQuery DataTables 1.10.20 introduces columns.adjust() method which fix Bootstrap toggle tab issue

     $('a[data-toggle="tab"]').on( 'shown.bs.tab', function (e) {
        $.fn.dataTable.tables( {visible: true, api: true} ).columns.adjust();
    } );
    

    Please refer the documentation : Scrolling and Bootstrap tabs

    0 讨论(0)
  • 2020-11-29 17:19

    Setting widths explicitly using sWidth for each column AND bAutoWidth: false in dataTable initialization solved my (similar) problem. Love the overflowing stack.

    0 讨论(0)
  • 2020-11-29 17:20

    find another useful link about this problem and it resolved my problem.

    <table width="100%">
    <tr>
        <td width="20%"> Left TD <td>
        <td width="80%"> Datatable </td>
    </tr>
    </table>
    

    Datatables force width table

    0 讨论(0)
  • 2020-11-29 17:21

    Add this css class to your page, it will fix the issue:

    #<your_table_id> {
        width: inherit !important;
    }
    
    0 讨论(0)
  • 2020-11-29 17:23

    You have to leave at least one field without fixed field, for example:

    $('.data-table').dataTable ({
    
     "bAutoWidth": false,
     "aoColumns" : [
        null,
        null,
        null,                    
        null,
        {"sWidth": "20px"},
        { "sWidth": "20px"}]
    });
    

    You can change all, but leave only one as null, so it can stretch. If you put widths on ALL it will not work. Hope I helped somebody today!

    0 讨论(0)
  • 2020-11-29 17:23

    I had a similar issue where the contents of the table were bigger than the table header and footer. Adding a div around the table and setting x-overflow seems to have sorted this issue:

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