How do I export a selected item in a dropdown list to PDF, CSV, EXCEL, etc.

How do I export a selected item in a dropdown list to PDF, CSV, EXCEL, etc.

soorrsoorr Posts: 4Questions: 2Answers: 0

I have a dropdown in one of my columns that displays a selected item depending on data received from my database. When I try to export the table as a PDF or any other means, all of my dropdown options are shown in that column in the exported document. How do I show only the dropdown item that is already selected?

I'm guessing I have to make use of the Customize option which isn't really covered in the DataTables documentation but I can't find where on the pdfmake.org site this is explained. An example would be really helpful as I've somehow managed to make it this far with very little jQuery/Ajax knowledge.

Thank you!

Answers

  • soorrsoorr Posts: 4Questions: 2Answers: 0

    Can I put the selected item in an HTML data-* attribute with PHP (on load) / jQuery (on change) and then use DataTables' buttons.exportData() to output that into the column? If that would work, how would I do that?

  • soorrsoorr Posts: 4Questions: 2Answers: 0

    I solved this by creating a duplicate column (but with text instead of dropdown buttons) on the end of my table and hiding it using

    columnDefs: [ {
    targets: -1,
    visible: false
    } ]

    The hidden column gets updated with the selected dropdown data in the other column using jQuery. Then I hid the dropdown column on export using

    exportOptions: { columns: [ 0, 1, 2, 3, 4, 5, 6, 7, 9 ] }

    (column 8 had the dropdowns)

    Not the cleanest solution and I'm sure there's a better way using the API but it works really well and is something I could actually handle - in case anyone else needs to do this.

This discussion has been closed.