Export to excel

Export to excel

canwejustcodecanwejustcode Posts: 42Questions: 12Answers: 1
edited May 7 in Free community support

This is two part question. I have a datatable that I want to export to excel, which works with using the default button, however:

  1. Is there a way to call that same function from my own button on the button click event? I have a row of buttons and don't want a random button over the datatable

  2. Is there a way to give the export file a name? Right now, it's naming it "home page", I want to specify the name. [ update, just found the answer to this one, so, just the first one ]

  3. Is there a way to just open the excel file instead of saving of option 2 isn't possible?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,961Questions: 26Answers: 5,070

    Is there a way to call that same function from my own button on the button click event? I have a row of buttons and don't want a random button over the datatable

    Are you saying you have a row of buttons in the -tag tbody` that you don't want to export?

    Possibly you can use the excelHtml5 button's exportOptions to select the rows to export. Maybe add a class to the rows you don't want to export and use the row-selector as a string to select the rows to export.

    Can you provide a simple example showing what you have with a description of what you don't want exported so we can provide more specific suggestions?
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • canwejustcodecanwejustcode Posts: 42Questions: 12Answers: 1

    I show a modal with the datatable, I have several buttons on the modal that do things, instead of using the default datatable buttons, I want my button to call the export to excel function instead of the default DT buttons in datatable toolbar. I'm able to export the datatable, but I want to show my buttons instead.

  • kthorngrenkthorngren Posts: 21,961Questions: 26Answers: 5,070

    Sorry misunderstood where the buttons were located. I think the easiest option is to create the standard Excel button and use buttons.buttons.className to set a class that hides the button. Then in the event handler for your button use button().trigger() to click the hidden Excel button.

    Kevin

  • canwejustcodecanwejustcode Posts: 42Questions: 12Answers: 1

    Do you have example of that? The documentation is kind of vague on it.

  • canwejustcodecanwejustcode Posts: 42Questions: 12Answers: 1
    Answer ✓

    never mind, I got it working, thanks

  • allanallan Posts: 64,373Questions: 1Answers: 10,628 Site admin

    Thanks for posting back - good to hear you've got it working.

    Allan

Sign In or Register to comment.