2017-02-10 5 views
-1

Ich habe hier durch alle anderen Antworten gesucht, aber konnte man nicht finden, die einfach eine Lösung heißt es in dem der Fehler das ich habe,Tables unbekannter Parameter Angeforderte

Mein JS-Code:

$('#product-table').DataTable({ 
    stateSave: true, 
    ajax: { 
     url: "/api/stock/products", 
     type: "POST", 
     "Columns": [ 
      { "data": "name" }, 
      { "data": "description" }, 
      { "data": "current_stock" }, 
      { "data": "cost_price" }, 
      { "data": "retail_price" } 
     ] 
    }, 
}); 

Json Daten zurückgegeben wird:

{ 
    "data": [ 
    { 
     "name": "product 1", 
     "description": "test product", 
     "current_stock": "200", 
     "cost_price": "2000", 
     "retail_price": "2500" 
    } 
    ] 
} 

HTML:

<table id="product-table" width="100%" class="table table-hover"> 
     <thead> 
      <tr> 
       <th>Name</th> 
       <th>Description</th> 
       <th>Current Stock</th> 
       <th>Cost Price</th> 
       <th>Retail price</th> 
      </tr> 
     </thead> 
</table> 

Der Ajax-Aufruf wird durch und gibt Daten gesendet, aber sobald die Seite geladen Datatable führt den folgenden Fehler:

DataTables warning: table id=product-table - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4

Antwort

1

Das JS funktioniert nicht richtig angezeigt werden, versuchen Sie stattdessen:

$('#product-table').DataTable({ 
    "stateSave": true, 
    "ajax": { 
     "url": "/api/stock/products", 
     "type": "POST" 
    }, 
    "columns": [{ 
     "data": "name" 
    }, { 
     "data": "description" 
    }, { 
     "data": "current_stock" 
    }, { 
     "data": "cost_price" 
    }, { 
     "data": "retail_price" 
    }] 
});