Skip to content

Commit

Permalink
fix #1586
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenFang committed Sep 20, 2017
1 parent f82ed35 commit 5ad7a75
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
40 changes: 33 additions & 7 deletions src/BootstrapTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,20 +568,30 @@ class BootstrapTable extends Component {
}

handleSort = (order, sortField) => {
if (this.props.options.onSortChange) {
this.props.options.onSortChange(sortField, order, this.props);
const { autoCollapse: { sort }, options } = this.props;
if (options.onSortChange) {
options.onSortChange(sortField, order, this.props);
}
this.store.setSortInfo(order, sortField);
if (this.allowRemote(Const.REMOTE_SORT)) {
if (sort) {
this.setState(() => {
return {
expanding: []
};
});
}
return;
}

const result = this.store.sort().get();
this.setState(() => {
return {
const newState = {
data: result,
reset: false
};
if (sort) newState.expanding = [];
return newState;
});
}

Expand Down Expand Up @@ -1039,17 +1049,20 @@ class BootstrapTable extends Component {
}

handleFilterData = filterObj => {
const { onFilterChange, pageStartIndex } = this.props.options;
const { autoCollapse: { filter }, options } = this.props;
const { onFilterChange, pageStartIndex } = options;
if (onFilterChange) {
const colInfos = this.store.getColInfos();
onFilterChange(filterObj, colInfos);
}

this.setState(() => {
return {
const newState = {
currPage: Util.getFirstPage(pageStartIndex),
reset: false
};
if (filter) newState.expanding = [];
return newState;
});

if (this.allowRemote(Const.REMOTE_FILTER)) {
Expand Down Expand Up @@ -1129,17 +1142,20 @@ class BootstrapTable extends Component {
if (this.refs.toolbar) {
this.refs.toolbar.setSearchInput(searchText);
}
const { autoCollapse: { search } } = this.props;
const { onSearchChange, pageStartIndex } = this.props.options;
if (onSearchChange) {
const colInfos = this.store.getColInfos();
onSearchChange(searchText, colInfos, this.props.multiColumnSearch);
}

this.setState(() => {
return {
const newState = {
currPage: Util.getFirstPage(pageStartIndex),
reset: false
};
if (search) newState.expanding = [];
return newState;
});

if (this.allowRemote(Const.REMOTE_SEARCH)) {
Expand Down Expand Up @@ -1635,6 +1651,11 @@ BootstrapTable.propTypes = {
ignoreSinglePage: PropTypes.bool,
expandableRow: PropTypes.func,
expandComponent: PropTypes.func,
autoCollapse: PropTypes.shape({
sort: PropTypes.bool,
filter: PropTypes.bool,
search: PropTypes.bool
}),
expandColumnOptions: PropTypes.shape({
columnWidth: PropTypes.oneOfType([ PropTypes.number, PropTypes.string ]),
expandColumnVisible: PropTypes.bool,
Expand Down Expand Up @@ -1791,7 +1812,12 @@ BootstrapTable.defaultProps = {
},
exportCSV: false,
csvFileName: 'spreadsheet.csv',
ignoreSinglePage: false
ignoreSinglePage: false,
autoCollapse: {
sort: Const.AUTO_COLLAPSE_WHEN_SORT,
filter: Const.AUTO_COLLAPSE_WHEN_FILTER,
search: Const.AUTO_COLLAPSE_WHEN_SEARCH
}
};

export default BootstrapTable;
5 changes: 4 additions & 1 deletion src/Const.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ const CONST_VAR = {
INSERT_FAIL_INDICATOR: 'Validation errors, please check!',
DEFAULT_CSV_SEPARATOR: ',',
CSV_STRING_TYPE: 'string',
CSV_NUMBER_TYPE: 'number'
CSV_NUMBER_TYPE: 'number',
AUTO_COLLAPSE_WHEN_SORT: false,
AUTO_COLLAPSE_WHEN_SEARCH: false,
AUTO_COLLAPSE_WHEN_FILTER: false
};

CONST_VAR.REMOTE = {};
Expand Down

0 comments on commit 5ad7a75

Please sign in to comment.