javascript - jquery datatable gives error when rendering -
i'm trying fill jquery datatable data via ajax:
html
<table id="table-productmaterials"> <thead> <tr> <th>id</th> <th>name</th> <th>quantity</th> <th>status</th> </tr> </thead> </table> javascript
$(document).ready(function () { var options = { "processing": true, "ajax": { "url": "productmaterials.ashx?action=get", "type": "post", "data": { "productid": $('#product_id').val() }, "columns": [ { "data": "id" }, { "data": "materialname" }, { "data": "quantity" }, { "data": "status" } ] }, }; table = $('#table-productmaterials').datatable(options); }); generic handler output:
{"data": [{"id":1,"quantity":15.00,"status":"1","materialname":"iron","productname":"french onion soup"},{"id":3,"quantity":14.00,"status":"1","materialname":"nails","productname":"french onion soup"}]} error message when reloading data: datatables warning: table id=table-productmaterials - requested unknown parameter '0' row 0. more information error, please see http://datatables.net/tn/4
i refered page , read example can't seem resolved. i'm making wrong?
you have place columns property outside of ajax property this:
$(document).ready(function () { var options = { "processing": true, "ajax": { "url": "productmaterials.ashx?action=get", "type": "post", "data": { "productid": $('#product_id').val() }, }, "columns": [ { "data": "id" }, { "data": "materialname" }, { "data": "quantity" }, { "data": "status" } ] }; table = $('#table-productmaterials').datatable(options); }); then work.
Comments
Post a Comment