From c4c1b7f377bbe3956b867d0afadf98e0e8c46cb6 Mon Sep 17 00:00:00 2001 From: AllenFang Date: Sat, 15 Apr 2017 14:32:42 +0800 Subject: [PATCH] fix #1166 --- src/BootstrapTable.js | 3 +++ src/TableBody.js | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/BootstrapTable.js b/src/BootstrapTable.js index 4e6468868..1748dbb8b 100644 --- a/src/BootstrapTable.js +++ b/src/BootstrapTable.js @@ -411,6 +411,7 @@ class BootstrapTable extends Component { withoutNoDataText={ this.props.options.withoutNoDataText } expanding={ this.state.expanding } onExpand={ this.handleExpandRow } + onlyOneExpanding={ this.props.options.onlyOneExpanding } beforeShowError={ this.props.options.beforeShowError } keyBoardNav={ this.props.keyBoardNav } onNavigateCell={ this.handleNavigateCell } @@ -1385,6 +1386,7 @@ BootstrapTable.propTypes = { expandRowBgColor: PropTypes.string, expandBy: PropTypes.string, expanding: PropTypes.array, + onlyOneExpanding: PropTypes.bool, beforeShowError: PropTypes.func, printToolBar: PropTypes.bool }), @@ -1529,6 +1531,7 @@ BootstrapTable.defaultProps = { expandRowBgColor: undefined, expandBy: Const.EXPAND_BY_ROW, expanding: [], + onlyOneExpanding: false, beforeShowError: undefined, printToolBar: true }, diff --git a/src/TableBody.js b/src/TableBody.js index 08b152b59..75d9bc374 100644 --- a/src/TableBody.js +++ b/src/TableBody.js @@ -303,7 +303,8 @@ class TableBody extends Component { expandableRow, selectRow: { clickToExpand - } + }, + onlyOneExpanding } = this.props; const selectRowAndExpand = this._isSelectRowDefined() && !clickToExpand ? false : true; columnIndex = this._isSelectRowDefined() ? columnIndex - 1 : columnIndex; @@ -320,7 +321,8 @@ class TableBody extends Component { if (expanding.indexOf(rowKey) > -1) { expanding = expanding.filter(k => k !== rowKey); } else { - expanding.push(rowKey); + if (onlyOneExpanding) expanding = [ rowKey ]; + else expanding.push(rowKey); } this.props.onExpand(expanding); } @@ -489,6 +491,7 @@ TableBody.propTypes = { expandBy: PropTypes.string, expanding: PropTypes.array, onExpand: PropTypes.func, + onlyOneExpanding: PropTypes.bool, beforeShowError: PropTypes.func, keyBoardNav: PropTypes.oneOfType([ PropTypes.bool, PropTypes.object ]), x: PropTypes.number,