【问题标题】:Requested unknown parameter 'nRow' for row 0, column 0(DataTables)请求第 0 行第 0 列的未知参数“nRow”(数据表)
【发布时间】:2018-03-22 09:25:15
【问题描述】:

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

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

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

【问题讨论】:

  • 问题可能出在您的 JSON 响应的格式上,您未在此处包含该格式。您已将数据定义为使用对象,因此您的响应应类似于本示例中的 Ajax 选项卡:datatables.net/examples/ajax/objects.html
  • 没有行号一切都很好,如果我添加它会发出警报,我认为这不是 json 的问题或将行号添加到 dataTable 的其他问题

标签: ajax datatables


【解决方案1】:

我找到了我们需要在 beans 类中声明 slno 并将其添加到 json String 并发送到 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;
                            },

以上功能,谢谢回复我问题的人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-28
    • 2014-09-16
    • 2020-03-18
    • 1970-01-01
    • 2016-09-24
    • 2015-08-30
    • 2019-01-25
    相关资源
    最近更新 更多