How to export to Excel all selected columns except one specific column

How to export to Excel all selected columns except one specific column

okazantsevaokazantseva Posts: 2Questions: 1Answers: 0

I have page where I need the Export to Excel button to export all columns that are selected, except for one specific column (the first, in this case). I had tried using ":visible:not(:eq(0))", but my table has so many columns that not all of them are visible at the same time, so the export ends up missing columns (maybe I'm doing something wrong there but that's not what this question's about). This is the only way I could get it to display all selected columns:

extend: 'excel',
text: 'Export to Excel',
filename: 'Search Results',
exportOptions:
{
    columns: '#ResultsDisplayTbl .sorting_asc,#ResultsDisplayTbl .sorting_desc,#ResultsDisplayTbl .sorting'
}

But that includes the first column, which I don't want. If I add ":not(:eq(0))" to any of those selectors, it'll just ignore the first column in any of the arrays of selected columns (so since I default sort on column 1, column 2 won't show up since it's the first column with the .sorting class).

Is there any way to only export selected columns, except for one specific column (the first column, in this case)?

Answers

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,736

    Is there any way to only export selected columns,

    What do you mean by selected? Are you using the Select Extension to select them?

    Its not clear to me exactly what you are looking for but maybe this example will help:
    http://live.datatables.net/kahefiyi/1/edit

    If you need further help then update my example with a representation of what you have and describe the columns you want exported.

    Kevin

  • okazantsevaokazantseva Posts: 2Questions: 1Answers: 0

    I'm using the colvis button to select columns.

    {
        extend: 'colvis',
        text: 'Show/Hide Columns',
        columns: ':gt(0)'
    },
    
This discussion has been closed.