提问者:小点点

DataTables警告:表ID=example-为行1,列1请求未知参数“1


获取错误“DataTables Warning:table ID=example-请求行1列1的未知参数”1“。有关此错误的详细信息,请参阅http://datatables.net/TN/4”当从ajax api调用加载数据时,从后端收到的json如下所示

[{"CustomerName":"Dinesh","product":"23234","perticulars":"wrwer","AddressOfCustomer":"wrew`","ContactNumbers":"jhkjhb"}, {"CustomerName":"dd","product":"dfsdfs","perticulars":"fsdfs","AddressOfCustomer":"sdfsdf","ContactNumbers":"fsfsf"}, {"CustomerName":"Pratik","product":"toothbrush","perticulars":"6 inch","AddressOfCustomer":"shreedhama white rose","ContactNumbers":"9949634396"}]

要填充表数据的HTML div标记片段如下所示。

         <table id="example" class="display" align="center" vertical-align="middle"; cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Customer Name</th>
                <th>Product</th>
                <th>Perticulars</th>
                <th>Address of customer.</th>
                <th>Contact number</th>
            </tr>
        </thead>
        <tbody>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
</tbody>
        <tfoot>
            <tr>
                <th>Customer Name</th>
                <th>Product</th>
                <th>Perticulars</th>
                <th>Address of customer.</th>
                <th>Contact number</th>
            </tr>
        </tfoot>
    </table>

下面是我正在执行的ajax调用,在success函数中尝试从json填充数据

        $.ajax({
            url:'AddQuotation',
            type:'get',      
            success:function(data){ 
                     alert(data);

                     var resultTable = $('#example').DataTable({

                         "columns": [
                         { data: "CustomerName" },
                         { data: "product" },
                         { data: "perticulars" },
                        { data: "AddressOfCustomer" },
                        { data: "ContactNumbers" }
                        ],
                        "destroy": true,
                        "dom": 'lrtip'
                        } );
            resultTable.rows.add(data1).draw();
            dataSet = data;         
             },
             error:function(){
              alert('error');
             }
             });

共2个答案

匿名用户

您需要有包含对象数组的对象。

{"data": [{"CustomerName":"Dinesh","product":"23234","perticulars":"wrwer","AddressOfCustomer":"wrew`","ContactNumbers":"jhkjhb"}, {"CustomerName":"dd","product":"dfsdfs","perticulars":"fsdfs","AddressOfCustomer":"sdfsdf","ContactNumbers":"fsfsf"}, {"CustomerName":"Pratik","product":"toothbrush","perticulars":"6 inch","AddressOfCustomer":"shreedhama white rose","ContactNumbers":"9949634396"}]}

一个工作演示。

匿名用户

在我的例子中,我只是在代码中更改了以下内容,错误是

DataTables警告:表ID=bootstrap-data-table2-为行0请求未知参数“0”。有关此错误的详细信息,请参阅http://datatables.net/TN/4

不见了:

null

<tbody>
  @foreach (var item in Model.HRMS_Tbl_ExpenseClaimModelList)
    {
      <tr>
        @if (item.Approved == "1")
        {
        <td>@item.Date</td>
        <td>@item.Date</td>
        <td>@item.Type</td>
        <td>@item.Amount</td>
        }
      </tr>
    }
</tbody>

致:

<tbody>
  @foreach (var item in Model.HRMS_Tbl_ExpenseClaimModelList)
    {
    if (item.Approved == "1")
      {
      <tr>
        <td>@item.Date</td>
        <td>@item.Date</td>
        <td>@item.Type</td>
        <td>@item.Amount</td>
      </tr>
      }
    }
</tbody>