mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-06 20:10:12 +02:00
handle scroll reset on grid page change
This commit is contained in:
@@ -52,6 +52,7 @@ import { LibraryItem } from '/@/shared/types/domain-types';
|
|||||||
interface VirtualizedGridListProps {
|
interface VirtualizedGridListProps {
|
||||||
_tableMetaVersion: number; // Used to trigger rerenders via React.memo comparison
|
_tableMetaVersion: number; // Used to trigger rerenders via React.memo comparison
|
||||||
controls: ItemControls;
|
controls: ItemControls;
|
||||||
|
currentPage?: number;
|
||||||
data: unknown[];
|
data: unknown[];
|
||||||
enableDrag?: boolean;
|
enableDrag?: boolean;
|
||||||
enableExpansion: boolean;
|
enableExpansion: boolean;
|
||||||
@@ -78,6 +79,7 @@ interface VirtualizedGridListProps {
|
|||||||
const VirtualizedGridList = React.memo(
|
const VirtualizedGridList = React.memo(
|
||||||
({
|
({
|
||||||
controls,
|
controls,
|
||||||
|
currentPage,
|
||||||
data,
|
data,
|
||||||
enableDrag,
|
enableDrag,
|
||||||
enableExpansion,
|
enableExpansion,
|
||||||
@@ -149,6 +151,20 @@ const VirtualizedGridList = React.memo(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const calculateInitialScrollOffset = (): number => {
|
const calculateInitialScrollOffset = (): number => {
|
||||||
|
// When page changes, always start at top (ignore initialTop)
|
||||||
|
if (currentPage !== undefined) {
|
||||||
|
if (currentPage === 0 && initialTop) {
|
||||||
|
if (initialTop.type === 'offset') {
|
||||||
|
return initialTop.to;
|
||||||
|
}
|
||||||
|
const columnCount = tableMeta?.columnCount || 1;
|
||||||
|
const itemHeight = tableMeta?.itemHeight || 0;
|
||||||
|
const rowIndex = Math.floor(initialTop.to / columnCount);
|
||||||
|
return rowIndex * itemHeight;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!initialTop) return 0;
|
if (!initialTop) return 0;
|
||||||
|
|
||||||
if (initialTop.type === 'offset') {
|
if (initialTop.type === 'offset') {
|
||||||
@@ -270,6 +286,7 @@ export interface ItemGridListProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const BaseItemGridList = ({
|
const BaseItemGridList = ({
|
||||||
|
currentPage,
|
||||||
data,
|
data,
|
||||||
enableDrag = true,
|
enableDrag = true,
|
||||||
enableExpansion = false,
|
enableExpansion = false,
|
||||||
@@ -687,6 +704,7 @@ const BaseItemGridList = ({
|
|||||||
<VirtualizedGridList
|
<VirtualizedGridList
|
||||||
_tableMetaVersion={tableMetaVersion}
|
_tableMetaVersion={tableMetaVersion}
|
||||||
controls={controls}
|
controls={controls}
|
||||||
|
currentPage={currentPage}
|
||||||
data={data}
|
data={data}
|
||||||
enableDrag={enableDrag}
|
enableDrag={enableDrag}
|
||||||
enableExpansion={enableExpansion}
|
enableExpansion={enableExpansion}
|
||||||
|
|||||||
Reference in New Issue
Block a user