Skip to content

Commit

Permalink
Fix smooth scrolling of table
Browse files Browse the repository at this point in the history
  • Loading branch information
platypii committed Oct 29, 2024
1 parent f633893 commit ff39a2c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@
"@rollup/plugin-terser": "0.4.4",
"@rollup/plugin-typescript": "12.1.1",
"@testing-library/react": "16.0.1",
"@types/node": "22.8.1",
"@types/node": "22.8.2",
"@types/react": "18.3.12",
"@types/react-dom": "18.3.1",
"@vitest/coverage-v8": "2.1.3",
"@vitest/coverage-v8": "2.1.4",
"eslint": "9.13.0",
"eslint-plugin-react": "7.37.2",
"http-server": "14.1.1",
"jsdom": "25.0.1",
"tslib": "2.8.0",
"typescript": "5.6.3",
"typescript-eslint": "8.11.0",
"vitest": "2.1.3"
"typescript-eslint": "8.12.1",
"vitest": "2.1.4"
},
"peerDependencies": {
"react": "^18.2.0",
Expand Down
4 changes: 1 addition & 3 deletions src/HighTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export default function HighTable({
const scrollTop = scrollRef.current?.scrollTop || 0 // scroll position

// determine rows to fetch based on current scroll position
// TODO: compute the floor delta so offsetTop adjustment is smooth
const startView = Math.floor(data.numRows * scrollTop / scrollHeight)
const endView = Math.ceil(data.numRows * (scrollTop + clientHeight) / scrollHeight)
const start = Math.max(0, startView - overscan)
Expand All @@ -129,8 +128,7 @@ export default function HighTable({
if (isNaN(end)) throw new Error('invalid end row ' + end)
if (end - start > 1000) throw new Error('too many rows to fetch ' + (end - start))

const preOffset = Math.min(overscan + padding, startView) * rowHeight
const offsetTop = Math.max(0, scrollTop - preOffset)
const offsetTop = Math.max(0, start - padding) * rowHeight

// Fetch a chunk of rows from the data frame
try {
Expand Down

0 comments on commit ff39a2c

Please sign in to comment.