我正在使用数据表,并使用 javascript 用数据填充表。它工作正常,但我想防止数据表在过滤后调整表的列宽。我已经尝试了在网上找到的几种解决方案,但似乎并没有解决问题。
我的 HTML 是:
<table class="table table-striped table-bordered table-hover" id="id-table" width="100%"></table>
我像这样实例化表格:
var table = $('#id-table').DataTable(
{
paging: false,
ordering: false,
info: false,
"bAutoWidth": false, // Disable the auto width calculation : false,
columns: columns,
data : assignments,
sScrollX: "100%",
// aoColumns : aoColumns
// aoColumns : [
// { "sWidth": "150px" },
// { "sWidth": "150px" },
// { "sWidth": "150px" },
// { "sWidth": "150px" },
// { "sWidth": "150px" },
// { "sWidth": "150px" },
// { "sWidth": "150px" },
// { "sWidth": "150px" },
// { "sWidth": "150px" },
// { "sWidth": "150px" },
// { "sWidth": "150px" },
// { "sWidth": "150px" }
// ]
// aoColumns: aoColumns
// columnDefs : cdefs
}
);
其中数据是包含数据的数组,列是对象数组,例如:
bSearchable false
sTitle "Column Title"
sWidth "100px"
title "Column Title"
mRender function(data, type, full, meta)
render function(data, type, full, meta)
我已经尝试直接在两个“列”中设置宽度并使用“aoColumns”选项(在上面的代码中注释掉)。在这两种情况下,列宽在过滤后仍会调整大小。关于如何禁用此自动调整大小的任何想法?
最佳答案
在您的 html 表格标签中,将样式 table-layout
设置为 'fixed'
并将 bAutoWidth = false
传递给数据表函数
关于javascript - 数据表:过滤后禁用列大小调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30706637/