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
Laravel 8 QR Code Generate Example
Laravel 8 QR Code Generate Exa...

In this post we will see Laravel 8 qr code generate example. we will generate QR Code using simple-qrcode package....

Read More

Jun-30-2021

How To Reset Modal Form In jQuery
How To Reset Modal Form In jQu...

Have you ever seen those pop-up boxes on websites? They're called modal forms, and they make it easier to do things...

Read More

Jan-04-2023

Laravel 8 Form Validation Example
Laravel 8 Form Validation Exam...

In this article, we will see the laravel 8 form validation example. form validation in laravel is a very common fun...

Read More

Oct-10-2020

How to Upgrade PHP 8.0 to 8.1 in Ubuntu
How to Upgrade PHP 8.0 to 8.1...

Hey there! I recently needed to upgrade my PHP version from 8.0 to the latest 8.1 on my Ubuntu server. It's a smart...

Read More

Nov-03-2023