"use client"; import type { Table } from "@tanstack/react-table"; import type { LucideIcon } from "lucide-react"; import { X } from "lucide-react"; import { Button } from "../button"; import { Input } from "../form"; import { DataTableFilter } from "./DataTableFilter"; export type FilterableItems = { title: string; tableAccessor: string; options: { label: string; value: string; icon?: LucideIcon; }[]; }[]; interface DataTableToolbarProps { table: Table; filterableItems?: FilterableItems; searchKey?: string; tableCTA?: React.ReactNode; } export function DataTableToolbar({ table, filterableItems, tableCTA, searchKey, }: DataTableToolbarProps) { // TODO: Is there a better way to check if the table is filtered? // If you select ALL filters for a column, the table is not filtered and we dont get a reset button const isFiltered = table.getState().columnFilters.length > 0; return (
{searchKey && ( table.getColumn(searchKey)?.setFilterValue(event.target.value)} /> )} {isFiltered && ( )} {filterableItems && filterableItems?.map((item) => { const foundColumn = table.getColumn(item.tableAccessor); if (foundColumn?.getCanFilter()) { return ( ); } })} {tableCTA ? tableCTA : null}
); }