Skip to content

Commit 881e934

Browse files
committed
Scroll to top on pagination change
1 parent fbbc123 commit 881e934

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

frontend/src/components/Table/data-table-pagination.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "lucide-react"
88
import { Button } from "../ui/button"
99
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../ui/select"
10+
import {useLayoutEffect} from "react";
1011

1112
interface DataTablePaginationProps<TData> {
1213
table: Table<TData>
@@ -19,6 +20,12 @@ export function DataTablePagination<TData>({
1920
rowsPerPage,
2021
setRowsPerPage,
2122
}: DataTablePaginationProps<TData>) {
23+
useLayoutEffect(() => {
24+
requestAnimationFrame(() => {
25+
window.scrollTo({ top: 0, behavior: "instant" })
26+
})
27+
}, [table.getState().pagination.pageIndex])
28+
2229
return (
2330
<div className="flex flex-col sm:flex-row items-center justify-between px-2 gap-2 sm:gap-0 my-5">
2431
<div className="flex-1 text-sm text-muted-foreground w-full sm:w-auto text-center sm:text-right pr-10">

0 commit comments

Comments
 (0)