Remove/Hide Columns While Export Data In Datatable

Websolutionstuff | Aug-24-2020 | Categories : Laravel PHP

In this article, we will see remove or hide columns while exporting data in datatable. When we are using jquery datatable for displaying data in datatable and exporting datatabel information into PDF, Excel, or CSV we might exclude or hide some columns. So, here I will give you a demo on how to remove or hide columns when exporting data using jquery. You can exclude some columns while exporting data from the datatable. And also, you can remove columns when exporting data when using jquery.

So, let's see how to export specific columns in datatable or remove a specific column while exporting data in datatable.

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

 


You might also like:

Recommended Post
Featured Post
How To Add Summernote Editor In Laravel
How To Add Summernote Editor I...

In this tutorial, I will let you know how to use summernote editor in laravel, In laravel or PHP many editors are a...

Read More

Jun-17-2020

Date Range Filter In Datatable jQuery Example
Date Range Filter In Datatable...

In this article, we will see the date range filter in the datatable jquery example. Many times we required data of ...

Read More

Nov-14-2022

Laravel Authentication Using Breeze
Laravel Authentication Using B...

In this article, we will share you new information about laravel authentication using a breeze. Laravel Breeze...

Read More

Feb-05-2021

How To Create Unique Slug In Laravel 9
How To Create Unique Slug In L...

In this article, we will see how to create a unique slug in laravel 9. A slug is the part of a URL that i...

Read More

Sep-27-2022