mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-08-12 04:00:16 +00:00
fix bug when remote pagination have same filter conds but change pages will cause data doesnt reflect
This commit is contained in:
+5
-3
@@ -23,12 +23,14 @@ export default (Base, {
|
||||
|
||||
componentWillReceiveProps({ isDataChanged, store, columns }) {
|
||||
// consider to use lodash.isEqual
|
||||
if (JSON.stringify(this.state.currFilters) !== JSON.stringify(store.filters)) {
|
||||
const isRemoteFilter = this.isRemoteFiltering() || this.isRemotePagination();
|
||||
if (isRemoteFilter ||
|
||||
JSON.stringify(this.state.currFilters) !== JSON.stringify(store.filters)) {
|
||||
// I think this condition only isRemoteFilter is enough
|
||||
store.filteredData = store.getAllData();
|
||||
this.setState(() => ({ isDataChanged: true, currFilters: store.filters }));
|
||||
} else if (isDataChanged) {
|
||||
if (!(this.isRemoteFiltering() || this.isRemotePagination()) &&
|
||||
Object.keys(this.state.currFilters).length > 0) {
|
||||
if (!isRemoteFilter && Object.keys(this.state.currFilters).length > 0) {
|
||||
store.filteredData = filters(store, columns, _)(this.state.currFilters);
|
||||
}
|
||||
this.setState(() => ({ isDataChanged }));
|
||||
|
||||
@@ -133,6 +133,25 @@ describe('Wrapper', () => {
|
||||
expect(instance.state.currFilters).toBe(nextProps.store.filters);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when remote filter is enabled', () => {
|
||||
let props;
|
||||
const nextData = [];
|
||||
|
||||
beforeEach(() => {
|
||||
props = createTableProps({ remote: { filter: true } });
|
||||
createFilterWrapper(props);
|
||||
nextProps = createTableProps({ remote: { filter: true } });
|
||||
nextProps.store.setAllData(nextData);
|
||||
instance.componentWillReceiveProps(nextProps);
|
||||
});
|
||||
|
||||
it('should setting states correctly', () => {
|
||||
expect(nextProps.store.filteredData).toEqual(nextData);
|
||||
expect(instance.state.isDataChanged).toBeTruthy();
|
||||
expect(instance.state.currFilters).toBe(nextProps.store.filters);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('onFilter', () => {
|
||||
|
||||
Reference in New Issue
Block a user