"use client"; // https://github.com/dracor-org/einakter/blob/466ca1663098a16cc1141129a6ba22628135b04c/src/components/Table.tsx#L26 // used the above for reference on how to fuzzy search import { useState } from "react"; import { Button } from "@/components/ui/button"; import { ColumnDef, SortingState, getSortedRowModel, flexRender, getFilteredRowModel, getCoreRowModel, getPaginationRowModel, useReactTable, } from "@tanstack/react-table"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import DebouncedInput from "./DebouncedInput"; interface DataTableProps { columns: ColumnDef[]; data: TData[]; } export function DataTable({ columns, data, }: DataTableProps) { const [sorting, setSorting] = useState([]); const [globalFilter, setGlobalFilter] = useState(""); const table = useReactTable({ data, columns, state: { sorting, globalFilter, }, onSortingChange: setSorting, onGlobalFilterChange: setGlobalFilter, getCoreRowModel: getCoreRowModel(), getPaginationRowModel: getPaginationRowModel(), getSortedRowModel: getSortedRowModel(), getFilteredRowModel: getFilteredRowModel(), }); return (
setGlobalFilter(String(value))} placeholder={`Search`} />
{table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => ( {header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext(), )} ))} ))} {table.getRowModel().rows?.length ? ( table.getRowModel().rows.map((row) => ( {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} )) ) : ( No results. )}
); }