I have a list that has many items and each item can be selected. For this I use Angular Material Virtual Scroll. When an item is selected, the selected item is highlighted and then is saved on the server. When I refresh the page, the selected item comes from the server and is again highlighted.
My code looks like
<cdk-virtual-scroll-viewport itemSize="40" class="wrapper">
<div *cdkVirtualFor="let item of list"
[class.selected]="item.id === selectedItem.id">
</div>
</cdk-virtual-scroll-viewport>
The problem is that if a select an item that is down in the list, it is highlighted, but I have to scroll down to the list to see it. I want to programmatically scroll down to it when that item comes from the server.
I the docs there is a scrollToIndex
method. Where I can find an instance of FixedSizeVirtualScrollStrategy
, so I can call this method?