Reputation: 669
...
// result is a JSON data passed to this function from outside
var result = getMyJSON();
var input = "{aaData: ["+result+"],"+'aoColumns':[
{ 'sTitle': 'Title', 'mDataProp': 'title' }]}";
$(document).ready(function() {
$('#example').dataTable(input);
});
</script>
<table id='example' class='example' border='1'>
I know that .dataTable() function expects initialization object as specified here: http://datatables.net/ref#aaData If inside the dataTable function I manually paste the JSON data - then it displays everything fine. How can I "prepare" and pass in as an initialization object to dataTables() function? Right now this is not working as it should.
Thanks
Upvotes: 1
Views: 5053
Reputation: 13649
I am not sure why you are building your input var as a string - it is an object. Try this instead
var input = {
"aaData" : [result],
"aoColumns" : [{
"sTitle" : "Title"
}, {
"mDataProp" : "title"
}]
};
Upvotes: 2