Skip to content

Commit f54ebc3

Browse files
committed
fix #1299
1 parent 61ff06b commit f54ebc3

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/BootstrapTable.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,11 @@ class BootstrapTable extends Component {
501501
});
502502
}
503503

504-
handleExpandRow = expanding => {
504+
handleExpandRow = (expanding, rowKey, isRowExpanding) => {
505+
const { onExpand } = this.props.options;
506+
if (onExpand) {
507+
onExpand(rowKey, !isRowExpanding);
508+
}
505509
this.setState({ expanding, reset: false }, () => {
506510
this._adjustHeaderWidth();
507511
});
@@ -1451,6 +1455,7 @@ BootstrapTable.propTypes = {
14511455
expandRowBgColor: PropTypes.string,
14521456
expandBy: PropTypes.string,
14531457
expanding: PropTypes.array,
1458+
onExpand: PropTypes.func,
14541459
onlyOneExpanding: PropTypes.bool,
14551460
beforeShowError: PropTypes.func,
14561461
printToolBar: PropTypes.bool
@@ -1598,6 +1603,7 @@ BootstrapTable.defaultProps = {
15981603
expandRowBgColor: undefined,
15991604
expandBy: Const.EXPAND_BY_ROW,
16001605
expanding: [],
1606+
onExpand: undefined,
16011607
onlyOneExpanding: false,
16021608
beforeShowError: undefined,
16031609
printToolBar: true

src/TableBody.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,17 @@ class TableBody extends Component {
316316
if configure as expanding by column */
317317
(expandBy === Const.EXPAND_BY_COL && columnIndex < 0) ||
318318
(expandBy === Const.EXPAND_BY_COL && columns[columnIndex].expandable))) {
319-
const rowKey = this.props.data[rowIndex - 1][keyField];
320319
let expanding = this.props.expanding;
321-
if (expanding.indexOf(rowKey) > -1) {
320+
const rowKey = this.props.data[rowIndex - 1][keyField];
321+
const isRowExpanding = expanding.indexOf(rowKey) > -1;
322+
323+
if (isRowExpanding) { // collapse
322324
expanding = expanding.filter(k => k !== rowKey);
323-
} else {
325+
} else { // expand
324326
if (onlyOneExpanding) expanding = [ rowKey ];
325327
else expanding.push(rowKey);
326328
}
327-
this.props.onExpand(expanding);
329+
this.props.onExpand(expanding, rowKey, isRowExpanding);
328330
}
329331
}
330332

0 commit comments

Comments
 (0)