next page and previous page not working in react-bootstrap-table2-paginator

╄→гoц情女王★ 提交于 2020-06-27 03:59:09

问题


I have implemented table with pagination using react-bootstrap-table2-paginator. on each pagenumber click it will call api and fetch table date. It works but nextpage,prevpage and last page was not working.

I have used pageButtonRenderer, also everything working but next page and previous page , last page not working.

class TableData extends React.PureComponent {
  constructor(props) {
    super(props);
    this.state={  page: 1,
      sizePerPage: 10};
  }
  render() {
    const pageButtonRenderer = ({
      page,
      currentPage,
      disabled,
      title,
      onPageChange
    }) => {
      const handleClick = (e) => {
        e.preventDefault();
        if(typeof page !== "string" ){
         this.setState({ page: page});
         this.props.pageClick(page, this.state.sizePerPage);// api call 
        }
       };    
      return (
        <div>
          {
           <li className="page-item">
             <a href="#"  onClick={ handleClick } className="page-link">{ page }</a>
           </li>
          }
        </div>
      );
    };
    const sizePerPageRenderer = ({
      options,
      currSizePerPage,
      onSizePerPageChange
    }) => (
      <div className="btn-group" role="group">
        {options.map(option => (
            <button
              key={option.text}
                 type="submit"
              onClick={(e) => {
                onSizePerPageChange(option.page);
                if (e) e.preventDefault();
              }}
              className={`btn ${
                currSizePerPage === `${option.page}`
                  ? "btn-secondary"
                  : "btn-warning"
              }`}
            >
              {option.text}
            </button>
          ))}
      </div>
    );
    const options = {
      sizePerPageRenderer,
      totalSize: 1000,
      pageButtonRenderer,
      onSizePerPageChange: (sizePerPage, page) => {
        this.setState({sizePerPage: sizePerPage},()=>{
         this.props.pageClick(page,sizePerPage);
        });
      }
    };
    return (
      <div className="table-wrapper">
        <BootstrapTable
          pagination={paginationFactory(options)}
          options={options}
          keyField="id"
          data={rows}
          columns={columns}
        />
      </div>
    );
  }
}
export default TableData;


回答1:


You will need to call onPageChange(page) in your handleClick

     const handleClick = (e) => {
        e.preventDefault();
        if(typeof page !== "string" ){
         this.setState({ page: page});
         this.props.pageClick(page, this.state.sizePerPage);// api call 
         onPageChange(page); <------ here
        }
       };

See here



来源:https://stackoverflow.com/questions/61789032/next-page-and-previous-page-not-working-in-react-bootstrap-table2-paginator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!