Skip to content
Snippets Groups Projects
Commit 32a220ac authored by legac's avatar legac
Browse files

the method Export.toCSV is working.

parent edcde228
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ Ext.define('App.grid.plugin.Export', { ...@@ -9,6 +9,7 @@ Ext.define('App.grid.plugin.Export', {
alias: 'plugin.pGridExport', alias: 'plugin.pGridExport',
delimiter: '"', delimiter: '"',
newLine: '\n',
separator: ',', separator: ',',
// Pre-defined configuration // Pre-defined configuration
...@@ -44,6 +45,7 @@ Ext.define('App.grid.plugin.Export', { ...@@ -44,6 +45,7 @@ Ext.define('App.grid.plugin.Export', {
* Export the content of the grid as a CSV file. * Export the content of the grid as a CSV file.
* The method scan the HTML to find the rendered headers, rows * The method scan the HTML to find the rendered headers, rows
* and cells content. * and cells content.
* Hidden columns and rows are ignored.
*/ */
toCSV: function () { toCSV: function () {
...@@ -56,7 +58,9 @@ Ext.define('App.grid.plugin.Export', { ...@@ -56,7 +58,9 @@ Ext.define('App.grid.plugin.Export', {
cell, cell,
columns, columns,
i, i,
link,
row, row,
s,
value; value;
// scan the grid header // scan the grid header
...@@ -105,6 +109,16 @@ Ext.define('App.grid.plugin.Export', { ...@@ -105,6 +109,16 @@ Ext.define('App.grid.plugin.Export', {
row = row.next(); row = row.next();
} while (row); } 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment