Programmatic method to call export buttons (csv, excel, etc)

Programmatic method to call export buttons (csv, excel, etc)

edmund.landgrafedmund.landgraf Posts: 6Questions: 1Answers: 0

The goal would to programmatically save the excel, csv, etc file to a local directory.

I thought I could use the button.trigger() event but I'm uncertain what the syntax is.

I'm using this page to test:

https://datatables.net/extensions/buttons/examples/initialisation/export.html

Thanks!

Answers

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin

    Unfortunately that isn't possible. It is a security restriction by browsers since such an ability would allow "drive by downloads" - i.e. as soon as you loaded a page it could start downloading stuff to the user's computer!

    A download must happen as a direct result of a user interaction.

    Allan

  • edmund.landgrafedmund.landgraf Posts: 6Questions: 1Answers: 0

    Thanks for the reply Allan! Nothing worse than unproductive rabbit holes :smile:

    I need to import a dataTable into a reporting DB and the example provided is identical to the situation I am facing with an external vendor.

    I'm sure this has been solved before; any thoughts (or links) to help my journey?

    Best,

  • edmund.landgrafedmund.landgraf Posts: 6Questions: 1Answers: 0

    It also occurs to me this particular datatable page is behind 2FA security so are there ways to disable said security restriction once other security conditions have been met?

  • edmund.landgrafedmund.landgraf Posts: 6Questions: 1Answers: 0

    What about just implementing "copy to clipboard"? This will copy to only one clipboard and I can probably figure out how to dump the clipboard.

  • kthorngrenkthorngren Posts: 20,299Questions: 26Answers: 4,769

    I need to import a dataTable into a reporting DB

    How does the data need to be formatted?

    One option might be to use rows().data() to get the row data. This can be manipulated into the format you need via Javascript methods. Then send the data via ajax to the reporting DB.

    Kevin

  • edmund.landgrafedmund.landgraf Posts: 6Questions: 1Answers: 0

    How would you call rows().data() on the page I provided above?

    https://datatables.net/extensions/buttons/examples/initialisation/export.html

    There are no REST capabilities out of the box, correct?

    (I'm new to DataTabes but not databases)

    Thanks!

  • kthorngrenkthorngren Posts: 20,299Questions: 26Answers: 4,769

    You can create a Custom Button like this example and in the buttons.buttons.action function use rows().data() to send via Ajax to the reporting DB.

    Kevin

  • edmund.landgrafedmund.landgraf Posts: 6Questions: 1Answers: 0

    Will this still require user input (i.e. the button press)? Allan suggest I can't call the button press programmatically. So no pull, only push?

    Thx!

  • kthorngrenkthorngren Posts: 20,299Questions: 26Answers: 4,769

    No you don't have to use a button. You can use rows().data() anywhere in your Javascript environment. If you have a way to request information from the client then you can use rows().data() to get the data in the event handler fired when you request the data.

    Kevin

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin

    I think we are probably missing a little bit of the bigger picture of what you are trying to achieve - perhaps yo could give us a run down?

    You can programmatically trigger the buttons (button().trigger()) but to be able to do something like generate a save that will be saved or copy to clipboard the event that originally causes that method to be called needs to be caused by an end user's interaction with the page. I wasn't clear that would be the case originally.

    If you could give us an overview of what you are trying to do, I might be able to say how it can be done (or point to some of our code you could base a solution off).

    Allan

Sign In or Register to comment.