fix(dashboard): reset table scroll on page change (#7916)
This commit is contained in:
+15
-1
@@ -5,7 +5,14 @@ import {
|
|||||||
Row,
|
Row,
|
||||||
flexRender,
|
flexRender,
|
||||||
} from "@tanstack/react-table"
|
} from "@tanstack/react-table"
|
||||||
import { ComponentPropsWithoutRef, Fragment, UIEvent, useState } from "react"
|
import {
|
||||||
|
ComponentPropsWithoutRef,
|
||||||
|
Fragment,
|
||||||
|
UIEvent,
|
||||||
|
useEffect,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
} from "react"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
import { useNavigate } from "react-router-dom"
|
import { useNavigate } from "react-router-dom"
|
||||||
import { NoResults } from "../../../common/empty-table-content"
|
import { NoResults } from "../../../common/empty-table-content"
|
||||||
@@ -79,6 +86,8 @@ export const DataTableRoot = <TData,>({
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const [showStickyBorder, setShowStickyBorder] = useState(false)
|
const [showStickyBorder, setShowStickyBorder] = useState(false)
|
||||||
|
|
||||||
|
const scrollableRef = useRef()
|
||||||
|
|
||||||
const hasSelect = columns.find((c) => c.id === "select")
|
const hasSelect = columns.find((c) => c.id === "select")
|
||||||
const hasActions = columns.find((c) => c.id === "actions")
|
const hasActions = columns.find((c) => c.id === "actions")
|
||||||
const hasCommandBar = commands && commands.length > 0
|
const hasCommandBar = commands && commands.length > 0
|
||||||
@@ -105,6 +114,10 @@ export const DataTableRoot = <TData,>({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
scrollableRef.current?.scroll({ top: 0, left: 0 })
|
||||||
|
}, [pageIndex])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={clx("flex w-full flex-col overflow-hidden", {
|
className={clx("flex w-full flex-col overflow-hidden", {
|
||||||
@@ -112,6 +125,7 @@ export const DataTableRoot = <TData,>({
|
|||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
ref={scrollableRef}
|
||||||
onScroll={handleHorizontalScroll}
|
onScroll={handleHorizontalScroll}
|
||||||
className={clx("w-full", {
|
className={clx("w-full", {
|
||||||
"min-h-0 flex-grow overflow-auto": layout === "fill",
|
"min-h-0 flex-grow overflow-auto": layout === "fill",
|
||||||
|
|||||||
Reference in New Issue
Block a user