DataTables:在Ajax请求之后添加行的问题

时间:2015-08-22 10:07:49

标签: jquery datatables

当我使用以下行将数据从服务器添加到数据表时,

allOrder.rows.add(response.orderList).draw();

我收到警告

  

DataTables警告:table id = {id} - 第0行请求的未知参数0

我的表初始化:

ele.DataTable({
   "retrieve": true,
   "responsive": false,
   "columns": [
      {"data": "eOrderNo"},
      {"data": "siebelOrderNo"},
      {"data": "networkId"},
      {"data": "serviceId"},
      {"data": "customerName"},
      {"data": "orderRef"},
      {"data": "ocn"},
      {"data": "originator"},
      {"data": "custService"},
      {"data": "status"},
      {"data": "orderType"},
      {"data": "productDetails"},
      {"data": "createDate"},
      {"data": "csd"},
      {"data": "crd"},
      {"data": "icd"},
      {"data": "cpd"},
      {"data": "ActualDate"}
   ],
   "scrollY": "300px",
   "scrollCollapse": true,
   "sScrollX": "100%",
   "sScrollXInner": "400%",
   "paging": true,
   "pageLength": 25,
   "lengthMenu": [10, 25, 50, 75, 100],
   "pagingType": "simple",

   /* for V Scroll */

   "bFilter": false,
   "bInfo": true,
   "bProcessing": true,
   "order": [
      [10, "desc"]
   ],
   "autoWidth": false,
});

JSON

