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 10 Create AJAX Pagination Example
Laravel 10 Create AJAX Paginat...

In this article, we will see laravel 10 create an ajax pagination example. Here, we will learn about how to create...

Read More

Apr-17-2023

How To Install VueJs In Laravel
How To Install VueJs In Larave...

In this article, we will see how to install vue js in the laravel framework. if you are not aware of you are freshe...

Read More

Jul-12-2020

How To Disable Dates After Week In jQuery Datepicker
How To Disable Dates After Wee...

In this tutorial, we will see how to disable dates after a week in jquery datepicker. In the date picker, we can di...

Read More

Jun-29-2022

How To Install phpMyAdmin In Ubuntu
How To Install phpMyAdmin In U...

In this article, we will explore the process of installing phpMyAdmin in Ubuntu. phpMyAdmin is a popular web-based admin...

Read More

Jul-24-2023