question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scroll position resetting to 0 on re-render

See original GitHub issue

Using v6.8.0

This is someone else pen, but it works as an example: https://codepen.io/Kamilius/pen/LpObwW?editors=0010

Scroll half way. Change someone’s name that’s visible in the viewport. Table re-renders and scroll position resets to 0.

If I have a dynamically created table, with a lot of records, while I’m viewing this table, a new record is created, the scroll position is reset to 0. I’d then need to scroll back down to my previous position.

React by default doesn’t change the scroll position. This must be a custom function in react-table is there any way to override/disable this behavior? So upon updating the table with a new record I’m not forced to scroll to my previous position?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
SelaOcommented, May 15, 2018

@pourmesomecode We managed to fix this, we overrode the body component with a function at first, but when we changed it to be a component it fixed it.

i.e:

<ReactTable
          data={data}
          TbodyComponent={BodyComponent}
....

class BodyComponent extends Component {
  render() {
    return (
      <myDiv>
        {ReactTableUtils.makeTemplateComponent('rt-tbody', 'Tbody')(this.props)}
      </myDiv>
    )
  }
}
0reactions
hattoncommented, Dec 26, 2018

Came here after running into this issue in 6.7.0. In my case, if React-Table becomes invisible (e.g. in a tabbed interface) and then visible again, it retains the selected row, but fails to retain the scroll position. I worked around this way for now (typescript):

  private scrollSelectedIntoView() {
    const table = document.getElementsByClassName("ReactTable")[0];
    table
      .getElementsByClassName("rt-tr selected")[0]
      .scrollIntoView({ block: "nearest" });
  }

<ReactTable
    ....
       onFetchData={() => this.scrollSelectedIntoView()}

This may well be an abuse of the onFetchData event, happy to hear of a better way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scroll position resetting to 0 on re-render · Issue #963 - GitHub
Scroll half way. Change someone's name that's visible in the viewport. Table re-renders and scroll position resets to 0. If I have a...
Read more >
Reset scroll position on component re-render - Stack Overflow
You need to manually change the scrollLeft position to 0 for the div which has overflow: scroll property which in your case is...
Read more >
[Solved]-Reset scroll position on component re-render-Reactjs
Coding example for the question Reset scroll position on component re-render-Reactjs.
Read more >
scroll bar not reset on refresh - GSAP - GreenSock
run wierd issue that cant figure out i have scrolltrigger and smoothscroll on everything is working and when i refresh page the page ......
Read more >
Maintain and restore scroll position in React mobile apps
Learn how to maintain React app scroll position when users close a full-page mobile menu to improve UX by implementing a custom Hook....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found