Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cdk virtualscroll with mat-grid-list

Is there a virtual scroll implementation that works with the grid-list? I think the default implementation won't work because each row should have an element around it.

I'm using the grid-list to display profile pictures, and need an infinite scroll or preferably virtual scroll to load new ones.

like image 395
Elger Mensonides Avatar asked Nov 26 '18 08:11

Elger Mensonides


Video Answer


1 Answers

So since cdk virtualscroll doesn't support multi column, I ended up using ngx-virtual-scroller, which does support multi-columns. The mat-grid-list I also had to let go because of this, but, creating your own tiles isn't that much work when using flexbox.

Here's a snippet using multi columns, [users-online-tile] is a component that represents a user-picture with a name. The IsHandset boolean (from cdk) I use to set the height of the tile so more or less tiles are displayed depending on the screen size.

Hope this helps someone

    <virtual-scroller [items]="users" (vsUpdate)="onVsUpdate($event)" (vsEnd)="fetchMore($event)"
      (vsChange)="onVsChange($event)" [scrollbarWidth]="20" [scrollbarHeight]="100" [bufferAmount]="100">
      <div [ngClass]="{ 'users-online-tile' :  (isHandset$ | async), 'users-online-tile-desktop' : !(isHandset$ | async) }" 
              *ngFor="let user of scrollItems">
        <div [users-online-tile]="user" [isHandset]="(isHandset$ | async)"></div>
        <!-- <div class="item">{{user.userName}}</div> -->
      </div>
    </virtual-scroller>

like image 193
Elger Mensonides Avatar answered Sep 21 '22 19:09

Elger Mensonides