How to set column widths to a jQuery datatable?

后端 未结 7 906
庸人自扰
庸人自扰 2020-12-08 02:45

I have a jQuery datatable(outlined in red), but what happens is that the table jumps out of the width I have set for the div(which is 650 px).

Here is the screen shot

相关标签:
7条回答
  • 2020-12-08 03:16

    The best solution I found this to work for me guys after trying all the other solutions.... Basically i set the sScrollX to 200% then set the individual column widths to the required % that I wanted. The more columns that you have and the more space that you require then you need to raise the sScrollX %... The null means that I want those columns to retain the datatables auto width they have set in their code. enter image description here

                $('#datatables').dataTable
                ({  
                    "sScrollX": "200%", //This is what made my columns increase in size.
                    "bScrollCollapse": true,
                    "sScrollY": "320px",
    
                    "bAutoWidth": false,
                    "aoColumns": [
                        { "sWidth": "10%" }, // 1st column width 
                        { "sWidth": "null" }, // 2nd column width 
                        { "sWidth": "null" }, // 3rd column width
                        { "sWidth": "null" }, // 4th column width 
                        { "sWidth": "40%" }, // 5th column width 
                        { "sWidth": "null" }, // 6th column width
                        { "sWidth": "null" }, // 7th column width 
                        { "sWidth": "10%" }, // 8th column width 
                        { "sWidth": "10%" }, // 9th column width
                        { "sWidth": "40%" }, // 10th column width
                        { "sWidth": "null" } // 11th column width
                        ],
                    "bPaginate": true,              
                    "sDom": '<"H"TCfr>t<"F"ip>',
                    "oTableTools": 
                    {
                        "aButtons": [ "copy", "csv", "print", "xls", "pdf" ],
                        "sSwfPath": "copy_cvs_xls_pdf.swf"
                    },
                    "sPaginationType":"full_numbers",
                    "aaSorting":[[0, "desc"]],
                    "bJQueryUI":true    
    
                });
    
    0 讨论(0)
提交回复
热议问题