Is there a way to trigger an export of a Datatables instance via Javascript? The only way I can think of is to put the buttons in a hidden div and then trigger a click event.
You need to use button().trigger() which is documented here.
All I had to do is change the dom option of the Datatable from this Bfrtip to frtip to hide it and I was still able to trigger the button. With the export buttons setup like this:
Yup - perfect answer :-). Thanks for posting back!
Worth noting for anyone else reading this, that if you happen to be using the Flash buttons this will not work due to the security restrictions in Flash. It will only work for HTML5 buttons.
Replies
Okay, I get to answer my own question Q&A style.
You need to use
button().trigger()
which is documented here.All I had to do is change the
dom
option of the Datatable from thisBfrtip
tofrtip
to hide it and I was still able to trigger the button. With the export buttons setup like this:I was able to select the export to PDF button with this selector:
0-3
Yup - perfect answer :-). Thanks for posting back!
Worth noting for anyone else reading this, that if you happen to be using the Flash buttons this will not work due to the security restrictions in Flash. It will only work for HTML5 buttons.
Allan