Skip to content

Commit

Permalink
fix #990
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenFang committed Feb 4, 2017
1 parent 6893be6 commit d31c71f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
37 changes: 28 additions & 9 deletions src/BootstrapTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,26 @@ class BootstrapTable extends Component {
* @return {Boolean}
*/
isRemoteDataSource(props) {
return (props || this.props).remote;
const { remote } = (props || this.props);
return remote === true || typeof remote === 'function';
}

/**
* Returns true if this action can be handled remote store
* From #990, Sometimes, we need some actions as remote, some actions are handled by default
* so function will tell you the target action is can be handled as remote or not.
* @param {String} [action] Required.
* @param {Object} [props] Optional. If not given, this.props will be used
* @return {Boolean}
*/
allowRemote(action, props) {
const { remote } = (props || this.props);
if (typeof remote === 'function') {
const remoteObj = remote(Const.REMOTE);
return remoteObj[action];
} else {
return remote;
}
}

render() {
Expand Down Expand Up @@ -411,7 +430,7 @@ class BootstrapTable extends Component {
this.props.options.onSortChange(sortField, order, this.props);
}
this.store.setSortInfo(order, sortField);
if (this.isRemoteDataSource()) {
if (this.allowRemote(Const.REMOTE_SORT)) {
return;
}

Expand Down Expand Up @@ -440,7 +459,7 @@ class BootstrapTable extends Component {
reset: false
});

if (this.isRemoteDataSource()) {
if (this.allowRemote(Const.REMOTE_PAGE)) {
return;
}

Expand Down Expand Up @@ -600,7 +619,7 @@ class BootstrapTable extends Component {
newVal = onCellEdit(this.state.data[rowIndex], fieldName, newVal);
}

if (this.isRemoteDataSource()) {
if (this.allowRemote(Const.REMOTE_CELL_EDIT)) {
if (afterSaveCell) {
afterSaveCell(this.state.data[rowIndex], fieldName, newVal);
}
Expand Down Expand Up @@ -634,7 +653,7 @@ class BootstrapTable extends Component {
onAddRow(newObj, colInfos);
}

if (this.isRemoteDataSource()) {
if (this.allowRemote(Const.REMOTE_INSERT_ROW)) {
if (this.props.options.afterInsertRow) {
this.props.options.afterInsertRow(newObj);
}
Expand Down Expand Up @@ -695,7 +714,7 @@ class BootstrapTable extends Component {

this.store.setSelectedRowKey([]); // clear selected row key

if (this.isRemoteDataSource()) {
if (this.allowRemote(Const.REMOTE_DROP_ROW)) {
if (this.props.options.afterDeleteRow) {
this.props.options.afterDeleteRow(dropRowKeys);
}
Expand Down Expand Up @@ -741,7 +760,7 @@ class BootstrapTable extends Component {
reset: false
});

if (this.isRemoteDataSource()) {
if (this.allowRemote(Const.REMOTE_FILTER)) {
if (this.props.options.afterColumnFilter) {
this.props.options.afterColumnFilter(filterObj, this.store.getDataIgnoringPagination());
}
Expand Down Expand Up @@ -825,7 +844,7 @@ class BootstrapTable extends Component {
reset: false
});

if (this.isRemoteDataSource()) {
if (this.allowRemote(Const.REMOTE_SEARCH)) {
if (this.props.options.afterSearch) {
this.props.options.afterSearch(searchText, this.store.getDataIgnoringPagination());
}
Expand Down Expand Up @@ -1104,7 +1123,7 @@ BootstrapTable.propTypes = {
height: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
maxHeight: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
data: PropTypes.oneOfType([ PropTypes.array, PropTypes.object ]),
remote: PropTypes.bool, // remote data, default is false
remote: PropTypes.oneOfType([ PropTypes.bool, PropTypes.func ]), // remote data, default is false
scrollTop: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
striped: PropTypes.bool,
bordered: PropTypes.bool,
Expand Down
24 changes: 22 additions & 2 deletions src/Const.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
const CONST_VAR = {
SORT_DESC: 'desc',
SORT_ASC: 'asc',
SIZE_PER_PAGE: 10,
Expand Down Expand Up @@ -39,5 +39,25 @@ export default {
FILTER_COND_LIKE: 'like',
EXPAND_BY_ROW: 'row',
EXPAND_BY_COL: 'column',
CANCEL_TOASTR: 'Pressed ESC can cancel'
CANCEL_TOASTR: 'Pressed ESC can cancel',
REMOTE_SORT: 'sort',
REMOTE_PAGE: 'pagination',
REMOTE_CELL_EDIT: 'cellEdit',
REMOTE_INSERT_ROW: 'insertRow',
REMOTE_DROP_ROW: 'dropRow',
REMOTE_FILTER: 'filter',
REMOTE_SEARCH: 'search',
REMOTE_EXPORT_CSV: 'exportCSV'
};

CONST_VAR.REMOTE = {};
CONST_VAR.REMOTE[CONST_VAR.REMOTE_SORT] = false;
CONST_VAR.REMOTE[CONST_VAR.REMOTE_PAGE] = false;
CONST_VAR.REMOTE[CONST_VAR.REMOTE_CELL_EDIT] = false;
CONST_VAR.REMOTE[CONST_VAR.REMOTE_INSERT_ROW] = false;
CONST_VAR.REMOTE[CONST_VAR.REMOTE_DROP_ROW] = false;
CONST_VAR.REMOTE[CONST_VAR.REMOTE_FILTER] = false;
CONST_VAR.REMOTE[CONST_VAR.REMOTE_SEARCH] = false;
CONST_VAR.REMOTE[CONST_VAR.REMOTE_EXPORT_CSV] = false;

export default CONST_VAR;

0 comments on commit d31c71f

Please sign in to comment.