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
How To Create Dynamic Line Chart In Laravel 9
How To Create Dynamic Line Cha...

In this article, we will see how to create a dynamic line chart in laravel 9. A dynamic line chart or line plot or...

Read More

Mar-22-2022

Carbon Add Years To Date In Laravel
Carbon Add Years To Date In La...

In this article, we will see examples of carbon adding years to date in laravel. Here we will laravel add...

Read More

Dec-07-2020

How to Display Validation Error Message in Laravel Vue JS
How to Display Validation Erro...

Hey folks, are you ready to make your Laravel Vue.js application even more user-friendly by implementing validation erro...

Read More

Mar-08-2024

How To Create Bar Chart In Laravel 9 Using Highcharts
How To Create Bar Chart In Lar...

In this article, we will see how to create a bar chart in laravel 9 using highcharts. A bar chart or bar graph is a...

Read More

Oct-05-2022