-
Notifications
You must be signed in to change notification settings - Fork 380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(react-grid): correct calculating start index of loading row for Infinite Scrolling #2256
Changes from 10 commits
f96c158
78d22eb
6769228
43f978d
11af8be
672a0e8
4878aef
9fb6479
37d1f00
89301ed
bdce541
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { intervalUtil } from './utils'; | ||
import { | ||
VirtualRows, Row, MergeRowsFn, CalculateRequestedRangeFn, Interval, GridViewport, GetRequestMeta, | ||
VirtualRows, Row, MergeRowsFn, CalculateRequestedRangeFn, | ||
Interval, GridViewport, GetRequestMeta, CorrectRangeFn, | ||
} from '../../types'; | ||
import { PureComputed } from '@devexpress/dx-core'; | ||
|
||
|
@@ -42,13 +43,26 @@ export const mergeRows: MergeRowsFn = ( | |
}; | ||
}; | ||
|
||
const correctRequestedRange: CorrectRangeFn = (calculatedRange, referenceIndex, pageSize) => { | ||
const { start, end } = calculatedRange; | ||
|
||
if (start - referenceIndex > pageSize / 2) { | ||
return { start: start - pageSize, end: end - pageSize }; | ||
} | ||
return { start, end }; | ||
}; | ||
|
||
export const calculateRequestedRange: CalculateRequestedRangeFn = ( | ||
virtualRows, newRange, pageSize, | ||
virtualRows, newRange, pageSize, referenceIndex, isInfiniteScroll, | ||
) => { | ||
const loadedInterval = intervalUtil.getRowsInterval(virtualRows); | ||
const isAdjacentPage = Math.abs(loadedInterval.start - newRange.start) < 2 * pageSize; | ||
if (isAdjacentPage) { | ||
return intervalUtil.difference(newRange, loadedInterval); | ||
const calculatedRange = intervalUtil.difference(newRange, loadedInterval); | ||
if (isInfiniteScroll && calculatedRange !== intervalUtil.empty) { | ||
return correctRequestedRange(calculatedRange, referenceIndex, pageSize); | ||
} | ||
return calculatedRange; | ||
} | ||
|
||
// load 3 pages at once because a missing page will be loaded anyway | ||
|
@@ -120,14 +134,16 @@ export const getForceReloadInterval: PureComputed<[VirtualRows, number, number], | |
}; | ||
|
||
export const getRequestMeta: GetRequestMeta = ( | ||
referenceIndex, virtualRows, pageSize, totalRowCount, forceReload, | ||
referenceIndex, virtualRows, pageSize, totalRowCount, forceReload, isInfiniteScroll, | ||
) => { | ||
const actualBounds = forceReload | ||
? getForceReloadInterval(virtualRows, pageSize!, totalRowCount) | ||
: recalculateBounds(referenceIndex, pageSize!, totalRowCount); | ||
const requestedRange = forceReload | ||
? actualBounds | ||
: calculateRequestedRange(virtualRows, actualBounds, pageSize!); | ||
: calculateRequestedRange( | ||
virtualRows, actualBounds, pageSize!, referenceIndex, isInfiniteScroll, | ||
); | ||
|
||
return { requestedRange, actualBounds }; | ||
}; | ||
|
@@ -138,7 +154,7 @@ export const needFetchMorePages: PureComputed<[VirtualRows, number, number], boo | |
const { start, end } = intervalUtil.getRowsInterval(virtualRows); | ||
const loadCount = end - start; | ||
const topTriggerIndex = start > 0 ? start + pageSize! : 0; | ||
const bottomTriggerIndex = end - pageSize!; | ||
const bottomTriggerIndex = Math.max(topTriggerIndex + pageSize, end - pageSize! * 1.5); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Half of page. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sometimes we may catch this bug not in beginning of table. It is quite difficult to catch, but can. This check fixes it. |
||
|
||
if (loadCount <= 0) { | ||
return false; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we want rows 300-400 if they're loaded already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we try load next page (rows 400-500) width index less than page 350 (for
pageSize === 100
), we catch index bug. It loads nextPage instead curren when we fast scroll up.We see at string 320, cache know about previous (200-300) and next page (400-500), and we load 400-500. Then, we get rows combination:
For index less than
start - pageSize/2
we need to shift loading interval.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it reproduce in non-infinite mode?