question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot use pageListRenderer with PaginationListStandalone

See original GitHub issue

I would like to use a custom page list as a standalone component so that I can change the order of the pagination list and total.

However, when I use a custom page list, while it does appear to pass my pageListRenderer in the props, the custom page list is not rendered when used as a standalone component. Instead, the table renders the default page list.

Here are some code snippets.

As a side note, I have my pageListRender in a separate file for re-use in other places. I have tried using it within the same file as the table, but this doesn’t have any impact.

PageListRenderer.js: (nothing fancy here, just copying and pasting the example from Storybook to illustrate the issue)


const PageListRenderer = ({ pages, onPageChange }) => {
  const pageWithoutIndication = pages.filter(p => typeof p.page !== "string");
  return (
    <div>
      {pageWithoutIndication.map(p => (
        <button
          className="btn btn-success"
          onClick={() => onPageChange(p.page)}
        >
          {p.page}
        </button>
      ))}
    </div>
  );
};

export default PageListRenderer;

SampleTable.js:

import BootstrapTable from "react-bootstrap-table-next";
import paginationFactory, {
  PaginationProvider,
  PaginationTotalStandalone,
  PaginationListStandalone
} from "react-bootstrap-table2-paginator";
import PageListRenderer from "./PageListRenderer";
import { rows, columns } from "../data/data.js";

class SampleTable extends PureComponent {
  render() {
    const options = {
      sizePerPage: 1,
      pageListRenderer: props => PageListRenderer({ ...props }),
      custom: true,
      totalSize: rows && rows.length
    };

    const pagination = paginationFactory(options);

    return (
      <PaginationProvider pagination={pagination}>
        {({ paginationProps, paginationTableProps }) => (
          <div>
            <PaginationTotalStandalone {...paginationProps} />
            <BootstrapTable
              keyField="id"
              data={rows}
              columns={columns}
              {...paginationTableProps}
            />
            <PaginationListStandalone {...paginationProps} />
          </div>
        )}
      </PaginationProvider>
    );
  }
}

export default SampleTable;

App.js:

import "./App.css";
import SampleTable from "./components/SampleTable.js";

function App() {
  return (
    <div className="container">
      <SampleTable />
    </div>
  );
}

export default App;

Expected: Screen Shot 2019-05-13 at 2 17 23 PM

Actual: Screen Shot 2019-05-13 at 2 29 04 PM

Thanks for your time!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
lhamcommented, Mar 20, 2020

@vhbert I ended up creating my own component replacing the <PageListRenderer> following the code in the library. I’ll just make a code dump and hopefully you can replicate it in a way you want 😃

Here is the component

import React from 'react';
import ButtonGroup from 'react-bootstrap/ButtonGroup';
import standaloneAdapter from 'react-bootstrap-table2-paginator/lib/src/standalone-adapter';
import PaginationHandler from 'react-bootstrap-table2-paginator/lib/src/pagination-handler';
import paginationListAdapter from 'react-bootstrap-table2-paginator/lib/src/pagination-list-adapter';

const ButtonGroupPaginationListComponent = ({ pages, onPageChange, pageButtonRenderer }) => {
    if (_.isEmpty(pages)) {
        return null;
    }

    const onClick = (page) => {
        if (!page.active && !page.disabled) {
            onPageChange(page.page)
        }
    };

    return (
        <ButtonGroup>
            {pages.map(page => pageButtonRenderer(page, () => onClick(page)))}
        </ButtonGroup>
    )
};

const ButtonGroupPaginationList = standaloneAdapter(PaginationHandler(paginationListAdapter(ButtonGroupPaginationListComponent)));

export default ButtonGroupPaginationList;

which I then use like this:

<PaginationProvider pagination={paginationFactory(paginationOptions)}>
    {paginationProviderProps => (
        <ButtonGroupPaginationList {...paginationProviderProps.paginationProps} />
    )}
</PaginationProvider>
1reaction
vhbertcommented, Mar 20, 2020

Thanks for the very quick answer, your solution works like a charm. I’ll just have to write some more typings for it since I am using TypeScript.

Thanks again for your help

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pagination Props · react-bootstrap-table2 - GitHub Pages
Use pagination.page specify the current page when table render. It's necessary value when remote pagination is enabled. pagination.sizePerPage ...
Read more >
and previous page not working in react-bootstrap-table2- ...
I have implemented table with pagination using react-bootstrap-table2-paginator. on each pagenumber click it will call api and fetch table ...
Read more >
react-bootstrap-table2-paginator-esm
Start using react-bootstrap-table2-paginator-esm in your project by running `npm i ... There are no other projects in the npm registry using ...
Read more >
React bootstrap table pagination
You can't perform that action at this time. ... Standalone Pagination List Standalone Pagination Total Standalone When render each standalone, you just need ......
Read more >
react-bootstrap-table2-paginator examples
Learn how to use react-bootstrap-table2-paginator by viewing and forking react-bootstrap-table2-paginator example apps on CodeSandbox.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found