diff --git a/static/plugin_dbui/src/grid/plugin/Export.js b/static/plugin_dbui/src/grid/plugin/Export.js index e7c779d201555f0c93213c62c6cbcd9fc6bd02c1..d660ca854e98c7235c0cd6cfae6235f0b6e75f4f 100644 --- a/static/plugin_dbui/src/grid/plugin/Export.js +++ b/static/plugin_dbui/src/grid/plugin/Export.js @@ -9,6 +9,7 @@ Ext.define('App.grid.plugin.Export', { alias: 'plugin.pGridExport', delimiter: '"', + newLine: '\n', separator: ',', // Pre-defined configuration @@ -44,6 +45,7 @@ Ext.define('App.grid.plugin.Export', { * Export the content of the grid as a CSV file. * The method scan the HTML to find the rendered headers, rows * and cells content. + * Hidden columns and rows are ignored. */ toCSV: function () { @@ -56,7 +58,9 @@ Ext.define('App.grid.plugin.Export', { cell, columns, i, + link, row, + s, value; // scan the grid header @@ -105,6 +109,16 @@ Ext.define('App.grid.plugin.Export', { row = row.next(); } while (row); - console.log(csv.join('\n')); + // special character like quote, / , ? are HTML encoded + s = encodeURIComponent(csv.join(this.newLine)); + + // download the file by simulating a click on a link + link = Ext.getBody().createChild({ + tag: "a", + href: "data:text/csv;charset=utf-8," + s, + download: "my_data.csv" + }); + link.dom.click(); + link.destroy(); } }); \ No newline at end of file