Catch Export to Excel onclick event

Catch Export to Excel onclick event

NoBullManNoBullMan Posts: 61Questions: 17Answers: 2

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
Hi
I have over 15K records (12 columns each row) to export to Excel and it seems datatable's built-in export to Excel can't handle it. I have a third party server-side export to Excel that I want to use but can't seem to be able to catch the click event to prevent default action. I can always exclude export the Excel from button group and add an additional button to handle the exporting but it looks ugly to have two buttons.

In $(document).ready() I tried both of these and

        $(".buttons-excel").on('click', function (event) {debugger
                event.preventDefault();
                // Do my own export
        });

        $(".buttons-excel").click(
            function (event) {debugger
                event.preventDefault();
                // Do my own export
            }
        );

What am I doing wrong? I am using 1.10.22 version.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794

    Maybe you can create a custom button like this example to perform your export.

    Kevin

  • NoBullManNoBullMan Posts: 61Questions: 17Answers: 2

    Thank you @kthorngren . So, I guess it is not possible to catch excelHtml5 buttons click event, right?

  • NoBullManNoBullMan Posts: 61Questions: 17Answers: 2

    So, can I then have something like:

                        buttons: [
                            {
                                text: 'My Excel Button',
                                action: function (e, dt, node, config) {
                                    alert('Button activated');
                                }
                            },
                            {
                               extend: 'csv',
                                orientation: 'landscape',
                                ...
                             }
                         ]
    

    Because I tried this and 'My Excel Button' does not show up.

  • NoBullManNoBullMan Posts: 61Questions: 17Answers: 2
    Answer ✓

    Never mind, operator error! :)

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Thanks for the update. Good to hear you've got it working.

    Allan

Sign In or Register to comment.