Skip to content

Commit

Permalink
fix #342
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenFang committed Mar 20, 2016
1 parent 00213b9 commit 2233de7
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/BootstrapTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ class BootstrapTable extends Component {
}

handleEditCell(newVal, rowIndex, colIndex) {
const { beforeSaveCell, afterSaveCell } = this.props.cellEdit;
let fieldName;
React.Children.forEach(this.props.children, function(column, i) {
if (i === colIndex) {
Expand All @@ -424,13 +425,23 @@ class BootstrapTable extends Component {
}
});

if (beforeSaveCell) {
const isValid = beforeSaveCell(this.state.data[rowIndex], fieldName, newVal);
if (!isValid && typeof isValid !== 'undefined') {
this.setState({
data: this.store.get()
});
return;
}
}

const result = this.store.edit(newVal, rowIndex, fieldName).get();
this.setState({
data: result
});

if (this.props.cellEdit.afterSaveCell) {
this.props.cellEdit.afterSaveCell(this.state.data[rowIndex], fieldName, newVal);
if (afterSaveCell) {
afterSaveCell(this.state.data[rowIndex], fieldName, newVal);
}
}

Expand Down Expand Up @@ -750,6 +761,7 @@ BootstrapTable.propTypes = {
cellEdit: PropTypes.shape({
mode: PropTypes.string,
blurToSave: PropTypes.bool,
beforeSaveCell: PropTypes.func,
afterSaveCell: PropTypes.func
}),
insertRow: PropTypes.bool,
Expand Down Expand Up @@ -811,6 +823,7 @@ BootstrapTable.defaultProps = {
cellEdit: {
mode: Const.CELL_EDIT_NONE,
blurToSave: false,
beforeSaveCell: undefined,
afterSaveCell: undefined
},
insertRow: false,
Expand Down

0 comments on commit 2233de7

Please sign in to comment.