Blazor.Virtualization
1.0.4
See the version list below for details.
dotnet add package Blazor.Virtualization --version 1.0.4
NuGet\Install-Package Blazor.Virtualization -Version 1.0.4
<PackageReference Include="Blazor.Virtualization" Version="1.0.4" />
paket add Blazor.Virtualization --version 1.0.4
#r "nuget: Blazor.Virtualization, 1.0.4"
// Install Blazor.Virtualization as a Cake Addin #addin nuget:?package=Blazor.Virtualization&version=1.0.4 // Install Blazor.Virtualization as a Cake Tool #tool nuget:?package=Blazor.Virtualization&version=1.0.4
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.4" />
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 TItem="int" Items="data">
<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>
@code {
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 TItem="int"
IncrementalItemsProvider="@this.LoadDataAsync">
<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>
@code {
private async ValueTask<IEnumerable<int>> LoadDataAsync()
{
await Task.Delay(500);
var items = Enumerable
.Range(0, 50)
.Select(o => new Random().Next(120, 600));
return items;
}
}
</details>
<details> <summary>3. GridListLayout</summary>
<VirtualList TItem="int"
IncrementalItemsProvider="@this.LoadDataAsync">
<Layout>
<GridListLayout VirtualList="context"
HorizontalSpacing="12"
VerticalSpacing="24"
ItemWidth="236"></GridListLayout>
</Layout>
<ItemTemplate>
<div style="height:100%;background-color:#aaccee;">@context</div>
</ItemTemplate>
</VirtualList>
@code {
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 TItem="int"
IncrementalItemsProvider="@this.LoadDataAsync">
<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>
@code {
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
Name | Type | Default value | Description |
---|---|---|---|
Items | IList<T> | null | The datasource. |
Layout | RenderFragment<TItem> | null | The list layout. |
EmptyTemplate | RenderFragment | null | The template if no data. |
IncrementalItemsProvider | ValueTask<List<TItem>> | null | The Incremental loading datasource provider |
WaterafallLayout
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
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
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.