import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, ElementRef, Input, ContentChild, ContentChildren, ViewChild, Output, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { Header, Footer, PrimeTemplate, SharedModule } from 'primeng/api'; import { CdkVirtualScrollViewport, ScrollingModule } from '@angular/cdk/scrolling'; class VirtualScroller { constructor(el) { this.el = el; this.trackBy = (index, item) => item; this.onLazyLoad = new EventEmitter(); this._totalRecords = 0; this.page = 0; this._first = 0; this.loadedPages = []; } get totalRecords() { return this._totalRecords; } set totalRecords(val) { this._totalRecords = val; console.log("totalRecords is deprecated, provide a value with the length of virtual items instead."); } get first() { return this._first; } set first(val) { this._first = val; console.log("first property is deprecated, use scrollToIndex function to scroll a specific item."); } get cache() { return this._cache; } set cache(val) { this._cache = val; console.log("cache is deprecated as it is always on."); } ngAfterContentInit() { this.templates.forEach((item) => { switch (item.getType()) { case 'item': this.itemTemplate = item.template; break; case 'loadingItem': this.loadingItemTemplate = item.template; break; case 'header': this.headerTemplate = item.template; break; case 'footer': this.footerTemplate = item.template; break; default: this.itemTemplate = item.template; break; } }); } onScrollIndexChange(index) { if (this.lazy) { let pageRange = this.createPageRange(Math.floor(index / this.rows)); pageRange.forEach(page => this.loadPage(page)); } } createPageRange(page) { let range = []; if (page !== 0) { range.push(page - 1); } range.push(page); if (page !== (Math.ceil(this.value.length / this.rows) - 1)) { range.push(page + 1); } return range; } loadPage(page) { if (!this.loadedPages.includes(page)) { this.onLazyLoad.emit({ first: this.rows * page, rows: this.rows }); this.loadedPages.push(page); } } getBlockableElement() { return this.el.nativeElement.children[0]; } //@deprecated scrollTo(index, mode) { this.scrollToIndex(index, mode); } scrollToIndex(index, mode) { if (this.viewport) { this.viewport.scrollToIndex(index, mode); } } clearCache() { this.loadedPages = []; } ngOnChanges(simpleChange) { if (simpleChange.value) { if (!this.lazy) { this.clearCache(); } } } } VirtualScroller.decorators = [ { type: Component, args: [{ selector: 'p-virtualScroller', template: `