我正在尝试设置数据表的列宽。请看下面的代码。
$('#datatable5').DataTable({
"order" : [ [ 0, "desc" ] ],
"columnDefs": [ { "width": "100px", "target":0 }, { "width": "400px", "target":1 }, { "width": "200px", "target":2 } ,{ "width": "200px", "target":3 } ,{ "width": "200px", "target":4 } ,{ "width": "200px", "target":5 } ,{ "width": "200px", "target":6 }, { "width": "200px" , "target":7 }, { "width": "200px", "target":8 }, { "width": "200px", "target":9 }],
//"sPaginationType" : "bs_two_button",
//"iDisplayLength" : 9,
"scrollX": true,
// "sScrollX" : "100%",
"paging": true,
"sPaginationType" : "bs_two_button",
"info" : false,
"fnDrawCallback" : function(oSettings) {
$('td').removeClass('sorting_1');
}
});
如何将列宽显式传递给数据表?我尝试了 css 来设置表格的宽度。然而,并没有成功?
最佳答案
尝试在 columnDefs 中使用“targets”,而不是“target”,即使你只给它一个列。
如果你想通过 CSS 来实现,那么你可以为每一列赋予它自己的类(在 columnDefs 中使用 className),并使用它来设置宽度。
关于jquery - 如何调整数据表列宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26744567/