0

I'm stuck at hiding a column in JQuery DataTables based on condition, I've radio button list based on checked value I need to display particular column in datatables how I can achieve this? I'm hiding column like below but when I click on Excel button all hidden column are displaying in Excel without any data

if ($scope.searchAtDefaultVal == 'Voucher') {
   // hide column for voucher
   $scope.voucherSearchTable.column(8).visible(false);
   $scope.voucherSearchTable.column(9).visible(false);
   $scope.voucherSearchTable.column(10).visible(false);
   $scope.voucherSearchTable.column(11).visible(true);
}
else {
   $scope.voucherSearchTable.column(8).visible(true);
   $scope.voucherSearchTable.column(9).visible(true);
   $scope.voucherSearchTable.column(10).visible(true);
   $scope.voucherSearchTable.column(11).visible(false);
}

This code is working, but the problem is when I click on Excel button hidden column also display in Excel sheet without data.

1
  • I actually had done some DOM manipulation on a datatables table, and created my own excel exporting function to show it. Commented Apr 13, 2020 at 7:14

1 Answer 1

1

When initializing the table, you can specify a selector of which data will be exported:

buttons: [
           {
             extend: 'excelHtml5',
             exportOptions: { 
                columns: ':visible' // <-- using datatables selector
            }
        }
    ]

That way only visible parts of the table will be exported, for more infomartion check https://datatables.net/extensions/buttons/examples/html5/columns.html

Sign up to request clarification or add additional context in comments.

1 Comment

I have added this but it will hide all hidden column from table in excel, how to show hidden columns in excel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.