Skip to content

Commit d31c71f

Browse files
committed
fix #990
1 parent 6893be6 commit d31c71f

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

src/BootstrapTable.js

+28-9
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,26 @@ class BootstrapTable extends Component {
287287
* @return {Boolean}
288288
*/
289289
isRemoteDataSource(props) {
290-
return (props || this.props).remote;
290+
const { remote } = (props || this.props);
291+
return remote === true || typeof remote === 'function';
292+
}
293+
294+
/**
295+
* Returns true if this action can be handled remote store
296+
* From #990, Sometimes, we need some actions as remote, some actions are handled by default
297+
* so function will tell you the target action is can be handled as remote or not.
298+
* @param {String} [action] Required.
299+
* @param {Object} [props] Optional. If not given, this.props will be used
300+
* @return {Boolean}
301+
*/
302+
allowRemote(action, props) {
303+
const { remote } = (props || this.props);
304+
if (typeof remote === 'function') {
305+
const remoteObj = remote(Const.REMOTE);
306+
return remoteObj[action];
307+
} else {
308+
return remote;
309+
}
291310
}
292311

293312
render() {
@@ -411,7 +430,7 @@ class BootstrapTable extends Component {
411430
this.props.options.onSortChange(sortField, order, this.props);
412431
}
413432
this.store.setSortInfo(order, sortField);
414-
if (this.isRemoteDataSource()) {
433+
if (this.allowRemote(Const.REMOTE_SORT)) {
415434
return;
416435
}
417436

@@ -440,7 +459,7 @@ class BootstrapTable extends Component {
440459
reset: false
441460
});
442461

443-
if (this.isRemoteDataSource()) {
462+
if (this.allowRemote(Const.REMOTE_PAGE)) {
444463
return;
445464
}
446465

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

603-
if (this.isRemoteDataSource()) {
622+
if (this.allowRemote(Const.REMOTE_CELL_EDIT)) {
604623
if (afterSaveCell) {
605624
afterSaveCell(this.state.data[rowIndex], fieldName, newVal);
606625
}
@@ -634,7 +653,7 @@ class BootstrapTable extends Component {
634653
onAddRow(newObj, colInfos);
635654
}
636655

637-
if (this.isRemoteDataSource()) {
656+
if (this.allowRemote(Const.REMOTE_INSERT_ROW)) {
638657
if (this.props.options.afterInsertRow) {
639658
this.props.options.afterInsertRow(newObj);
640659
}
@@ -695,7 +714,7 @@ class BootstrapTable extends Component {
695714

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

698-
if (this.isRemoteDataSource()) {
717+
if (this.allowRemote(Const.REMOTE_DROP_ROW)) {
699718
if (this.props.options.afterDeleteRow) {
700719
this.props.options.afterDeleteRow(dropRowKeys);
701720
}
@@ -741,7 +760,7 @@ class BootstrapTable extends Component {
741760
reset: false
742761
});
743762

744-
if (this.isRemoteDataSource()) {
763+
if (this.allowRemote(Const.REMOTE_FILTER)) {
745764
if (this.props.options.afterColumnFilter) {
746765
this.props.options.afterColumnFilter(filterObj, this.store.getDataIgnoringPagination());
747766
}
@@ -825,7 +844,7 @@ class BootstrapTable extends Component {
825844
reset: false
826845
});
827846

828-
if (this.isRemoteDataSource()) {
847+
if (this.allowRemote(Const.REMOTE_SEARCH)) {
829848
if (this.props.options.afterSearch) {
830849
this.props.options.afterSearch(searchText, this.store.getDataIgnoringPagination());
831850
}
@@ -1104,7 +1123,7 @@ BootstrapTable.propTypes = {
11041123
height: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
11051124
maxHeight: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
11061125
data: PropTypes.oneOfType([ PropTypes.array, PropTypes.object ]),
1107-
remote: PropTypes.bool, // remote data, default is false
1126+
remote: PropTypes.oneOfType([ PropTypes.bool, PropTypes.func ]), // remote data, default is false
11081127
scrollTop: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
11091128
striped: PropTypes.bool,
11101129
bordered: PropTypes.bool,

src/Const.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default {
1+
const CONST_VAR = {
22
SORT_DESC: 'desc',
33
SORT_ASC: 'asc',
44
SIZE_PER_PAGE: 10,
@@ -39,5 +39,25 @@ export default {
3939
FILTER_COND_LIKE: 'like',
4040
EXPAND_BY_ROW: 'row',
4141
EXPAND_BY_COL: 'column',
42-
CANCEL_TOASTR: 'Pressed ESC can cancel'
42+
CANCEL_TOASTR: 'Pressed ESC can cancel',
43+
REMOTE_SORT: 'sort',
44+
REMOTE_PAGE: 'pagination',
45+
REMOTE_CELL_EDIT: 'cellEdit',
46+
REMOTE_INSERT_ROW: 'insertRow',
47+
REMOTE_DROP_ROW: 'dropRow',
48+
REMOTE_FILTER: 'filter',
49+
REMOTE_SEARCH: 'search',
50+
REMOTE_EXPORT_CSV: 'exportCSV'
4351
};
52+
53+
CONST_VAR.REMOTE = {};
54+
CONST_VAR.REMOTE[CONST_VAR.REMOTE_SORT] = false;
55+
CONST_VAR.REMOTE[CONST_VAR.REMOTE_PAGE] = false;
56+
CONST_VAR.REMOTE[CONST_VAR.REMOTE_CELL_EDIT] = false;
57+
CONST_VAR.REMOTE[CONST_VAR.REMOTE_INSERT_ROW] = false;
58+
CONST_VAR.REMOTE[CONST_VAR.REMOTE_DROP_ROW] = false;
59+
CONST_VAR.REMOTE[CONST_VAR.REMOTE_FILTER] = false;
60+
CONST_VAR.REMOTE[CONST_VAR.REMOTE_SEARCH] = false;
61+
CONST_VAR.REMOTE[CONST_VAR.REMOTE_EXPORT_CSV] = false;
62+
63+
export default CONST_VAR;

0 commit comments

Comments
 (0)