Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
130
rated 0 times [  135] [ 5]  / answers: 1 / hits: 17971  / 8 Years ago, thu, february 11, 2016, 12:00:00

I use the angular-datatable plugin, with export buttons.



Example here: http://l-lin.github.io/angular-datatables/#/withButtons



vm.dtOptions = DTOptionsBuilder.fromSource('data.json')
.withDOM('frtip')
.withPaginationType('full_numbers')
// Active Buttons extension
.withButtons([
'columnsToggle',
'colvis',
'copy',
'print',
'excel',
{
text: 'Some button',
key: '1',
action: function (e, dt, node, config) {
alert('Button activated');
}
}
]);


My problem is that When I try to export, the hidden columns shown.



I try to find solution for export just the visible columns, And I find the solution here
https://datatables.net/forums/discussion/3210/tabletools-how-to-hide-columns-when-exporting-copying



$('#list').dataTable({
sDom: 'T<clear>lfrtip',
oTableTools: {
sSwfPath: swf/copy_cvs_xls_pdf.swf, // setting path for swf file. Displays export buttons
aButtons: [{
sExtends: copy,
mColumns: [0, 1, 2, 3, 4, 5] // Export settings for Copy to Clipboard
}, {
sExtends: csv,
mColumns: [0, 1, 2, 3, 4, 5] // Export settings for CSV file
}, {
sExtends: xls,
mColumns: [0, 1, 2, 3, 4, 5] // Export settings for Excel file
}, {
sExtends: pdf,
mColumns: [0, 1, 2, 3, 4, 5], // Export settings for PDF file
sPdfOrientation: landscape
}],
},



  1. How can I add this option to angular-datatable plugin, For select which column export?

  2. How can I change the file name for the export file (like excel, pdf)?


More From » jquery

 Answers
13

Here is the code I have followed and it works. This is for the file name change (2nd question).
Please let me know if you have any issues with the following.



buttons: [
{
extend: excelHtml5,
fileName: CustomFileName + .xlsx,
exportOptions: {
columns: ':visible'
},
//CharSet: utf8,
exportData: { decodeEntities: true }
},
{
extend: csvHtml5,
fileName: CustomFileName + .xlsx,
exportOptions: {
columns: ':visible'
},
exportData: {decodeEntities:true}
}
]

[#63349] Tuesday, February 9, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dominickmackenziet

Total Points: 583
Total Questions: 101
Total Answers: 117

Location: Saint Lucia
Member since Wed, Feb 8, 2023
1 Year ago
dominickmackenziet questions
Wed, Apr 7, 21, 00:00, 3 Years ago
Fri, Feb 12, 21, 00:00, 3 Years ago
;