4
我跟着這個帖子:DataTable: Server Side Processing in ASP.Net
我使用這個代碼來初始化數據表:隱藏列與服務器端處理
<script type="text/javascript">
$(function() {
$('#example').dataTable({
'bProcessing': true,
'bServerSide': true,
'sAjaxSource': '/data.ashx'
});
});
</script>
我的JSON是這樣的:
{
"iTotalRecords": "57",
"iTotalDisplayRecords": "57",
"aaData": [
[
"id001",
"Name001",
"Addr001",
],
[
"id002",
"Name002",
"Addr002",
]
]
}
我想達到如下:
<table id="datatable">
<thead>...</thead>
<tbody>
<tr id="id001">
<td>Name001</td>
<td>Addr001</td>
</tr>
<tr id="id002">
<td>Name002</td>
<td>Addr002</td>
</tr>
.
.
</tbody>
</table>
注:
到ID分配給<tr>
我使用:
"fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
$(nRow).attr("id",aData[0]);
return nRow;
}
但它不是隱藏ID
列。 請幫忙。
更新: 我找到了解決我的問題的完美解決方案。
我必須創建我的JSON如下
{
"iTotalRecords": "57",
"iTotalDisplayRecords": "57",
"aaData": [
[
"0":"Name001",
"1":"Addr001",
"DT_RowId": "id001",
],
[
"0":"Name002",
"1":"Addr002",
"DT_RowId": "id002",
]
]
}
有關更多信息,請點擊此鏈接:DateTable - automatic row ID addition