我不确定是哪个版本数据表你在使用吗,但我希望这有帮助。我应该说我没有测试它,所以这个例子只是我认为问题所在的主要思想。
在您的 JS 代码中,您可以指示要检索表上数据的源,在本例中我使用 C#,因此我使用“Url.Action”。您应该在 sAjaxSource 中指出这一点。例子是这样的......
var oTable;
$(function() {
oTable = $('#agentDetails')
.dataTable({
"bServerSide": true,
"bProcessing": true,
"bSort": true,
"sAjaxSource": "@Url.Action("Method")",
"sPaginationType": "full_numbers",
"bSearchable":true,
"bFilter": true,
"sDom": '<"top"fip>',
"bInfo": true,
"bLengthChange": false,
"aoColumns": [
{ "mData": "UserId" },
{ "mData": "ParentId", "width": "22%", "bSortable": true},
{ "mData": "Country", "width": "35%" },
],
});
在 aoColumns 上,“mData”意味着映射您从方法中获取的日期的方式,因此您应该准确地指定模型中包含该值的 var 的名称。之后,您不需要使用 for 子句,数据表应该能够自行处理搜索和过滤。
Example
<table id="agentDetails" >
<thead>
<tr>
<th>User Id</th>
<th>Parent Id</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>