Datatables PDF export - How to order for fix export ?
Datatables PDF export - How to order for fix export ?
Hello,
I have two button PDF.
The first to export the table (with the sorting the user want) and an other one to export data with a specific order.
The problem is : how can i order data (asc or desc) just for one button ? I don't want to export data with basic order or the user order choice but with my own order.
example : the table is order like this at the beginning :
> var table = $('#example1').DataTable( {
"scrollX": true,
"responsive": false,
"order": [[0,"desc"]],
autoWidth: true,
dom: 'lf<"floatright"B>rtip',
buttons: [
{
extend: 'pdfHtml5',
text: 'PDF',
orientation: 'landscape',
title: 'Trials',
},
{
second pdf button...
}
....
Is it possible to specify in the button a special order like : "order": [[0,"desc"]], ?
This question has accepted answers - jump to:
Answers
What you would need to do for this is create a custom button and use
order()
to set the order for the table that you want to export. Then call the PDF button's original action function - there is an example in thebuttons.buttons.action
documentation showing how to do that.Allan
Thanks for your reply, it works fine with this code :
`
`
I have a last question, is it possible to have the same result without using the draw() function ? Because without 'draw()', the order is not apply to the pdf. Or maybe i forgot something
No - the draw actually enacts the order. What you would need to do is read the current order, then apply your own order and export the pdf. Then trigger the order to switch back to what it used to be.
Allan