将ID从json数据分配给datatable行 [英] Assign ID to datatable row from json data
问题描述
我被卡住了超过2天。我有一个Json数据,我还没有加载表,我也想分配第一列为行的id
这里是html:
< table cellpadding =0cellspacing =0border =0class =display
id =accDetailTable >
< thead>
< tr>
< th>货币< / th>
< th>当前/储蓄账户号码< / th>
< th>证券账户号码< / 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 :20,currency:1,currentAccNo:aa,secureAccNo:aa},
{DT_RowId ,$ a $,
{DT_RowId:2034,currency:1,currentAccNo:a,secureAccNo:aa},
]
}
但它总是打击:
$ b $数据表警告(表id ='accDetailTable'):添加的数据(大小未定义)与已知列数不匹配(3)
这很简单。让我们做一个微小的变化,因为你想要第一列包含id,你可能需要使用fnRender,请检查api的数据表,我没有添加这部分代码:
var oTable = $('#accDetailTable' ).dataTable({
bProcessing:true,
bServerSide:true,
sAjaxSource:contextPath +/ user / investorAjax?method = getInvestorAccDetailList,
aoColumns:[
{mDataProp:currency},
{mDataProp:currentAccNo},
{mDataProp:secureAccNo}
]
});
i'm new to datatable jquery plugin. I got stuck with this for more than 2 days. I have a Json Data, i still cant load the table and i also want to assign first column to be id of the row
Here is 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>
and my initialization
var oTable=$('#accDetailTable').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": contextPath + "/user/investorAjax?method=getInvestorAccDetailList",
"iDeferLoading": 57,
} );
Return jsonData from server :
{"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"},
]}
}
But it always hit :
DataTables warning (table id = 'accDetailTable'): Added data (size undefined) does not match known number of columns (3)
It's kind of easy. Let's just do a tiny change, since you want the first column contains id, you may need to use fnRender, please check the api of datatables, I didn't add this part of code:
var oTable=$('#accDetailTable').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": contextPath + "/user/investorAjax?method=getInvestorAccDetailList",
"aoColumns":[
{"mDataProp":"currency"},
{"mDataProp":"currentAccNo"},
{"mDataProp":"secureAccNo"}
]
});
这篇关于将ID从json数据分配给datatable行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!