DataTable生成不需要的额外列

时间:2017-06-21 07:44:50

标签: javascript jquery datatable

我正在尝试使用来自服务器的数据来制作数据表,但是它生成了不存在的function pdate_product_desc_preview($fieldvalues, $company_digms1, $company_digms2, $company_digms3) { $query = "INSERT INTO eco_product_descTemp(`blockdigms1`, `blockdigms2`, `blockdigms3`) values(:company_digms1,:company_digms2,:company_digms3)"; try { $stmt = $this->conn->prepare($query); $stmt->bindValue(":company_digms1", $company_digms1); echo $company_digms2; $stmt->bindValue(":company_digms2", $company_digms2); echo $company_digms3; $stmt->bindValue(":company_digms3", $company_digms3); $stmt->execute(); var_dump($stmt->errorInfo()); $productid = $this->conn->lastInsertId(); return $productid; } catch (PDOException $e) { $e->getMessage(); } } ,我还没有定义。

的Javascript

td

HTML:

 $('.datatable-basic').DataTable({
          "processing": true,
        "serverSide": false,
        "ajax": {
            "url": base_url + 'leave/DraftJSON/'            
        },

         "columns": [
            { "data": "name" },
            { "data": "sd" },
            { "data": "end" },
            { "data": "id"}       

        ] 
    });

Ajax请求响应:

<table class="table datatable-basic" >
<thead>
  <tr>                                                                    
     <th>Leave</th>                                                              
     <th>Start</th>                                                               
     <th>End</th>                                                                 
     <th class="text-center" col="2">Actions</th>
   </tr>
</thead>                                                                                                                        
</table>

DataTable生成的HTML:

{"data":[{"id":"2","uid":"2","lid":"2","sd":"21 June, 2017","stod":"Afternoon","end":"21 June, 2017"
,"etod":"Afternoon","reason":"ddada","rid":"1","draft":"0","name":"Compassionate","person":"Ms. Ochieng
, Alphonc O"},{"id":"3","uid":"1","lid":"4","sd":"2017\/06\/20","stod":"Morning","end":"2017\/06\/22"
,"etod":"Afternoon","reason":"qeqeqeq","rid":"1","draft":"0","name":"Paternity","person":"Ms. Ochieng
, Alphonc O"}]}

评论的<tbody> <tr class="odd" role="row"> <td class="sorting_1">Compassionate</td> <td>21 June, 2017</td> <td>21 June, 2017</td> <td>2</td> <td></td> //non-existent <td></td> //non-existent </tr> <tr class="even" role="row"> <td class="sorting_1">Paternity</td> <td>2017/06/20</td> <td>2017/06/22</td> <td>3</td> <td></td> //non-existent <td></td> //non-existent </tr> </tbody> 被数据表额外的伤害,然后产生错误。任何见解?

1 个答案:

答案 0 :(得分:0)

它可以随心所欲地使用here

当我试图美化你的json文件时,json formatter给了我一个错误的人物属性。我删除了人物属性中的无效字符,并使用您的json数据准备了plunker。

{
  "data":
  [
    {
      "id":"2",
      "uid":"2",
      "lid":"2",
      "sd":"21 June, 2017",
      "stod":"Afternoon",
      "end":"21 June, 2017",
      "etod":"Afternoon",
      "reason":"ddada",
      "rid":"1",
      "draft":"0",
      "name":"Compassionate",
      "person":"Ms. Ochieng, Alphonc O"
    },
    {
      "id":"3",
      "uid":"1",
      "lid":"4",
      "sd":"2017\/06\/20",
      "stod":"Morning",
      "end":"2017\/06\/22",
      "etod":"Afternoon",
      "reason":"qeqeqeq",
      "rid":"1",
      "draft":"0",
      "name":"Paternity",
      "person":"Ms. Ochieng, Alphonc O"
    }
  ]

}

<强> // jquery的

$('.datatable-basic').DataTable({
        "processing": true,
        "serverSide": false,
        "ajax": {
            "url": 'data.json'            
        },

         "columns": [
            { "data": "name" },
            { "data": "sd" },
            { "data": "end" },
            { "data": "id"}       
        ] 
});