How to set data source from an object?
How to set data source from an object?
I try to set data of datatable with an object as code below but my datatable is still empty. So, can I pass an object to data source?
$('#example').dataTable( {
data: {rows: [{c: "xxx", d: "eee"}, {c: "xxx", d: "eee"}, {c: "xxx", d: "eee"}, {c: "xxx", d: "eee"}]},
"sAjaxDataProp": "rows",
"aoColumns": [
{ "mDataProp": "c" },
{ "mDataProp": "d" }
]
} );
This question has an accepted answers - jump to answer
Answers
data
doesn't take an object - it takes an array. Just pass in your array of data.Allan
Thank you for your quick answer. I made it work.
var oData = {rows: [{c: "xxx", d: "eee"}, {c: "xxx", d: "eee"}, {c: "xxx", d: "eee"}, {c: "xxx", d: "eee"}]};
$('#example').dataTable( {
data: oData.rows,
"columns": [
{ "data": "c" },
{ "data": "d" }
]
} );