Use Buttons for export of multiple datatables into single Excel file (multiple sheets)

Use Buttons for export of multiple datatables into single Excel file (multiple sheets)

genomergenomer Posts: 2Questions: 1Answers: 0

I have multiple datatables in a div and use Buttons extension to enable the export (PDF/Excel/CSV) for each of the tables. How can I add new button to allow the export of all tables into a single Excel file. I'd also like the content of each of the table to be exported into its own sheet inside the excel file.

I know that there were earlier discussion how to do that using TableTools, but not sure how to do it using Buttons.

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    edited October 2015

    From my point of view.. theres two options, one I recommend, and one I don't...

    1. [Recommended] Use the buttons.exportData() to basically generate the data thats exported, exactly as it would be for an export, but instead of exporting it, save it to a variable. Do this for both tables, combine them, then export them using your own code to export them (Or just poke around the dataTables.buttons.js file and get the exact code it uses to export the content, since it is open source..
    2. Write some JS to get the exact content you wish to export from both tables, then create a 3rd (hidden) DT instance, import all the rows, then export the contents of that table, then destroy the table...

    1 is the way I would go, Its just the "correct" way to go, IMO..

    2 is obviously a bit less work (At first glance, it might actually be more work though..), but its just not right to create an entire 3rd DataTable out of sight just to export data, then destroy it... I mean you're supposed to treat these things with respect! Not just use them for what you want , out of sight from everyone else, then toss them in the trash! They arent just pieces of code! (Kidding)

  • roundboxroundbox Posts: 4Questions: 1Answers: 0

    Genomer, were you able to get this working? I have been staring at my page with 12 tables containing unique data in each one trying to get 1 PDF output and am lost.

  • genomergenomer Posts: 2Questions: 1Answers: 0
    edited December 2015

    No, didn't get it to work yet. Once I extract data from individual tables using exportData(), I believe it would still require exploring and hacking to append it to the prospective report (Excel, PDF, etc). I plan to explore the 1st [recommended] approach though.

  • roundboxroundbox Posts: 4Questions: 1Answers: 0

    Would you mind sharing how you got the individual data with exportData? I've done some work directly with pdfmake and if I could get all the data, I think I could get it formatted to create the single pdf.

This discussion has been closed.