[
    {
        "eOrderNo": "000050002",
        "siebelOrderNo": "000050002",
        "networkId": "",
        "serviceId": "",
        "customerName": "PIPPO",
        "orderRef": "",
        "ocn": "",
        "originator": "BREZZOLARI",
        "custService": "",
        "status": "Migrated to OH&P",
        "orderType": "New Order",
        "productDetails": " Voice Connect",
        "createDate": "2000-04-27 20:40:17.0",
        "csd": "",
        "crd": "",
        "icd": "",
        "cpd": "2000-05-03 23:00:00.0",
        "ActualDate": "2000-10-18 17:52:55.0"
    },
    {
        "eOrderNo": "000083855",
        "siebelOrderNo": "000083855",
        "networkId": "",
        "serviceId": "LON/LON/E1D24282,\nLON/LON/E1D24284, \nLON/LON/E1D24285  (Ceased)",
        "customerName": "PAINE WEBBER",
        "orderRef": "",
        "ocn": "",
        "originator": "SHARRON GANDER",
        "custService": "",
        "status": "Completed",
        "orderType": "Cease",
        "productDetails": "Customer Related Services",
        "createDate": "2002-02-07 13:57:12.0",
        "csd": "",
        "crd": "2001-12-14 00:00:00.0",
        "icd": "",
        "cpd": "2002-03-07 00:00:00.0",
        "ActualDate": "2002-03-07 00:00:00.0"
    },
    {
        "eOrderNo": "000084305",
        "siebelOrderNo": "000084305",
        "networkId": "",
        "serviceId": "",
        "customerName": "PAINE WEBBER",
        "orderRef": "MC600",
        "ocn": "",
        "originator": "PAUL BURTON",
        "custService": "",
        "status": "Completed",
        "orderType": "Cease",
        "productDetails": " Link Metro",
        "createDate": "2001-04-17 09:11:03.0",
        "csd": "",
        "crd": "2001-04-14 00:00:00.0",
        "icd": "",
        "cpd": "2001-05-17 00:00:00.0",
        "ActualDate": "2001-05-03 00:00:00.0"
    },
    {
        "eOrderNo": "000084799",
        "siebelOrderNo": "000084799",
        "networkId": "",
        "serviceId": "LON/LON/LE-100779  (ceased)",
        "customerName": "INVESTEC",
        "orderRef": "",
        "ocn": "22593",
        "originator": "",
        "custService": "",
        "status": "Completed",
        "orderType": "Cease",
        "productDetails": " LANLink Metro",
        "createDate": "2002-11-21 16:48:36.0",
        "csd": "",
        "crd": "2002-11-21 00:00:00.0",
        "icd": "",
        "cpd": "2003-01-06 06:00:00.0",
        "ActualDate": "2002-11-29 00:00:00.0"
    },
    {
        "eOrderNo": "000088037",
        "siebelOrderNo": "000088037",
        "networkId": "",
        "serviceId": "LON/LON/E1-027579",
        "customerName": "EVOLUTION CONSULTING GROUP",
        "orderRef": "",
        "ocn": "",
        "originator": "STUART HORINE",
        "custService": "",
        "status": "Completed",
        "orderType": "Modification",
        "productDetails": " Voice Line",
        "createDate": "2001-01-22 11:06:21.0",
        "csd": "",
        "crd": "",
        "icd": "",
        "cpd": "2001-02-12 00:00:00.0",
        "ActualDate": "2001-01-22 00:00:00.0"
    },
    {
        "eOrderNo": "000100001",
        "siebelOrderNo": "000100001",
        "networkId": "",
        "serviceId": "DLEI00003",
        "customerName": "ECOMP ENGINEERING GMBH",
        "orderRef": "",
        "ocn": "",
        "originator": "HERR WELLER",
        "custService": "",
        "status": "Closed",
        "orderType": "New Order",
        "productDetails": " LANLink Metro",
        "createDate": "2000-01-03 09:18:32.0",
        "csd": "",
        "crd": "2000-01-14 23:00:00.0",
        "icd": "",
        "cpd": "2000-01-14 23:00:00.0",
        "ActualDate": "2000-01-13 16:31:38.0"
    },
    {
        "eOrderNo": "000100001/1",
        "siebelOrderNo": "000100001/1",
        "networkId": "",
        "serviceId": "DLEI00003",
        "customerName": "NEXTRA DEUTSCHLAND COMMUNICATION GMBH",
        "orderRef": "",
        "ocn": "OMN01",
        "originator": "HERR RUDOLF MORBITZER",
        "custService": "",
        "status": "Completed",
        "orderType": "Cease",
        "productDetails": " LANLink Metro",
        "createDate": "2001-02-23 09:22:20.0",
        "csd": "",
        "crd": "2001-03-30 23:00:00.0",
        "icd": "",
        "cpd": "2001-04-01 23:00:00.0",
        "ActualDate": "2001-04-02 16:19:56.0"
    },
    {
        "eOrderNo": "000100002",
        "siebelOrderNo": "000100002",
        "networkId": "",
        "serviceId": "SE0100135-142",
        "customerName": " TELECOM STUTTGART",
        "orderRef": "",
        "ocn": "",
        "originator": "LUDWIG MODRA",
        "custService": "",
        "status": "Completed",
        "orderType": "Internal",
        "productDetails": " Link Metro",
        "createDate": "2000-01-03 09:10:34.0",
        "csd": "",
        "crd": "",
        "icd": "",
        "cpd": "2000-01-11 23:00:00.0",
        "ActualDate": "2000-01-13 06:55:10.0"
    },
    {
        "eOrderNo": "000100003",
        "siebelOrderNo": "000100003",
        "networkId": "",
        "serviceId": "HE0X01125",
        "customerName": "MEDIA CONSULTING JOERG MANDT",
        "orderRef": "",
        "ocn": "",
        "originator": "HERR JOERG MANDT",
        "custService": "",
        "status": "Closed",
        "orderType": "New Order",
        "productDetails": " Voice Line",
        "createDate": "2000-01-03 09:18:36.0",
        "csd": "",
        "crd": "",
        "icd": "",
        "cpd": "2000-01-16 23:00:00.0",
        "ActualDate": "2000-08-13 23:00:00.0"
    },
    {
        "eOrderNo": "000100003/1",
        "siebelOrderNo": "000100003/1",
        "networkId": "",
        "serviceId": "HE0X01125",
        "customerName": "MEDIA CONSULTING JOERG MANDT",
        "orderRef": "",
        "ocn": "",
        "originator": "HERR JOERG MANDT",
        "custService": "",
        "status": "Completed",
        "orderType": "Cease",
        "productDetails": " Voice Line",
        "createDate": "2000-08-03 12:16:25.0",
        "csd": "",
        "crd": "2000-08-03 23:00:00.0",
        "icd": "",
        "cpd": "2000-08-15 23:00:00.0",
        "ActualDate": "2000-08-13 23:00:00.0"
    },
    {
        "eOrderNo": "000100004",
        "siebelOrderNo": "000100004",
        "networkId": "",
        "serviceId": "FE1V11746",
        "customerName": " TELECOM FRANKFURT",
        "orderRef": "",
        "ocn": "",
        "originator": "HERR SANDRO INGLESE",
        "custService": "",
        "status": "Completed",
        "orderType": "Internal",
        "productDetails": " Link Metro",
        "createDate": "2000-01-03 09:22:23.0",
        "csd": "",
        "crd": "",
        "icd": "",
        "cpd": "2000-01-23 23:00:00.0",
        "ActualDate": "2000-02-02 12:53:57.0"
    },
    {
        "eOrderNo": "000100005",
        "siebelOrderNo": "000100005",
        "networkId": "",
        "serviceId": "FE1S11747",
        "customerName": " TELECOM FRANKFURT",
        "orderRef": "",
        "ocn": "",
        "originator": "HERR SANDRO INGLESE",
        "custService": "",
        "status": "Completed",
        "orderType": "Internal",
        "productDetails": " Link Metro",
        "createDate": "2000-01-03 09:26:12.0",
        "csd": "",
        "crd": "",
        "icd": "",
        "cpd": "2000-01-23 23:00:00.0",
        "ActualDate": "2000-01-20 07:27:36.0"
    },
    {
        "eOrderNo": "000100006",
        "siebelOrderNo": "000100006",
        "networkId": "",
        "serviceId": "HE0X01126.",
        "customerName": "MEDIA CONSULTING JOERG MANDT",
        "orderRef": "",
        "ocn": "",
        "originator": "HERR JOERG MANDT",
        "custService": "",
        "status": "Closed",
        "orderType": "New Order",
        "productDetails": " Voice Line",
        "createDate": "2000-01-03 09:38:33.0",
        "csd": "",
        "crd": "",
        "icd": "",
        "cpd": "2000-01-16 23:00:00.0",
        "ActualDate": "2000-08-13 23:00:00.0"
    },
    {
        "eOrderNo": "000100006/1",
        "siebelOrderNo": "000100006/1",
        "networkId": "",
        "serviceId": "HE0X01126",
        "customerName": "MEDIA CONSULTING JOERG MANDT",
        "orderRef": "",
        "ocn": "",
        "originator": "HERR JOERG MANDT",
        "custService": "",
        "status": "Completed",
        "orderType": "Cease",
        "productDetails": " Voice Line",
        "createDate": "2000-08-03 12:20:49.0",
        "csd": "",
        "crd": "2000-08-03 23:00:00.0",
        "icd": "",
        "cpd": "2000-08-15 23:00:00.0",
        "ActualDate": "2000-08-13 23:00:00.0"
    },
    {
        "eOrderNo": "000100007",
        "siebelOrderNo": "000100007",
        "networkId": "",
        "serviceId": "FE5RI0529",
        "customerName": " TELECOM FRANKFURT",
        "orderRef": "",
        "ocn": "",
        "originator": "HERR OLIVER GROSS",
        "custService": "",
        "status": "Completed",
        "orderType": "New Order",
        "productDetails": "INTERNAL",
        "createDate": "2000-01-03 09:34:31.0",
        "csd": "",
        "crd": "",
        "icd": "",
        "cpd": "2000-02-20 23:00:00.0",
        "ActualDate": "2000-02-21 07:36:34.0"
    },
    {
        "eOrderNo": "000100008",
        "siebelOrderNo": "000100008",
        "networkId": "",
        "serviceId": "NA",
        "customerName": " TELECOM FRANKFURT",
        "orderRef": "",
        "ocn": "",
        "originator": "HERR BRIAN CALLAN",
        "custService": "",
        "status": "Completed",
        "orderType": "Internal",
        "productDetails": "INTERNAL",
        "createDate": "2000-01-03 09:41:09.0",
        "csd": "",
        "crd": "2000-01-30 23:00:00.0",
        "icd": "",
        "cpd": "2000-01-31 23:00:00.0",
        "ActualDate": "2000-02-22 17:10:27.0"
    },
    {
        "eOrderNo": "000100009",
        "siebelOrderNo": "000100009",
        "networkId": "",
        "serviceId": "F_IA00053",
        "customerName": " TELECOM FRANKFURT",
        "orderRef": "",
        "ocn": "",
        "originator": "HERR JENS MOELLER",
        "custService": "",
        "status": "Completed",
        "orderType": "Internal",
        "productDetails": "Others (PW)",
        "createDate": "2000-01-03 09:46:59.0",
        "csd": "",
        "crd": "",
        "icd": "",
        "cpd": "2000-01-25 23:00:00.0",
        "ActualDate": "2000-01-20 14:30:23.0"
    },
    {
        "eOrderNo": "000100011",
        "siebelOrderNo": "000100011",
        "networkId": "",
        "serviceId": "FE1X11748",
        "customerName": "AZYX DEUTSCHLAND GMBH",
        "orderRef": "",
        "ocn": "",
        "originator": "HERR HERRWIG",
        "custService": "",
        "status": "Closed",
        "orderType": "New Order",
        "productDetails": " Voice Line",
        "createDate": "2000-01-03 10:50:19.0",
        "csd": "",
        "crd": "2000-01-21 23:00:00.0",
        "icd": "",
        "cpd": "2000-02-10 23:00:00.0",
        "ActualDate": "2000-02-11 13:01:59.0"
    },
    {
        "eOrderNo": "000100011/1",
        "siebelOrderNo": "000100011/1",
        "networkId": "",
        "serviceId": "FE1X11748",
        "customerName": "AZYX",
        "orderRef": "",
        "ocn": "AZY01",
        "originator": "TBA",
        "custService": "",
        "status": "Completed",
        "orderType": "Cease",
        "productDetails": " Voice Line",
        "createDate": "2003-04-30 11:16:33.0",
        "csd": "2003-04-29 23:00:00.0",
        "crd": "2003-04-29 23:00:00.0",
        "icd": "",
        "cpd": "2003-05-01 07:00:00.0",
        "ActualDate": "2003-05-13 14:40:52.0"
    },
    {
        "eOrderNo": "000100013",
        "siebelOrderNo": "000100013",
        "networkId": "",
        "serviceId": "FE1P11864",
        "customerName": "CARPENET INFORMATION TECHNOLOGIES GMBH",
        "orderRef": "",
        "ocn": "",
        "originator": "HERR DAVIS",
        "custService": "",
        "status": "Closed",
        "orderType": "New Order",
        "productDetails": " Link Metro",
        "createDate": "2000-01-03 10:48:03.0",
        "csd": "",
        "crd": "1999-12-31 23:00:00.0",
        "icd": "",
        "cpd": "2000-02-20 23:00:00.0",
        "ActualDate": "2000-02-21 13:28:33.0"
    },
    {
        "eOrderNo": "000100013/1",
        "siebelOrderNo": "000100013/1",
        "networkId": "",
        "serviceId": "FE1P11864",
        "customerName": "CARRIER1 GMBH & CO. KG",
        "orderRef": "",
        "ocn": "CAR01",
        "originator": "FRAU BRIGITTE DAVIS",
        "custService": "",
        "status": "Completed",
        "orderType": "Cease, All",
        "productDetails": " Link Metro",
        "createDate": "2004-12-06 14:29:00.0",
        "csd": "2004-11-28 23:00:00.0",
        "crd": "2004-12-31 16:00:00.0",
        "icd": "",
        "cpd": "2005-01-03 11:00:00.0",
        "ActualDate": "2005-02-03 14:56:54.0"
    },
    {
        "eOrderNo": "000100013SH1",
        "siebelOrderNo": "000100013SH1",
        "networkId": "",
        "serviceId": "96W/89002/89002/10421, DA: 11;\n96W/89002/89002/12220; DA72;",
        "customerName": "NEUBO HAUSVERWALTUNG GMBH & CO. BETRIEBS KG",
        "orderRef": "",
        "ocn": "517322",
        "originator": "HERR HELMUT SCHLACHTER",
        "custService": "",
        "status": "Closed",
        "orderType": "Upgrade",
        "productDetails": " Voice Line",
        "createDate": "2002-07-05 10:40:02.0",
        "csd": "2002-07-03 23:00:00.0",
        "crd": "",
        "icd": "",
        "cpd": "2002-08-12 07:00:00.0",
        "ActualDate": "2002-08-12 11:21:38.0"
    },
    {
        "eOrderNo": "000100013SH1/1",
        "siebelOrderNo": "000100013SH1/1",
        "networkId": "",
        "serviceId": "96W/89002/89002/10421, DA11;\n96W/89002/89002/12220; DA72;",
        "customerName": "NEUBO HAUSVERWALTUNG GMBH & CO. BETRIEBS KG",
        "orderRef": "",
        "ocn": "517322",
        "originator": "HERR HELMUT SCHLACHTER",
        "custService": "",
        "status": "Closed",
        "orderType": "Modification",
        "productDetails": " Voice Line",
        "createDate": "2002-08-05 15:55:25.0",
        "csd": "2002-08-04 23:00:00.0",
        "crd": "",
        "icd": "",
        "cpd": "2002-08-25 23:00:00.0",
        "ActualDate": "2002-08-26 09:45:04.0"
    },
    {
        "eOrderNo": "000100013SH1/2",
        "siebelOrderNo": "000100013SH1/2",
        "networkId": "",
        "serviceId": "96W/89002/89002/10421, DA11;\n96W/89002/89002/12220; DA72;",
        "customerName": "NEUBO HAUSVERWALTUNG GMBH & CO. BETRIEBS KG",
        "orderRef": "",
        "ocn": "517322",
        "originator": "HERR HELMUT SCHLACHTER",
        "custService": "",
        "status": "Completed",
        "orderType": "Cease, All",
        "productDetails": " Voice Line",
        "createDate": "2004-10-11 10:43:06.0",
        "csd": "2004-10-03 23:00:00.0",
        "crd": "",
        "icd": "",
        "cpd": "2004-10-11 11:00:00.0",
        "ActualDate": "2004-10-11 10:45:12.0"
    },
    {
        "eOrderNo": "000100014",
        "siebelOrderNo": "000100014",
        "networkId": "",
        "serviceId": "N/A",
        "customerName": " TELECOM GMBH",
        "orderRef": "",
        "ocn": "",
        "originator": "THORSTEN KULKE",
        "custService": "",
        "status": "Completed",
        "orderType": "Internal",
        "productDetails": "Others (PW)",
        "createDate": "2000-01-03 10:56:10.0",
        "csd": "",
        "crd": "2000-02-03 23:00:00.0",
        "icd": "",
        "cpd": "2000-04-13 23:00:00.0",
        "ActualDate": "2000-04-13 10:59:08.0"
    }
]

