Modify the export button to additionally trigger an Ajax request.

Modify the export button to additionally trigger an Ajax request.

FiezDevFiezDev Posts: 5Questions: 3Answers: 0

I created a customized Excel export button with code similar to this.

    {
        extend: 'excel',
        text: '<i class="fas fa-file-excel text-primary_orange"></i> Excel',
        titleAttr: 'Export to Excel',
        title: 'Export to Excel',
        exportOptions: {
            columns: ':not(.noExport)',
        },
        action: function (e ,dt ) {
                let obj = dt.buttons.exportData()
                let data = {
                    'data': obj,
                    'currentUrl': window.location.href,
                  };
                $.ajax({
                  type: "POST",
                  url: "/logexport/?type=excel",
                  data: JSON.stringify(data),
                });
        }
    },

Although the AJAX request is sent as expected, the file-saving popup doesn't work. How can I fix this issue?

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Please see Allan's comment on this thread - as I think that'll do the trick for you too,

    Colin

Sign In or Register to comment.