Prevent export of a column with Buttons

Prevent export of a column with Buttons

TDubTDub Posts: 1Questions: 1Answers: 0

I am using Buttons to do a DataTables export. I'm trying to export the visible columns in the table, but also want to prevent the first column from exporting regardless of the column visibility options set (the first column has an Edit button in it that messes up the export).

In all the examples I could find, they referenced TableTools and mColumn which are retired. And I couldn't seem to find a combination of hiding a specific column on export while retaining visibility of the remaining columns.

Anyone know what I'm missing? Here is what I have so far (just using Copy in this example though I'm also using Excel and PDF):

buttons: [
    
   {              
         
     extend: 'copy',
     exportOptions: {
         columns: [ ':visible' ]        
     }
   },                               
   
   'colvis'             

],

Answers

  • nerznerz Posts: 2Questions: 0Answers: 0

    same here :/ does anyone have a solution for this? (DataTables 1.10.9)

  • tombombtombomb Posts: 5Questions: 3Answers: 0

    Poke, im trying to do this too, I tried columns: [ ':visible', '-1' ] as I was hoping that would hide the first but no dice...

    Maybe set the column to hidden then export and set it back to visible?

  • allanallan Posts: 63,210Questions: 1Answers: 10,415 Site admin

    There is an example of how to select which columns to export.

    In the case of hiding just the first column you could try :not(:first-child).

    Allan

  • anujeetanujeet Posts: 39Questions: 15Answers: 0
    edited April 2016

    @allan
    What if I need to hide the last two columns only?

  • allanallan Posts: 63,210Questions: 1Answers: 10,415 Site admin

    jQuery allows you do combine selectors in the :not() selector using the standard comma separator. See the jQuery selector documentation for full details of the selectors available.

    Allan

This discussion has been closed.