mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-07-01 14:40:02 +00:00
implement remote resolver
This commit is contained in:
28
packages/react-bootstrap-table2/src/container.js
vendored
28
packages/react-bootstrap-table2/src/container.js
vendored
@@ -11,46 +11,22 @@ import {
|
||||
wrapWithPagination
|
||||
} from './table-factory';
|
||||
|
||||
import remoteResolver from './props-resolver/remote-resolver';
|
||||
import _ from './utils';
|
||||
|
||||
const withDataStore = Base =>
|
||||
class BootstrapTableContainer extends Component {
|
||||
class BootstrapTableContainer extends remoteResolver(Component) {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.store = new Store(props.keyField);
|
||||
this.store.data = props.data;
|
||||
this.handleUpdateCell = this.handleUpdateCell.bind(this);
|
||||
this.handleRemotePageChange = this.handleRemotePageChange.bind(this);
|
||||
this.handleRemoteFilterChange = this.handleRemoteFilterChange.bind(this);
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
this.store.data = nextProps.data;
|
||||
}
|
||||
|
||||
getNewestState(state = {}) {
|
||||
return {
|
||||
page: this.store.page,
|
||||
sizePerPage: this.store.sizePerPage,
|
||||
filters: this.store.filters,
|
||||
...state
|
||||
};
|
||||
}
|
||||
|
||||
handleRemotePageChange() {
|
||||
this.props.onTableChange('pagination', this.getNewestState());
|
||||
}
|
||||
|
||||
// refactoring later for isRemotePagination
|
||||
handleRemoteFilterChange(isRemotePagination) {
|
||||
const newState = {};
|
||||
if (isRemotePagination) {
|
||||
const options = this.props.pagination.options || {};
|
||||
newState.page = _.isDefined(options.pageStartIndex) ? options.pageStartIndex : 1;
|
||||
}
|
||||
this.props.onTableChange('filter', this.getNewestState(newState));
|
||||
}
|
||||
|
||||
handleUpdateCell(rowId, dataField, newValue) {
|
||||
const { cellEdit } = this.props;
|
||||
// handle cell editing internal
|
||||
|
||||
37
packages/react-bootstrap-table2/src/props-resolver/remote-resolver.js
vendored
Normal file
37
packages/react-bootstrap-table2/src/props-resolver/remote-resolver.js
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import _ from '../utils';
|
||||
|
||||
export default ExtendBase =>
|
||||
class RemoteResolver extends ExtendBase {
|
||||
getNewestState(state = {}) {
|
||||
const store = this.store || this.props.store;
|
||||
return {
|
||||
page: store.page,
|
||||
sizePerPage: store.sizePerPage,
|
||||
filters: store.filters,
|
||||
...state
|
||||
};
|
||||
}
|
||||
|
||||
isRemotePagination() {
|
||||
const { remote } = this.props;
|
||||
return remote === true || (_.isObject(remote) && remote.pagination);
|
||||
}
|
||||
|
||||
isRemoteFiltering() {
|
||||
const { remote } = this.props;
|
||||
return remote === true || (_.isObject(remote) && remote.filter);
|
||||
}
|
||||
|
||||
handleRemotePageChange() {
|
||||
this.props.onTableChange('pagination', this.getNewestState());
|
||||
}
|
||||
|
||||
handleRemoteFilterChange() {
|
||||
const newState = {};
|
||||
if (this.isRemotePagination()) {
|
||||
const options = this.props.pagination.options || {};
|
||||
newState.page = _.isDefined(options.pageStartIndex) ? options.pageStartIndex : 1;
|
||||
}
|
||||
this.props.onTableChange('filter', this.getNewestState(newState));
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user