为第 0 行第 0 列请求的未知参数'nRow'(数据表)



我正在使用DataTables with Ajax data我想为数据表放serial number

我尝试了下面的代码.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' }

                        ]
                    } );

当数据表以 为目标时,它显示以下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

上面的代码有什么问题,请帮助我。

我找到了我们需要在 beans 类中声明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;
                            },

以上功能,感谢谁回答了我的问题。

最新更新