From cf96a98f9157dbe21984371005b034d08787c76a Mon Sep 17 00:00:00 2001 From: Markus Thielker Date: Tue, 3 Dec 2024 16:20:09 +0100 Subject: [PATCH] NORY-15: add data-table component --- dashboard/src/components/ui/data-table.tsx | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 dashboard/src/components/ui/data-table.tsx diff --git a/dashboard/src/components/ui/data-table.tsx b/dashboard/src/components/ui/data-table.tsx new file mode 100644 index 0000000..e5698ac --- /dev/null +++ b/dashboard/src/components/ui/data-table.tsx @@ -0,0 +1,70 @@ +'use client'; + +import { ColumnDef, flexRender, getCoreRowModel, useReactTable } from '@tanstack/react-table'; +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'; + +interface DataTableProps { + columns: ColumnDef[]; + data: TData[]; +} + +export function DataTable( + { + columns, + data, + }: DataTableProps, +) { + + const table = useReactTable({ + data, + columns, + getCoreRowModel: getCoreRowModel(), + }); + + return ( +
+ + + {table.getHeaderGroups().map((headerGroup) => ( + + {headerGroup.headers.map((header) => { + return ( + + {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. + + + )} + +
+
+ ); +}