Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
Scroll virtual list to specified row

Struggle to make virtualized list scrolled to a particular row after content refresh. Scenario: there are few rows, user scrolls to somewhere in the list, and then triggers an event (e.g. presses a button in the app) that modifies the content of the list items. Ideally the user must see the same row at the top of the scroll view that was before the event occurred.

Here is the snippet from my code where I try to make it work with no success.

class MyList extends React.Component {
  state = {
    newScrollToIndex: undefined
  }

  // function triggered from outsided events
  onCellContentChanged() {
    const index = this.listRowIndex

    // Don't know really which one to call exactlty
    // Just called everything
    this.cellMeasurerCache.clearAll()
    this.listView.recomputeRowHeights()
    this.listView.measureAllRows()

    /*
     * Tried this did not work at all.
     * const off = this.listView.getOffsetForRow({ index })
     * this.listView.scrollToPosition(off)
     */

    // This two seem to work equivalently with 50% chance to work correctly.
    // this.listView.scrollToRow(index)
    this.setState({ newScrollToIndex: index })
  }

  renderInfiniteList({ height, width }) {
    return (
      <InfiniteLoader
        isRowLoaded={this.isRowLoaded}
        loadMoreRows={this.loadMoreRows}
        rowCount={this.rowCount}
      >
        {({ onRowsRendered, registerChild }) => {
          return (
            <List
              style={{ outline: 'none' }}
              noRowsRenderer={() => (
                <NoRows
                  loading={
                    this.state.loadingMoreRows || this.state.loadingFields
                  }
                />
              )}
              height={height}
              width={width}
              overscanRowCount={2}
              rowCount={this.listViewRowCount}
              rowHeight={this.cellMeasurerCache.rowHeight}
              deferredMeasurementCache={this.cellMeasurerCache}
              rowRenderer={this.rowRenderer}
              scrollToIndex={this.state.newScrollToIndex}
              onRowsRendered={(o) => {
                onRowsRendered(o)
                this.listRowIndex = o.startIndex
              }}
              ref={(listView) => {
                registerChild(listView)
                this.listView = listView
              }}
            />
          )
        }}
      </InfiniteLoader>
    )
  }
}

Any clarification on what is the proper way to make of this scenario to work is appreciated.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!