how to scroll to index in deeply hierarchical list in react-virtualized

后端 未结 1 1024
小蘑菇
小蘑菇 2021-01-23 20:26

The List component of react-virtualized offers a property scrollToIndex to enable scrolling to a list item that is currently not visible.

The official tree

相关标签:
1条回答
  • 2021-01-23 21:09

    Your intuition is correct here. You can't use the scrollToIndex to scroll within a large row in the way you're describing. However you could use the scrollTop property instead. (Internally Grid is just converting the index to a scroll offset anyway.)

    function render ({ scrollToIndex, ...rest }) {
      // Convert scrollToIndex to scrollStop
      const scrollTop =
        rowOffset + // Position of row within List
        innerOffset // Position of inner target within row
    
      return (
        <List
          scrollTop={scrollTop}
          {...rest}
        />
      )
    }
    

    PS: This is a pretty cool tree component built on top of react-virtualized. Thought you may find it interesting: https://fritz-c.github.io/react-sortable-tree/

    0 讨论(0)
提交回复
热议问题