From 7660f1037b26ea2825b1465c822793a8e958d523 Mon Sep 17 00:00:00 2001 From: Markus Thielker Date: Mon, 11 Mar 2024 10:27:52 +0100 Subject: [PATCH] N-FIN-19: add page size drop down The default page size is set to 50 --- src/components/ui/data-table.tsx | 102 ++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 37 deletions(-) diff --git a/src/components/ui/data-table.tsx b/src/components/ui/data-table.tsx index 33815e4..5492642 100644 --- a/src/components/ui/data-table.tsx +++ b/src/components/ui/data-table.tsx @@ -4,8 +4,9 @@ import { ColumnDef, flexRender, getCoreRowModel, getPaginationRowModel, useReact import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'; import { Button } from '@/components/ui/button'; -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from 'lucide-react'; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; interface DataTableProps { columns: ColumnDef[]; @@ -20,6 +21,7 @@ export function DataTable({ pagination, className, }: DataTableProps) { + const table = useReactTable({ data, columns, @@ -27,6 +29,13 @@ export function DataTable({ getPaginationRowModel: pagination ? getPaginationRowModel() : undefined, }); + const [pageSize, setPageSize] = useState(50); + useEffect(() => { + if (pagination) { + table.setPageSize(pageSize); + } + }, [table, pagination, pageSize]); + return (
@@ -75,43 +84,62 @@ export function DataTable({
{ pagination && ( -
- - + + + +
) }