DataTables Export
DataTables Export

Hi, I am trying to figure out how to call the DataTables export from somewhere else on the page with a custom button nowhere near the DataTable and not utilizing the available DataTable buttons. I added a click event for the button to be triggered and would like the DataTable export button to be hidden and the custom button to perform the export.
$(document).ready(function () { $('#example').DataTable({ dom: 'Bfrtip', buttons: [ { extend: 'excel' } ] }); //added click event for the button to be triggered $("#ExportToExcel").on("click", function() { //table.button('.buttons-excel').trigger(); $('.buttons-excel').click() }); });<button onclick="$('#ExportToExcel').click()">Custom Button Export</button>
Can someone please assist me?
Thank you in advance!
This question has an accepted answers - jump to answer
Answers
button().trigger()
is the way to do it. Here is a little example: http://live.datatables.net/nifefaca/1/edit .Allan
Allan, thank you for the quick and accurate answer. I knew you folks would come through! Now if I would like to hide all of the DataTables export buttons and just show the one custom button is that possible?
Allan, I know your busy so I looked and found it.
$('.buttons-excel')[0].style.visibility = 'hidden'
https://datatables.net/ is awesome!
Thank you!