Gathering detailed insights and metrics for ng-virtual-list
Gathering detailed insights and metrics for ng-virtual-list
Gathering detailed insights and metrics for ng-virtual-list
Gathering detailed insights and metrics for ng-virtual-list
npm install ng-virtual-list
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
2
Maximum performance for extremely large lists.
Angular version 20.X.X.
1npm i ng-virtual-list
Template:
1<ng-virtual-list class="list" direction="hotizontal" [items]="horizontalItems" [itemsOffset]="50" 2 [itemRenderer]="hotizontalItemRenderer" [itemSize]="64"></ng-virtual-list> 3 4<ng-template #hotizontalItemRenderer let-data="data"> 5 @if (data) { 6 <div class="list__h-container" (click)="onItemClick(data)"> 7 <span>{{data.name}}</span> 8 </div> 9 } 10</ng-template>
Component:
1import { NgVirtualListComponent, IVirtualListCollection } from 'ng-virtual-list';
2
3const HORIZONTAL_ITEMS: IVirtualListCollection = [];
4for (let i = 0, l = 1000000; i < l; i++) {
5 HORIZONTAL_ITEMS.push({ id: i + 1, name: `${i}` });
6}
7
8@Component({
9 selector: 'app-root',
10 imports: [NgVirtualListComponent],
11 templateUrl: './app.component.html',
12 styleUrl: './app.component.scss'
13})
14export class AppComponent {
15 horizontalItems = HORIZONTAL_ITEMS;
16}
Template:
1<ng-virtual-list class="list" direction="hotizontal" [items]="horizontalGroupItems" [itemRenderer]="horizontalGroupItemRenderer" 2 [itemsOffset]="50" [stickyMap]="horizontalGroupItemsStickyMap" [itemSize]="54" [snap]="true"></ng-virtual-list> 3 4<ng-template #horizontalGroupItemRenderer let-data="data"> 5 @if (data) { 6 @switch (data.type) { 7 @case ("group-header") { 8 <div class="list__h-group-container"> 9 <span>{{data.name}}</span> 10 </div> 11 } 12 @default { 13 <div class="list__h-container" (click)="onItemClick(data)"> 14 <span>{{data.name}}</span> 15 </div> 16 } 17 } 18 } 19</ng-template>
Component:
1import { NgVirtualListComponent, IVirtualListCollection, IVirtualListStickyMap } from 'ng-virtual-list'; 2 3const GROUP_NAMES = ['A', 'B', 'C', 'D', 'E']; 4 5const getGroupName = () => { 6 return GROUP_NAMES[Math.floor(Math.random() * GROUP_NAMES.length)]; 7}; 8 9const HORIZONTAL_GROUP_ITEMS: IVirtualListCollection = [], 10 HORIZONTAL_GROUP_ITEMS_STICKY_MAP: IVirtualListStickyMap = {}; 11 12for (let i = 0, l = 1000000; i < l; i++) { 13 const id = i + 1, type = Math.random() > .895 ? 'group-header' : 'item'; 14 HORIZONTAL_GROUP_ITEMS.push({ id, type, name: type === 'group-header' ? getGroupName() : `${i}` }); 15 HORIZONTAL_GROUP_ITEMS_STICKY_MAP[id] = type === 'group-header' ? 1 : 0; 16} 17 18@Component({ 19 selector: 'app-root', 20 imports: [NgVirtualListComponent], 21 templateUrl: './app.component.html', 22 styleUrl: './app.component.scss' 23}) 24export class AppComponent { 25 horizontalGroupItems = HORIZONTAL_GROUP_ITEMS; 26 horizontalGroupItemsStickyMap = HORIZONTAL_GROUP_ITEMS_STICKY_MAP; 27}
Template:
1<ng-virtual-list class="list simple" [items]="items" [itemsOffset]="50" [itemRenderer]="itemRenderer" 2 [itemSize]="40"></ng-virtual-list> 3 4<ng-template #itemRenderer let-data="data"> 5 @if (data) { 6 <div class="list__container"> 7 <p>{{data.name}}</p> 8 </div> 9 } 10</ng-template>
Component:
1import { NgVirtualListComponent, IVirtualListCollection } from 'ng-virtual-list';
2
3const ITEMS: IVirtualListCollection = [];
4
5for (let i = 0, l = 100000; i < l; i++) {
6 ITEMS.push({ id: i, name: `Item: ${i}` });
7}
8
9@Component({
10 selector: 'app-root',
11 imports: [NgVirtualListComponent],
12 templateUrl: './app.component.html',
13 styleUrl: './app.component.scss'
14})
15export class AppComponent {
16 items = ITEMS;
17}
Template:
1<ng-virtual-list class="list simple" [items]="groupItems" [itemsOffset]="50" [itemRenderer]="groupItemRenderer" 2 [stickyMap]="groupItemsStickyMap" [itemSize]="40" [snap]="false"></ng-virtual-list> 3 4<ng-template #groupItemRenderer let-data="data"> 5 @if (data) { 6 @switch (data.type) { 7 @case ("group-header") { 8 <div class="list__group-container"> 9 <p>{{data.name}}</p> 10 </div> 11 } 12 @default { 13 <div class="list__container"> 14 <p>{{data.name}}</p> 15 </div> 16 } 17 } 18 } 19</ng-template>
Template (with snapping):
1<ng-virtual-list class="list simple" [items]="groupItems" [itemsOffset]="50" [itemRenderer]="groupItemRenderer" 2 [stickyMap]="groupItemsStickyMap" [itemSize]="40" [snap]="true"></ng-virtual-list> 3 4<ng-template #groupItemRenderer let-data="data"> 5 @if (data) { 6 @switch (data.type) { 7 @case ("group-header") { 8 <div class="list__group-container"> 9 <p>{{data.name}}</p> 10 </div> 11 } 12 @default { 13 <div class="list__container"> 14 <p>{{data.name}}</p> 15 </div> 16 } 17 } 18 } 19</ng-template>
Component:
1import { NgVirtualListComponent, IVirtualListCollection, IVirtualListStickyMap } from 'ng-virtual-list'; 2 3const GROUP_ITEMS: IVirtualListCollection = [], 4 GROUP_ITEMS_STICKY_MAP: IVirtualListStickyMap = {}; 5 6let groupIndex = 0; 7for (let i = 0, l = 10000000; i < l; i++) { 8 const id = i, type = Math.random() > .895 ? 'group-header' : 'item'; 9 if (type === 'group-header') { 10 groupIndex++; 11 } 12 GROUP_ITEMS.push({ id, type, name: type === 'group-header' ? `Group ${groupIndex}` : `Item: ${i}` }); 13 GROUP_ITEMS_STICKY_MAP[id] = type === 'group-header' ? 1 : 0; 14} 15 16@Component({ 17 selector: 'app-root', 18 imports: [NgVirtualListComponent], 19 templateUrl: './app.component.html', 20 styleUrl: './app.component.scss' 21}) 22export class AppComponent { 23 groupItems = GROUP_ITEMS; 24 groupItemsStickyMap = GROUP_ITEMS_STICKY_MAP; 25} 26
The example demonstrates the scrollTo method by passing it the element id. It is important not to confuse the ordinal index and the element id. In this example, id = index + 1
Template
1<div class="scroll-to__controls"> 2 <input type="number" class="scroll-to__input" [(ngModel)]="itemId" [required]="true" [min]="items[0].id" 3 [max]="items[items.length - 1].id"> 4 <button class="scroll-to__button" (click)="onButtonScrollToIdClickHandler($event)">Scroll</button> 5</div> 6 7<ng-virtual-list #virtualList class="list" [items]="items" [itemRenderer]="itemRenderer" [itemsOffset]="50" 8 [itemSize]="40"></ng-virtual-list> 9 10<ng-template #itemRenderer let-data="data"> 11@if (data) { 12 <div class="list__container"> 13 <span>{{data.name}}</span> 14 </div> 15} 16</ng-template>
Component
1import { NgVirtualListComponent, IVirtualListCollection, Id } from 'ng-virtual-list'; 2 3const MAX_ITEMS = 1000000; 4 5const ITEMS: IVirtualListCollection = []; 6for (let i = 0, l = MAX_ITEMS; i < l; i++) { 7 ITEMS.push({ id: i + 1, name: `Item: ${i}` }); 8} 9 10@Component({ 11 selector: 'app-root', 12 imports: [FormsModule, NgVirtualListComponent], 13 templateUrl: './app.component.html', 14 styleUrl: './app.component.scss' 15}) 16export class AppComponent { 17 protected _listContainerRef = viewChild('virtualList', { read: NgVirtualListComponent }); 18 19 items = ITEMS; 20 21 itemId: Id = this.items[0].id; 22 23 onButtonScrollToIdClickHandler = (e: Event) => { 24 const list = this._listContainerRef(); 25 if (list) { 26 list.scrollTo(this.itemId, 'smooth'); 27 } 28 } 29} 30
Virtual list with height-adjustable elements.
Template
1<ng-virtual-list #dynamicList class="list" [items]="groupDynamicItems" [itemRenderer]="groupItemRenderer" [itemsOffset]="10" 2 [stickyMap]="groupDynamicItemsStickyMap" [dynamicSize]="true" [snap]="true"></ng-virtual-list> 3 4<ng-template #groupItemRenderer let-data="data"> 5 @if (data) { 6 @switch (data.type) { 7 @case ("group-header") { 8 <div class="list__group-container"> 9 <span>{{data.name}}</span> 10 </div> 11 } 12 @default { 13 <div class="list__container"> 14 <span>{{data.name}}</span> 15 </div> 16 } 17 } 18 } 19</ng-template>
Component
1import { NgVirtualListComponent, IVirtualListCollection } from 'ng-virtual-list'; 2 3const CHARS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']; 4 5const generateLetter = () => { 6 return CHARS[Math.round(Math.random() * CHARS.length)]; 7} 8 9const generateWord = () => { 10 const length = 5 + Math.floor(Math.random() * 50), result = []; 11 while (result.length < length) { 12 result.push(generateLetter()); 13 } 14 return `${result.join('')}`; 15}; 16 17const generateText = () => { 18 const length = 2 + Math.floor(Math.random() * 10), result = []; 19 while (result.length < length) { 20 result.push(generateWord()); 21 } 22 result[0] = result[0].toUpperCase(); 23 return `${result.join(' ')}.`; 24}; 25 26const GROUP_DYNAMIC_ITEMS: IVirtualListCollection = [], 27 GROUP_DYNAMIC_ITEMS_STICKY_MAP: IVirtualListStickyMap = {}; 28 29let groupDynamicIndex = 0; 30for (let i = 0, l = 100000; i < l; i++) { 31 const id = i + 1, type = i === 0 || Math.random() > .895 ? 'group-header' : 'item'; 32 if (type === 'group-header') { 33 groupDynamicIndex++; 34 } 35 GROUP_DYNAMIC_ITEMS.push({ id, type, name: type === 'group-header' ? `Group ${groupDynamicIndex}` : `${id}. ${generateText()}` }); 36 GROUP_DYNAMIC_ITEMS_STICKY_MAP[id] = type === 'group-header' ? 1 : 0; 37} 38 39@Component({ 40 selector: 'app-root', 41 imports: [FormsModule, NgVirtualListComponent], 42 templateUrl: './app.component.html', 43 styleUrl: './app.component.scss' 44}) 45export class AppComponent { 46 groupDynamicItems = GROUP_DYNAMIC_ITEMS; 47 groupDynamicItemsStickyMap = GROUP_DYNAMIC_ITEMS_STICKY_MAP; 48}
List items are encapsulated in shadowDOM, so to override default styles you need to use ::part access
1.list::part(scroller) { 2 scroll-behavior: auto; 3 4 /* custom scrollbar */ 5 &::-webkit-scrollbar { 6 width: 16px; 7 height: 16px; 8 } 9 10 &::-webkit-scrollbar-track { 11 background-color: #ffffff; 12 } 13 14 &::-webkit-scrollbar-thumb { 15 background-color: #d6dee1; 16 border-radius: 20px; 17 border: 6px solid transparent; 18 background-clip: content-box; 19 min-width: 60px; 20 min-height: 60px; 21 } 22 23 &::-webkit-scrollbar-thumb:hover { 24 background-color: #a8bbbf; 25 } 26} 27 28.list { 29 border-radius: 3px; 30 box-shadow: 1px 2px 8px 4px rgba(0, 0, 0, 0.075); 31 border: 1px solid rgba(0, 0, 0, 0.1); 32}
1.list::part(list) { 2 background-color: #ffffff; 3}
1.list::part(item) { 2 background-color: unset; // override default styles 3}
Inputs
Property | Type | Description |
---|---|---|
id | number | Readonly. Returns the unique identifier of the component. |
items | IVirtualListCollection | Collection of list items. The collection of elements must be immutable. |
itemSize | number? = 24 | If direction = 'vertical', then the height of a typical element. If direction = 'horizontal', then the width of a typical element. Ignored if the dynamicSize property is true. |
itemsOffset | number? = 2 | Number of elements outside the scope of visibility. Default value is 2. |
itemRenderer | TemplateRef | Rendering element template. |
stickyMap | IVirtualListStickyMap? | Dictionary zIndex by id of the list element. If the value is not set or equal to 0, then a simple element is displayed, if the value is greater than 0, then the sticky position mode is enabled for the element. |
snap | boolean? = false | Determines whether elements will snap. Default value is "false". |
direction | Direction? = 'vertical' | Determines the direction in which elements are placed. Default value is "vertical". |
dynamicSize | boolean? = false | If true then the items in the list can have different sizes and the itemSize property is ignored. If false then the items in the list have a fixed size specified by the itemSize property. The default value is false. |
enabledBufferOptimization | boolean? = true | Experimental! Enables buffer optimization. Can only be used if items in the collection are not added or updated. |
trackBy | string? = 'id' | The name of the property by which tracking is performed. |
Outputs
Event | Type | Description |
---|---|---|
onScroll | (IScrollEvent) => void | Fires when the list has been scrolled. |
onScrollEnd | (IScrollEvent) => void | Fires when the list has completed scrolling. |
Methods
Method | Type | Description |
---|---|---|
scrollTo | (id: Id, behavior: ScrollBehavior = 'auto') => number | The method scrolls the list to the element with the given id and returns the value of the scrolled area. Behavior accepts the values "auto", "instant" and "smooth". |
Angular version | ng-virtual-list version | git | npm |
---|---|---|---|
19.x | 19.1.37 | 19.x | 19.1.37 |
18.x | 18.0.21 | 18.x | 18.0.21 |
17.x | 17.0.19 | 17.x | 17.0.19 |
16.x | 16.0.21 | 16.x | 16.0.21 |
15.x | 15.0.20 | 15.x | 15.0.20 |
14.x | 14.0.20 | 14.x | 14.0.20 |
MIT License
Copyright (c) 2025 Evgenii Grebennikov
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
No security vulnerabilities found.