0

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.

2
  • Does it need to be part of the datatable? ie would a standard html button do? Or have you looked at datatables.net/extensions/buttons? Commented Aug 9, 2016 at 18:38
  • Actually, it doesn't need to be part of the datatable. What wouldn't hurt is being able to include it in the datatable markup though so it's next to the other Excel button Commented Aug 9, 2016 at 18:55

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I can see where this would work, unfortunately I'm in a web part and I'm trying to call the code behind from the ascx, whole new question I think. Thanks for the response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.