Laravel 8 Remove/Hide Columns While Export Data In Datatables

Websolutionstuff | Oct-13-2020 | Categories : Laravel PHP jQuery

In this article, 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 exporting datatable information into PDF, Excel, or CSV we might exclude or hide some columns. So, we will give you a demo of how to remove/hide columns while exporting data in datatables in laravel 8 using jQuery.

So, let's see, datatables export only visible columns, exclude columns from export in jquery datatables and remove 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 and other datatable hide columns.

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'
        ]
    } );
} );

 


You might also like:

Recommended Post
Featured Post
Laravel tips: DB Models and Eloquent
Laravel tips: DB Models and El...

In the realm of web development, an efficient and robust data handling mechanism is paramount. Laravel, a PHP web applic...

Read More

Oct-11-2023

How To Install Vue 3 In Laravel 9 With Vite
How To Install Vue 3 In Larave...

In this article, we will see how to install Vue 3 in laravel 9 with vite. In the previous article, we will install...

Read More

Oct-10-2022

Laravel 10 Desktop and Mobile User Agent Parser
Laravel 10 Desktop and Mobile...

Discover the magic of Laravel 10's Desktop and Mobile User Agent Parser! With the help of the jenssegers/agent packa...

Read More

Nov-24-2023

Laravel tips DB Models and Eloquent - Part 5
Laravel tips DB Models and Elo...

Welcome to the fifth installment of our ongoing series, "Laravel Tips: DB Models and Eloquent." In this latest...

Read More

Oct-20-2023