我遇到了一个问题,当我将 columnFilter() 应用于 jQuery Datatables 时,列宽变得非常大。我尝试对每个 aoColumn 使用 sWidth ,但没有成功。另外,我也关闭了 bAutoWidth,但没有成功。
这是我的数据表:
oAgentDataTable = $("#agentDataTable").dataTable({
"bServerSide": true,
"sAjaxSource": "Agents/GetAgents",
"bProcessing": true,
"aoColumns": [
{
"mDataProp": "FirstName"
},
{ "mDataProp": "LastName" },
{
"mDataProp": "AnniversaryDate",
"bSearchable": false,
"bSortable": false
},
{ "mDataProp": "Location" },
{
"mDataProp": "Active",
"bSearchable": false
},
{
"mDataProp": "Links",
"bSearchable": false,
"bSortable": false,
"fnRender": function (oObj) {
return "<input type='hidden' value='" + oObj.aData['ID'] + "'/>";
}
}
],
"fnDrawCallback": function (oSettings) {
$('#agentDataTable tbody tr').each(function () {
$(this).click(function () {
// Calls Agent Edit Partial
$.get("/Agents/Edit/" + $(this).find("td:last input").val(), function (data) {
$("#partialContentHolder").html(data);
$(".datepicker").datepicker();
applyUnPaidFeeDataTable();
applayPaidFeeDataTable();
});
});
});
}
}).columnFilter({
sPlaceHolder: "head:before",
"aoColumns": [
{ type: "text" },
{ type: "text" },
{ type: "date-range" },
{ type: "text" },
{
type: "select",
values: ["True", "False"]
},
null
]
});
标记:
<table id="agentDataTable">
<thead>
<tr>
<th>
First Name
</th>
<th>
Last Name
</th>
<th>
Anniversary Date
</th>
<th>
Location
</th>
<th>
Both
</th>
<th></th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Anniversary Date</th>
<th>Location</th>
<th>Active</th>
<th></th>
</tr>
</tfoot>
</table>
这是渲染时的结果:
更新:
我弄清楚那是什么。asp.net mvc 生成的 site.css 具有以下输入样式:
input, textarea {
border: 1px solid #e2e2e2;
background: #fff;
color: #333;
font-size: 1.2em;
margin: 5px 0 6px 0;
padding: 5px;
width: 300px;
}