javascript - How to virtualize rows inside an expandable panel in React Virtualized? - Stack Overflow

I am using React Virtualized to render a list with expandable panels. The issue is that when a panel ex

I am using React Virtualized to render a list with expandable panels. The issue is that when a panel expands, all 500+ rows inside it are loaded at once, making the UI very slow.

The outer list is virtualized, but I also want to virtualize the rows inside the expanded panel so only visible rows are rendered.

Wrapping the inner rows with List from react-virtualized, but it didn’t work as expected. I am facing issues with height calculations when trying to virtualize both levels. How can I efficiently virtualize the inner rows inside an expanded panel?

Here’s my CodeSandbox link showing the issue:

Reference

I am using React Virtualized to render a list with expandable panels. The issue is that when a panel expands, all 500+ rows inside it are loaded at once, making the UI very slow.

The outer list is virtualized, but I also want to virtualize the rows inside the expanded panel so only visible rows are rendered.

Wrapping the inner rows with List from react-virtualized, but it didn’t work as expected. I am facing issues with height calculations when trying to virtualize both levels. How can I efficiently virtualize the inner rows inside an expanded panel?

Here’s my CodeSandbox link showing the issue:

Reference

Share Improve this question edited Mar 8 at 15:23 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Mar 8 at 13:41 Aman SadhwaniAman Sadhwani 3,5683 gold badges19 silver badges28 bronze badges 2
  • 1 Do you need to see multiple panels at once? If yes, have three separate togglable lists. If not, have one list populated with the filtered entries of the selected category. – moonwave99 Commented Mar 8 at 15:15
  • The panels are already separated; the question is how to virtualize the rows inside these panels. – Aman Sadhwani Commented Mar 8 at 15:22
Add a comment  | 

1 Answer 1

Reset to default 1

When you don't set a fixed height for the inner container, the virtualization engine can't determine which rows are visible, rendering every row in the expanded section. By wrapping the inner list in a container with a specific height (say 300px), you let React Virtualized know how much space it has to work with. Then, using an AutoSizer, it calculates the available width and height, and the List component only renders the rows that fit within that space.

Maybe like this :

{expanded && (
  <div style={{ height: 300 }}>
    <AutoSizer>
      {({ height, width }) => (
        <List
          width={width}
          height={height}
          rowCount={rows.length}
          rowHeight={50}
          rowRenderer={innerRowRenderer}
        />
      )}
    </AutoSizer>
  </div>
)}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744894793a4599629.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信