'use client'; import * as React from 'react'; import { Search } from 'lucide-react'; import { flexRender, getCoreRowModel, getSortedRowModel, useReactTable, type ColumnDef, type SortingState, } from '@tanstack/react-table'; import * as Button from '@/components/ui/button'; import * as Checkbox from '@/components/ui/checkbox'; import * as Input from '@/components/ui/input'; import * as Table from '@/components/ui/table'; import { cn } from '@/utils/cn'; const data: Data[] = [ { id: '1', name: 'Payroll deposit', amount: 3450, date: new Date('2024-03-15'), }, { id: '2', name: 'Investment Return', amount: 1280.75, date: new Date('2024-03-14'), }, { id: '3', name: 'Dividend Income', amount: 890.25, date: new Date('2024-03-13'), }, { id: '4', name: 'Consulting Fee', amount: 2500, date: new Date('2024-03-12'), }, { id: '5', name: 'Rental Income', amount: 1750, date: new Date('2024-03-11'), }, ]; type Data = { id: string; name: string; amount: number; date: Date; }; const columns: ColumnDef[] = [ { id: 'select', header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label='Select all' /> ), cell: ({ row }) => ( row.toggleSelected(!!value)} aria-label='Select row' /> ), enableSorting: false, enableHiding: false, }, { id: 'name', accessorKey: 'name', header: () =>
Name
, cell: ({ row }) => (
{row.original.name}
), }, { id: 'amount', accessorKey: 'amount', header: () =>
Amount
, cell: ({ row }) => (
{new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', }).format(row.original.amount)}
), }, { id: 'date', accessorKey: 'date', header: ({ column }) => ( column.toggleSorting(column.getIsSorted() === 'asc')} > Date ), enableSorting: true, cell: ({ row }) => (
{row.original.date.toLocaleDateString()}
), }, ]; export default function FinancialTransactionsCheckboxTable() { const [sorting, setSorting] = React.useState([]); const table = useReactTable({ data, columns, onSortingChange: setSorting, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), state: { sorting, }, initialState: { sorting: [ { id: 'member', desc: true, }, ], }, }); return (
Select Financial Transactions
View and manage your transaction history.
All transacitions
{table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header, i) => { return ( {header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext(), )} ); })} ))} {table.getRowModel().rows?.length > 0 && table.getRowModel().rows.map((row, i, arr) => ( {row.getVisibleCells().map((cell, i2) => ( {flexRender( cell.column.columnDef.cell, cell.getContext(), )} ))} {i < arr.length - 1 && } ))}
); }