2014-01-24 97 views
5

数据表列不是自动调整大小的。这里是我的代码自动调整列宽度数据表的大小

 var oTable =$('#test').dataTable({ 
       "bJQueryUI": true, 
       "aaData": aDataSet, 
       "sPaginationType": "full_numbers", 
       "oTableTools": { 
       "aButtons": [ {"sExtends": "csv" , "sButtonText": "Save as CSV"}], 
       "sSwfPath": "js/jquery/copy_csv_xls.swf" 
       }, 
       "bAutoWidth" : true, 
       "sDom": '<"H"lCf>t"H"<"F"iTp>', 
       "aoColumnDefs": [ 
       { "bVisible": true, "aTargets": [ 11 ] } 
       ], 
       "aoColumns": [ 
        { "sTitle": "column1" }, 
        { "sTitle": "column1" }, 
        { "sTitle": "column1" }, 
        { "sTitle": "column1"}, 
        { "sTitle": "column1"}, 
        { "sTitle": "column1" }, 
        { "sTitle": "column1" }, 
        { "sTitle": "column1" }, 
        { "sTitle": "column1"}, 
        { "sTitle": "column1 By"}, 
        { "sTitle": "column1 Date"} 
       ] 
      }); 
      oTable.fnAdjustColumnSizing(); 
     }); 

我希望所有的列自动调整ATLEAST基于thier头值

回答

0

将这个代码数据表初始化后:

oTable.find('thead th').css('width', 'auto'); 
1

您还可以使用DataTable的Fluid column width功能。这将有助于自动调整大小,并添加滚动无论在XY轴你应该有更多的列显示

$(document).ready(function() { 
    var table = $('#example').DataTable({ 
     scrollY:  "300px", 
     scrollX:  true, 
     scrollCollapse: true, 
     paging:   false, 
     columnDefs: [ 
      { width: '20%', targets: 0 } 
     ], 
     fixedColumns: true 
    }); 
}); 

HERE

得到
相关问题