ng-virtual-list 18.7.3 → 18.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,29 +1,60 @@
1
1
  # NgVirtualList
2
2
 
3
- Maximum performance for extremely large lists.<br/>
4
- Flexible, and actively maintained Angular library that excels with high-performance, feature-rich virtualized lists—including grouping, sticky headers, snapping, animations, single and multiple selection of elements and both scroll directions. Whether you're rendering millions of items or building interactive list components, it delivers scalability and customization.
3
+ 🚀 High-performance virtual scrolling for Angular apps. Render 100,000+ items in Angular without breaking a sweat. Smooth, customizable, and developer-friendly.
4
+
5
+ Flexible, and actively maintained Angular library that excels with high-performance, feature-rich virtualized lists—including grouping, sticky headers, snapping, animations, single and multiple selection of elements and both scroll directions. Whether you're rendering millions of items or building interactive list components, it delivers scalability and customization. Angular (14–20) compatibility.
5
6
 
6
7
  <img width="1033" height="171" alt="logo" src="https://github.com/user-attachments/assets/b559cfde-405a-4361-b71b-6715478d997d" />
7
8
 
8
- Angular version 18.X.X.
9
+ <b>Angular version 18.X.X</b>.
10
+
11
+ ![npm](https://img.shields.io/npm/v/ng-virtual-list)
12
+ ![npm downloads](https://img.shields.io/npm/dm/ng-virtual-list)
13
+ ![npm total downloads](https://img.shields.io/npm/dt/ng-virtual-list)
9
14
 
10
15
  [Live Demo](https://ng-virtual-list-chat-demo.eugene-grebennikov.pro/)
16
+ [(Code)](https://github.com/DjonnyX/ng-virtual-list-demo)
11
17
 
12
18
  [Live Examples](https://ng-virtual-list.eugene-grebennikov.pro/)
19
+ [(Code)](https://github.com/DjonnyX/ng-virtual-list-demo/tree/main/src/app)
13
20
 
14
21
  <br/>
15
22
 
16
- | **Pros** | **Description** |
17
- | --- | --- |
18
- | **High performance** | Only renders items visible in the viewport (plus a buffer), reducing DOM overhead and improving responsiveness—even with very large datasets |
19
- | **Grouped lists with sticky headers & snapping** | Supports grouping items, sticky headers, and optional “snap” behavior for clean section scrolling |
20
- | **Angular (14–20) compatibility** | Compatible with Angular versions 14 through 20.x, ensuring seamless integration in modern Angular projects |
21
- | **Scroll-to capabilities** | Allows programmatic navigation to specific items by ID |
22
- | **TypeScript support** | Comes with typing for safety and better integration in TypeScript projects |
23
+ ## Why use ng-virtual-list?
24
+
25
+ Blazing fast only renders what’s visible (plus a smart buffer).<br/>
26
+ 📱 Works everywhere smooth on desktop & mobile.<br/>
27
+ 🔀 Flexible layouts vertical, horizontal, grouped lists, sticky headers.<br/>
28
+ 📏 Dynamic sizes handles items of varying height/width.<br/>
29
+ 🎯 Precise control scroll to an ID, or snap to positions.<br/>
30
+ 🔌 Angular-friendly — simple inputs/outputs, trackBy support.<br/>
23
31
 
24
32
  <br/>
25
33
 
26
- ## When to Use It: Ideal Use Cases
34
+ ## ⚙️ Key Features
35
+
36
+ Virtualization modes
37
+ - Fixed size (fastest)
38
+ - Dynamic size (auto-measured)
39
+ - Scrolling control
40
+ - Scroll to item ID
41
+ - Smooth or instant scroll
42
+ - Custom snapping behavior
43
+ - Advanced layouts
44
+ - Grouped lists with sticky headers
45
+ - Horizontal or vertical scrolling
46
+ - Advanced layouts
47
+ - Grouped lists with sticky headers
48
+ - Horizontal or vertical scrolling
49
+ - Selecting elements
50
+ - Single selection
51
+ - Multiple selection
52
+ - Performance tuning
53
+ - bufferSize and maxBufferSize for fine-grained control
54
+
55
+ <br/>
56
+
57
+ ## 📱 When to Use It: Ideal Use Cases
27
58
 
28
59
  Drawing on general virtual-scroll insights and ng-virtual-list features:
29
60
 
@@ -50,26 +81,45 @@ Support for element animation
50
81
 
51
82
  <br/>
52
83
 
53
- ## Installation
84
+ ## 📦 Installation
54
85
 
55
86
  ```bash
56
87
  npm i ng-virtual-list
57
88
  ```
58
89
 
59
- ## Examples
90
+ <br/>
91
+
92
+ ## 🚀 Quick Start
93
+ ```html
94
+ <ng-virtual-list [items]="items" [bufferSize]="5" [itemRenderer]="itemRenderer" [itemSize]="64"></ng-virtual-list>
95
+
96
+ <ng-template #itemRenderer let-data="data">
97
+ @if (data) {
98
+ <span>{{data.name}}</span>
99
+ }
100
+ </ng-template>
101
+ ```
102
+ ```ts
103
+ items = Array.from({ length: 100000 }, (_, i) => ({ id: i, name: `Item #${i}` }));
104
+ ```
105
+
106
+ <br/>
107
+
108
+ ## 📱 Examples
60
109
 
61
- ### Horizontal virtual list
110
+ ### Horizontal virtual list (Single selection)
62
111
 
63
112
  ![preview](https://github.com/user-attachments/assets/5a16d4b3-5e66-4d53-ae90-d0eab0b246a1)
64
113
 
65
114
  Template:
66
115
  ```html
67
116
  <ng-virtual-list class="list" direction="horizontal" [items]="horizontalItems" [bufferSize]="50"
68
- [itemRenderer]="horizontalItemRenderer" [itemSize]="64" (onItemClick)="onItemClick($event)"></ng-virtual-list>
117
+ [itemRenderer]="horizontalItemRenderer" [itemSize]="64" [methodForSelecting]="'select'"
118
+ [selectedIds]="2" (onSelect)="onSelect($event)" (onItemClick)="onItemClick($event)"></ng-virtual-list>
69
119
 
70
- <ng-template #horizontalItemRenderer let-data="data">
120
+ <ng-template #horizontalItemRenderer let-data="data" let-config="config">
71
121
  @if (data) {
72
- <div class="list__h-container">
122
+ <div [ngClass]="{'list__h-container': true, 'selected': config.selected}">
73
123
  <span>{{data.name}}</span>
74
124
  </div>
75
125
  }
@@ -84,10 +134,7 @@ interface ICollectionItem {
84
134
  name: string;
85
135
  }
86
136
 
87
- const HORIZONTAL_ITEMS: IVirtualListCollection<ICollectionItem> = [];
88
- for (let i = 0, l = 1000000; i < l; i++) {
89
- HORIZONTAL_ITEMS.push({ id: i + 1, name: `${i}` });
90
- }
137
+ const HORIZONTAL_ITEMS: IVirtualListCollection<ICollectionItem> = Array.from({ length: 100000 }, (_, i) => ({ id: i, name: `${i}` }));
91
138
 
92
139
  @Component({
93
140
  selector: 'app-root',
@@ -103,19 +150,24 @@ export class AppComponent {
103
150
  console.info(`Click: (ID: ${item.id}) Item ${item.data.name}`);
104
151
  }
105
152
  }
153
+
154
+ onSelect(data: Array<Id> | Id | undefined) {
155
+ console.info(`Select: ${JSON.stringify(data)}`);
156
+ }
106
157
  }
107
158
  ```
108
159
 
109
- ### Horizontal grouped virtual list
160
+ ### Horizontal grouped virtual list (Multiple selection)
110
161
 
111
162
  ![preview](https://github.com/user-attachments/assets/99584660-dc0b-4cd0-9439-9b051163c077)
112
163
 
113
164
  Template:
114
165
  ```html
115
166
  <ng-virtual-list class="list" direction="horizontal" [items]="horizontalGroupItems" [itemRenderer]="horizontalGroupItemRenderer"
116
- [bufferSize]="50" [itemConfigMap]="horizontalGroupItemConfigMap" [itemSize]="54" [snap]="true" (onItemClick)="onItemClick($event)"></ng-virtual-list>
167
+ [bufferSize]="50" [itemConfigMap]="horizontalGroupItemConfigMap" [itemSize]="54" [snap]="true" [methodForSelecting]="'multi-select'"
168
+ [selectedIds]="[3,2]" (onSelect)="onSelect($event)" (onItemClick)="onItemClick($event)"></ng-virtual-list>
117
169
 
118
- <ng-template #horizontalGroupItemRenderer let-data="data">
170
+ <ng-template #horizontalGroupItemRenderer let-data="data" let-config="config">
119
171
  @if (data) {
120
172
  @switch (data.type) {
121
173
  @case ("group-header") {
@@ -124,7 +176,7 @@ Template:
124
176
  </div>
125
177
  }
126
178
  @default {
127
- <div class="list__h-container">
179
+ <div [ngClass]="{'list__h-container': true, 'selected': config.selected}">
128
180
  <span>{{data.name}}</span>
129
181
  </div>
130
182
  }
@@ -172,6 +224,10 @@ export class AppComponent {
172
224
  console.info(`Click: (ID: ${item.id}) Item ${item.data.name}`);
173
225
  }
174
226
  }
227
+
228
+ onSelect(data: Array<Id> | Id | undefined) {
229
+ console.info(`Select: ${JSON.stringify(data)}`);
230
+ }
175
231
  }
176
232
  ```
177
233
 
@@ -441,7 +497,9 @@ export class AppComponent {
441
497
  }
442
498
  ```
443
499
 
444
- ## Stylization
500
+ <br/>
501
+
502
+ ## 🖼️ Stylization
445
503
 
446
504
  List items are encapsulated in shadowDOM, so to override default styles you need to use ::part access
447
505
 
@@ -525,7 +583,9 @@ Selecting even elements:
525
583
  }
526
584
  ```
527
585
 
528
- ## API
586
+ <br/>
587
+
588
+ ## 📚 API
529
589
 
530
590
  [NgVirtualListComponent](https://github.com/DjonnyX/ng-virtual-list/blob/18.x/projects/ng-virtual-list/src/lib/ng-virtual-list.component.ts)
531
591
 
@@ -540,7 +600,7 @@ Inputs
540
600
  | maxBufferSize | number? = 100 | Maximum number of elements outside the scope of visibility. Default value is 100. If maxBufferSize is set to be greater than bufferSize, then adaptive buffer mode is enabled. The greater the scroll size, the more elements are allocated for rendering. |
541
601
  | itemRenderer | TemplateRef | Rendering element template. |
542
602
  | methodForSelecting | [MethodForSelecting](https://github.com/DjonnyX/ng-virtual-list/blob/18.x/projects/ng-virtual-list/src/lib/enums/method-for-selecting.ts) | Method for selecting list items. Default value is 'none'. 'select' - List items are selected one by one. 'multi-select' - Multiple selection of list items. 'none' - List items are not selectable. |
543
- | itemConfigMap | [IVirtualListItemConfigMap?](https://github.com/DjonnyX/ng-virtual-list/blob/18.x/projects/ng-virtual-list/src/lib/models/item-config-map.model.ts) | Sets sticky position and selectable for the list item element. If sticky position is greater than 0, then sticky position is applied. If the sticky value is greater than `0`, then the sticky position mode is enabled for the element. `1` - position start, `2` - position end. Default value is `0`. Selectable determines whether an element can be selected or not. Default value is `true`. |
603
+ | itemConfigMap | [IVirtualListItemConfigMap?](https://github.com/DjonnyX/ng-virtual-list/blob/18.x/projects/ng-virtual-list/src/lib/models/item-config-map.model.ts) | Sets `sticky` position and `selectable` for the list item element. If `sticky` position is greater than `0`, then `sticky` position is applied. If the `sticky` value is greater than `0`, then the `sticky` position mode is enabled for the element. `1` - position start, `2` - position end. Default value is `0`. `selectable` determines whether an element can be selected or not. Default value is `true`. |
544
604
  | selectByClick | boolean? = true | If `false`, the element is selected using the config.select method passed to the template; if `true`, the element is selected by clicking on it. The default value is `true`. |
545
605
  | snap | boolean? = false | Determines whether elements will snap. Default value is "false". |
546
606
  | snappingMethod | [SnappingMethod? = 'normal'](https://github.com/DjonnyX/ng-virtual-list/blob/18.x/projects/ng-virtual-list/src/lib/enums/snapping-method.ts) | Snapping method. 'normal' - Normal group rendering. 'advanced' - The group is rendered on a transparent background. List items below the group are not rendered. |
@@ -575,7 +635,15 @@ Methods
575
635
 
576
636
  <br/>
577
637
 
578
- ## License
638
+ ## 🤝 Contributing
639
+
640
+ PRs and feature requests are welcome!
641
+ Open an issue or start a discussion to shape the future of [ng-virtual-list](https://github.com/DjonnyX/ng-virtual-list/).
642
+ Try it out, star ⭐ the repo, and let us know what you’re building.
643
+
644
+ <br/>
645
+
646
+ ## 📄 License
579
647
 
580
648
  MIT License
581
649
 
@@ -597,4 +665,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
597
665
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
598
666
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
599
667
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
600
- SOFTWARE.
668
+ SOFTWARE.