Connect with us

Hi, what are you looking for?

Editor's Picks

Implement Server Side Pagination in React Table

windows registry

In this tutorial, I will show you how to make React Table Pagination (Server-side) using a React Hooks Application using react-table v7 for data table with data using Axios for API call.

We show you the working example of Server Side Pagination in React Table here:
Here we are using functional components so we are using useState, useEffect hooks here for state Updates and manipulation.
For API calls, we are using Axios and “react-data-table-component” for Table rendering. Please see basic example here, if you have any issue or any confusion comment below.

import React, { useState, useEffect } from "react";
import DataTable from "react-data-table-component";
import axios from "axios";

const columns = [
  {
    name: "Avatar",
    cell: (row) => (
      <img height="30px" width="30px" alt={row.first_name} src={row.avatar} />
    )
  },
  {
    name: "First Name",
    selector: "first_name"
  },
  {
    name: "Last Name",
    selector: "last_name"
  },
  {
    name: "Email",
    selector: "email"
  }
];

function App() {
  const [users, setUsers] = useState({});
  const [page, setPage] = useState(1);
  const countPerPage = 5;

  const getUserList = () => {
    axios
      .get(
        `https://reqres.in/api/users?page=${page}&per_page=${countPerPage}&delay=1`
      )
      .then((res) => {
        setUsers(res.data);
      })
      .catch((err) => {
        setUsers({});
      });
  };

  useEffect(() => {
    getUserList();
  }, [page]);

  return (
    <div className="App">
      <h3>
        Server side pagination in DataTable -{" "}
        <a
          href="https://crackaccount.com"
          target="_blank"
          rel="noopener noreferrer"
        >
          Crackaccount
        </a>
      </h3>
      <DataTable
        title="Crackaccount"
        columns={columns}
        data={users.data}
        highlightOnHover
        pagination
        paginationServer
        paginationTotalRows={users.total}
        paginationPerPage={countPerPage}
        paginationComponentOptions={{
          noRowsPerPage: true
        }}
        onChangePage={(page) => setPage(page)}
      />
    </div>
  );
}

export default App;

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Premium Account

Zee5 Premium Account ID and Password Free 2023:Are you searching Zee5 Premium Account Free WORKING Account? Zee5 is a popular and on-demand Indian Video Streaming...

Entertainment

[ad_1] AP CM Jagan led YSRCP government has hiked the value added tax (VAT) on cooking gas by ten percent. Earlier the tax was...

Books

Antenna & Wave Propagation By KD Prasad ***CONTENTS****Chapter 6: Antenna TerminologyAnd Hertzian Dipole, Half Wave DipoleMore Chapters Coming Soon …DOWNLOAD Chapter:6(15MB)

Entertainment

[ad_1] Movie4Me 2021 is a pirated website. The Movie 4 Mi website allows its users to download the latest Bollywood, Hollywood movies for free...