VirtualRows with rendering sub components
Hey everyone.
I am currently building a table that uses both tanstack virtual (mainly the useWindowVirtualizer hook) as well as tanstack table. In the tanstack table examples there is a way to render sub components. Functionally I have it all working but when combined with the useWindowVirtualizer stuff it doesn't change the
getTotalSize
which I think its because in this situation the count doesn't change so the virtualizer doesn't adjust the total height.
I thought of passing the measureElement
to the fragment but that isn't possible. Does anyone have any idea of a solution to this?
1 Reply
broad-brown•4w ago
Hey! Yep, you’re right , the issue here is that when using useWindowVirtualizer, it calculates getTotalSize based on the number of rows (count), so if you're rendering sub components (like expanded rows) outside the virtualizer’s control, it won’t account for their height.
To fix that, you have two options:
* Treat expanded rows the same as TableBodyRowElement, meaning, make them part of the virtualized list and position them absolutely just like the other rows. This way, you can pass measureElement to them and let the virtualizer adjust based on their actual height.
* Alternative strategy, insert a "before" and/or "after" row that mimics the expanded content and adjusts the height, kind of like a spacer https://codesandbox.io/p/sandbox/virtual-simple-table-cdqqpg