Getting User Defined File Name when Exporting

Getting User Defined File Name when Exporting

oneillgoneillg Posts: 33Questions: 9Answers: 0

Hello,
I am using the excel export but would like a dialog box to come up asking for a name and location of the file they want to export. I know how to change the name, but can't seem to find out how to "interrupt" the process. Here is what I have so far when I declare the button. I tried 'init:' but that came too early. fnClick doesn't seem to work in this instance, nor does the word 'click'. I would replace the alert call with the necessary code to bring up the dialog. Thanks for any input. -Gabe

 var buttonsObj = [       {
            extend:   'excel',
            className: 'ExcelButton',
            text: "",
            titleAttr: 'Export to Excel',
            fnClick: function(dt, node, config){
                alert('hello');
            }
        },]

Answers

  • oneillgoneillg Posts: 33Questions: 9Answers: 0

    One obvious solution is to have a separate button that asks for the file name and then trigger the export after changing the name. (duh). I was hoping for a more elegant solution that was handled internally.

  • oneillgoneillg Posts: 33Questions: 9Answers: 0

    Ok after further digging I see this isn't as easy as it should be. For security reasons you can't seem to get directory names from javascript or even php for that matter. Any workaround ideas would be appreciated.

  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin

    There is no fnClick or click in Buttons. buttons.buttons.action is what you want there - see the documentation here. fnClick is for TableTools which is no longer supported or in use.

    What dialogue would you use to get the directory location? My understanding is that the download action is 100% controlled by the browser. For example in Chrome it just downloads to the default location without asking - while in IE I think it asks where you want to put it or if you want to open it. I'm not aware of any API that can be used to control that - although happy to be corrected!

    Allan

  • oneillgoneillg Posts: 33Questions: 9Answers: 0

    After doing more digging I think you are correct about the download location Allan. Although I think it's rather lacking. Thanks for the response.

  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin

    Don't disagree with you there - you aren't the first to ask about that and you won't be the last! If the browsers provide an option for that in the file saving APIs I'll be adding it!

    Allan

This discussion has been closed.