Remove/Hide Columns While Export Data In Datatable

In this tutorial we will see how to remove/hide columns while export data datatable in laravel. 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 laravel.

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

 

So, let's see remove hide columns export data datatable using exportoptions jquery.

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: [ 2, ':visible' ]
                }
            },
            {
                extend: 'excelHtml5',
                exportOptions: {
                    columns: ':visible'
                }
            },
            {
                extend: 'pdfHtml5',
                exportOptions: {
                    columns: [ 2, 4, 6 ]
                }
            },
            'colvis'
        ]
    } );
} );

 


You might also like :

techsolutionstuff

Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of techsolutionstuff.com. Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.

RECOMMENDED POSTS

FEATURE POSTS