I am trying to refer to this code where a we are downloading a CSV file on click of a link.
$(document).ready(function () {
function exportTableToCSV($
Here is a bit that worked for me (in Chrome and Firefox). I'm building a xls file out of a table.
function downloadInnerHtml(filename,elId,mimeType){
var elHtml=''+document.getElementById(elId).innerHTML+'
';
var link=document.createElement('a');
mimeType=mimeType || 'application/xls';
var blob=new Blob([elHtml],{type:mimeType});
var url=URL.createObjectURL(blob);
link.href=url;
link.setAttribute('download', filename);
link.innerHTML = "Export to CSV";
document.body.appendChild(link);
link.click();
}
$(document).on("click","#exportButton",function(){
var date=new Date();
var mm=date.getMonth()+1;
var dd=date.getDate();
var yy=date.getFullYear();
var timeStamp=yy+""+((mm<10)?"0"+mm:mm)+""+((dd<10)?"0"+dd:dd);
var fileName=timeStamp+'_Employees.xls';
downloadInnerHtml(fileName,'mainEmployeeTable','application/xls');
});
Hope that helps someone else...
--Charles