Skip to content
This repository was archived by the owner on May 29, 2018. It is now read-only.

Commit 19893e1

Browse files
committed
Adds new option exporting.csv.dataFormatter, which allows overriding the default number format for HTML data table and exported CSV
1 parent d5d2b83 commit 19893e1

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

export-csv.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,23 +187,23 @@
187187
var csv = '',
188188
rows = this.getDataRows(),
189189
options = (this.options.exporting || {}).csv || {},
190+
dataFormatter = options.dataFormatter || function (val) {
191+
return Highcharts.numberFormat(val, -1, useLocalDecimalPoint ? (1.1).toLocaleString()[1] : '.', '');
192+
},
190193
itemDelimiter = options.itemDelimiter || ',', // use ';' for direct import to Excel
191194
lineDelimiter = options.lineDelimiter || '\n'; // '\n' isn't working with the js csv data extraction
192195

193196
// Transform the rows to CSV
194197
each(rows, function (row, i) {
195198
var val = '',
196-
j = row.length,
197-
n = useLocalDecimalPoint ? (1.1).toLocaleString()[1] : '.';
199+
j = row.length;
198200
while (j--) {
199201
val = row[j];
200202
if (typeof val === "string") {
201203
val = '"' + val + '"';
202204
}
203205
if (typeof val === 'number') {
204-
if (n === ',') {
205-
val = val.toString().replace(".", ",");
206-
}
206+
val = dataFormatter(val);
207207
}
208208
row[j] = val;
209209
}
@@ -223,24 +223,24 @@
223223
*/
224224
Highcharts.Chart.prototype.getTable = function (useLocalDecimalPoint) {
225225
var html = '<table><thead>',
226-
rows = this.getDataRows();
226+
rows = this.getDataRows(),
227+
options = (this.options.exporting || {}).csv || {},
228+
dataFormatter = options.dataFormatter || function (val) {
229+
return Highcharts.numberFormat(val, -1, useLocalDecimalPoint ? (1.1).toLocaleString()[1] : '.', '');
230+
};
227231

228232
// Transform the rows to HTML
229233
each(rows, function (row, i) {
230234
var tag = i ? 'td' : 'th',
231235
val,
232-
j,
233-
n = useLocalDecimalPoint ? (1.1).toLocaleString()[1] : '.';
236+
j;
234237

235238
html += '<tr>';
236239
for (j = 0; j < row.length; j = j + 1) {
237240
val = row[j];
238241
// Add the cell
239242
if (typeof val === 'number') {
240-
val = val.toString();
241-
if (n === ',') {
242-
val = val.replace('.', n);
243-
}
243+
val = dataFormatter(val);
244244
html += '<' + tag + ' class="number">' + val + '</' + tag + '>';
245245

246246
} else {

0 commit comments

Comments
 (0)