11import React from "react" ;
2+ import { Search } from "lucide-react" ;
23import {
34 Table ,
45 TableBody ,
@@ -10,13 +11,17 @@ import {
1011
1112import {
1213 ColumnDef ,
14+ ColumnFiltersState ,
1315 SortingState ,
1416 flexRender ,
1517 getCoreRowModel ,
18+ getFilteredRowModel ,
1619 getSortedRowModel ,
1720 useReactTable ,
1821} from "@tanstack/react-table" ;
1922
23+ import { Input } from "@/components/ui/input" ;
24+
2025interface DataTableProps < TData , TValue > {
2126 columns : ColumnDef < TData , TValue > [ ] ;
2227 data : TData [ ] ;
@@ -27,20 +32,42 @@ export default function ListTable<TData, TValue>({
2732 data,
2833} : DataTableProps < TData , TValue > ) {
2934 const [ sorting , setSorting ] = React . useState < SortingState > ( [ ] ) ;
35+ const [ columnFilters , setColumnFilters ] =
36+ React . useState < ColumnFiltersState > ( [ ] ) ;
3037 const table = useReactTable ( {
3138 data,
3239 columns,
3340 getCoreRowModel : getCoreRowModel ( ) ,
3441 onSortingChange : setSorting ,
3542 getSortedRowModel : getSortedRowModel ( ) ,
43+ onColumnFiltersChange : setColumnFilters ,
44+ getFilteredRowModel : getFilteredRowModel ( ) ,
3645 state : {
3746 sorting,
47+ columnFilters,
3848 } ,
3949 } ) ;
4050 return (
41- < div className = "w-full flex justify-center px-1 sm:px-5 md:px-10 lg:px-20 pt-5" >
42- < div className = "mx-auto max-w-7xl overflow-x-auto border rounded-lg" >
43- < Table >
51+ < div className = "w-full flex flex-col justify-center px-2 sm:px-5 md:px-10 lg:px-20 pt-5" >
52+ < div className = "mx-auto max-w-7xl w-full flex flex-row items-center justify-start py-4" >
53+ < Search className = "w-5 h-5 mr-3" />
54+ < Input
55+ placeholder = "Search products..."
56+ value = {
57+ ( table
58+ . getColumn ( "product" )
59+ ?. getFilterValue ( ) as string ) ?? ""
60+ }
61+ onChange = { ( event ) =>
62+ table
63+ . getColumn ( "product" )
64+ ?. setFilterValue ( event . target . value )
65+ }
66+ className = "max-w-md"
67+ />
68+ </ div >
69+ < div className = "mx-auto max-w-7xl w-full overflow-x-auto border rounded-lg" >
70+ < Table className = "w-full" >
4471 < TableHeader className = "bg-zinc-100" >
4572 { table . getHeaderGroups ( ) . map ( ( headerGroup ) => (
4673 < TableRow key = { headerGroup . id } >
0 commit comments