Adds column sorting to Nginx tables

This commit is contained in:
DOLBA3B committed 2026-05-05 21:12:04 +02:00
1 parent 34374cbe09
commit ff066d5626
5 files changed
+117 -10

No files matched your search

+29 -2
View File
@@ -1,3 +1,5 @@
import { IconArrowsSort, IconChevronDown, IconChevronUp } from "@tabler/icons-react";
import { flexRender } from "@tanstack/react-table";
import type { TableLayoutProps } from "src/components";
function TableHeader<T>(props: TableLayoutProps<T>) {
@@ -11,9 +13,34 @@ function TableHeader<T>(props: TableLayoutProps<T>) {
{headerGroup.headers.map((header: any) => {
const { column } = header;
const { className } = (column.columnDef.meta as any) ?? {};
const canSort = column.getCanSort();
const sortDir = column.getIsSorted();
const headerContent = header.isPlaceholder
? null
: typeof column.columnDef.header === "string"
? column.columnDef.header
: flexRender(column.columnDef.header, header.getContext());
const sortIcon = canSort ? (
sortDir === "asc" ? (
<IconChevronUp size={14} className="ms-1" />
) : sortDir === "desc" ? (
<IconChevronDown size={14} className="ms-1" />
) : (
<IconArrowsSort size={14} className="ms-1 opacity-50" />
)
) : null;
return (
<th key={header.id} className={className}>
{typeof column.columnDef.header === "string" ? `${column.columnDef.header}` : null}
<th
key={header.id}
className={className}
onClick={canSort ? column.getToggleSortingHandler() : undefined}
style={canSort ? { cursor: "pointer", userSelect: "none" } : undefined}
>
{headerContent}
{sortIcon}
</th>
);
})}