added sorting

This commit is contained in:
polaris
2024-07-07 11:07:23 -04:00
parent ecb9663f6d
commit 4a91c642b0
2 changed files with 34 additions and 5 deletions

View File

@ -2,6 +2,8 @@
import { Button } from "@/components/ui/button";
import {
ColumnDef,
SortingState,
getSortedRowModel,
flexRender,
getCoreRowModel,
getPaginationRowModel,
@ -16,6 +18,7 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
import { useState } from "react";
interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[];
@ -26,12 +29,18 @@ export function DataTable<TData, TValue>({
columns,
data,
}: DataTableProps<TData, TValue>) {
const [sorting, setSorting] = useState<SortingState>([]);
const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
onSortingChange: setSorting,
getSortedRowModel: getSortedRowModel(),
state: {
sorting,
},
});
return (