What is rc-pagination?
The rc-pagination package is a React component for creating paginated interfaces, allowing users to navigate through pages of items. It provides a range of customization options to tailor the pagination behavior and appearance to the needs of different applications.
What are rc-pagination's main functionalities?
Basic Pagination
This code sample demonstrates how to render a basic pagination component with a total of 50 items.
import Pagination from 'rc-pagination';
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<Pagination total={50} />,
document.getElementById('container')
);
Custom Page Size
This code sample shows how to set a custom page size and enable a size changer dropdown for the user to select how many items to display per page.
import Pagination from 'rc-pagination';
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<Pagination total={500} defaultPageSize={20} showSizeChanger />,
document.getElementById('container')
);
Controlled Component
This code sample illustrates how to create a controlled pagination component where the current page state is managed by the parent component.
import Pagination from 'rc-pagination';
import React, { useState } from 'react';
import ReactDOM from 'react-dom';
const App = () => {
const [current, setCurrent] = useState(1);
const onChange = page => {
setCurrent(page);
};
return (
<Pagination current={current} onChange={onChange} total={100} />
);
};
ReactDOM.render(<App />, document.getElementById('container'));
Jump to Page
This code sample demonstrates how to enable the 'quick jumper' feature, allowing users to jump to a specific page directly.
import Pagination from 'rc-pagination';
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<Pagination total={100} showQuickJumper />,
document.getElementById('container')
);
Other packages similar to rc-pagination
react-paginate
react-paginate is a React component to create pagination. It provides built-in styles and is highly customizable. Compared to rc-pagination, react-paginate might be more suitable for those who prefer a component with out-of-the-box styled elements.
react-js-pagination
react-js-pagination is another React component for pagination. It is similar to rc-pagination but offers different customization options and styles. It might be a good alternative for users looking for a slightly different look and feel.
material-ui
material-ui is a set of React components that implement Google's Material Design, including a pagination component. It is a comprehensive UI framework that offers a Material Design styled pagination component, which is different from the minimalistic approach of rc-pagination.
React Pagination Component
Development
npm install
npm start
Example
http://localhost:3000/examples/
online example: http://react-component.github.io/pagination/examples/
Feature
- support ie8,ie8+,chrome,firefox,safari
Keyboard
install
Usage
var Pagination = require('rc-pagination');
var React = require('react');
React.render(<Pagination />, container);
API
props
Parameter | Description | Type | Default |
---|
defaultCurrent | uncontrolled current page | Number | 1 |
current | current page | Number | undefined |
total | items total count | Number | 0 |
pageSize | items per page | Number | 10 |
onChange | page change callback | Function | noop |
showSizeChanger | show pageSize changer | Bool | false |
pageSizeOptions | specify the sizeChanger selections | Array | ['10', '20', '30', '40'] |
onShowSizeChange | pageSize chagne callback | Function | noop |
showQuickJump | show quick goto jumper | Bool | false |
className | when set "mini", show mini version | String | rc-pagination |
simple | when set, show simple pager | Object | null |
Test Case
http://localhost:3000/tests/runner.html?coverage
Coverage
http://localhost:3000/node_modules/rc-server/node_modules/node-jscover/lib/front-end/jscoverage.html?w=http://localhost:3000/tests/runner.html?coverage
License
rc-pagination is released under the MIT license.