Here, first of all you can check the current status of the app without virtual scrolling:
Image Preview Of the Website Here
The scrolling is pretty smooth but as you can see searching and navigating back and forth is a bit slow as there's a reloading of the DOM. Its not the searching logic that is slow as I'm just using a simple pipe to filter out the Pokemon list based on only Pokemon Names and ID. I have tested and found out that the culprit is the insane no of Elements in the DOM. (There are nested Divs in each Pokemon Item)
The pokemon list component without Virtual Scrolling.:
<div class="row justify-content-center">
<app-pokemon-item *ngFor="let pokemon of pokemons | searchFilter: searchItem; let i = index;"
[pokemon]="pokemon"></app-pokemon-item>
</div>
So now I'm trying to implement Virtual Scrolling to improve performance but this happens:
- The list shutters a lot while scrolling.(Doesn't Feels like normal scrolling).
- The Pokemon Images are disturbed (shuffled/randomized).
- The Images are not even static the images for a single Pokemon change on scrolling up and down.
- Also I want to retain the previous Grid look.
Modified Pokemon list Component with Virtual Scrolling.
<cdk-virtual-scroll-viewport style="height: 90vh" itemSize="100">
<ng-container *cdkVirtualFor="let pokemon of pokemons | searchFilter: searchItem; let i = index;">
<app-pokemon-item [pokemon]="pokemon"></app-pokemon-item>
</ng-container>
</cdk-virtual-scroll-viewport>