Export All to Excel, PDF, etc when using Server Side Processing
Export All to Excel, PDF, etc when using Server Side Processing
I am currently using server side processing for my datatables and I understand that the buttons api will only export the visible rows when the button is pressed as the others are not yet rendered in the dom. Therefore, I want to extend the button such that when someone clicks on one of the export buttons, it will first show all rows in the table and then run the usual export process. I have been experimenting with the following datatables setting but it is not working. Is there something else that I need to do?
Everything else is working perfectly.
var metrics_data_table = datatable_object.DataTable({
'processing': true,
'serverSide': true,
'lengthChange' : false,
'ajax': {
'url': datatable_settings.url,
'type': 'POST',
'data': {
'form_filter': $(".javascript__datatables_display__form :input").serialize(),
'csrfmiddlewaretoken': $('.javascript__data_tables_display__csrf_token').val()
},
},
'columns': datatable_settings.columns,
'order': datatable_settings.order,
'columnDefs': datatable_settings.columnDefs,
'createdRow': datatable_settings.createdRow,
'initComplete': function(){
datatable_object.fadeIn();
var api = this.api();
new $.fn.dataTable.Buttons(api, {
'buttons': [
'colvis',
]
});
new $.fn.dataTable.Buttons(api, {
'buttons': [
'copy',
'csv',
'excel',
{
'extend': 'pdfHtml5',
'orientation': 'landscape',
'pageSize': 'LETTER',
'exportOptions':
{
'columns': ':visible'
},
'action': function(e, dt, button, config) {
// Add code to make changes to table here
metrics_data_table.settings().page.len(-1);
metrics_data_table.settings().drawCallback = function (settings) {
// Call the original action function afterwards to
// continue the action.
// Otherwise you're just overriding it completely.
$.fn.dataTable.ext.buttons.pdfHtml5.action(e, dt, button, config);
}
metrics_data_table.draw();
}
}
]
});
Answers
See this FAQ: "Q. How can I export the whole table when using serverSide and Buttons.".
Allan
I just solve this by adding
lengthMenu: [
[ 10, 25, 50, -1 ],
[ '10 rows', '25 rows', '50 rows', 'Show all' ]
],
Then
"dom": 'Blfrtip',
"buttons": [
'excel', 'pdf'
],
So just select Show all and then export =D