All Projects → ChoTotOSS → React Paginating

ChoTotOSS / React Paginating

Licence: mit
Simple, lightweight, flexible pagination ReactJS component ⏮⏪1️⃣2️⃣3️⃣⏩⏭

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
flowtype
47 projects

Projects that are alternatives of or similar to React Paginating

paginated
⚛️ React render props component & custom hook for pagination.
Stars: ✭ 20 (-77.53%)
Mutual labels:  pagination, render-props
Queryql
Easily add filtering, sorting, and pagination to your Node.js REST API through your old friend: the query string!
Stars: ✭ 76 (-14.61%)
Mutual labels:  pagination
Kaminari
⚡ A Scope & Engine based, clean, powerful, customizable and sophisticated paginator for Ruby webapps
Stars: ✭ 8,085 (+8984.27%)
Mutual labels:  pagination
Mmm Pages
Add pages to your MagicMirror²!
Stars: ✭ 61 (-31.46%)
Mutual labels:  pagination
Ngx Pagination
Pagination for Angular
Stars: ✭ 1,080 (+1113.48%)
Mutual labels:  pagination
Sequelize Paginate
Sequelize model plugin for add paginate method
Stars: ✭ 70 (-21.35%)
Mutual labels:  pagination
Cursor Pagination
Cursor pagination for your Laravel API
Stars: ✭ 47 (-47.19%)
Mutual labels:  pagination
Pagination
Pagination for javascript and nodejs
Stars: ✭ 84 (-5.62%)
Mutual labels:  pagination
Lightquery
Lightweight solution for sorting and paging Asp.Net Core API results
Stars: ✭ 75 (-15.73%)
Mutual labels:  pagination
Squid
Declarative and Reactive Networking for Swift.
Stars: ✭ 61 (-31.46%)
Mutual labels:  pagination
Dva Starter
完美使用 dva react react-router,最好用的ssr脚手架,服务器渲染最佳实践
Stars: ✭ 60 (-32.58%)
Mutual labels:  server-rendering
React Grid Table
A modular table, based on a CSS grid layout, optimized for customization.
Stars: ✭ 57 (-35.96%)
Mutual labels:  pagination
Dotnetpaging
Data paging with ASP.NET and ASP.NET Core
Stars: ✭ 70 (-21.35%)
Mutual labels:  pagination
Templateplugin
A template for creating minecraft plugin from 1.7.10 to 1.16.2
Stars: ✭ 51 (-42.7%)
Mutual labels:  pagination
Pagination view
Flutter package to simplify pagination of list of items from the internet.
Stars: ✭ 82 (-7.87%)
Mutual labels:  pagination
Sesame
Android architecture components made right
Stars: ✭ 48 (-46.07%)
Mutual labels:  pagination
Vulcan
🌋 A toolkit to quickly build apps with React, GraphQL & Meteor
Stars: ✭ 8,027 (+8919.1%)
Mutual labels:  server-rendering
Utils
🛠 Lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.
Stars: ✭ 1,158 (+1201.12%)
Mutual labels:  pagination
Pager Api
Easy API pagination for Rails
Stars: ✭ 86 (-3.37%)
Mutual labels:  pagination
Filterable
Filtering from incoming params in Elixir/Ecto/Phoenix with easy to use DSL.
Stars: ✭ 83 (-6.74%)
Mutual labels:  pagination

React Paginating

ci/cd cypress

jest Download monthly codecov npm version License: MIT PRs Welcome

gzip size module formats Package Quality

Package Quality

Motivation

During development, we were facing problems supporting server-rendering of our web app & SEO (require pagination links). To solve that, we had to add 2 snippets of code, one to support the server-side and another to support the client-side which lead to being hard for maintenance. Most of the pagination libraries only support client-rendering by attaching event handlers on the pagination button to redirect. Because of that, we created this library which allows flexibly to customize behaviors (attaching event handlers or href attribute) and user interface.




The component applied Render Props pattern. (You can read more about this pattern here).

This approach allows you to fully control UI component and behaviours.

See the intro blog post

Table content

Installation

npm install --save react-paginating

or

yarn add react-paginating

Usage

You can check out the basic demo here:

.bg-red {
  background-color: red;
}
import React from 'react';
import { render } from 'react-dom';
import Pagination from 'react-paginating';

const fruits = [
  ['apple', 'orange'],
  ['banana', 'avocado'],
  ['coconut', 'blueberry'],
  ['payaya', 'peach'],
  ['pear', 'plum']
];
const limit = 2;
const pageCount = 3;
const total = fruits.length * limit;

class App extends React.Component {
  constructor() {
    super();
    this.state = {
      currentPage: 1
    };
  }

  handlePageChange = (page, e) => {
    this.setState({
      currentPage: page
    });
  };

  render() {
    const { currentPage } = this.state;
    return (
      <div>
        <ul>
          {fruits[currentPage - 1].map(item => <li key={item}>{item}</li>)}
        </ul>
        <Pagination
          className="bg-red"
          total={total}
          limit={limit}
          pageCount={pageCount}
          currentPage={currentPage}
        >
          {({
            pages,
            currentPage,
            hasNextPage,
            hasPreviousPage,
            previousPage,
            nextPage,
            totalPages,
            getPageItemProps
          }) => (
            <div>
              <button
                {...getPageItemProps({
                  pageValue: 1,
                  onPageChange: this.handlePageChange
                })}
              >
                first
              </button>

              {hasPreviousPage && (
                <button
                  {...getPageItemProps({
                    pageValue: previousPage,
                    onPageChange: this.handlePageChange
                  })}
                >
                  {'<'}
                </button>
              )}

              {pages.map(page => {
                let activePage = null;
                if (currentPage === page) {
                  activePage = { backgroundColor: '#fdce09' };
                }
                return (
                  <button
                    {...getPageItemProps({
                      pageValue: page,
                      key: page,
                      style: activePage,
                      onPageChange: this.handlePageChange
                    })}
                  >
                    {page}
                  </button>
                );
              })}

              {hasNextPage && (
                <button
                  {...getPageItemProps({
                    pageValue: nextPage,
                    onPageChange: this.handlePageChange
                  })}
                >
                  {'>'}
                </button>
              )}

              <button
                {...getPageItemProps({
                  pageValue: totalPages,
                  onPageChange: this.handlePageChange
                })}
              >
                last
              </button>
            </div>
          )}
        </Pagination>
      </div>
    );
  }
}

render(<App />, document.getElementById('root'));

Examples

Input Props

total

number

Total results

className

string

Customizable style for pagination wrapper

limit

number

Number of results per page

pageCount

number

How many pages number you want to display in pagination zone.

currentPage

number

Current page number

Child callback functions

getPageItemProps

function({ pageValue: number, onPageChange: func })

Allow to pass props and event to page item. When page is clicked, onPageChange will be executed with param value pageValue.

Note: This callback function should only use for paging with state change. If you prefer parsing page value from query url (Please don't use this callback function).

Controlled Props

pages

array: [number]

List of pages number will be displayed. E.g: [1, 2, 3, 4, 5]

currentPage

number

previousPage

number

nextPage

number

totalPages

number

hasNextPage

boolean

Check if it has next page or not.

hasPreviousPage

boolean

Check if it has previous page or not.

Alternatives

If you don’t agree with the choices made in this project, you might want to explore alternatives with different tradeoffs. Some of the more popular and actively maintained ones are:

Contributors


Dzung Nguyen

📖 💻 🤔 👀 🐛

Chau Tran

💻 🤔 👀 🐛

Faris Abusada

💻 🐛
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].