代码之家  ›  专栏  ›  技术社区  ›  bharath

为第0行第0列(DataTables)请求了未知参数“nRow”

  •  0
  • bharath  · 技术社区  · 7 年前

    我正在使用 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>
    

    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' }
    
    
                            ]
                        } );
    

    当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
    

    以上代码有什么问题,请帮我解决。

    1 回复  |  直到 7 年前
        1
  •  0
  •   bharath    7 年前

    我找到了我们需要宣布的答案 slno 在beans类中,将其添加到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;
                                },
    

    以上功能,感谢您曾经回答过我的问题。