Export jQuery DataTables

2

I have a table and I use DataTables, I'm using the native export functionality and give a hide in the columns my code looks something like this:

"buttons": 
[
    'copy', 'csv', 'excel', 'pdf', 'print', 
    { 
        extend: 'colvis', 
        text: '+ Colunas' 
    }
],
"columnDefs": 
[
    {
        "targets": [ 7,8,9,10,11,12,13,14,15,16,17,18,19,20,21 ],
        "visible": false,
    }
]

    
asked by anonymous 11.07.2018 / 13:39

2 answers

1

Try using the columns: ':visible' parameter in the exportOptions option of the button, like this:

"buttons": 
[
    'copy', 'csv', 'excel', 'pdf', 'print', 
    { 
        extend: 'colvis', 
        text: '+ Colunas',
        exportOptions: {
           columns: ':visible'
        }

    }
],
"columnDefs": 
[
    {
        "targets": [ 7,8,9,10,11,12,13,14,15,16,17,18,19,20,21 ],
        "visible": false,
    }
]
    
11.07.2018 / 14:27
0

To do this, simply use the exportOptions property of the DataTable:

"buttons": [
                    {
                        extend: 'excelHtml5',
                        exportOptions: {
                            columns: ':visible'
                        }
                    },
                    {
                        extend: 'copyHtml5',
                        exportOptions: {
                            columns: ':visible'
                        }
                    },
                    {
                        extend: 'pdfHtml5',
                        exportOptions: {
                            columns: ':visible'
                        }
                    },
                    { 
                        extend: 'colvis', 
                        text: '+ Colunas' ,
                        exportOptions: {
                            columns: ':visible'
                        }
                    },
                ],

Source: DataTables

    
11.07.2018 / 14:27