I'm struggling using my JSON data with datatables. Sorry for the formatting, but this is what I get in developer tools:
Object
pharmacy:Array[3]
0:"Walmart"
1:"Safeway"
2:"Kroger Pharmacy"
length:3
__proto__:Array[0]
price: Array[3]
0:58.14
1:65.45
2:66.76
length:3
__proto__:Array[0]
...
I'm getting that using this:
$.ajax({
url: 'test.php',
type: 'POST',
dataType: 'JSON',
data: {
drug: picked_drug,
},
success: function(data) {
var all_data = JSON.parse(data);
final_data = all_data.data.price_detail;
console.log(final_data); //this outputs object above.
}
});
Then I'm rendering the table like this:
var drugtable = $("#drug_datatable").DataTable({
"data": final_data,
"paging": true,
"dom": '<"top">Bt<"bottom"><"clear">',
"pageLength": 25,
"order": [
[0, "desc"]
],
"columns": [
{
"data": "pharmacy",
"searchable": false,
"width": "20%",
"className": "lang_body_2",
"title": "Attribute"
},
{
"data": "price",
"searchable": false,
"width": "20%",
"className": "lang_body_2",
"title": "Attribute"
},
],
});
The problem is that my table returns "No data available in table". I'm sure there's a problem with how my object is formatted, but I can't figure out what to change.
Thanks!