diff --git a/tableExport.js b/tableExport.js index 1bfaa0fc..b55f3e25 100644 --- a/tableExport.js +++ b/tableExport.js @@ -27,6 +27,7 @@ THE SOFTWARE.*/ separator: ',', ignoreColumn: [], tableName:'yourTableName', + filename:'exportData', type:'csv', pdfFontSize:14, pdfLeftMargin:20, @@ -47,7 +48,7 @@ THE SOFTWARE.*/ $(this).filter(':visible').find('th').each(function(index,data) { if ($(this).css('display') != 'none'){ if(defaults.ignoreColumn.indexOf(index) == -1){ - tdData += '"' + parseString($(this)) + '"' + defaults.separator; + tdData += '"' + parseString($(this).find(':visible')) + '"' + defaults.separator; } } @@ -74,8 +75,15 @@ THE SOFTWARE.*/ if(defaults.consoleLog == 'true'){ console.log(tdData); } - var base64data = "base64," + $.base64.encode(tdData); - window.open('data:application/'+defaults.type+';filename=exportData;' + base64data); + + var mimeType = 'csv'; + if(defaults.type === 'txt') { + mimeType = 'plain'; + } + + var base64data = "base64," + B64.encode(tdData); + + openDownloadLink(defaults.filename + '.' + defaults.type, 'data:text/'+mimeType+';charset=utf-8;filename=' + defaults.filename + '.' + defaults.type + ';' + base64data); }else if(defaults.type == 'sql'){ // Header @@ -85,7 +93,7 @@ THE SOFTWARE.*/ $(this).filter(':visible').find('th').each(function(index,data) { if ($(this).css('display') != 'none'){ if(defaults.ignoreColumn.indexOf(index) == -1){ - tdData += '`' + parseString($(this)) + '`,' ; + tdData += '`' + parseString($(this).find(':visible')) + '`,' ; } } @@ -118,10 +126,9 @@ THE SOFTWARE.*/ console.log(tdData); } - var base64data = "base64," + $.base64.encode(tdData); - window.open('data:application/sql;filename=exportData;' + base64data); - - + var base64data = "base64," + B64.encode(tdData); + + openDownloadLink(defaults.filename + '.sql', 'data:application/sql;filename=' + defaults.filename + '.sql;' + base64data); }else if(defaults.type == 'json'){ var jsonHeaderArray = []; @@ -132,7 +139,7 @@ THE SOFTWARE.*/ $(this).filter(':visible').find('th').each(function(index,data) { if ($(this).css('display') != 'none'){ if(defaults.ignoreColumn.indexOf(index) == -1){ - jsonArrayTd.push(parseString($(this))); + jsonArrayTd.push(parseString($(this).find(':visible'))); } } }); @@ -167,8 +174,8 @@ THE SOFTWARE.*/ if(defaults.consoleLog == 'true'){ console.log(JSON.stringify(jsonExportArray)); } - var base64data = "base64," + $.base64.encode(JSON.stringify(jsonExportArray)); - window.open('data:application/json;filename=exportData;' + base64data); + var base64data = "base64," + B64.encode(JSON.stringify(jsonExportArray)); + openDownloadLink(defaults.filename + '.json', 'data:application/json;filename=' + defaults.filename + '.json;' + base64data); }else if(defaults.type == 'xml'){ var xml = ''; @@ -179,7 +186,7 @@ THE SOFTWARE.*/ $(this).filter(':visible').find('th').each(function(index,data) { if ($(this).css('display') != 'none'){ if(defaults.ignoreColumn.indexOf(index) == -1){ - xml += "" + parseString($(this)) + ""; + xml += "" + parseString($(this).find(':visible')) + ""; } } }); @@ -208,9 +215,8 @@ THE SOFTWARE.*/ console.log(xml); } - var base64data = "base64," + $.base64.encode(xml); - window.open('data:application/xml;filename=exportData;' + base64data); - + var base64data = "base64," + B64.encode(xml); + openDownloadLink(defaults.filename + '.xml', 'data:application/xml;filename=' + defaults.filename + '.xml;' + base64data); }else if(defaults.type == 'excel' || defaults.type == 'doc'|| defaults.type == 'powerpoint' ){ //console.log($(this).html()); var excel=""; @@ -220,7 +226,7 @@ THE SOFTWARE.*/ $(this).filter(':visible').find('th').each(function(index,data) { if ($(this).css('display') != 'none'){ if(defaults.ignoreColumn.indexOf(index) == -1){ - excel += ""; + excel += ""; } } }); @@ -253,6 +259,7 @@ THE SOFTWARE.*/ var excelFile = ""; excelFile += ""; + excelFile += ''; excelFile += "
" + parseString($(this))+ "" + parseString($(this).find(':visible'))+ "