javascript - How to load json to datatables on jquery on click function? -
i have json data , need feed json data datatables whenever search button clicked based on sending values.
[ { "port_code":"bom", "cont_details_id":"9", "price":"44.000", "cont_price":"500", "cont_no":"11", "cont_size":"20", "cont_type":"gp" }, { "port_code":"bom", "cont_details_id":"10", "price":"87.000", "cont_price":"500", "cont_no":"22", "cont_size":"20", "cont_type":"gp" }, ..... ..... etc., ]
and tried in jquery store json $("#search").click(function() in function calling json file , tried store in datatables, not working. please me this. thank you.
$(document).ready(function() { var otable = $('#example').datatable(); $("#search").click(function() { $.post("invoice_ajax.php", { loc : $("#location").val(), cust : $("#customer_details_id").val() }, function(data) { $("#text").html(data); var s = json.parse(data); for(var = 0; < s.length; i++) { otable.fnadddata([ s[i].block_id, s[i].block_id, s[i].block_id, s[i].block_id, s[i].block_id, s[i].block_id, s[i].block_id ]); } // end }); }); });
you right, except using old 1.9.x fnadddata
method on 1.10.x api. instead :
otable.row.add([ s[i].port_code, s[i].cont_details_id, s[i].price, s[i].cont_price, s[i].cont_no, s[i].cont_size, s[i].cont_type ]).draw();
or
var otable = $('#example').datatable(); ... otable.fnadddata([ s[i].port_code, s[i].cont_details_id, s[i].price, s[i].cont_price, s[i].cont_no, s[i].cont_size, s[i].cont_type ]);
Comments
Post a Comment