mirror of
https://github.com/gosticks/react-table.git
synced 2026-07-01 10:00:03 +00:00
Fix server-side pagination (#1894)
This commit is contained in:
@@ -20,4 +20,4 @@
|
||||
"test": "react-scripts test --env=jsdom",
|
||||
"eject": "react-scripts eject"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable react/no-did-update-set-state */
|
||||
import React, { Component } from 'react'
|
||||
import classnames from 'classnames'
|
||||
|
||||
@@ -71,6 +72,14 @@ export default class ReactTablePagination extends Component {
|
||||
page: this.props.page,
|
||||
})
|
||||
}
|
||||
/* when the last page from new props is smaller
|
||||
than the current page in the page box,
|
||||
the current page needs to be the last page. */
|
||||
if (this.props.pages !== prevProps.pages && this.props.pages <= this.state.page) {
|
||||
this.setState({
|
||||
page: this.props.pages - 1,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
getSafePage (page) {
|
||||
@@ -148,7 +157,7 @@ export default class ReactTablePagination extends Component {
|
||||
if (!canPrevious) return
|
||||
this.changePage(page - 1)
|
||||
}}
|
||||
disabled={!canPrevious}
|
||||
disabled={!canPrevious || this.state.page < 1}
|
||||
>
|
||||
{this.props.previousText}
|
||||
</PreviousComponent>
|
||||
@@ -160,13 +169,13 @@ export default class ReactTablePagination extends Component {
|
||||
{this.props.ofText} {renderTotalPagesCount(pages)}
|
||||
</span>
|
||||
{showPageSizeOptions &&
|
||||
renderPageSizeOptions({
|
||||
pageSize,
|
||||
rowsSelectorText: this.props.rowsSelectorText,
|
||||
pageSizeOptions,
|
||||
onPageSizeChange,
|
||||
rowsText: this.props.rowsText,
|
||||
})}
|
||||
renderPageSizeOptions({
|
||||
pageSize,
|
||||
rowsSelectorText: this.props.rowsSelectorText,
|
||||
pageSizeOptions,
|
||||
onPageSizeChange,
|
||||
rowsText: this.props.rowsText,
|
||||
})}
|
||||
</div>
|
||||
<div className="-next">
|
||||
<NextComponent
|
||||
@@ -174,7 +183,7 @@ export default class ReactTablePagination extends Component {
|
||||
if (!canNext) return
|
||||
this.changePage(page + 1)
|
||||
}}
|
||||
disabled={!canNext}
|
||||
disabled={!canNext || this.state.page >= this.props.pages - 1}
|
||||
>
|
||||
{this.props.nextText}
|
||||
</NextComponent>
|
||||
|
||||
Reference in New Issue
Block a user