Replies: 2 comments 1 reply
-
Hi, I also noticed this problem with the visualizer and tree combination, it seems as if the visualizer does not take into account the record that is expanded when you set the expanded flag to true. I managed to get it working with this workaround: rowVirtualizerInstanceRef.current?.scrollToIndex(index, { Example: |
Beta Was this translation helpful? Give feedback.
-
Hi guys, first of all, MRT uses TanStack Virtual under the hood. You can customize the virtualizer according to your needs using const scrollToIndex = (targetIndex: number) => {
// Gets the parent index (doesn't use flatRows as that will take into account the child rows)
const parentRow = table.getRowModel().rows[targetIndex];
if (parentRow && parentRow.subRows?.[0]) {
setExpanded({ [parentRow.id]: true });
// Maybe use flushSync here instead of setTimeout
// Wait for expand state to update before scrolling
setTimeout(() => {
// Find the child row's index in flat rows
const childFlatIndex = table.getRowModel().flatRows.findIndex(
row => row.id === parentRow.subRows[0].id
);
if (childFlatIndex !== -1) {
rowVirtualizerInstanceRef.current?.scrollToIndex(childFlatIndex, {
align: 'center'
});
}
}, 0);
}
}; Also just as a bit of advise try not to use |
Beta Was this translation helpful? Give feedback.
-
mantine-react-table version
2.0.0-beta.7
react & react-dom versions
18.2.0
Describe the bug and the steps to reproduce it
Hello, i'm using a table with
enableRowVirtualization
set to true, i have injected arowVirtualizerInstanceRef
to the table and i'm using the methodrowVirtualizerInstanceRef.current?.scrollToIndex(rowIndex)
the problem is it does the scroll but it doesn't scroll to the exact index, i tried several params for thescrollToIndex
method but the result is always the sameMinimal, Reproducible Example - (Optional, but Recommended)
Screenshots or Videos (Optional)
No response
Do you intend to try to help solve this bug with your own PR?
None
Terms
Beta Was this translation helpful? Give feedback.
All reactions