Skip to content

Commit

Permalink
Move to last page only if row is added at the end, otherwise switch t…
Browse files Browse the repository at this point in the history
…o first page
  • Loading branch information
harshjv committed Nov 2, 2016
1 parent f14900e commit 3a4432a
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/BootstrapTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ class BootstrapTable extends Component {
} catch (e) {
return e;
}
this._handleAfterAddingRow(newObj);
this._handleAfterAddingRow(newObj, true);
}

handleAddRow = newObj => {
Expand All @@ -584,7 +584,7 @@ class BootstrapTable extends Component {
} catch (e) {
return e;
}
this._handleAfterAddingRow(newObj);
this._handleAfterAddingRow(newObj, false);
}

getSizePerPage() {
Expand Down Expand Up @@ -961,17 +961,29 @@ class BootstrapTable extends Component {
}
}

_handleAfterAddingRow(newObj) {
_handleAfterAddingRow(newObj, atTheBeginning) {
let result;
if (this.props.pagination) {
// if pagination is enabled and insert row be trigger, change to last page
// if pagination is enabled and inserting row at the end,
// change page to the last page
// otherwise, change it to the first page
const { sizePerPage } = this.state;
const currLastPage = Math.ceil(this.store.getDataNum() / sizePerPage);
result = this.store.page(currLastPage, sizePerPage).get();
this.setState({
data: result,
currPage: currLastPage
});

if (atTheBeginning) {
const firstPage = 1;
result = this.store.page(firstPage, sizePerPage).get();
this.setState({
data: result,
currPage: firstPage
});
} else {
const currLastPage = Math.ceil(this.store.getDataNum() / sizePerPage);
result = this.store.page(currLastPage, sizePerPage).get();
this.setState({
data: result,
currPage: currLastPage
});
}
} else {
result = this.store.get();
this.setState({
Expand Down

0 comments on commit 3a4432a

Please sign in to comment.