I have added an HTML button in my DataTable to export data in different formats. It working fine, but I want to disable some columns in DataTable export time. How can I do it?
$(document).ready( function () { $('#MyDataTable').DataTable({ dom: 'Bfrtip', buttons: [{ extend: 'pdf', },{ extend: 'excel', }, { extend: 'csv', } ] }); } );
To hide some columns in DataTable export time add a class in the table th tag.
<th class="noExport">Column Name</th>
Apply this code:
$(document).ready( function () { $('#MyDataTable').DataTable({ dom: 'Bfrtip', buttons: [{ extend: 'pdf', exportOptions: { columns: "thead th:not(.noExport)" } },{ extend: 'excel', exportOptions: { columns: "thead th:not(.noExport)" } }, { extend: 'csv', exportOptions: { columns: "thead th:not(.noExport)" } } ] }); } );
Hope it will be helpful for you.
Question and answer is powered by AnsPress.io