DEV Community

Techsolutionstuff
Techsolutionstuff

Posted on • Originally published at techsolutionstuff.com

Laravel 8 Remove/Hide Columns While Export Data In Datatables

In this tutorial we will see how to remove / hide columns while export data in datatables in laravel 8. When we are using jquery datatable for displaying data in datatable and export datatabel information into PDF, Excel or CSV file we might be exclude or hide some columns. Using jquery you can remove column while export data in laravel datatable or exclude column from export data in datatables.

So, In this example I will give you demo how to remove / hide columns while export data in datatables in laravel 8 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, 3 and 5 only and other datatable hide column.

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, 3, 5 ]
                }
            },
            'colvis'
        ]
    } );
} );
Enter fullscreen mode Exit fullscreen mode

Read Also : Laravel 8 Create Custom Helper Function Example

Top comments (0)