Export CSV or PDF Based On Datatables Laravel 4 Export CSV or PDF Based On Datatables Laravel 4 laravel laravel

Export CSV or PDF Based On Datatables Laravel 4


I would probably post the keyword to my server and run the sql query again filtering those results and then create the csv/pdf


One way you could do it is to use jQuery and make an ajax call.

Firstly, give the table an ID. Next, get the table itself and get its HTML using this bit of code:

var html = $('#myCoolTable').html();

Then make an ajax call to Laravel to generate the PDF passing through the HTML. You can use this HTML to PDF library: http://wkhtmltopdf.org/

You should then get back the PDF with the exact table you had on screen (with any filters etc).

As a sidenote, you can also add your CSS to the HTML to give to the PDF library and it will even style the table to be the same too!

Hope this helps.