【问题标题】:DataTables warning: table id=example - Requested unknown parameter '1' for row 1, column 1DataTables 警告:表 id=example - 请求第 1 行第 1 列的未知参数“1”
【发布时间】:2017-01-08 11:01:36
【问题描述】:

在从 ajax api 调用 json 加载数据时出现错误“DataTables warning: table id=example - Requested unknown parameter '1' for row 1, column 1。有关此错误的更多信息,请参阅http://datatables.net/tn/4”从后端收到如下

[{"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 调用,并在成功函数中尝试从 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');
             }
             });

【问题讨论】:

  • 这方面有什么进展吗?

标签: javascript ajax datatables


【解决方案1】:

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

{"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"}]}

一个工作的DEMO

【讨论】:

    【解决方案2】:

    就我而言,我只是在代码中更改了以下内容和错误

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

    消失了:

    发件人:

    <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>   
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-15
      • 2020-11-30
      • 2013-11-15
      • 2018-01-20
      • 2019-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多