Code written for exporting PDF from a table but need to export only visible columns.
Code written for exporting PDF from a table but need to export only visible columns.
NiteshJ
Posts: 2Questions: 1Answers: 0
Hello,
I have written a code for exporting the datatable to pdf and xls and csv formats. when I am exporting I am getting all the columns exported which are visible or and invisible. I need to just export those columns that are visible. Can you please help me with it.
Following is the code that I have written.
var oTable = $('#tblSearchRes').dataTable( {
"sDom" : "<'row'<'dataTables_header clearfix'<'col-md-11'Tf><'col-md-1'C>r>>t<'row'<'dataTables_footer clearfix'<'col-md-6'i><'col-md-5'p><'col-md-1'l>>>",
"oTableTools": {
"aButtons": [ {
"sExtends": "download",
"mColumns": "visible",
"sToolTip": "CSV",
"sButtonText": "<i class='fa fa-file-text'></i>",
"sUrl": "/aaa/yyy/xxx?download=Y&downloadFormat=CSV&attributename=${params.attributename}&sevents=${params.sevents}&sresources=${params.sresources}&usersId=${params.usersId}&toDate=${params.toDate}&fromDate=${params.fromDate}&attribute=${params.attribute}&attrvalue=${params.attrvalue}&flag=${params.flag}&profile_Id=${params.profile_Id}&sfilelocation=${params.sfilelocation}&sfiles=${params.sfiles}&sattribute=${params.sattribute}",
"sButtonClass":"DTTT_button_csv"
}, {
"sExtends": "download",
"sToolTip": "XLS",
"mColumns": "visible",
"sButtonText": "<i class='fa fa-file-excel-o'></i>",
"sUrl": "/aaa/yyy/xxx?download=Y&downloadFormat=XLS&attributename=${params.attributename}&sevents=${params.sevents}&sresources=${params.sresources}&usersId=${params.usersId}&toDate=${params.toDate}&fromDate=${params.fromDate}&attribute=${params.attribute}&attrvalue=${params.attrvalue}&flag=${params.flag}&profile_Id=${params.profile_Id}&sfilelocation=${params.sfilelocation}&sfiles=${params.sfiles}&sattribute=${params.sattribute}",
"sButtonClass":"DTTT_button_xls"
}, {
"sExtends": "download",
"sToolTip": "PDF",
"iColumns": "visible",
"sButtonText": "<i class='fa fa-file-pdf-o'></i>",
"sUrl": "/aaa/yyy/xxx?download=Y&downloadFormat=PDF&attributename=${params.attributename}&sevents=${params.sevents}&sresources=${params.sresources}&usersId=${params.usersId}&toDate=${params.toDate}&fromDate=${params.fromDate}&attribute=${params.attribute}&attrvalue=${params.attrvalue}&flag=${params.flag}&profile_Id=${params.profile_Id}&sfilelocation=${params.sfilelocation}&sfiles=${params.sfiles}&sattribute=${params.sattribute}",
"sButtonClass":"DTTT_button_pdf"
}]
},
"bServerSide" : true,
"bProcessing" : true,
"iDisplayLength":10,
"sAjaxSource": "/gra/activityMonitoring/fetchSearchResult",
"fnServerParams": function ( aoData ) {
aoData.push( { "name": "attributename", "value": "${params.attributename}"},{ "name": "sevents", "value": "${params.sevents}"},{ "name": "sresources", "value": "${params.sresources}"},{ "name": "usersId", "value": "${params.usersId}"},{ "name": "toDate", "value": "${params.toDate}"},{ "name": "fromDate", "value": "${params.fromDate}"},{ "name": "attribute", "value": "${params.attribute}"},{ "name": "attrvalue", "value": "${params.attrvalue}"},{ "name": "flag", "value": "${params.flag}"},{ "name": "profile_Id", "value": "${params.profile_Id}"},{ "name": "sfilelocation", "value": "${params.sfilelocation}"},{ "name": "sfiles", "value": "${params.sfiles}"},{ "name": "sattribute", "value": "${params.sattribute}"});
},
"scrollX": true,
"oLanguage": {
"sProcessing": "<i class='fa fa-spinner fa-spin'></i> Loading",
"oPaginate": {
"sPrevious": "Prev", // This is the link to the previous page
"sNext": "Next", // This is the link to the next page
"sZeroRecords": "No Data to Display"
}
},
"aoColumns": [
{ "mData": "employeeId", "sWidth":"100px"},
{ "mData": "eventdesc", "sWidth":"180px"},
{ "mData": "DateTime", "sWidth":"115px"},
{ "mData": "ObjectName", "sWidth":"105px"},
]
}
);
$('.dataTables_filter input').addClass('form-control').attr('placeholder','Search');
$('.dataTables_length select').addClass('form-control');
This discussion has been closed.
Answers
@Allen.... Can you please give me some workaround.