Skip to content

Commit 2fab4d8

Browse files
author
luqin
committed
Support table props keyField
1 parent 7d2ee7b commit 2fab4d8

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/BootstrapTable.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,21 @@ class BootstrapTable extends React.Component {
1414
super(props);
1515

1616
this._attachCellEditFunc();
17-
let keyField = null;
17+
let {keyField} = props;
1818
let customSortFuncMap = {};
1919

20-
React.Children.forEach(this.props.children, function (column) {
21-
if (column.props.isKey) {
22-
if (keyField != null) throw "Error. Multiple key column be detected in TableHeaderColumn.";
23-
keyField = column.props.dataField;
24-
}
20+
if (!(typeof keyField === 'string' && keyField.length)) {
21+
React.Children.forEach(this.props.children, column=> {
22+
if (column.props.isKey) {
23+
if (keyField != null) {
24+
throw "Error. Multiple key column be detected in TableHeaderColumn.";
25+
}
26+
keyField = column.props.dataField;
27+
}
28+
}, this);
29+
}
30+
31+
React.Children.forEach(this.props.children, column=> {
2532
if (column.props.sortFunc) {
2633
customSortFuncMap[column.props.dataField] = column.props.sortFunc;
2734
}
@@ -485,6 +492,7 @@ class BootstrapTable extends React.Component {
485492
}
486493

487494
BootstrapTable.propTypes = {
495+
keyField: React.PropTypes.string,
488496
height: React.PropTypes.string,
489497
data: React.PropTypes.array,
490498
remote: React.PropTypes.bool, // remote data, default is false

0 commit comments

Comments
 (0)