Skip to content
Related Articles

Related Articles

Improve Article

ReactJS UI Ant Design Pagination Component

  • Last Updated : 19 May, 2021

Ant Design Library has this component pre-built, and it is very easy to integrate as well. Pagination Component allows the user to show the page number and switch between pages easily with the next and previous button. We can use the following approach in ReactJS to use the Ant Design Pagination Component.

Syntax:

<Pagination defaultCurrent={ } total={ } />

Pagination Props:

  • current: It is used to denote the value of the current page number.
  • defaultCurrent: It is used to denote the default value of the initial page number.
  • defaultPageSize: It is used to denote the default value of a number of data items per page.
  • disabled: It is used to disable the pagination.
  • hideOnSinglePage: It is used to indicate whether to hide pager on a single page or not.
  • itemRender: It is used to customize the item’s innerHTML content.
  • pageSize: It is used to denote the value of the number of data items per page.
  • pageSizeOptions: It is used to specify the options for sizeChanger.
  • responsive: It is used to allow the pagination to fit according to the window width if the size is not specified.
  • showLessItems: It is used to show fewer i.e less page items.
  • showQuickJumper: It is used to indicate whether you can jump to pages directly or not.
  • showSizeChanger: It is used to indicate whether to show pageSize select.
  • showTitle: It is used to indicate whether to show the page item’s title.
  • showTotal: It is used to display the ranger and the total number.
  • simple: It is used to indicate whether to use simple mode or not.
  • size: It is used to specify the size of Pagination.
  • total: It is used to denote the value of the total number of data items.
  • onChange: It is a callback function that is triggered when the page number or pageSize is changed.
  • onShowSizeChange: It is a callback function that is triggered when the pageSize is changed.

Creating React Application And Installing Module:

  • Step 1: Create a React application using the following command:



    npx create-react-app foldername
  • Step 2: After creating your project folder i.e. folder name, move to it using the following command:

    cd foldername
  • Step 3: After creating the ReactJS application, Install the required module using the following command:

    npm install antd

Project Structure: It will look like the following.

Project Structure

Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.

App.js




import React from 'react'
import "antd/dist/antd.css";
import { Pagination } from 'antd';
  
export default function App() {
  
  return (
    <div style={{ display: 'block', width: 700, padding: 30 }}>
      <h4>ReactJS Ant-Design Pagination Component</h4>
      <Pagination defaultCurrent={1} total={100} />
    </div>
  );
}

Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

Reference: https://ant.design/components/pagination/

My Personal Notes arrow_drop_up
Recommended Articles
Page :