Get query to send back via JSON

Get query to send back via JSON

shimy1984shimy1984 Posts: 7Questions: 0Answers: 0
edited October 2009 in General
I would like to use datatables for basic reporting... basically, the user sorts and filters the data from a MySQL table with datatables then they have a PDF button that exports their result (on the same page as the actual datatable).

I have the PDF class that I will be using, I just need to know how I could get the query back from the server side code... My guess is I'd add something to the JSON return but I'm not 100% sure if this would break datatables or not. It also needs to be secure (when is this not the case) :).

I am using a slightly modified version of the serverside code provided with datatables.

Any ideas? Thanks!

Replies

  • allanallan Posts: 63,407Questions: 1Answers: 10,453 Site admin
    Hi shimy1984,

    Sounds like a nice idea. There is a post about the possibility of modifying TableTools to include a server-side generated PDF button ( http://datatables.net/forums/comments.php?DiscussionID=327&page=2#Item_28 ), but what might be easier, is just to make use of fnGetData() - http://datatables.net/api#fnGetData - and you could send the returned 2D array to the server side to be processed into a PDF. It might be best to convert your 2D array into a CSV string or something like that to send via Ajax.

    Regards,
    Allan
  • allanallan Posts: 63,407Questions: 1Answers: 10,453 Site admin
    Another thought on this actually... :-)

    Since you are using server-side processing, you might want to do something a little different... What you could do is make use of the queries you have on the server-side, so it's not actually pulling the data from the table, but rather from your database. What you would need to do is make a customer fnServerData function which will either do the normal thing of drawing the table, or it will send the request to the server (with the request going to a slightly different URL, one which will generate the PDF based on the GET variables sent) and then, simply not reload the table. There are other ways to do it as well, but I think with server-side processing, a custom fnServerData function might be the way to go.

    Regards,
    Allan
  • shimy1984shimy1984 Posts: 7Questions: 0Answers: 0
    That's a good idea... I'll be playing with it for a bit. When and if I come up with something, I'll be sure to post the results.
This discussion has been closed.