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

+20 -2
View File
@@ -1,6 +1,12 @@
import { IconDotsVertical, IconEdit, IconPower, IconTrash } from "@tabler/icons-react";
import { createColumnHelper, getCoreRowModel, useReactTable } from "@tanstack/react-table";
import { useMemo } from "react";
import {
createColumnHelper,
getCoreRowModel,
getSortedRowModel,
type SortingState,
useReactTable,
} from "@tanstack/react-table";
import { useMemo, useState } from "react";
import type { DeadHost } from "src/api/backend";
import {
CertificateFormatter,
@@ -29,6 +35,7 @@ export default function Table({ data, isFetching, onEdit, onDelete, onDisableTog
() => [
columnHelper.accessor((row: any) => row.owner, {
id: "owner",
enableSorting: false,
cell: (info: any) => {
const value = info.getValue();
return <GravatarFormatter url={value ? value.avatar : ""} name={value ? value.name : ""} />;
@@ -40,6 +47,11 @@ export default function Table({ data, isFetching, onEdit, onDelete, onDisableTog
columnHelper.accessor((row: any) => row, {
id: "domainNames",
header: intl.formatMessage({ id: "column.source" }),
sortingFn: (a, b) => {
const aVal = a.original.domainNames?.[0] ?? "";
const bVal = b.original.domainNames?.[0] ?? "";
return aVal.localeCompare(bVal);
},
cell: (info: any) => {
const value = info.getValue();
return <DomainsFormatter domains={value.domainNames} createdOn={value.createdOn} />;
@@ -47,6 +59,7 @@ export default function Table({ data, isFetching, onEdit, onDelete, onDisableTog
}),
columnHelper.accessor((row: any) => row.certificate, {
id: "certificate",
enableSorting: false,
header: intl.formatMessage({ id: "column.ssl" }),
cell: (info: any) => {
return <CertificateFormatter certificate={info.getValue()} />;
@@ -128,10 +141,15 @@ export default function Table({ data, isFetching, onEdit, onDelete, onDisableTog
[columnHelper, onDelete, onEdit, onDisableToggle],
);
const [sorting, setSorting] = useState<SortingState>([]);
const tableInstance = useReactTable<DeadHost>({
columns,
data,
state: { sorting },
onSortingChange: setSorting,
getCoreRowModel: getCoreRowModel(),
getSortedRowModel: getSortedRowModel(),
rowCount: data.length,
meta: {
isFetching,