如何增加数据表中的列宽

时间:2016-06-30 11:45:03

标签: javascript jquery datatables

$(document).ready(function() {
    var myTable = $('#example').DataTable({
      "serverSide": true,
      "processing": true,
      "paging": true,
      "autoWidth": false,
      //"searching": { "regex": true },
      searching: false,
      "lengthMenu": [ [10, 25, 50, 100, 250,500 ,1000], [10, 25, 50, 100, 250,500 ,1000] ],
      "ajax": {
          "type": "POST",
          "url": "packetsScannedListData?total=" +total ,
          "dataType": "json",
          "contentType": 'application/json; charset=utf-8',
          "data": function (data) {
              var info = $('#example').DataTable().page.info();
              pageOrders = {};
              return JSON.stringify(info);
          } 

    }, 
      "columns": [
                { "data": "orderNo" },
                { "data": "crderDate" },
                { "data": "clientName" }
             ],

     }); 

4 个答案:

答案 0 :(得分:2)

您可以使用类似

设置列
 "columns": [
                { "data": "orderNo" , "width":"20%" },
                { "data": "crderDate" , "width":"50%" },
                { "data": "clientName" , "width":"30%" }
             ],

https://datatables.net/reference/option/columns.width

答案 1 :(得分:1)

你可以添加:

"columnDefs": [
    { "width": "percent%", "targets": numOfDesiredColumn }
]

答案 2 :(得分:1)

像这样,      使用

将第一列的宽度设置为20%
$('#example').dataTable( {
      "columns": [
        { "width": "20%" },
        null,
        null,
        null,
        null
      ]
    } );

答案 3 :(得分:0)

你可以通过

来完成
$('#example').dataTable( {
  "columns": [
    { "width": "20%" },
    null,
    null,
    null,
    null
  ]
} );

这将设置第一列宽度20%

相关问题