components icon indicating copy to clipboard operation
components copied to clipboard

Is it possible to use multiple cdk-virtual-scroll-viewport in single component with different buffer size?

Open sthan001 opened this issue 5 years ago • 3 comments

Feature Description

We would like to have multiple cdk-virtual-scroll-viewport in single component each initialized with different startup details i.e. constructor(itemSize: number, minBufferPx: number, maxBufferPx: number);

Use Case

We have a grid and list view of same datasource. We first have trouble to fold the scroller height for grid view (scaled by 3 in a row).

We could try to manage that challenge. But now we have another requirement to display grid view with different buffer size when user changes the view. Is it possibly to destroy FixedSizeVirtualScrollStrategy and recreate with new values defined in component via - providers: [{provide: VIRTUAL_SCROLL_STRATEGY, useClass: CustomVirtualScrollStrategy}] from within same component?

sthan001 avatar Jun 03 '21 07:06 sthan001

i

mport {ChangeDetectionStrategy, Component, OnInit} from '@angular/core'; import {FixedSizeVirtualScrollStrategy, VIRTUAL_SCROLL_STRATEGY} from '@angular/cdk/scrolling';

export class CustomVirtualScrollStrategy extends FixedSizeVirtualScrollStrategy { constructor() { super(200, 2000, 2000); } }

@Component({ selector: 'app-cdk-scroll-simple-v002', templateUrl: './cdk-scroll-simple-v002.component.html', styleUrls: ['./cdk-scroll-simple-v002.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, providers: [{provide: VIRTUAL_SCROLL_STRATEGY, useClass: CustomVirtualScrollStrategy}] }) export class CdkScrollSimpleV002Component implements OnInit { items = Array.from({length: 25}).map((_, i) => Item #${i}); constructor() { } ngOnInit(): void { } }

  1. Here we would like to have one more custom virtual scroll strategy(CustomVirtualScrollStrategy) so that other element able to use it.
  2. Still not sure how the variable can be supplied for this constructor than the fixed value. we would like to avoid reference in html template as well.

sthan001 avatar Jun 03 '21 07:06 sthan001

Please keep GitHub issues for bug reports / feature requests. Better avenues for troubleshooting / questions are stack overflow, gitter, mailing list, etc.

crisbeto avatar Jun 08 '21 07:06 crisbeto

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.