diff --git a/src/BootstrapTable.js b/src/BootstrapTable.js index d66e7de4a..6b63b0ac7 100644 --- a/src/BootstrapTable.js +++ b/src/BootstrapTable.js @@ -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() { @@ -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; } @@ -440,7 +459,7 @@ class BootstrapTable extends Component { reset: false }); - if (this.isRemoteDataSource()) { + if (this.allowRemote(Const.REMOTE_PAGE)) { return; } @@ -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); } @@ -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); } @@ -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); } @@ -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()); } @@ -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()); } @@ -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, diff --git a/src/Const.js b/src/Const.js index 3a4bed15c..e70668fa8 100644 --- a/src/Const.js +++ b/src/Const.js @@ -1,4 +1,4 @@ -export default { +const CONST_VAR = { SORT_DESC: 'desc', SORT_ASC: 'asc', SIZE_PER_PAGE: 10, @@ -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;