Skip to content

Commit 5ad7a75

Browse files
committed
fix #1586
1 parent f82ed35 commit 5ad7a75

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

src/BootstrapTable.js

+33-7
Original file line numberDiff line numberDiff line change
@@ -568,20 +568,30 @@ class BootstrapTable extends Component {
568568
}
569569

570570
handleSort = (order, sortField) => {
571-
if (this.props.options.onSortChange) {
572-
this.props.options.onSortChange(sortField, order, this.props);
571+
const { autoCollapse: { sort }, options } = this.props;
572+
if (options.onSortChange) {
573+
options.onSortChange(sortField, order, this.props);
573574
}
574575
this.store.setSortInfo(order, sortField);
575576
if (this.allowRemote(Const.REMOTE_SORT)) {
577+
if (sort) {
578+
this.setState(() => {
579+
return {
580+
expanding: []
581+
};
582+
});
583+
}
576584
return;
577585
}
578586

579587
const result = this.store.sort().get();
580588
this.setState(() => {
581-
return {
589+
const newState = {
582590
data: result,
583591
reset: false
584592
};
593+
if (sort) newState.expanding = [];
594+
return newState;
585595
});
586596
}
587597

@@ -1039,17 +1049,20 @@ class BootstrapTable extends Component {
10391049
}
10401050

10411051
handleFilterData = filterObj => {
1042-
const { onFilterChange, pageStartIndex } = this.props.options;
1052+
const { autoCollapse: { filter }, options } = this.props;
1053+
const { onFilterChange, pageStartIndex } = options;
10431054
if (onFilterChange) {
10441055
const colInfos = this.store.getColInfos();
10451056
onFilterChange(filterObj, colInfos);
10461057
}
10471058

10481059
this.setState(() => {
1049-
return {
1060+
const newState = {
10501061
currPage: Util.getFirstPage(pageStartIndex),
10511062
reset: false
10521063
};
1064+
if (filter) newState.expanding = [];
1065+
return newState;
10531066
});
10541067

10551068
if (this.allowRemote(Const.REMOTE_FILTER)) {
@@ -1129,17 +1142,20 @@ class BootstrapTable extends Component {
11291142
if (this.refs.toolbar) {
11301143
this.refs.toolbar.setSearchInput(searchText);
11311144
}
1145+
const { autoCollapse: { search } } = this.props;
11321146
const { onSearchChange, pageStartIndex } = this.props.options;
11331147
if (onSearchChange) {
11341148
const colInfos = this.store.getColInfos();
11351149
onSearchChange(searchText, colInfos, this.props.multiColumnSearch);
11361150
}
11371151

11381152
this.setState(() => {
1139-
return {
1153+
const newState = {
11401154
currPage: Util.getFirstPage(pageStartIndex),
11411155
reset: false
11421156
};
1157+
if (search) newState.expanding = [];
1158+
return newState;
11431159
});
11441160

11451161
if (this.allowRemote(Const.REMOTE_SEARCH)) {
@@ -1635,6 +1651,11 @@ BootstrapTable.propTypes = {
16351651
ignoreSinglePage: PropTypes.bool,
16361652
expandableRow: PropTypes.func,
16371653
expandComponent: PropTypes.func,
1654+
autoCollapse: PropTypes.shape({
1655+
sort: PropTypes.bool,
1656+
filter: PropTypes.bool,
1657+
search: PropTypes.bool
1658+
}),
16381659
expandColumnOptions: PropTypes.shape({
16391660
columnWidth: PropTypes.oneOfType([ PropTypes.number, PropTypes.string ]),
16401661
expandColumnVisible: PropTypes.bool,
@@ -1791,7 +1812,12 @@ BootstrapTable.defaultProps = {
17911812
},
17921813
exportCSV: false,
17931814
csvFileName: 'spreadsheet.csv',
1794-
ignoreSinglePage: false
1815+
ignoreSinglePage: false,
1816+
autoCollapse: {
1817+
sort: Const.AUTO_COLLAPSE_WHEN_SORT,
1818+
filter: Const.AUTO_COLLAPSE_WHEN_FILTER,
1819+
search: Const.AUTO_COLLAPSE_WHEN_SEARCH
1820+
}
17951821
};
17961822

17971823
export default BootstrapTable;

src/Const.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ const CONST_VAR = {
6262
INSERT_FAIL_INDICATOR: 'Validation errors, please check!',
6363
DEFAULT_CSV_SEPARATOR: ',',
6464
CSV_STRING_TYPE: 'string',
65-
CSV_NUMBER_TYPE: 'number'
65+
CSV_NUMBER_TYPE: 'number',
66+
AUTO_COLLAPSE_WHEN_SORT: false,
67+
AUTO_COLLAPSE_WHEN_SEARCH: false,
68+
AUTO_COLLAPSE_WHEN_FILTER: false
6669
};
6770

6871
CONST_VAR.REMOTE = {};

0 commit comments

Comments
 (0)