Get query to send back via JSON
Get query to send back via JSON
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!
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!
This discussion has been closed.
Replies
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
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