How can i hide the last column in printing and exporting to excel only but appear in the normal viewing
http://jsfiddle.net/andrew_safwat/qokbv1sj/
$(document).ready(function () {
$('#example').DataTable({
dom: 'Brtip',
buttons: [
{
extend: 'print'
},
{
extend: 'excel'
}
]
});
});
To hide and show columns use columns() and visible() method. Call it on dataTables instance and pass column index in columns() method and false to visible() method. Similarly, pass true to visible() if you want to show the columns.
You can use JQuery to disable/enable the button based on the row count. Here's an example where the CSV export is disabled if the row count is zero. You could tie this to rowCallback option or a custom event.
Use exportOptions
Here's how you do it
$(document).ready(function() {
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [
{
extend: 'copyHtml5',
exportOptions: {
columns: [ 0, ':visible' ]
}
},
{
extend: 'excelHtml5',
exportOptions: {
columns: ':visible'
}
},
{
extend: 'pdfHtml5',
exportOptions: {
columns: [ 0, 1, 2, 5 ]
}
},
'colvis'
]
} );
} );
https://datatables.net/extensions/buttons/examples/html5/columns.html
$(document).ready(function () {
$('#example').DataTable({
dom: 'Brtip',
buttons: [
{
extend: 'print',
exportOptions: {
columns: [ 0, 1, 2, 3, 4, 5, 6 ] //Your Column value those you want
}
},
{
extend: 'excel',
exportOptions: {
columns: [ 0, 1, 2, 3, 4 5, 6 ] //Your Column value those you want
}
},
],
});
});
Here is the answer
buttons.exportData(), you can specify which columns to export with a column-selector, which takes an array of IDs or Indexes
http://datatables.net/forums/discussion/comment/85649#Comment_85649
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With