Reputation: 65
I am using jquery datatable and listing only the required values in each pagination. However when I am trying to export it to pdf using pdf option, I can only export data present in the datatable. Is there any way I can get all values
Upvotes: 0
Views: 2556
Reputation: 3892
According to DataTable Documentation there is no way to export all rows when you are using server side processing.
Server-side processing
Special note on server-side processing: When using DataTables in server-side processing mode (serverSide) the selector-modifier has very little effect on the rows selected since all processing (ordering, search etc) is performed at the server. Therefore, the only rows that exist on the client-side are those shown in the table at any one time, and the selector can only select those rows which are on the current page.
Well the only way is to add the ALL
parameter to length menu and select it before exporting.
This way DataTable
will export all the rows as those are shown on the UI.
For example:
var table = $('#example').DataTable({
serverSide: true,
ajax: "/your_ajax_url/",
lengthMenu: [[10, 100, -1], [10, 100, "All"]],
.....
Well if you want some custom message with DataTable
then it provides the functionality to export table with some custom message to identify the result better.
The message is
message :
Optional description message that will be shown above the table in the created PDF.
DEMO : https://jsfiddle.net/Prakash_Thete/n6gsh0j1/1/
The syntax for adding message to table is like below
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [
{
extend: 'pdfHtml5',
message: 'PDF created by Prakash with Buttons for DataTables.'
}
]
});
If you want to modify(I mean styling) the exported PDF have a look at http://pdfmake.org/#/gettingstarted
They have provided some cool stuff for the exported PDF.
I you want to explore the other options available with PDF export have a look at https://datatables.net/reference/button/pdf
Upvotes: 1