Skip to content

Commit

Permalink
fix(react-grid): change processing of last page in lazy load mode (#2067
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ushkal committed Jun 6, 2019
1 parent 35c4642 commit 2b52fe0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Expand Up @@ -203,6 +203,14 @@ describe('VirtualTableState helpers', () => {
expect(calculateRequestedRange(loadedInterval, newInterval, 399, pageSize))
.toEqual({ start: 300, end: 500 });
});

it('should correctly process the last page', () => {
const loadedInterval = createInterval(0, 200);
const newInterval = createInterval(1000, 1200);

expect(calculateRequestedRange(loadedInterval, newInterval, 1180, pageSize))
.toEqual({ start: 1000, end: 1200 });
});
});

describe('fast scroll', () => {
Expand Down
21 changes: 12 additions & 9 deletions packages/dx-grid-core/src/plugins/virtual-table-state/helpers.ts
Expand Up @@ -45,16 +45,19 @@ export const mergeRows: MergeRowsFn = (
export const calculateRequestedRange: CalculateRequestedRangeFn = (
loadedInterval, newRange, referenceIndex, pageSize,
) => {
if (Math.abs(loadedInterval.start - newRange.start) >= 2 * pageSize) {
const useFirstHalf = referenceIndex % pageSize < pageSize / 2;
const start = useFirstHalf
? newRange.start
: newRange.start + pageSize;
const end = Math.min(newRange.end, start + 2 * pageSize);

return { start, end };
const isAdjacentPage = Math.abs(loadedInterval.start - newRange.start) < 2 * pageSize;
if (isAdjacentPage) {
return intervalUtil.difference(newRange, loadedInterval);
}
return intervalUtil.difference(newRange, loadedInterval);

const useFirstHalf = referenceIndex % pageSize < pageSize / 2;
const isLastPage = intervalUtil.getLength(newRange) / pageSize < 3;
const start = useFirstHalf || isLastPage
? newRange.start
: newRange.start + pageSize;
const end = Math.min(newRange.end, start + 2 * pageSize);

return { start, end };
};

export const rowToPageIndex: PureComputed<[number, number]> = (
Expand Down

0 comments on commit 2b52fe0

Please sign in to comment.