Skip to content

Commit

Permalink
fix #1613
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenFang committed Sep 18, 2017
1 parent a545c46 commit d810c9c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/BootstrapTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,7 @@ class BootstrapTable extends Component {
column.props.hidden === false)) {
keys.push({
field: column.props.dataField,
type: column.props.csvFieldType,
format: column.props.csvFormat,
extraData: column.props.csvFormatExtraData,
header: column.props.csvHeader || column.props.dataField,
Expand Down
4 changes: 3 additions & 1 deletion src/Const.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ const CONST_VAR = {
REMOTE_SEARCH: 'search',
REMOTE_EXPORT_CSV: 'exportCSV',
INSERT_FAIL_INDICATOR: 'Validation errors, please check!',
DEFAULT_CSV_SEPARATOR: ','
DEFAULT_CSV_SEPARATOR: ',',
CSV_STRING_TYPE: 'string',
CSV_NUMBER_TYPE: 'number'
};

CONST_VAR.REMOTE = {};
Expand Down
2 changes: 2 additions & 0 deletions src/TableHeaderColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ TableHeaderColumn.propTypes = {
dataFormat: PropTypes.func,
csvFormat: PropTypes.func,
csvHeader: PropTypes.string,
csvFieldType: PropTypes.oneOf([ Const.CSV_STRING_TYPE, Const.CSV_NUMBER_TYPE ]),
isKey: PropTypes.bool,
editable: PropTypes.any,
hidden: PropTypes.bool,
Expand Down Expand Up @@ -323,6 +324,7 @@ TableHeaderColumn.defaultProps = {
dataFormat: undefined,
csvFormat: undefined,
csvHeader: undefined,
csvFieldType: Const.CSV_STRING_TYPE,
isKey: false,
editable: true,
onSort: undefined,
Expand Down
8 changes: 5 additions & 3 deletions src/csv_export_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/* eslint no-var: 0 */
/* eslint no-unused-vars: 0 */
import Util from './util';
import Const from './Const';

if (Util.canUseDOM()) {
const filesaver = require('./filesaver');
Expand Down Expand Up @@ -45,9 +46,10 @@ function toString(data, keys, separator, excludeCSVHeader) {

data.map(function(row) {
keys.map(function(col, i) {
const { field, format, extraData } = col;
const value = typeof format !== 'undefined' ? format(row[field], row, extraData) : row[field];
const cell = typeof value !== 'undefined' ? ('"' + value + '"') : '';
const { field, format, extraData, type } = col;
let value = typeof format !== 'undefined' ? format(row[field], row, extraData) : row[field];
value = type === Const.CSV_NUMBER_TYPE ? Number(value) : `"${value}"`;
const cell = typeof value !== 'undefined' ? value : '';
dataString += cell;
if (i + 1 < keys.length) dataString += separator;
});
Expand Down

0 comments on commit d810c9c

Please sign in to comment.