reactjs - 从 React Bootstrap 表中禁用/删除分页编号

标签 reactjs bootstrap-4 pagination react-bootstrap-table

我想从分页中删除所有数字(1,2,...,n)。我只想显示上一个、第一个、下一个最后一个按钮。

这是使用react-bootstrap-table创建的Table组件。

附带的代码沙箱工作示例。

codesandbox

表格组件:

import React from "react";
import { BootstrapTable, TableHeaderColumn } from "react-bootstrap-table";
import { products } from "./products";

function Table() {
    const renderShowsTotal = (start, to, total) => {
        return (
            <p style={{ color: "blue" }}>
                From {start} to {to}, totals is {total}&nbsp;&nbsp;(its a
                customize text)
            </p>
        );
    };
    const options = {
        sizePerPageList: [
            {
                text: "5",
                value: 5
            },
            {
                text: "10",
                value: 10
            },
            {
                text: "All",
                value: products.length
            }
        ],
        sizePerPage: 10, // which size per page you want to locate as default
        // pageStartIndex: 0, // where to start counting the pages
        // paginationSize: 3,  // the pagination bar size.
        prePage: "Prev", // Previous page button text
        nextPage: "Next", // Next page button text
        firstPage: "First", // First page button text
        lastPage: "Last", // Last page button text
        paginationShowsTotal: renderShowsTotal(), // Accept bool or function
        paginationPosition: "bottom", // default is bottom, top and both is all available
        hideSizePerPage: true, // You can hide the dropdown for sizePerPage
        alwaysShowAllBtns: true // Always show next and previous button
        // withFirstAndLast: false // Hide the going to First and Last page button
    };
    return (
        <div className="react-bootstrap-table container mt-4">
            <h2>React Bootstrap Table with pagination</h2>
            <BootstrapTable data={products} pagination options={options}>
                <TableHeaderColumn dataField="id" isKey={true}>
                    Product ID
                </TableHeaderColumn>
                <TableHeaderColumn dataField="name">
                    Product Name
                </TableHeaderColumn>
                <TableHeaderColumn dataField="price">
                    Product Price
                </TableHeaderColumn>
            </BootstrapTable>
        </div>
    );
}

export default Table;

提前致谢。

最佳答案

您可以在此处应用此技巧。

paginationSize添加到您的选项

const options = {
  ...
  paginationSize : 1,
  ...
}

然后应用CSS

.page-item.active {
  display: none;
}

Demo

关于reactjs - 从 React Bootstrap 表中禁用/删除分页编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59495648/

相关文章:

javascript - 如何使用 RxJS 发出多个 HTTP 请求并将响应合并到一个有效负载中并将其映射到另一个操作?

javascript - 在 Form.Item 内使用 value 属性进行选择不会反射(reflect)该 value 属性的任何更改

javascript - 简单按钮组件不接受变量

html - 如何让 Bootstrap 4 卡片不一直向右拉伸(stretch)

postgresql - 具有随机排序行的可重复分页

angular - 如何在 Angular Material 中将 Angular pageIndex 默认设置为 1?

css - 使用 <div> 标签会破坏 Material UI 网格

html - Bootstrap 4 Forms With 2 Columns(动态)

css - CasperJs 测试找不到 css 选择器(从 jade 迁移到 pug 后测试失败)

mysql - Cakephp 具有多个订单条件的分页