Using json var as sajaxsource :/

Using json var as sajaxsource :/

willgtwillgt Posts: 3Questions: 1Answers: 0
edited November 2013 in General
Hi everyone, really struggling to get my head round this but I am sure it is simple, making it even more frustrating...

I have pasted an exampled below but in summary, I am using $.merge to join two json sources to load into datatables. This part is working as i have checked the results of the merge and it is joining correctly. However, datatables will not load the data. Can anyone see why?? Even if i select just one of the variables before any merging it still does not populate. Appreciate any help.


var dataset = {"posts":[{"d":"Three.gif,24,7.87","M":"0","T":"0","D":"1.00","I":"188.88,0.00,","P":"0.00","O":"7.87","l":"xxxxx,17.gif"}]};

var append = {"posts":[{"d":"Three.gif,24,15.99","M":"0","T":"0","D":"15.00","I":"271.83,0.00,","P":"0.00","O":"11.33","l":"t\/a\/MCC\/URMOB-xmakex-xmodelx-xtariffx\/track.php%253fid=4191930,6.gif"},{"d":"Three.gif,18,10.49","M":"0","T":"0","D":"1.00","I":"208.81,0.00,","P":"19.99","O":"11.60","l":"xxxxxx,6.gif"}]};

dataset === $.merge(dataset.posts, append.posts);


var myObject = JSON.stringify(dataset);



$(document).ready( function () {


$('#example').dataTable( {

"bProcessing": true,
"sAjaxSource": dataset,
"bDeferRender": true,
"bSortClasses": false,
"sAjaxDataProp": "posts",
"bFilter": true,
"sDom": '<"top">rt<"bottom"ip><"clear">',
"iDisplayLength": 9,

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    The sAjaxSource option expects to be a string, as noted in the documentation. So passing in an array of data isn't going to work. I rather suspect you want to use aaData :-)

    Allan
  • willgtwillgt Posts: 3Questions: 1Answers: 0
    Allan - thank you! I can't believe how simple that was to fix. Loading correctly now.

    Although one thing - is there any way I can get aaData to work with the dataset above? I had to remove {"posts": from the beginning and } from the end in order to get it to load, apart from changing my source data can i change something on datatable config?

    Thanks :)
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    [code]
    aaData: dataset.posts
    [/code]

    looks like it should do it.

    Allan
This discussion has been closed.