Export jQuery Datatables

Asked

Viewed 79 times

2

I have a tabla and I use Datatables, I am using the native export functionality and give an Hide in the columns my code this more or less 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,
    }
]

only that when the user will export all the data to the columns that are not visible I would like to know if it is possible and if it has as someone to help me so that only the data and columns that are visible are exported

2 answers

1


Try with the parameter columns: ':visible' in the option exportOptions of the button, that way:

"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,
    }
]

0

to do this just use the Datatable exportOptions property:

"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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.