我试图在初始化时设置jQuery数据表中单元格的宽度,但它似乎从未起作用。我已经尝试过官方网站和其他示例推荐的内容。以下是我尝试过的一些选择。请帮帮我做错了什么?
例:1
$('#dataTables-comments').DataTable({
"bLengthChange": false,
"bFilter": false,
"iDisplayLength": 5,
"aoColumns": [{
"sWidth": "50%"
},
{
"sWidth": null
},
{
"sWidth": null
},
{
"sWidth": null
},
{
"sWidth": null
}
],
"responsive": true
});
例:2
$('#dataTables-tbl').DataTable({
"bLengthChange": false,
"bFilter": false,
"iDisplayLength": 5,
"columnDefs": [{
"width": "50%",
"targets": 0
}],
"responsive": true
});
例:3
$('#dataTables-tbl').DataTable({
"bLengthChange": false,
"bFilter": false,
"iDisplayLength": 5,
"columns": [{
"width": "50%"
}, {
"width": "10%"
}, {
"width": "10%"
}, {
"width": "10%"
}, {
"width": "10%"
}],
"responsive": true
});
发布于 2016-05-12 02:39:29
与CSS百分比值的任何其他用法一样,该值必须是某个值的百分比。如果表本身没有定义的width
,那么10%
是不可翻译的。所以给你的桌子一个width
:
#dataTables-comments {
width: 800px;
}
并确保关闭autoWidth,这样dataTables就不会开始取消预定义的列宽度:
$('#dataTables-tbl').DataTable({
autoWidth: false, //<---
"bLengthChange": false,
"bFilter": false,
"iDisplayLength": 5,
"columns": [{
"width": "50%"
}, {
"width": "10%"
}, {
"width": "10%"
}, {
"width": "10%"
}, {
"width": "10%"
}],
"responsive": true
});
https://stackoverflow.com/questions/37172274
复制相似问题