Blazor.Virtualization
1.0.5
dotnet add package Blazor.Virtualization --version 1.0.5
NuGet\Install-Package Blazor.Virtualization -Version 1.0.5
<PackageReference Include="Blazor.Virtualization" Version="1.0.5" />
paket add Blazor.Virtualization --version 1.0.5
#r "nuget: Blazor.Virtualization, 1.0.5"
// Install Blazor.Virtualization as a Cake Addin #addin nuget:?package=Blazor.Virtualization&version=1.0.5 // Install Blazor.Virtualization as a Cake Tool #tool nuget:?package=Blazor.Virtualization&version=1.0.5
Blazor.Virtualization
This is a virtual list component packaged with blazor. Built in layouts such as Waterfall, LinedFlow, and GridList. And it supports incremental loading.
However, the size of the data items for WaterfallLayout and LinedFlowLayout must be known, or can be calculated based on the data items. So the two layouts don't support auto-sizing items.
Installation
1 .NET CLI
dotnet add package Blazor.Virtualization
2 Package Manager
PM> Install-Package Blazor.Virtualization
3 PackageReference
<PackageReference Include="Blazor.Virtualization" Version="1.0.5" />
Quick start
- Add the package to project.
- Add the style reference.
<link href="_content/Blazor.Virtualization/Blazor.Virtualization.bundle.scp.css" rel="stylesheet" />
- Add the following reference to the file _Imports. razor.
@using Blazor.Virtualization @using Blazor.Virtualization.Layout
- Create razor page or component to use the VirtualList.
Samples
<details open> <summary>1. WaterfallLayout.</summary>
<VirtualList @ref="virtualList"
TItem="int"
Items="data"
@bind-ScrollTop="scrollTop">
<Layout>
<WaterfallLayout VirtualList="context"
HorizontalSpacing="12"
VerticalSpacing="24"
HeightCalculator="(o,_)=>o"></WaterfallLayout>
</Layout>
<ItemTemplate>
<div style="height:100%;background-color:#aaccee;">@context</div>
</ItemTemplate>
</VirtualList>
<div class="toolkit">
@if (scrollTop > 200)
{
<button class="toolkit-item oi oi-arrow-top"
title="Back to the top"
@onclick="()=>this.virtualList?.ScrollTopAsync()"></button>
}
</div>
@code {
private float scrollTop;
private VirtualList<int> virtualList;
private List<int> data =
Enumerable
.Range(0, 500)
.Select(o => new Random().Next(120, 300))
.ToList();
}
</details>
<details> <summary>2. Incremental loading WaterafllLayout.</summary>
<VirtualList @ref="virtualList"
TItem="int"
ItemsProvider="@this.LoadDataAsync"
@bind-ScrollTop="scrollTop">
<Layout>
<WaterfallLayout VirtualList="context"
HorizontalSpacing="12"
VerticalSpacing="24"
HeightCalculator="(o,_)=>o"></WaterfallLayout>
</Layout>
<ItemTemplate>
<div style="height:100%;background-color:#aaccee;">@context</div>
</ItemTemplate>
</VirtualList>
<div class="toolkit">
@if (scrollTop > 200)
{
<button class="toolkit-item oi oi-arrow-top"
title="Back to the top"
@onclick="()=>scrollTop=0"></button>
}
<button class="toolkit-item oi oi-reload"
title="Reload"
@onclick="()=>this.virtualList?.RefreshAsync()"></button>
</div>
@code {
private float scrollTop;
private VirtualList<int> virtualList;
private async ValueTask<IEnumerable<int>> LoadDataAsync()
{
await Task.Delay(200);
var items = Enumerable
.Range(0, 50)
.Select(o => new Random().Next(120, 600));
return items;
}
}
</details>
<details> <summary>3. GridListLayout</summary>
<VirtualList @ref="virtualList"
TItem="int"
ItemsProvider="@this.LoadDataAsync"
@bind-ScrollTop="scrollTop">
<Layout>
<GridListLayout VirtualList="context"
HorizontalSpacing="12"
VerticalSpacing="24"
ItemWidth="236"></GridListLayout>
</Layout>
<ItemTemplate>
<div style="height:100%;background-color:#aaccee;">@context</div>
</ItemTemplate>
</VirtualList>
<div class="toolkit">
@if (scrollTop > 200)
{
<button class="toolkit-item oi oi-arrow-top"
title="Back to the top"
@onclick="()=>this.virtualList?.ScrollTopAsync()"></button>
}
<button class="toolkit-item oi oi-reload"
title="Reload"
@onclick="()=>this.virtualList?.RefreshAsync()"></button>
</div>
@code {
private float scrollTop;
private VirtualList<int> virtualList;
private async ValueTask<IEnumerable<int>> LoadDataAsync()
{
await Task.Delay(300);
var items = Enumerable
.Range(0, 50)
.Select(o => new Random().Next(120, 600));
return items;
}
}
</details>
<details> <summary>4. LindedFlowLayout</summary>
<VirtualList @ref="virtualList"
TItem="int"
ItemsProvider="@this.LoadDataAsync"
@bind-ScrollTop="scrollTop">
<Layout>
<LinedFlowLayout VirtualList="context"
HorizontalSpacing="8"
VerticalSpacing="24"
WidthCalculator="o=>o*1f"></LinedFlowLayout>
</Layout>
<ItemTemplate>
<div style="height:100%;background-color:#aaccee;">@context</div>
</ItemTemplate>
</VirtualList>
<div class="toolkit">
@if (scrollTop > 200)
{
<button class="toolkit-item oi oi-arrow-top"
title="Back to the top"
@onclick="()=>this.virtualList?.ScrollTopAsync()"></button>
}
<button class="toolkit-item oi oi-reload"
title="Reload"
@onclick="()=>this.virtualList?.RefreshAsync()"></button>
</div>
@code {
private float scrollTop;
private VirtualList<int> virtualList;
private async ValueTask<IEnumerable<int>> LoadDataAsync()
{
await Task.Delay(300);
var items = Enumerable
.Range(0, 50)
.Select(o => new Random().Next(120, 300));
return items;
}
}
</details>
API
VirtualList
Properties
Name | Type | Description |
---|---|---|
EmptyTemplate | RenderFragment | The template if no data. |
Items | IList<T> | The datasource. |
ItemsProvider | ValueTask<List<TItem>> | The Incremental loading datasource provider |
Layout | RenderFragment<TItem> | The list layout. |
ScrollTop | float | |
ScrollTopChanged | EventCallback<float> |
Methods
Name | Description |
---|---|
RefreshAsync() | Refresh. |
LoadMoreAsync() | Load more data. |
ScrollToTopAsync() | Scroll to top. |
ScrollToAsync(float) | Scroll the the position by the parameter. |
WaterafallLayout
Properties
Name | Type | Default value | Description |
---|---|---|---|
ItemWidth | float | 0 | If this value is greater than 0, then MinItemWidth will be invalid and all items will be centered. |
HorizontalSpacing | float | 8 | The horizontal spacing of items. |
VerticalSpacing | float | 8 | The vertical spacing of items. |
HeightCalculator | Func<TItem, float, float> | null | The calculator of item height. <br>The first parameter is the data item. <br>And then second parameter is the ItemWidth. <br>You can calculate the height based on these two parameters. |
MinItemWidth | float | 200 | The minimum width of the item. |
MinColumnCount | float | 1 | The minimum column count of the component. |
GridListLayout
Properties
Name | Type | Default value | Description |
---|---|---|---|
ItemWidth | float | 0 | If this value is greater than 0, then MinItemWidth will be invalid and all items will be centered. |
HorizontalSpacing | float | 8 | The horizontal spacing of items. |
VerticalSpacing | float | 8 | The vertical spacing of items. |
MinItemWidth | float | 200 | The minimum width of the item. |
MinColumnCount | float | 1 | The minimum column count of the component. |
ItemHeight | float | 0 | The height of all the items. If the value is greater than 0, then the height will be equal to it. |
LinedFlowLayout
Properties
Name | Type | Default value | Description |
---|---|---|---|
HorizontalSpacing | float | 8 | The horizontal spacing of items. |
VerticalSpacing | float | 8 | The vertical spacing of items. |
RowHeight | float | 200 | The height of all the rows. |
WidthCalculator | Func<TItem, float> | null | The calculator of the minwidth. The parameter is data of the item. |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net5.0
- AspNetCore.SassCompiler (>= 1.72.0)
- Microsoft.AspNetCore.Components.Web (>= 5.0.3)
-
net6.0
- AspNetCore.SassCompiler (>= 1.72.0)
- Microsoft.AspNetCore.Components.Web (>= 6.0.0)
-
net7.0
- AspNetCore.SassCompiler (>= 1.72.0)
- Microsoft.AspNetCore.Components.Web (>= 7.0.0)
-
net8.0
- AspNetCore.SassCompiler (>= 1.72.0)
- Microsoft.AspNetCore.Components.Web (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.