Help: Datatable not loading JSON data on server-side processing

Help: Datatable not loading JSON data on server-side processing

jon.bluksjon.bluks Posts: 15Questions: 0Answers: 0
edited July 2009 in General
Hi,

I've almost got the server-side processing of DataTables to work. The problem I'm encountering is getting the JSON data to load into the table for some reason. The data I get back is as follows:

{"iTotalRecords": 12151, "iTotalDisplayRecords": 12151, "aaData": [ ['View | Edit | Delete','Half Life 2005 Cultivation Event',' ','March 16, 2005','March 16, 2005',' '],['View | Edit | Delete','Piper Gala Fundraiser 2002',' ','August 11, 2001','August 11, 2001','Factory Theatre'],['View | Edit | Delete','Beer, Bach and Bernier','$75','Not Specified','Not Specified','Steam Whistle Brewer...'],['View | Edit | Delete','Tamara Salon','$250','Not Specified','Not Specified','Graydon Hall'],['View | Edit | Delete','Stratford 2003','$125','Not Specified','Not Specified','Stratford'],['View | Edit | Delete','In Kind Donation Misc.',' ','Not Specified','Not Specified','Various'],['View | Edit | Delete','United Way Annual Campaign',' ','Not Specified','Not Specified','Various']] }

Any thoughts why the function in $.getJSON wouldn't be called? Is there a problem with the format of the data?

Also, I think there is a bug in the code at the following line:

[code]
/* if there is an ajax source */
if ( oSettings.sAjaxSource !== null && !oSettings.oFeatures.bServerSide )
{
//snip
}
[/code]

I think [code]!oSettings.oFeatures.bServerSide[/code] should be [code]oSettings.oFeatures.bServerSide[/code]. When the bServerSide is set to true on initialization, the ajax source code would never be called.

Thanks,

Jonathan

Replies

  • jon.bluksjon.bluks Posts: 15Questions: 0Answers: 0
    Note: The numbers are off in the above JSON data because I accidentally used the wrong query to get the totals.
  • jon.bluksjon.bluks Posts: 15Questions: 0Answers: 0
    I think I figured it out. The syntax is wrong in the JSON data: for the arrays, double-quote (") is required to surround the data.
  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    Hi Jonathan,

    Good stuff - thanks for letting us know you got it sorted. The web-site www.jsonlint.com is absolutely second to none for helping to sort out JSON problems!

    Also regarding your question about:

    [code]
    /* if there is an ajax source */
    if ( oSettings.sAjaxSource !== null && !oSettings.oFeatures.bServerSide )
    {
    //snip
    }
    [/code]

    I don't think there is anything wrong with this actually. Remember that DataTables can get data from four different basic sources:

    - DOM
    - JS Array
    - Ajax single get
    - Ajax sever-side processing

    The above condition is the one which matches the 'Ajax single get', which is what the code in that block deals with. The server-side processing is dealt with by a mechanism in fnDraw() in order to ensure that the server data is pulled each time the table is redrawn.

    Hope that helps to explain the code!

    Regards,
    Allan
  • jon.bluksjon.bluks Posts: 15Questions: 0Answers: 0
    Thanks Allan. After I posted the problem, I found jsonlint which helped me clear up the problems quite handily.

    The application I've been working on was nearly done and I was importing data from their old database, about 12,000 records or so. Not a huge amount, but enough that loading it all into the datatable would take way too long. I kind of panicked because I thought I was screwed, but then I checked out your site and noticed you'd done some updating and provided a server-side sample. I got that all working in a short time and the performance is great, so I was quite relieved.

    Thanks for all your hard work on this project.

    Jonathan
  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    Hi Jonathan,

    Fantastic stuff - good to hear it is working well for you! Are you using the PHP examples that I've provided in the DataTables distribution as the basis for your backend? If so, I've made some improvements to the SQL which will show a significant performance increase for server-side processing. This will be in the next 1.5 beta, but if you want to drop me an e-mail ( www.datatables.net/contact ) I'll send you the updated scripts if you like.

    Regards,
    Allan
  • jon.bluksjon.bluks Posts: 15Questions: 0Answers: 0
    Hey Allan...I used the sample you posted on the website. I found the link in other posts with people using large datasets. Is the that the newest version?

    Jonathan
  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    edited July 2009
    Hi Jonathan,

    I've got a newer version than that which is available with 1.5 beta 9 (which is the currently available one). 1.5 beta 10 will include a number of little bug fixes (looking forward to 1.5 final now) and one of them is it make the SQL in my demo scripts significantly faster - you should see a reasonable decrease in the amount of time it takes to answer your XHR draw requests for each update - how long are they at the moment on average?

    Allan
  • jon.bluksjon.bluks Posts: 15Questions: 0Answers: 0
    Hi Allan,

    Looks like the rendering time is about 2 - 3 seconds, which I think is reasonable. But if you have some updates or optimizations available, that would be great.

    Jonathan
  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    Hi Jonathan,

    It's on it's way. Hopefully you'll see a nice little speed improvement :-)

    Allan
This discussion has been closed.