From 2770c2153601095d89f15228229d38756d305f86 Mon Sep 17 00:00:00 2001 From: sergesoroka Date: Tue, 18 Feb 2025 11:03:48 +0200 Subject: [PATCH 1/6] Improved Pagination logic --- src/DataTable/TemplateTable.css | 62 +++++++++++++++++++++++++ src/DataTable/TemplateTable.tsx | 41 ++++++++++++---- src/StartScreenComp/StartScreenComp.css | 17 ------- 3 files changed, 94 insertions(+), 26 deletions(-) create mode 100644 src/DataTable/TemplateTable.css diff --git a/src/DataTable/TemplateTable.css b/src/DataTable/TemplateTable.css new file mode 100644 index 0000000..258c7b0 --- /dev/null +++ b/src/DataTable/TemplateTable.css @@ -0,0 +1,62 @@ +.paginationPageCount { + /* width: 120px; */ + display: flex; + gap: 12px; + justify-content: space-around; + align-items: center; +} + +.pagination { + margin-top: 2rem; + display: flex; + align-items: center; + justify-content: flex-end; + gap: 12px; +} + +.paginBtn { + padding: 0.5rem 1rem; + border: none; + background: #def4ff; + color: #282828; + white-space: nowrap; + border-radius: 6px; + user-select: none; +} + +.paginBtn:hover { + background-color: #bfeaff; +} + +.paginBtn:disabled { + background-color: #f5f5f5; +} + +.pageBtn { + background-color: #fff; + display: flex; + align-items: center; + justify-content: center; + width: 20px; + height: 20px; + padding: 8px; + border-radius: 50%; + cursor: pointer; + user-select: none; +} + +.pageCurrent { + background-color: #def4ff; + display: flex; + align-items: center; + justify-content: center; + width: 20px; + height: 20px; + padding: 8px; + border-radius: 50%; + user-select: none; +} + +.pageBtn:hover { + background-color: #f0faff; +} diff --git a/src/DataTable/TemplateTable.tsx b/src/DataTable/TemplateTable.tsx index 97607f0..1a0515d 100644 --- a/src/DataTable/TemplateTable.tsx +++ b/src/DataTable/TemplateTable.tsx @@ -10,6 +10,8 @@ import { import { useEffect, useState } from "react"; +import "./TemplateTable.css"; + import { RowsIcon } from "lucide-react"; import { useSetIsShosen } from "../store/store"; import { ontLookup } from "./CategoryLookUp"; @@ -250,16 +252,37 @@ export default function TemplateTable({ data }) { Previous
-

- page{" "} - - {currentPage + 1} - {" "} - of{" "} - + {currentPage < 2 ? null : ( + + )} + {currentPage < 3 ? null :

...

} + {currentPage > 0 ? ( +
table.setPageIndex(currentPage - 1)} + > + {currentPage} +
+ ) : null} +
{currentPage + 1}
+ {currentPage + 2 > pageCount ? null : ( + <> +
table.setPageIndex(currentPage + 1)} + > + {currentPage + 2} +
+ {pageCount - currentPage < 4 ? null :

...

} + + )} + {pageCount - currentPage < 3 ? null : ( + + )}
)} + setEnteredPageNumber(e.target.value)} + onKeyDown={handleKeyDown} + className="pageNumberImput" + type="text" + placeholder="Page Number" + /> + +
+ {currentPage < 2 ? null : ( + + )} + {currentPage < 3 ? null :

...

} + {currentPage > 0 ? ( +
table.setPageIndex(currentPage - 1)} + > + {currentPage} +
+ ) : null} +
{currentPage + 1}
+ {currentPage + 2 > pageCount ? null : ( + <> +
table.setPageIndex(currentPage + 1)} + > + {currentPage + 2} +
+ {pageCount - currentPage < 4 ? null :

...

} + + )} + {pageCount - currentPage < 3 ? null : ( + + )} +
+ setEnteredPageNumber(e.target.value)} + onKeyDown={handleKeyDown} + className="pageNumberImput" + type="text" + placeholder="Page Number" + /> + + + + ); +} diff --git a/src/DataTable/TemplateTable.tsx b/src/DataTable/TemplateTable.tsx index b6d5410..38bdef7 100644 --- a/src/DataTable/TemplateTable.tsx +++ b/src/DataTable/TemplateTable.tsx @@ -10,6 +10,8 @@ import { import { useEffect, useState } from "react"; +import Pagination from "./Pagination"; + import "./TemplateTable.css"; import { RowsIcon } from "lucide-react"; @@ -247,70 +249,14 @@ export default function TemplateTable({ data }) { {pageCount > 2 ? ( -
- -
- {currentPage < 2 ? null : ( - - )} - {currentPage < 3 ? null :

...

} - {currentPage > 0 ? ( -
table.setPageIndex(currentPage - 1)} - > - {currentPage} -
- ) : null} -
{currentPage + 1}
- {currentPage + 2 > pageCount ? null : ( - <> -
table.setPageIndex(currentPage + 1)} - > - {currentPage + 2} -
- {pageCount - currentPage < 4 ? null :

...

} - - )} - {pageCount - currentPage < 3 ? null : ( - - )} -
- setEnteredPageNumber(e.target.value)} - onKeyDown={handleKeyDown} - className="pageNumberImput" - type="text" - placeholder="Page Number" - /> - - -
+ ) : null}
From 8fc648b8a6962eddc1fa1c01daa251479e5478ec Mon Sep 17 00:00:00 2001 From: sergesoroka Date: Fri, 13 Jun 2025 18:26:07 +0300 Subject: [PATCH 6/6] Fixed: pagination if pageCount > 1 --- src/DataTable/TemplateTable.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DataTable/TemplateTable.tsx b/src/DataTable/TemplateTable.tsx index 38bdef7..2b17db2 100644 --- a/src/DataTable/TemplateTable.tsx +++ b/src/DataTable/TemplateTable.tsx @@ -248,7 +248,7 @@ export default function TemplateTable({ data }) { - {pageCount > 2 ? ( + {pageCount > 1 ? (