在表上绘制行,但没有数据添加到表中。

我的表格标题如下:

<table id="allOrders" class="table table-hover" cellspacing="0">
<thead>
<th data-toggle="tooltip" title="title description goes here..">eOrderNo</th>
<th data-toggle="tooltip" title="title description goes here..">siebelOrderNo</th>
<th data-toggle="tooltip" title="title description goes here..">networkId</th>
<th data-toggle="tooltip" title="title description goes here..">serviceId</th>
<th data-toggle="tooltip" title="title description goes here..">customerName</th>
<th data-toggle="tooltip" title="title description goes here..">orderRef</th>
<th data-toggle="tooltip" title="title description goes here..">ocn</th>
<th data-toggle="tooltip" title="title description goes here..">originator</th>
<th data-toggle="tooltip" title="title description goes here..">custService</th>
<th data-toggle="tooltip" title="title description goes here..">status</th>
<th data-toggle="tooltip" title="title description goes here..">orderType</th>
<th data-toggle="tooltip" title="title description goes here..">productDetails</th>
<th data-toggle="tooltip" title="title description goes here..">createDate</th>
<th data-toggle="tooltip" title="title description goes here..">csd</th>
<th data-toggle="tooltip" title="title description goes here..">crd</th>
<th data-toggle="tooltip" title="title description goes here..">icd</th>
<th data-toggle="tooltip" title="title description goes here..">cpd</th>
<th data-toggle="tooltip" title="title description goes here..">coltActualDate</th>
</thead>
</table>
  

