Reputation: 1060
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.
Upvotes: 0
Views: 2134
Reputation: 2594
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: [
'excel',
{
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, dt.data()
. 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.
Upvotes: 1