mirror of
https://github.com/Alvin-Zilverstand/nginx-proxy-manager.git
synced 2026-11-23 22:53:09 +01:00
Adds column sorting to Nginx tables
This commit is contained in:
1 parent
34374cbe09
commit
ff066d5626
5 files changed
+117
-10
No files matched your search
@@ -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>
|
||||
);
|
||||
})}
|
||||
|
||||
Reference in new issue
Block a user