How to export DataTable with dinamics columns releated with visibilty

How to export DataTable with dinamics columns releated with visibilty

prox108prox108 Posts: 27Questions: 12Answers: 0

Hi guys!

Currently I have a dataTable where I hide and show some columns depending on which tab I am:

When I want to export I use this code where I choose what columns I want to export

'buttons': [ { extend: 'excel', title: 'Report', exportOptions: { columns: [3, 4, 5, 6, 7, 8, 9, 10] } }

unfortunately,It is static, it does not adapt to the tab I am in.

Do you know a way to export only the columns that are currently visible?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    Answer ✓

    See if this example helps.

    Kevin

  • prox108prox108 Posts: 27Questions: 12Answers: 0

    It worked, thanks!!,

    extend: 'excel', title: 'Reporte lista de espera', exportOptions: { columns: ':visible :not(:first-child)' }

    Now, I have to figure it out how, apart from the furst child, hide one column specifically, like:

    columns: ':visible :not(:first-child, 4)', something like that.

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    Look at the copyHtml5 button for how to specify a string of classes and an individual column. Like this:

    columns: [':visible :not(:first-child', 4]
    

    Kevin

  • prox108prox108 Posts: 27Questions: 12Answers: 0

    don't worry, I found out the solution

    columns: [':visible :not(:first-child,:nth-child(4))']

Sign In or Register to comment.