将分页从“ react-js-pagination`转换为`react-bootstrap`分页

时间:2019-09-10 13:26:20

标签: javascript reactjs pagination react-bootstrap

我有一个现成的分页组件:https://www.npmjs.com/package/react-js-pagination

import React, { Component } from "react";
import ReactDOM from "react-dom";
import Pagination from "react-js-pagination";
require("bootstrap/less/bootstrap.less");

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      activePage: 1,
      todos: []
    };
  }

  handlePageChange(pageNumber) {
    console.log(`active page is ${pageNumber}`);
    this.setState({activePage: pageNumber});
  }

  render() {
    return (
      <div>
        <Pagination
          activePage={this.state.activePage}
          totalItemsCount={this.state.todos.length}
          pageRangeDisplayed={2}
          onChange={this.handlePageChange}
        />
      </div>
    );
  }
}

如何将分页从react-js-pagination转换为react-bootstrap分页https://react-bootstrap.github.io/components/pagination/

1 个答案:

答案 0 :(得分:8)

react-bootstrap分页只是一个UI组件,它呈现分页项并且无法处理react-js-pagination正在处理的内容。 react-js-pagination文档中提到,您可以导入自己的CSS样式并将这些类用于分页项。因此,仅导入bootstrap样式就足够了,然后您可以执行以下操作:

import "bootstrap/dist/css/bootstrap.min.css";

<ReactPagination
    itemClass="page-item"
    linkClass="page-link"
    hideNavigation
    activePage={2}
    itemsCountPerPage={10}
    totalItemsCount={450}
    pageRangeDisplayed={5}
/>

选中此代码和框:https://codesandbox.io/s/polished-darkness-pm7v8?fontsize=14