最终编辑:我的问题是填充代码的位置   表。它的范围与代码范围不同   表初始化被放置,因此它与   原始初始化。

2 个答案:

答案 0 :(得分:1)

选中此项:https://www.datatables.net/manual/tech-notes/4。 在您的情况下,“诊断/参数是整数”部分是相关的:

  

当{parameter}是一个整数时,DataTables正在寻找数组中的数据。当使用DOM源数据时通常就是这种情况(即,从文档中自动读取表的数据)。在这种情况下,源数组中不存在请求的数据 - 可能是因为数组不够长。如果出现这种情况:

     
      
  • 表格的tbody中有一个colspan或rowspan,DataTables不支持。

  •   
  • 使用columns或columnDefs指定的列数多于HTML中的列数

  •   
  • 表中的单元格数不满足等式#cells = #columns * #rows(即标题中定义的列数多于表格中的列数,反之亦然)。
  •   

您的html代码中没有<tbody>标记,因此请按照链接文档中的说明添加它。

<强>更新

同时检查一下:在列定义中,您有{"data": "coltActualDate"},在JSON数组中,您有"ActualDate": "2000-10-18 17:52:55.0"。可能它不起作用,因为名称不匹配。

更新2

我用你的代码创建了JSfiddle,一切正常。 https://jsfiddle.net/uosa3dha/1/

答案 1 :(得分:1)

  

<强>解

添加ajax.dataSrc并将其设置为空字符串('')以匹配您的数据结构,如下所示:

ele.DataTable({
    ajax: {
        url: 'script.php',
        dataSrc: '' 
    },
    /* ... skipped ... */
});

来自ajax.dataSrc选项说明:

  

请注意,如果您的Ajax源只是返回一个数据数组   显示而不是对象,将此参数设置为空   字符串。

  

备注

您的代码存在其他问题

  • "autoWidth": false
  • 之后的逗号
  • thead元素必须包含tr标记,并在th中包含tr