Extend default button action - excel/excelHtml5

Extend default button action - excel/excelHtml5

morcuttmorcutt Posts: 4Questions: 2Answers: 0
edited March 2016 in Free community support

I'm using the excel export button with no issue but I would like to extend it to add an additional behavior. Essentially, I'd like for it to do the excel export AND make an ajax call to a server file so it can record what data was exported. I tried using the code below, but when I specify an action it overrides the default action instead of extending it. How can I extend the action to perform the excel export and the ajax call?

                    buttons: [ 'copy', 
                        {
                            extend: 'excelHtml5',
                            exportOptions: {
                                modifier: {
                                    selected: true
                                }
                            },
                            action: function (e, dt, node, config ){
                                var url = '[my url ]';
                                var params = '';
                                
                                jQuery.ajax({
                                      dataType: 'html',
                                      type: 'POST',
                                      evalScripts: true,
                                      url: url,
                                      data: params
                                  });
                            }
                        }]

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 61,822Questions: 1Answers: 10,129 Site admin

    Hi,

    There isn't actually a good way of getting this information in the current release I'm afraid. However, I can absolutely see how this would be useful, so I've just committed a change that adds a new customizeData option to the excel buttons types and that can be used to be notified of the data used for the export. For example:

    {
      extend: 'excelHtml5',
      customizeData: function ( data ) {
        // Send to the server
        $.ajax( ... );
      }
    }
    

    Regards,
    Allan

  • morcuttmorcutt Posts: 4Questions: 2Answers: 0

    Allan, that's awesome! Thanks for the mod. I've download the latest build and will try this out today. Hopefully others will find it useful.

This discussion has been closed.