我试图在react表中单击“下一步”时获取当前的pageNumber,但是看不到当前的页码。
<div className="article_full">
<h2>DETAILS</h2>
<ReactTable filterable columns= .
{this.getTableColumns()} data={items} pagination={true} onChange={this.onPageChange}/>
</div>
onPageChange(pagination, filters, sorter) {
//projectId = this.props.match.params;
alert(pagination.current)
}
答案 0 :(得分:0)
您正在调用ReactTable组件上的错误的受控状态回调。尝试调用onChange
而不是onPageChange
:
<div className="article_full">
<h2>DETAILS</h2>
<ReactTable
filterable
columns={this.getTableColumns()}
data={items}
pagination={true}
onPageChange={this.onPageChange}/>
</div>
onPageChange(pageIndex) {
alert(pageIndex);
}
您可以使用此working example on codesandbox
进行测试基于react-table documentation的可能的回调列表:
// Callbacks
onPageChange={(pageIndex) => {...}} // Called when the page index is changed by the user
onPageSizeChange={(pageSize, pageIndex) => {...}} // Called when the pageSize is changed by the user. The resolve page is also sent to maintain approximate position in the data
onSortedChange={(newSorted, column, shiftKey) => {...}} // Called when a sortable column header is clicked with the column itself and if the shiftkey was held. If the column is a pivoted column, `column` will be an array of columns
onExpandedChange={(newExpanded, index, event) => {...}} // Called when an expander is clicked. Use this to manage `expanded`
onFilteredChange={(filtered, column) => {...}} // Called when a user enters a value into a filter input field or the value passed to the onFiltersChange handler by the Filter option.
onResizedChange={(newResized, event) => {...}} // Called when a user clicks on a resizing component (the right edge of a column header)