From 94f38f1b83aed8c1dd1f2cd31232d7dae348b6ca Mon Sep 17 00:00:00 2001 From: whien Date: Wed, 23 Mar 2016 10:20:55 +0800 Subject: [PATCH 1/2] improve the example about selection externally last page event issue --- .../js/selection/externally-managed-selection.js | 14 +++++++++++--- src/BootstrapTable.js | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/examples/js/selection/externally-managed-selection.js b/examples/js/selection/externally-managed-selection.js index 98effe8d2..bc2d677d6 100644 --- a/examples/js/selection/externally-managed-selection.js +++ b/examples/js/selection/externally-managed-selection.js @@ -23,14 +23,21 @@ export default class ExternallyManagedSelection extends React.Component { constructor(props) { super(props); this.state = { - selected: [] + selected: [], + currPage: 1 }; } render() { - const onRowSelect = ({ id }, isSelected) => { + const { + currPage + } = this.state; + const onRowSelect = ({ id }, isSelected, page) => { if (isSelected && this.state.selected.length !== 2) { - this.setState({ selected: [ ...this.state.selected, id ].sort() }); + this.setState({ + selected: [ ...this.state.selected, id ].sort(), + currPage: page + }); } else { this.setState({ selected: this.state.selected.filter(it => it !== id) }); } @@ -47,6 +54,7 @@ export default class ExternallyManagedSelection extends React.Component { const options = { sizePerPageList: [ 5, 10, 15, 20 ], sizePerPage: 10, + page: currPage, sortName: 'id', sortOrder: 'desc' }; diff --git a/src/BootstrapTable.js b/src/BootstrapTable.js index eabdb7cc2..ca1550e24 100644 --- a/src/BootstrapTable.js +++ b/src/BootstrapTable.js @@ -389,12 +389,15 @@ class BootstrapTable extends Component { } handleSelectRow = (row, isSelected) => { + const { + currPage + } = this.state; let result = true; let currSelected = this.store.getSelectedRowKeys(); const rowKey = row[ this.store.getKeyField() ]; const { selectRow } = this.props; if (selectRow.onSelect) { - result = selectRow.onSelect(row, isSelected); + result = selectRow.onSelect(row, isSelected, currPage); } if (typeof result === 'undefined' || result !== false) { From 8518d5ee9dc429d005ff72b7a2102a051c445cf7 Mon Sep 17 00:00:00 2001 From: whien Date: Wed, 23 Mar 2016 11:32:24 +0800 Subject: [PATCH 2/2] try the ref for table to get the correct page --- examples/js/selection/externally-managed-selection.js | 6 +++--- src/BootstrapTable.js | 5 +---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/examples/js/selection/externally-managed-selection.js b/examples/js/selection/externally-managed-selection.js index bc2d677d6..380508c05 100644 --- a/examples/js/selection/externally-managed-selection.js +++ b/examples/js/selection/externally-managed-selection.js @@ -32,11 +32,11 @@ export default class ExternallyManagedSelection extends React.Component { const { currPage } = this.state; - const onRowSelect = ({ id }, isSelected, page) => { + const onRowSelect = ({ id }, isSelected) => { if (isSelected && this.state.selected.length !== 2) { this.setState({ selected: [ ...this.state.selected, id ].sort(), - currPage: page + currPage: this.refs.table.state.currPage }); } else { this.setState({ selected: this.state.selected.filter(it => it !== id) }); @@ -60,7 +60,7 @@ export default class ExternallyManagedSelection extends React.Component { }; return ( - + Product ID Product Name Product Price diff --git a/src/BootstrapTable.js b/src/BootstrapTable.js index ca1550e24..eabdb7cc2 100644 --- a/src/BootstrapTable.js +++ b/src/BootstrapTable.js @@ -389,15 +389,12 @@ class BootstrapTable extends Component { } handleSelectRow = (row, isSelected) => { - const { - currPage - } = this.state; let result = true; let currSelected = this.store.getSelectedRowKeys(); const rowKey = row[ this.store.getKeyField() ]; const { selectRow } = this.props; if (selectRow.onSelect) { - result = selectRow.onSelect(row, isSelected, currPage); + result = selectRow.onSelect(row, isSelected); } if (typeof result === 'undefined' || result !== false) {