Added some more pagination

This commit is contained in:
Tiago Ribeiro
2024-09-08 23:02:48 +01:00
parent eab6ab03b7
commit 745eef981f
4 changed files with 102 additions and 47 deletions

View File

@@ -1,4 +1,4 @@
import React from "react";
import React, {useEffect, useMemo, useState} from "react";
import {CorporateUser, User} from "@/interfaces/user";
import {BsFileExcel, BsBank, BsPersonFill} from "react-icons/bs";
import IconCard from "../IconCard";
@@ -44,8 +44,11 @@ interface UserCount {
const searchFilters = [["email"], ["user"], ["userId"]];
const SIZE = 16;
const MasterStatistical = (props: Props) => {
const {users, corporateUsers, displaySelection = true} = props;
const [page, setPage] = useState(0);
// const corporateRelevantUsers = React.useMemo(
// () => corporateUsers.filter((x) => x.type !== "student") as CorporateUser[],
@@ -215,8 +218,14 @@ const MasterStatistical = (props: Props) => {
const {rows: filteredRows, renderSearch, text: searchText} = useListSearch(searchFilters, tableResults);
useEffect(() => setPage(0), [searchText]);
const rows = useMemo(
() => filteredRows.slice(page * SIZE, (page + 1) * SIZE > filteredRows.length ? filteredRows.length : (page + 1) * SIZE),
[filteredRows, page],
);
const table = useReactTable({
data: filteredRows,
data: rows,
columns: defaultColumns,
getCoreRowModel: getCoreRowModel(),
});
@@ -345,7 +354,22 @@ const MasterStatistical = (props: Props) => {
</div>
</div>
<div>
<div className="w-full h-full flex flex-col gap-4">
<div className="w-full flex gap-2 justify-between">
<Button className="w-full max-w-[200px]" disabled={page === 0} onClick={() => setPage((prev) => prev - 1)}>
Previous Page
</Button>
<div className="flex items-center gap-4 w-fit">
<span className="opacity-80">
{page * SIZE + 1} - {(page + 1) * SIZE > filteredRows.length ? filteredRows.length : (page + 1) * SIZE} /{" "}
{filteredRows.length}
</span>
<Button className="w-[200px]" disabled={(page + 1) * SIZE >= rows.length} onClick={() => setPage((prev) => prev + 1)}>
Next Page
</Button>
</div>
</div>
<table className="rounded-xl h-full bg-mti-purple-ultralight/40 w-full">
<thead>
{table.getHeaderGroups().map((headerGroup) => (