From 32a67c8accc9a41686923b2406242d8165eca5bc Mon Sep 17 00:00:00 2001 From: sergesoroka Date: Fri, 13 Dec 2024 09:37:15 +0200 Subject: [PATCH 1/2] Table Cell sorting --- src/DataTable/TemplateTable.tsx | 93 +++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 3 deletions(-) diff --git a/src/DataTable/TemplateTable.tsx b/src/DataTable/TemplateTable.tsx index 36c49bc..428fe90 100644 --- a/src/DataTable/TemplateTable.tsx +++ b/src/DataTable/TemplateTable.tsx @@ -12,6 +12,7 @@ import { useEffect, useState } from "react"; import { RowsIcon } from "lucide-react"; import { useSetIsShosen } from "../store/store"; import { ontLookup } from "./CategoryLookUp"; +import SortingIcon from "@/IconsComponents/SortingIcon"; const columns = [ { @@ -87,6 +88,9 @@ export default function TemplateTable({ data }) { }, }); + const pageCount = table.getPageCount(); + const currentPage = table.getState().pagination.pageIndex; + const setIdShosen = useSetIsShosen(); useEffect(() => { setIdShosen(data && rowSelection ? data[rowSelection]?.uuid : null); @@ -112,9 +116,86 @@ export default function TemplateTable({ data }) { className="thSorted" onClick={header.column.getToggleSortingHandler()} > - {header.column.columnDef.header} - {/* {{ asc: " ", desc: "" }[header.column.getIsSorted() ?? null]} - */} + {header.column.getIsSorted() === "asc" || + header.column.getIsSorted() === "desc" ? ( + + {header.column.columnDef.header}   + + ) : ( + {header.column.columnDef.header}   + )} + {/* {header.column.columnDef.header}   */} + {header.column.getIsSorted() === "asc" && ( + + + + + + )} + {header.column.getIsSorted() === "desc" && ( + + + + + + )} + {/* { + { asc: "a ", desc: "d" }[ + header.column.getIsSorted() ?? null + ] + } */} + {/* */} ))} @@ -164,6 +245,12 @@ export default function TemplateTable({ data }) { > Previous +
+

+ page {currentPage + 1} of{" "} + {pageCount} +

+