我使用的是DataTables with Ajax data,我想将serial number放在datatable中
我尝试了下面的html代码
<div class="col-md-12">
<table class="table-striped table-bordered" id="salestbl">
<thead>
<tr><th>S.no</th><th>Invoice Number</th><th>Total Amount</th><th>Discoint Amount</th><th>Total Tax</th><th>Grand Total</th><th>Date</th></tr>
</thead>
<tbody>
</tbody>
</table>
</div>阿贾克斯
$('#salestbl').DataTable( {
"fnRowCallback" : function(nRow, aData, iDisplayIndex){
$("td:first", nRow).html(iDisplayIndex +1);
return nRow;
},
destroy: true,
data: response,
columns: [
{ data: 'nRow' },
{ data: 'invoiceNum' },
{ data: 'totalAmt' },
{ data: 'disAmt' },
{ data: 'taxAmt' },
{ data: 'grandTotal' },
{ data: 'date' }
]
} );当dataTable被锁定时,它显示了下面的alert
DataTables warning: table id=salestbl - Requested unknown parameter 'nRow' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4以上代码有什么问题,请帮帮我。
发布于 2018-03-22 10:20:18
我找到了我们需要在bean类中声明slno并将其添加到json字符串并发送到ajax的答案。
$('#salestbl').DataTable( {
"fnRowCallback" : function(nRow, aData, iDisplayIndex){
$("td:first", nRow).html(iDisplayIndex +1);
return nRow;
},
destroy: true,
data: response,
columns: [
{ data: 'nRow' },
{ data: 'invoiceNum' },
{ data: 'totalAmt' },
{ data: 'disAmt' },
{ data: 'taxAmt' },
{ data: 'grandTotal' },
{ data: 'date' }
]
} );这里不应该是{ data: 'nRow' },,它应该是类{ data: 'slno' },的成员变量。
然后,数据表将为first td of every row分配行号。
"fnRowCallback" : function(nRow, aData, iDisplayIndex){
$("td:first", nRow).html(iDisplayIndex +1);
return nRow;
},以上功能,谢谢你曾经回答我的问题。
https://stackoverflow.com/questions/49424863
复制相似问题