[英]Jquery Datatable drag and drop rows , Row reordering from json data
[英]Assign ID to datatable row from json data
我是datatable jquery插件的新手。 我堅持了超過2天。 我有一個Json數據,我仍然無法加載表,我也想將第一列指定為該行的ID
這是html:
<table cellpadding="0" cellspacing="0" border="0" class="display"
id="accDetailTable">
<thead>
<tr>
<th>Currency</th>
<th>Current/Savings Account No.</th>
<th>Securities Account No.</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
和我的初始化
var oTable=$('#accDetailTable').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": contextPath + "/user/investorAjax?method=getInvestorAccDetailList",
"iDeferLoading": 57,
} );
從服務器返回jsonData:
{"sEcho":1,"iColumns":4,"iTotalRecords":16,"iTotalDisplayRecords":16,
"aaData":
[{"DT_RowId":2032,"currency":1,"currentAccNo":"aa","secureAccNo":"aa"},
{"DT_RowId":2033,"currency":1,"currentAccNo":"111","secureAccNo":"111"},
{"DT_RowId":2034,"currency":1,"currentAccNo":"a","secureAccNo":"aa"},
]}
}
但它總是命中:
DataTables警告(表ID ='accDetailTable'):添加的數據(大小未定義)與已知的列數不匹配(3)
這很容易。 讓我們做一個微小的更改,因為您希望第一列包含id,所以您可能需要使用fnRender,請檢查datatables的api ,我沒有添加這部分代碼:
var oTable=$('#accDetailTable').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": contextPath + "/user/investorAjax?method=getInvestorAccDetailList",
"aoColumns":[
{"mDataProp":"currency"},
{"mDataProp":"currentAccNo"},
{"mDataProp":"secureAccNo"}
]
});
您的數據表正在等待每行三個條目,您給它四個。 在表聲明中(用html部分表示),在行的開頭指定新的標題單元格<th>
。 您將在其中放入ID。 然后,在dataTables初始化之后,可以使用fnSetColumnVis(index, visibility)
函數隱藏第一列:
oTable.fnSetColumnVis(0, false); //It will hide your first column
這樣做每一行都包含他的ID(DT_RowId),但不顯示它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.