-
Notifications
You must be signed in to change notification settings - Fork 161
feat: Added virtual scroll component and sample implementation #17281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
2c3168d
feat: Added virtual scroll component and sample implementation
rkaraivanov e7ce7a1
fix: ng-packagr build errors for virtual scroll component
rkaraivanov 5aa53cf
chore: update virtual scroll component spec
rkaraivanov 90dc5ec
fix: fixes the issue with the virtual scroll component not updating t…
rkaraivanov fe32fac
feat: Use Binary Indexed Tree for the scroll engine
rkaraivanov b987e22
chore: Lint error in scroll engine
rkaraivanov 1e3de56
Merge remote-tracking branch 'origin/master' into rkaraivanov/virtual…
rkaraivanov 0c240ea
fix: Adjusted dataRequest event test
rkaraivanov 1d87ba5
Merge remote-tracking branch 'origin/master' into rkaraivanov/virtual…
rkaraivanov f7dd940
Merge remote-tracking branch 'origin/master' into rkaraivanov/virtual…
rkaraivanov 042c5e4
feat: Added RTL support for horizontal virtual scroll
rkaraivanov d0e4b77
fix: fix virtual scroll component spec test
rkaraivanov 242dd44
Merge remote-tracking branch 'origin/master' into rkaraivanov/virtual…
rkaraivanov 1fed9b5
Merge remote-tracking branch 'origin/master' into rkaraivanov/virtual…
rkaraivanov ed2aa0a
Merge remote-tracking branch 'origin/master' into rkaraivanov/virtual…
rkaraivanov 133e4e0
refactor: Skip zone re-entry when scrolling
rkaraivanov ebd89f9
Merge remote-tracking branch 'origin/master' into rkaraivanov/virtual…
rkaraivanov 17adfaf
Merge remote-tracking branch 'origin/master' into rkaraivanov/virtual…
rkaraivanov 1fc98be
Merge remote-tracking branch 'origin/master' into rkaraivanov/virtual…
rkaraivanov fe1917c
Merge branch 'master' into rkaraivanov/virtual-scroll-component
ChronosSF 65119a7
Merge branch 'rkaraivanov/virtual-scroll-component' of https://github…
rkaraivanov 356753d
Merge remote-tracking branch 'origin/master' into rkaraivanov/virtual…
rkaraivanov f23bac2
feat: align with the web components implementation
rkaraivanov 459758c
Merge branch 'master' into rkaraivanov/virtual-scroll-component
simeonoff 6c853b6
refactor(virtual-scroll): restructure structural CSS conventions
simeonoff 65f9300
Merge branch 'master' into rkaraivanov/virtual-scroll-component
viktorkombov c0f421c
Merge branch 'master' into rkaraivanov/virtual-scroll-component
viktorkombov 3b63af6
Merge branch 'master' into rkaraivanov/virtual-scroll-component
simeonoff fc40c26
refactor(ESF, combo): use IgxVirtualScrollComponent instead of igxFor…
viktorkombov 1638ed2
Merge remote-tracking branch 'origin/master' into rkaraivanov/virtual…
rkaraivanov 277d80a
chore: remove duplicate import of 'signal' from '@angular/core'
rkaraivanov a6769df
Merge branch 'master' into rkaraivanov/virtual-scroll-component
ChronosSF 6d390f0
test(virtual-scroll): failing specs for nearest align and runtime dir…
ChronosSF 547ef1c
test(*): failing specs for compression tail, remeasure and header skip
ChronosSF 1c8cf2c
Merge remote-tracking branch 'origin/master' into rkaraivanov/virtual…
rkaraivanov 5d9bf7a
Fix virtual scroll review findings
rkaraivanov d5139b9
Merge branch 'master' into rkaraivanov/virtual-scroll-component
rkaraivanov 98bfa2b
Fix navigateToChildGrid ending before its child renders
rkaraivanov 6d6f455
Merge branch 'rkaraivanov/virtual-scroll-component' of https://github…
rkaraivanov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| # IgxVirtualScrollComponent | ||
|
|
||
| A high-performance virtual-scrolling component that renders only the items visible inside the viewport (plus a configurable over-scan buffer). It supports both vertical and horizontal axes, variable item sizes measured at runtime, and remote / infinite scrolling through the `dataRequest` event. | ||
|
|
||
| ## Imports | ||
|
|
||
| ```ts | ||
| import { | ||
| IgxVirtualScrollComponent, | ||
| IgxVirtualItemDirective, | ||
| } from 'igniteui-angular/virtual-scroll'; | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Basic usage | ||
|
|
||
| Define your list and provide a template using the `igxVirtualItem` directive: | ||
|
|
||
| ```html | ||
| <igx-virtual-scroll [data]="items" style="height: 400px;"> | ||
| <ng-template igxVirtualItem let-item let-i="index"> | ||
| <div class="list-row">{{ i }}: {{ item.name }}</div> | ||
| </ng-template> | ||
| </igx-virtual-scroll> | ||
| ``` | ||
|
|
||
| ```ts | ||
| @Component({ /* ... */ }) | ||
| export class MyComponent { | ||
| items = Array.from({ length: 10_000 }, (_, i) => ({ name: `Item ${i}` })); | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Inputs | ||
|
|
||
| | Input | Type | Default | Description | | ||
| |---|---|---|---| | ||
| | `data` | `T[]` | `[]` | The array of items to virtualise. | | ||
| | `orientation` | `'vertical' \| 'horizontal'` | `'vertical'` | Scroll axis. | | ||
| | `overScan` | `number` | `2` | Extra items to render beyond each edge of the viewport. Higher values reduce blank-flash artefacts during fast scrolling at the cost of slightly more DOM nodes. | | ||
| | `estimatedItemSize` | `number` | `50` | Pixel size used for items before they are measured in the DOM. Set this close to the real average size for the best initial-render accuracy. | | ||
| | `itemTemplate` | `TemplateRef<IgxVsItemContext<T>> \| null` | `null` | Programmatic template that takes precedence over a content `ng-template[igxVirtualItem]`. | | ||
|
|
||
| --- | ||
|
|
||
| ## Outputs | ||
|
|
||
| | Output | Payload | Description | | ||
| |---|---|---| | ||
| | `stateChange` | `VirtualScrollState` | Emitted after every render pass with a snapshot of the current virtual window. | | ||
| | `dataRequest` | `VirtualScrollDataRequest` | Emitted when the scroll position approaches the end of loaded data. Use this to implement infinite / remote scrolling. | | ||
|
|
||
| --- | ||
|
|
||
| ## Public API | ||
|
|
||
| ### `scrollToIndex(index: number): void` | ||
|
|
||
| Programmatically scrolls the viewport so that the item at `index` is at the leading edge. | ||
|
|
||
| ```ts | ||
| @ViewChild(IgxVirtualScrollComponent) vs!: IgxVirtualScrollComponent<any>; | ||
|
|
||
| this.vs.scrollToIndex(500); | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## `IgxVirtualItemDirective` | ||
|
|
||
| Marks an `ng-template` as the item template for the nearest `igx-virtual-scroll`. The template context is typed as `IgxVsItemContext<T>`. | ||
|
|
||
| ### Template context variables | ||
|
|
||
| | Variable | Type | Description | | ||
| |---|---|---| | ||
| | `$implicit` (or `let-item`) | `T` | The current item. | | ||
| | `index` | `number` | The item's index within the full data array. | | ||
| | `count` | `number` | Total number of items in `data`. | | ||
| | `first` | `boolean` | `true` when `index === 0`. | | ||
| | `last` | `boolean` | `true` when `index === count - 1`. | | ||
| | `even` | `boolean` | `true` when `index` is even. | | ||
| | `odd` | `boolean` | `true` when `index` is odd. | | ||
|
|
||
| ```html | ||
| <ng-template igxVirtualItem let-item let-i="index" let-first="first"> | ||
| <div [class.first-row]="first">{{ i }}: {{ item }}</div> | ||
| </ng-template> | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Output type reference | ||
|
|
||
| ### `VirtualScrollState` | ||
|
|
||
| ```ts | ||
| interface VirtualScrollState { | ||
| startIndex: number; // First rendered item index | ||
| endIndex: number; // Last rendered item index (inclusive) | ||
| viewportSize: number; // Viewport height (or width) in px | ||
| totalSize: number; // Total virtual content size in px | ||
| } | ||
| ``` | ||
|
|
||
| ### `VirtualScrollDataRequest` | ||
|
|
||
| ```ts | ||
| interface VirtualScrollDataRequest { | ||
| startIndex: number; // First index that does not yet have data | ||
| count: number; // Suggested number of items to fetch | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Horizontal scrolling | ||
|
|
||
| Set `orientation="horizontal"`. Items are laid out in a row; ensure each item has an explicit `width` so the engine can measure sizes correctly. | ||
|
|
||
| ```html | ||
| <igx-virtual-scroll [data]="items" orientation="horizontal" style="width: 100%; height: 60px;"> | ||
| <ng-template igxVirtualItem let-item> | ||
| <div class="col" style="width: 120px; height: 60px;">{{ item }}</div> | ||
| </ng-template> | ||
| </igx-virtual-scroll> | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Infinite / remote scrolling | ||
|
|
||
| Listen to the `dataRequest` output and append more items to the `data` array: | ||
|
|
||
| ```html | ||
| <igx-virtual-scroll [data]="items" (dataRequest)="loadMore($event)" style="height: 500px;"> | ||
| <ng-template igxVirtualItem let-item> | ||
| <div class="row">{{ item.label }}</div> | ||
| </ng-template> | ||
| </igx-virtual-scroll> | ||
| ``` | ||
|
|
||
| ```ts | ||
| loadMore(req: VirtualScrollDataRequest) { | ||
| this.myService.fetch(req.startIndex, req.count).subscribe(newItems => { | ||
| this.items = [...this.items, ...newItems]; | ||
| }); | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Programmatic template | ||
|
|
||
| Pass a `TemplateRef` via `[itemTemplate]` when the template is defined outside the component: | ||
|
|
||
| ```html | ||
| <ng-template #myTpl let-item> | ||
| <div>{{ item }}</div> | ||
| </ng-template> | ||
|
|
||
| <igx-virtual-scroll [data]="items" [itemTemplate]="myTpl" style="height: 400px;" /> | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Styling | ||
|
|
||
| The component exposes the following CSS classes: | ||
|
|
||
| | Class | Element | Notes | | ||
| |---|---|---| | ||
| | `igx-virtual-scroll` | Host | Always present. | | ||
| | `igx-virtual-scroll--vertical` | Host | Added when `orientation="vertical"`. | | ||
| | `igx-virtual-scroll--horizontal` | Host | Added when `orientation="horizontal"`. | | ||
| | `igx-vs__track` | Inner spacer div | Sized to the full virtual height/width. | | ||
| | `igx-vs__content` | Rendered-items wrapper | Absolutely positioned; translated to the correct virtual offset. | | ||
|
|
||
| The host element must have a **fixed height** (vertical) or **fixed width** (horizontal) and `overflow: auto` or `overflow: scroll` — the default styles already set this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './src/public_api'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export { IgxVirtualScrollComponent} from './virtual-scroll/virtual-scroll.component'; | ||
| export { IgxVirtualItemDirective } from './virtual-scroll/virtual-scroll-item.directive'; | ||
| export * from './virtual-scroll/types'; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.