Skip to content

Commit 4c89f91

Browse files
committed
implement remote resolver
1 parent 90bea38 commit 4c89f91

File tree

2 files changed

+39
-26
lines changed

2 files changed

+39
-26
lines changed

packages/react-bootstrap-table2/src/container.js

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,22 @@ import {
1111
wrapWithPagination
1212
} from './table-factory';
1313

14+
import remoteResolver from './props-resolver/remote-resolver';
1415
import _ from './utils';
1516

1617
const withDataStore = Base =>
17-
class BootstrapTableContainer extends Component {
18+
class BootstrapTableContainer extends remoteResolver(Component) {
1819
constructor(props) {
1920
super(props);
2021
this.store = new Store(props.keyField);
2122
this.store.data = props.data;
2223
this.handleUpdateCell = this.handleUpdateCell.bind(this);
23-
this.handleRemotePageChange = this.handleRemotePageChange.bind(this);
24-
this.handleRemoteFilterChange = this.handleRemoteFilterChange.bind(this);
2524
}
2625

2726
componentWillReceiveProps(nextProps) {
2827
this.store.data = nextProps.data;
2928
}
3029

31-
getNewestState(state = {}) {
32-
return {
33-
page: this.store.page,
34-
sizePerPage: this.store.sizePerPage,
35-
filters: this.store.filters,
36-
...state
37-
};
38-
}
39-
40-
handleRemotePageChange() {
41-
this.props.onTableChange('pagination', this.getNewestState());
42-
}
43-
44-
// refactoring later for isRemotePagination
45-
handleRemoteFilterChange(isRemotePagination) {
46-
const newState = {};
47-
if (isRemotePagination) {
48-
const options = this.props.pagination.options || {};
49-
newState.page = _.isDefined(options.pageStartIndex) ? options.pageStartIndex : 1;
50-
}
51-
this.props.onTableChange('filter', this.getNewestState(newState));
52-
}
53-
5430
handleUpdateCell(rowId, dataField, newValue) {
5531
const { cellEdit } = this.props;
5632
// handle cell editing internal
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import _ from '../utils';
2+
3+
export default ExtendBase =>
4+
class RemoteResolver extends ExtendBase {
5+
getNewestState(state = {}) {
6+
const store = this.store || this.props.store;
7+
return {
8+
page: store.page,
9+
sizePerPage: store.sizePerPage,
10+
filters: store.filters,
11+
...state
12+
};
13+
}
14+
15+
isRemotePagination() {
16+
const { remote } = this.props;
17+
return remote === true || (_.isObject(remote) && remote.pagination);
18+
}
19+
20+
isRemoteFiltering() {
21+
const { remote } = this.props;
22+
return remote === true || (_.isObject(remote) && remote.filter);
23+
}
24+
25+
handleRemotePageChange() {
26+
this.props.onTableChange('pagination', this.getNewestState());
27+
}
28+
29+
handleRemoteFilterChange() {
30+
const newState = {};
31+
if (this.isRemotePagination()) {
32+
const options = this.props.pagination.options || {};
33+
newState.page = _.isDefined(options.pageStartIndex) ? options.pageStartIndex : 1;
34+
}
35+
this.props.onTableChange('filter', this.getNewestState(newState));
36+
}
37+
};

0 commit comments

Comments
 (0)