@@ -568,20 +568,30 @@ class BootstrapTable extends Component {
568
568
}
569
569
570
570
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 ) ;
573
574
}
574
575
this . store . setSortInfo ( order , sortField ) ;
575
576
if ( this . allowRemote ( Const . REMOTE_SORT ) ) {
577
+ if ( sort ) {
578
+ this . setState ( ( ) => {
579
+ return {
580
+ expanding : [ ]
581
+ } ;
582
+ } ) ;
583
+ }
576
584
return ;
577
585
}
578
586
579
587
const result = this . store . sort ( ) . get ( ) ;
580
588
this . setState ( ( ) => {
581
- return {
589
+ const newState = {
582
590
data : result ,
583
591
reset : false
584
592
} ;
593
+ if ( sort ) newState . expanding = [ ] ;
594
+ return newState ;
585
595
} ) ;
586
596
}
587
597
@@ -1039,17 +1049,20 @@ class BootstrapTable extends Component {
1039
1049
}
1040
1050
1041
1051
handleFilterData = filterObj => {
1042
- const { onFilterChange, pageStartIndex } = this . props . options ;
1052
+ const { autoCollapse : { filter } , options } = this . props ;
1053
+ const { onFilterChange, pageStartIndex } = options ;
1043
1054
if ( onFilterChange ) {
1044
1055
const colInfos = this . store . getColInfos ( ) ;
1045
1056
onFilterChange ( filterObj , colInfos ) ;
1046
1057
}
1047
1058
1048
1059
this . setState ( ( ) => {
1049
- return {
1060
+ const newState = {
1050
1061
currPage : Util . getFirstPage ( pageStartIndex ) ,
1051
1062
reset : false
1052
1063
} ;
1064
+ if ( filter ) newState . expanding = [ ] ;
1065
+ return newState ;
1053
1066
} ) ;
1054
1067
1055
1068
if ( this . allowRemote ( Const . REMOTE_FILTER ) ) {
@@ -1129,17 +1142,20 @@ class BootstrapTable extends Component {
1129
1142
if ( this . refs . toolbar ) {
1130
1143
this . refs . toolbar . setSearchInput ( searchText ) ;
1131
1144
}
1145
+ const { autoCollapse : { search } } = this . props ;
1132
1146
const { onSearchChange, pageStartIndex } = this . props . options ;
1133
1147
if ( onSearchChange ) {
1134
1148
const colInfos = this . store . getColInfos ( ) ;
1135
1149
onSearchChange ( searchText , colInfos , this . props . multiColumnSearch ) ;
1136
1150
}
1137
1151
1138
1152
this . setState ( ( ) => {
1139
- return {
1153
+ const newState = {
1140
1154
currPage : Util . getFirstPage ( pageStartIndex ) ,
1141
1155
reset : false
1142
1156
} ;
1157
+ if ( search ) newState . expanding = [ ] ;
1158
+ return newState ;
1143
1159
} ) ;
1144
1160
1145
1161
if ( this . allowRemote ( Const . REMOTE_SEARCH ) ) {
@@ -1635,6 +1651,11 @@ BootstrapTable.propTypes = {
1635
1651
ignoreSinglePage : PropTypes . bool ,
1636
1652
expandableRow : PropTypes . func ,
1637
1653
expandComponent : PropTypes . func ,
1654
+ autoCollapse : PropTypes . shape ( {
1655
+ sort : PropTypes . bool ,
1656
+ filter : PropTypes . bool ,
1657
+ search : PropTypes . bool
1658
+ } ) ,
1638
1659
expandColumnOptions : PropTypes . shape ( {
1639
1660
columnWidth : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . string ] ) ,
1640
1661
expandColumnVisible : PropTypes . bool ,
@@ -1791,7 +1812,12 @@ BootstrapTable.defaultProps = {
1791
1812
} ,
1792
1813
exportCSV : false ,
1793
1814
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
+ }
1795
1821
} ;
1796
1822
1797
1823
export default BootstrapTable ;
0 commit comments