Skip to content

Commit

Permalink
Merge pull request #2 from miki-tebe/main
Browse files Browse the repository at this point in the history
More pagination features and header ui fix
  • Loading branch information
frectonz authored Jun 14, 2024
2 parents f16a36d + 7c9b47d commit b44039a
Show file tree
Hide file tree
Showing 6 changed files with 440 additions and 19 deletions.
225 changes: 225 additions & 0 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"dependencies": {
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tabs": "^1.0.4",
"@tanstack/react-query": "^5.44.0",
Expand Down
71 changes: 54 additions & 17 deletions ui/src/components/ui/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ import {
TableRow,
} from "@/components/ui/table";

import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";

interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[];
data: TData[];
Expand Down Expand Up @@ -84,23 +92,52 @@ export function DataTable<TData, TValue>({
</TableBody>
</Table>
</div>
<div className="flex items-center justify-end space-x-2 py-4">
<Button
variant="outline"
size="sm"
onClick={() => table.previousPage()}
disabled={!table.getCanPreviousPage()}
>
Previous
</Button>
<Button
variant="outline"
size="sm"
onClick={() => table.nextPage()}
disabled={!table.getCanNextPage()}
>
Next
</Button>
<div className="flex items-center justify-between space-x-2 py-4">
<div className="flex text-sm text-muted-foreground">
Page {table.getState().pagination.pageIndex + 1} of{" "}
{table.getPageCount().toLocaleString()} page(s).
</div>
<div className="space-x-2">
<Button
variant="outline"
size="sm"
onClick={() => table.previousPage()}
disabled={!table.getCanPreviousPage()}
>
Previous
</Button>
<Button
variant="outline"
size="sm"
onClick={() => table.nextPage()}
disabled={!table.getCanNextPage()}
>
Next
</Button>
</div>
<div>
<Select
onValueChange={(pageSize) => table.setPageSize(Number(pageSize))}
defaultValue="10"
>
<SelectTrigger className="text-sm">
<SelectValue>
Rows per page: {table.getState().pagination.pageSize}
</SelectValue>
</SelectTrigger>
<SelectContent>
{[10, 20, 30, 40, 50, 100].map((pageSize) => (
<SelectItem
key={pageSize}
onClick={() => table.setPageSize(pageSize)}
value={String(pageSize)}
>
{pageSize}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
</div>
</div>
);
Expand Down
Loading

0 comments on commit b44039a

Please sign in to comment.