Do not include hidden data in Export

Do not include hidden data in Export

spacemancwspacemancw Posts: 26Questions: 7Answers: 0

I am using datatables buttons to allow export to PDF, CSV,EXCEL, print or copy, using the javascript at:
https://datatables.net/extensions/buttons/examples/initialisation/export.html
using Blfrtip

I am also using the code at https://datatables.net/examples/api/show_hide.html to Show/Hide columns

all works great, I can hide and show columns by clicking on the buttons.
But the export to Excel etc, exports ALL the columns even when I am hiding some columns.

My table has a number of rows for informative viewing, but for practical purposes for instance, I want to export only columns Hostname and IPaddress to CSV and feed that file into some other script.

As it is, I get all the columns and I have to delete all the stuff I don't want.
Is there a way to only export the data in the columns that are showing?

thanks

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    You can use buttons.exportData() - the `columns' selector for that - see here,

    Colin

  • spacemancwspacemancw Posts: 26Questions: 7Answers: 0

    Thanks very much. I have this working now, https://datatables.net/extensions/buttons/examples/html5/columns.html

    So this give me the options to export to COPY, EXCEL, PDF. How can I add CSV and Print?

  • colincolin Posts: 15,112Questions: 1Answers: 2,583
    Answer ✓

    The same principle would apply to those other export methods, you just need to add the same exportOptions for those other buttons,

    Colin

  • spacemancwspacemancw Posts: 26Questions: 7Answers: 0

    Excellent, ya I see it now thanks.
    The print option prints all the columns, I tried to apply exportoptions to print,

            'print',
                exportOptions: {
                    columns: ':visible'
                }
    

    But that didnt work. Other than that everything is awesome.
    thanks very much

  • colincolin Posts: 15,112Questions: 1Answers: 2,583
    Answer ✓

    Glad almost there. For print, you would need,

      extend: 'print',
        exportOptions: {
            columns: ':visible'
        }
    

    you missed the extend:

    Colin

  • spacemancwspacemancw Posts: 26Questions: 7Answers: 0

    That's it! Thanks again.

Sign In or Register to comment.