Skip to content

Commit

Permalink
custom CSV separator (unable to use semicolon instead)
Browse files Browse the repository at this point in the history
  • Loading branch information
fedysalah committed Jun 12, 2017
1 parent 1ec3b2d commit 1c9e2c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/BootstrapTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ class BootstrapTable extends Component {
} else {
result = this.store.getDataIgnoringPagination();
}

const separator = this.props.options.exportCSVSeparator || ',';
const keys = [];
this.props.children.filter(_ => _ != null).map(function(column) {
if (column.props.export === true ||
Expand All @@ -1006,7 +1006,7 @@ class BootstrapTable extends Component {
csvFileName = csvFileName();
}

exportCSVUtil(result, keys, csvFileName);
exportCSVUtil(result, keys, csvFileName, separator);
}

handleSearch = searchText => {
Expand Down Expand Up @@ -1454,6 +1454,7 @@ BootstrapTable.propTypes = {
lastPageTitle: PropTypes.string,
searchDelayTime: PropTypes.number,
exportCSVText: PropTypes.string,
exportCSVSeparator: PropTypes.string,
insertText: PropTypes.string,
deleteText: PropTypes.string,
saveText: PropTypes.string,
Expand Down
10 changes: 5 additions & 5 deletions src/csv_export_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (Util.canUseDOM()) {
var saveAs = filesaver.saveAs;
}

function toString(data, keys) {
function toString(data, keys, separator) {
let dataString = '';
if (data.length === 0) return dataString;

Expand All @@ -35,7 +35,7 @@ function toString(data, keys) {
}
}).filter(key => {
return typeof key !== 'undefined';
}).join(',') + '\n';
}).join(separator) + '\n';
}

keys = keys.filter(key => {
Expand All @@ -48,7 +48,7 @@ function toString(data, keys) {
const value = typeof format !== 'undefined' ? format(row[field], row, extraData) : row[field];
const cell = typeof value !== 'undefined' ? ('"' + value + '"') : '';
dataString += cell;
if (i + 1 < keys.length) dataString += ',';
if (i + 1 < keys.length) dataString += separator;
});

dataString += '\n';
Expand All @@ -57,8 +57,8 @@ function toString(data, keys) {
return dataString;
}

const exportCSV = function(data, keys, filename) {
const dataString = toString(data, keys);
const exportCSV = function(data, keys, filename, separator) {
const dataString = toString(data, keys, separator);
if (typeof window !== 'undefined') {
saveAs(new Blob([ dataString ],
{ type: 'text/plain;charset=utf-8' }),
Expand Down

0 comments on commit 1c9e2c5

Please sign in to comment.