diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js index c2282a1..b0ca541 100644 --- a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js @@ -2571,7 +2571,7 @@ define( keys = _.pluck(self.columns, 'name'); // Fetch the items from fullCollection and convert it as csv format - var csv = labels.join(',') + '\n'; + var csv = keys.join(',') + '\n'; csv += coll.map(function(item) { return _.map(keys, function(key) { var cell = csv_col [key].cell, @@ -2583,11 +2583,6 @@ define( }).join(','); }).join('\n'); - // Download the file. - var encodedUri = encodeURI('data:text/csv;charset=utf-8,' + csv), - link = document.createElement('a'); - link.setAttribute('href', encodedUri); - /* If download is from view data then file name should be * the object name for which data is to be displayed. */ @@ -2598,8 +2593,7 @@ define( success: function(res) { if (res.data.status) { filename = res.data.result + '.csv'; - link.setAttribute('download', filename); - link.click(); + self._save_csv_file(csv, filename); } }, error: function(e) { @@ -2622,14 +2616,32 @@ define( else { var cur_time = new Date(); var filename = 'data-' + cur_time.getTime() + '.csv'; - link.setAttribute('download', filename); - link.click(); + self._save_csv_file(csv, filename); } } else { alertify.alert('Download Data', 'No data is available to download'); } }, + // We will use this function to save the file across browser + _save_csv_file: function(csvData, filename) { + var blob = new Blob([csvData], { type: 'text/csv;charset=utf-8;' }); + if (navigator.msSaveBlob) { // IE 10+ + navigator.msSaveBlob(blob, filename); + } else { + var link = document.createElement("a"); + if (link.download !== undefined) { // feature detection + // Browsers that support HTML5 download attribute + var url = URL.createObjectURL(blob); + link.setAttribute("href", url); + link.setAttribute("download", filename); + link.style.visibility = 'hidden'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + } + } + }, _auto_rollback: function() { var self = this;