File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed
packages/react-bootstrap-table2-filter Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -23,12 +23,14 @@ export default (Base, {
2323
2424 componentWillReceiveProps ( { isDataChanged, store, columns } ) {
2525 // consider to use lodash.isEqual
26- if ( JSON . stringify ( this . state . currFilters ) !== JSON . stringify ( store . filters ) ) {
26+ const isRemoteFilter = this . isRemoteFiltering ( ) || this . isRemotePagination ( ) ;
27+ if ( isRemoteFilter ||
28+ JSON . stringify ( this . state . currFilters ) !== JSON . stringify ( store . filters ) ) {
29+ // I think this condition only isRemoteFilter is enough
2730 store . filteredData = store . getAllData ( ) ;
2831 this . setState ( ( ) => ( { isDataChanged : true , currFilters : store . filters } ) ) ;
2932 } else if ( isDataChanged ) {
30- if ( ! ( this . isRemoteFiltering ( ) || this . isRemotePagination ( ) ) &&
31- Object . keys ( this . state . currFilters ) . length > 0 ) {
33+ if ( ! isRemoteFilter && Object . keys ( this . state . currFilters ) . length > 0 ) {
3234 store . filteredData = filters ( store , columns , _ ) ( this . state . currFilters ) ;
3335 }
3436 this . setState ( ( ) => ( { isDataChanged } ) ) ;
Original file line number Diff line number Diff line change @@ -133,6 +133,25 @@ describe('Wrapper', () => {
133133 expect ( instance . state . currFilters ) . toBe ( nextProps . store . filters ) ;
134134 } ) ;
135135 } ) ;
136+
137+ describe ( 'when remote filter is enabled' , ( ) => {
138+ let props ;
139+ const nextData = [ ] ;
140+
141+ beforeEach ( ( ) => {
142+ props = createTableProps ( { remote : { filter : true } } ) ;
143+ createFilterWrapper ( props ) ;
144+ nextProps = createTableProps ( { remote : { filter : true } } ) ;
145+ nextProps . store . setAllData ( nextData ) ;
146+ instance . componentWillReceiveProps ( nextProps ) ;
147+ } ) ;
148+
149+ it ( 'should setting states correctly' , ( ) => {
150+ expect ( nextProps . store . filteredData ) . toEqual ( nextData ) ;
151+ expect ( instance . state . isDataChanged ) . toBeTruthy ( ) ;
152+ expect ( instance . state . currFilters ) . toBe ( nextProps . store . filters ) ;
153+ } ) ;
154+ } ) ;
136155 } ) ;
137156
138157 describe ( 'onFilter' , ( ) => {
You can’t perform that action at this time.
0 commit comments