【问题标题】:use pagination with react-bootstrap table对 react-bootstrap 表使用分页
【发布时间】:2018-07-31 15:38:46
【问题描述】:

我正在使用 create-react-app 和 react-bootstrap 构建一个基本的 react 应用程序。我正在使用表格来显示来自 react-bootstrap https://react-bootstrap.github.io/components/table/ 的信息。我正在尝试让分页为表格工作,但我不确定如何绕过它来处理表格。以下是我的组件的代码 sn-p,我添加了 react-bootstrap 中的分页代码片段,它仅在底部显示分页页脚,但实际上并未对结果进行分页。 应用.js

import React, { Component } from 'react';
import Table from 'react-bootstrap/lib/Table';
import Pagination from 'react-bootstrap/lib/Pagination';

export class App extends Component {

renderList() {
  return(
    <Table striped hover bordered condensed>
      <thead>
        <tr>
          <th>Name</th>
          <th>Description</th>
          <th>Forks</th>
          <th>Clone URL</th>
        </tr>
      </thead>
      <tbody>
        {this.state.response.map((object) => {
          return (
            <tr>
              <td><a onClick={this.handleClick.bind(this,object)}>{object.name} </a></td>
              <td>{object.description}</td>
              <td><Glyphicon glyph="cutlery" /> {object.forks_count}</td>
              <td>{object.clone_url}</td>
            </tr>
          );
        })}
        </tbody>
      </Table>
    );
  }

  renderPagination() {
    let items = [];
    for (let number = 1; number <= 10; number++) {
      items.push(
       <Pagination.Item>{number}</Pagination.Item>
      );
    }
    return (
      <Pagination bsSize="small">{items}</Pagination>
    );
  }

  render() {
    return (
      <div className="App">
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h1 className="App-title">Netflix Repositories</h1>
        </header>
        {this.renderList()}
        <CommitList ref={(ref) => this.commitList = ref} 
          show={this.state.show}
          commits={this.state.commits} />
        {this.renderPagination()}
      </div>
    );
  }
}

如何对表格上的结果进行分页?

【问题讨论】:

    标签: reactjs react-bootstrap create-react-app


    【解决方案1】:

    两种处理方法:

    1. 仅使用前端分页:获取全部结果并将结果除以列表大小,例如 10,假设您总共有 50 个列表项,那么您有 50/10 == 5 页。为每个分页项添加一个“onClick”并更改您显示的页面。

    2. 同时使用前端和后端分页:仅获取结果的特定部分,并在前端进行处理。 (搜索 Spring JPA 分页了解更多详情。)

    【讨论】:

      猜你喜欢
      • 2018-06-13
      • 2020-04-17
      • 2020-05-11
      • 1970-01-01
      • 2020-01-12
      • 2021-01-25
      • 2021-06-09
      • 2021-12-30
      • 1970-01-01
      相关资源
      最近更新 更多