TrevorGoodchild TrevorGoodchild - 2 months ago 16x
jQuery Question

jQuery Datatables multiple Excel export buttons

New to JQuery Datatables and I'm trying to include two Excel buttons. One that exports the current table, and then another that makes a call to the controller for a completely different report. I've got the current table export working, but stumped as to how to include this second button.


If you already have a controller you want the second button to call (which it sounds like you do), then you should just have one Excel button and once custom button that you can label whatever you want (and have call whatever controller you want). The syntax for a custom button looks like this:

buttons: [
         text: 'Custom Excel Button',
         action: function (e, dt, node, config) {
              //Make a call to a javascript function here (description below)

Within the action function, you can use the dt parameter to pass a DataTables API instance to the javascript function. This will allow you to access all of the data with, say, You can then make a custom ajax call to your other controller with that data.

As a concluding note, see that you can essentially have a button do whatever you want, but if you're using a button that doesn't have built in functionality like the excel button, then you will have to implement the functionality yourself.

See this documentation page if you want to see what e, dt, node, and config are used for if you ever want more complicated custom buttons.