Remove/Hide Columns While Export Data In Datatable

Websolutionstuff
1 min readJan 13, 2021

--

Hello Guys,

In this small tutorial I will give example of remove or hide columns while export data from datatable.

And I will give you example of yajra datatable export button.

When we are using jquery datatable for displaying data in datatable and export datatabel information into PDF, Excel or CSV we might be exclude or hide some columns. So, here I will give you demo how to remove or hide columns when exporting data when using jquery.

In this example the copy button will export column index 1 and all visible columns, the Excel button will export only the visible columns and the PDF button will export column indexes 1, 2 and 4 only.

Column visibility controls are also included so you can change the columns easily and see the effect of the export options.

$(document).ready(function() {
$('#demo').DataTable( {
dom: 'Bfrtip',
buttons: [
{
extend: 'copyHtml5',
exportOptions: {
columns: [ 1, ':visible' ]
}
},
{
extend: 'excelHtml5',
exportOptions: {
columns: ':visible'
}
},
{
extend: 'pdfHtml5',
exportOptions: {
columns: [ 1, 2, 4 ]
}
},
'colvis'
]
} );
} );

Read Also : Disable Sorting On Specific Columns In Datatable

Thanks For Reading 🙏

--

--

Websolutionstuff
Websolutionstuff

Written by Websolutionstuff

I am Laravel and PHP Developer. I have also Good Knowledge of JavaScript, jQuery, Bootstrap and REST API. Visit Website: http://websolutionstuff.com/

No responses yet