Export to excel error when having dynamic table columns
Export to excel error when having dynamic table columns
nadeemahmad
Posts: 4Questions: 0Answers: 0
Thanks in advance!!!
var tableToExport;
$.ajax( {
"url": contextPath + '/getData',
"type" : "POST",
"success": function ( json ) {
tableToExport= $('#reportList').dataTable( {
"data":json["data"],
"columns":json["columns"],
dom: 'B',
buttons: [
{
extend: 'excelHtml5',
title: 'Report',
text: '<i class="fa fa-file-excel-o"></i>',
titleAttr: 'Excel',
'exportOptions':
{
},
customize: function ( xslx ) {
}
}
],
"drawCallback": function( settings ) {
tableToExport.button().trigger();
}
} );
},
"dataType": "json"
} );
I don't know but this isn't working, getting "Uncaught TypeError: Cannot read property 'button' of undefined" error when it comes to "drawCallback".
Can anyone help?
This discussion has been closed.
Replies
Hi @nadeemahmad ,
The problem is on line 24,
tableToExport.button().trigger()
.tableToExport
won't be visible at that point in thedrawCallback
(see the second example on that page), so trythis.api().button().trigger()
instead,Cheers,
Colin
Thank you @colin
That was really helpful.