formaui-net.Blazor.DataView
1.0.0-preview.27
Prefix Reserved
dotnet add package formaui-net.Blazor.DataView --version 1.0.0-preview.27
NuGet\Install-Package formaui-net.Blazor.DataView -Version 1.0.0-preview.27
<PackageReference Include="formaui-net.Blazor.DataView" Version="1.0.0-preview.27" />
<PackageVersion Include="formaui-net.Blazor.DataView" Version="1.0.0-preview.27" />
<PackageReference Include="formaui-net.Blazor.DataView" />
paket add formaui-net.Blazor.DataView --version 1.0.0-preview.27
#r "nuget: formaui-net.Blazor.DataView, 1.0.0-preview.27"
#:package formaui-net.Blazor.DataView@1.0.0-preview.27
#addin nuget:?package=formaui-net.Blazor.DataView&version=1.0.0-preview.27&prerelease
#tool nuget:?package=formaui-net.Blazor.DataView&version=1.0.0-preview.27&prerelease
Forma.Blazor.DataView
FormaDataView, the collection component of the Forma component library. Its engine manages a
set of items and the state around them, the source, sort, page, selection, grouping, the address and
the empty and loading states, and interchangeable views present them: FormaDataGrid as rows with
aligned columns, FormaDataList as a list, FormaDataCards as cards and FormaDataTree as a tree,
or a view of the host's own. One data view can hold several views, with a switch choosing between
them.
.NET 11 · Blazor components.
Install and register
dotnet add package formaui-net.Blazor.DataView --prerelease
The package depends on formaui-net.Blazor, which restores beside it. Its components are in the
Forma.Blazor.Components.DataView namespace.
using Forma.Blazor;
using Forma.Blazor.Components.DataView;
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.AddFormaServerIntegration();
builder.Services.AddFormaDataViewServices();
AddFormaDataViewServices() registers the IDataViewQueryExecutor a data view counts and reads a queryable
through, one that enumerates it in memory. A host whose items come from a database registers its own
first, as shown under "Reading from a database".
A grid
@using Forma.Blazor.Components.DataView
@using Forma.Framework.Culture
@using Forma.Framework.Currencies
@inject IOrderService OrderService
@inject ICultureState CultureState
<FormaDataView Items="_orders" PageSize="20" AddressOptions='@(new DataViewAddressOptions("orders"))'>
<FormaDataGrid>
<Columns>
<FormaPropertyColumn Property="@(order => order.Number)" />
<FormaPropertyColumn Property="@(order => order.Customer)" />
<FormaPropertyColumn Property="@(order => order.PlacedOn)" Title="Placed" Format="d" />
<FormaTemplateColumn Title="Total" SortName="Total" SortBy="TotalSort" Align="ColumnAlign.End">
@CurrencyCatalog.FormatAmount(context.Total, context.CurrencyCode, CultureState.Culture)
</FormaTemplateColumn>
<FormaTemplateColumn Title="Status">@context.Status</FormaTemplateColumn>
</Columns>
</FormaDataGrid>
</FormaDataView>
@code {
private static readonly DataViewSort<Order> TotalSort = DataViewSort<Order>.ByAscending(order => order.Total);
private IQueryable<Order> _orders = Enumerable.Empty<Order>().AsQueryable();
protected override async Task OnInitializedAsync()
=> _orders = (await OrderService.GetRecentOrdersAsync()).AsQueryable();
}
Items is an IQueryable<TItem>, which the engine sorts, counts and pages. A new queryable is a
new set, which the data view reads again, so a page holds its queryable in a field. PageSize sets the
page, EnablePagination="false" shows every item in one scroll region, and AppendMode appends each
page to the items from a Load More action after them, Manual, and as the reader reaches their end,
Automatic. AddressOptions writes
the sort, the page and the active view to the address under its prefix, so a link reproduces them
and two data views on one page keep theirs apart. Status is the host's text in the footer, such as
how many items are checked; a data view that names it names its views inside ChildContent, as Razor
requires once a second fragment is named:
<FormaDataView Items="_orders" PageSize="20" EnableCheckedSelection="true" @bind-SelectedItems="_checked">
<ChildContent>
<FormaDataGrid>...</FormaDataGrid>
</ChildContent>
<Status>@_checked.Count checked.</Status>
</FormaDataView>
A FormaPropertyColumn shows a member, titled by the member's name unless Title is given, and
sorts by it when its header is pressed, which Sortable="false" turns off. A FormaTemplateColumn
renders its content for each item, given as context, and sorts by its SortBy under its SortName.
An amount of money is written in its currency by CurrencyCatalog.FormatAmount, from
formaui-net.Framework.Currencies, in a template column sorting by the amount: the C format string
writes the culture's own currency instead, the shekel for he-IL whatever the amount is in and ¤ for
a culture such as en that names no country. Width sets a column's width, Frozen keeps
it in place while the others scroll sideways, and Priority decides which columns give way when the
width runs out.
Given the parts of a narrow row, a grid too narrow for its columns, on a phone or in a sidebar, draws
each item on two lines instead, or three where its detail needs them: ThumbnailTemplate at the row's
start, the data view's ItemName on the first line, and ItemTemplate beneath, each cut short rather
than wrapped. ActionsTemplate holds the row's own actions. It draws its columns again once its width
holds them:
<FormaDataView Items="_files" ItemName="@(file => file.Name)">
<FormaDataGrid>
<ThumbnailTemplate Context="file"><img src="@file.ThumbnailUrl" alt="" /></ThumbnailTemplate>
<ItemTemplate Context="file">@file.Modified.ToString("d") · @file.Size</ItemTemplate>
<Columns>
<FormaPropertyColumn Property="@(file => file.Name)" />
<FormaPropertyColumn Property="@(file => file.Modified)" />
<FormaPropertyColumn Property="@(file => file.Size)" />
</Columns>
</FormaDataGrid>
</FormaDataView>
At a narrow width a data view draws no standing boxes and no actions column. A swipe toward a row's
inline start shows the row's own ActionsTemplate, as the keyboard's focus on the row does. A long
press on an item checks it and starts selecting, Selecting, which draws every item's box. A menu
of three dots at the view's head offers Select, Stop Selecting and Select All, and the commands the
host gives in SelectionCommands. Each command is enabled where it can act on every selected item,
AppliesTo and TakesMany deciding which, and says why where it can't. OnSelectionCommand runs it
on the selected items:
<FormaDataView Items="_files" ItemName="@(file => file.Name)" EnableCheckedSelection="true"
@bind-Selecting="_selecting" SelectionCommands="_commands" OnSelectionCommand="RunAsync">
...
</FormaDataView>
@code {
private bool _selecting;
private readonly IReadOnlyList<DataViewCommand<FileEntry>> _commands =
[
new() { Id = "edit", Title = "Edit", AppliesTo = file => !file.IsLocked },
new() { Id = "delete", Title = "Delete", TakesMany = true },
];
private Task RunAsync(DataViewCommandInvocation<FileEntry> invocation)
=> invocation.Command.Id == "edit" ? EditAsync(invocation.Items[0]) : DeleteAsync(invocation.Items);
}
Several views
The views are declared inside the data view, and FormaDataViewSwitch and FormaDataSortMenu
choose the view and the sort, inside the data view or, given its reference, beside it:
@if (_products is not null)
{
<FormaDataViewSwitch DataView="_products" />
<FormaDataSortMenu TItem="Product" DataView="_products" Sorts="_sorts" />
}
<FormaDataView @ref="_products" TItem="Product" Items="_catalog" EnablePagination="false"
ItemName="@(product => product.Name)" AddressOptions='@(new DataViewAddressOptions("products"))'>
<FormaDataGrid>
<Columns>
<FormaPropertyColumn Property="@(product => product.Name)" />
<FormaTemplateColumn Title="Price" SortName="price" SortBy="PriceSort">@FormatPrice(context)</FormaTemplateColumn>
</Columns>
</FormaDataGrid>
<FormaDataList>
<ItemTemplate Context="product">@product.Category</ItemTemplate>
</FormaDataList>
<FormaDataCards>
<ThumbnailTemplate Context="product"><img src="@product.ImageUrl" alt="" /></ThumbnailTemplate>
<ItemTemplate Context="product">@FormatPrice(product)</ItemTemplate>
</FormaDataCards>
</FormaDataView>
@code {
private static readonly DataViewSort<Product> PriceSort = DataViewSort<Product>.ByAscending(product => product.Price);
private FormaDataView<Product>? _products;
private IQueryable<Product> _catalog = Enumerable.Empty<Product>().AsQueryable();
private readonly IReadOnlyList<DataViewSortOption<Product>> _sorts =
[
new("name", "Name", DataViewSort<Product>.ByAscending(product => product.Name)),
new("price", "Price", PriceSort) { InitialDirection = DataViewSortDirection.Descending },
new("category", "Category", DataViewSort<Product>.ByAscending(product => product.Category).ThenAscending(product => product.Name)),
];
private string FormatPrice(Product product)
=> CurrencyCatalog.FormatAmount(product.Price, "USD", CultureState.Culture, 0);
}
DefaultSort names the sort the data view opens in, one of the sort options, before any view has
drawn, so cards open in the order a grid would; a sort the address names wins. RequiresSort keeps a
sort applied, a header turning its direction rather than clearing it.
View and ViewChanged name the active view by its key: grid, list, cards or tree. A tree
reads the hierarchy from ParentKey, and CurrentItem names the node whose children the other
views show. A provider is asked with the node in the request's Parent, and its Kind says
whether the request reads the content the other views show, Content, or the children a tree
shows, Children, so a provider answers each its own way, even at the roots, as a file browser
lists every file beside a tree of folders.
Layout="DataViewLayout.Host" hands the arrangement to the host: it places the views, a sidebar tree
among them, inside the data view's content wherever it wants them, and FormaDataViewFooter where the
paginator and the status belong, the data view drawing no footer of its own. The host's arrangement
fills the data view's region, so each of its places scrolls within itself:
<FormaDataView TItem="Entry" Items="_entries" Layout="DataViewLayout.Host" ...>
<div class="arrangement">
<aside class="sidebar"><FormaDataTree TItem="Entry" SelectsCurrent="true" /></aside>
<FormaSplitter @bind-Value="_sidebarWidth" Min="10" Max="24" Label="Resize Folders" />
<div class="content">
<FormaDataGrid TItem="Entry">...</FormaDataGrid>
<FormaDataViewFooter />
</div>
</div>
</FormaDataView>
A sidebar's RootsItem is an item of the host's, under a key of its own, that stands for the roots,
drawn first among the top-level nodes: it never opens, it shows as current while the roots are, and
choosing it makes them current again, as a file browser's All Files row does.
OnCurrentItemChanging is raised before a move into a node changes anything, with the node and the
one before it, and its handler calls Refuse() to keep the reader where they are, as a host that
checks a folder may be opened does.
InitialOpenKeys names the nodes that start open, by the keys ItemKey reads, so a tree reopens
the branches its reader left open; each opens once, as the level holding it loads, and only those
branches are asked for. A node that becomes current opens the ancestors that reach it, so a host
opening on a node deep in the hierarchy names those ancestors too:
<FormaDataView TItem="Entry" ItemsProvider="ProvideAsync" ItemKey="@(entry => entry.Id)"
HasChildren="@(entry => entry.IsFolder)" InitialOpenKeys="_openFolderIds"
@bind-CurrentItem="_folder">
<FormaDataTree TItem="Entry" SelectsCurrent="true" />
<FormaDataGrid TItem="Entry">...</FormaDataGrid>
</FormaDataView>
Items from a provider
ItemsProvider stands in for Items where the store answers one slice at a time. It receives a
DataViewRequest of StartIndex, Count, the sort and the grouping, and returns a DataViewPage
of the slice and the total count, null where the store cannot count cheaply. ApplySorting orders
a queryable the provider holds as the request asks, here an Entity Framework Core set:
<FormaDataView TItem="Order" ItemsProvider="ProvideOrdersAsync" PageSize="50">
...
</FormaDataView>
private async ValueTask<DataViewPage<Order>> ProvideOrdersAsync(DataViewRequest<Order> request)
{
var sorted = request.ApplySorting(_database.Orders);
var slice = sorted.Skip(request.StartIndex);
return new DataViewPage<Order>(
await (request.Count is { } count ? slice.Take(count) : slice).ToArrayAsync(request.CancellationToken),
await _database.Orders.CountAsync(request.CancellationToken));
}
Grouping and virtualization
GroupBy folds the items under headings, each of which the reader can collapse:
<FormaDataView Items="_orders" PageSize="20" GroupBy="@(DataViewGrouping<Order>.By(order => order.Customer))">
<FormaDataGrid>
<Columns>
<FormaPropertyColumn Property="@(order => order.Number)" />
<FormaPropertyColumn Property="@(order => order.PlacedOn)" Title="Placed" Format="d" />
</Columns>
</FormaDataGrid>
</FormaDataView>
Virtualize renders only the items near the viewport while EnablePagination is off, in every
view, with ItemHeight as the height of one row. A provider behind a grouped, virtualized data view
answers a request whose IncludesGroupSizes is set with GroupSizes, which
request.CountGroups(source) computes.
Selection
EnableCheckedSelection gives every item a checkbox with a master control over them, and
EnableItemSelection selects by pointer and keyboard on the items themselves. Both report through
SelectedItems and SelectedItemsChanged, bound as @bind-SelectedItems. ItemKey identifies an
item across reloads. CheckedSelectionOptions sets a Minimum and a Maximum, reported through
OnSelectionRejected when a change would cross one, a Maximum of one making each choice replace the
last, and its SelectAllMode sets what the master
control reaches: Direct selects the whole set at one press, FromMenu the items on screen with a
menu offering the page and the set, FromPager the items on screen with the footer offering the set,
and None leaves the master control out.
EnableItemFocus gives the items the focus where no selection is on: the collection is one tab stop,
the arrows move the focus from item to item without selecting or opening anything, and Enter and a
press activate the item, raising OnItemClick. A selection mode turns checked selection on over it,
its ChecksOnPress having a press check the item's box while Enter still activates it, a press on an
item that cannot be selected activating it, and the switch keeps the focus on the item it stood on:
<FormaDataView Items="_files" EnableItemFocus="true" EnableCheckedSelection="_isSelecting"
CheckedSelectionOptions="@(new CheckedSelectionOptions { ChecksOnPress = true })"
@bind-SelectedItems="_chosen" OnItemClick="Open">
<FormaDataCards Dense="true" />
</FormaDataView>
FocusItemAsync brings the item a key names back on screen with the focus once the items on their
way have arrived, so a reader coming back to a list lands on the item they opened. It looks on the
page shown, among the pages appended, or among the items a virtualizing view draws, which
ScrollToItemAsync reaches first where the host knows the index, and answers whether the item took
the focus:
<FormaDataView @ref="_list" Items="_issues" ItemKey="@(issue => issue.Id)" EnableItemFocus="true"
@bind-Page="_page" OnItemClick="Open">
<FormaDataList />
</FormaDataView>
@code {
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender && _openedIssueId is { } id)
{
await _list!.FocusItemAsync(id);
}
}
}
Four rules, each a function of the item, say what an item may do. IsItemDisabled mutes an item and
takes it out of every selection and activation, CanSelectItem keeps an item from being selected
while it still activates, CanActivateItem keeps it from activating or becoming the current node,
and CanFocusItem draws it without a marker, so the keys pass over it. ItemDisabledReason says
why a disabled item is disabled, which the item shows as its tooltip on hover, focus and tap and is
described by:
<FormaDataView Items="_entries" EnableItemSelection="true" ItemKey="@(entry => entry.Id)"
IsItemDisabled="@(entry => entry.IsLocked)"
ItemDisabledReason="@(entry => $"Locked by {entry.LockedBy}")"
CanSelectItem="@(entry => !entry.IsFolder)">
<FormaDataList />
</FormaDataView>
TabOrder="DataViewTabOrder.ActiveItem" takes every item's own controls out of the Tab sequence but the
active item's, the one holding the focus or the collection's tab stop, so Tab enters a collection of
hundreds of items once and leaves it after one item's controls. A control inside an item that carries
data-item-actions opens the item's actions, which Shift+F10 and the Menu key on the item press, the
focus coming back to the item as they close:
<FormaDataView Items="_files" EnableItemSelection="true" TabOrder="DataViewTabOrder.ActiveItem">
<FormaDataCards>
<ActionsTemplate Context="file">
<FormaButton OnClick="() => Open(file)">Open</FormaButton>
<FormaOverflowMenu Label="@($"Actions for {file.Name}")" data-item-actions>
<FormaDropDownMenuItem OnClick="() => Rename(file)">Rename</FormaDropDownMenuItem>
</FormaOverflowMenu>
</ActionsTemplate>
</FormaDataCards>
</FormaDataView>
A grid whose rows hold editors, links or controls its callers reach directly keeps the default,
EveryItem, and a row being edited keeps its editors in the Tab sequence either way.
ItemAttributes gives the element a view draws for an item attributes and handlers of the host's, a
drag source's among them, under the view's own, which win:
<FormaDataView Items="_entries" ItemKey="@(entry => entry.Id)"
ItemAttributes="@(entry => new Dictionary<string, object>
{
["draggable"] = "true",
["ondragstart"] = EventCallback.Factory.Create<DragEventArgs>(this, () => _dragged = entry),
})">
<FormaDataCards />
</FormaDataView>
Inline editing
With EnableInlineEditing and a CloneForEdit that copies an item, the grid edits one row at a
time. BeginEdit(item) opens a row on its copy, each FormaPropertyColumn showing an editor for its
member's type; SaveEditAsync() validates the copy against its data annotations and raises
OnRowSave with it, and CancelEditAsync() discards it:
<FormaDataView Items="_employees" EnablePagination="false">
<FormaDataGrid @ref="_grid" EnableInlineEditing="true" CloneForEdit="@(employee => employee with { })" OnRowSave="SaveAsync">
<Columns>
<FormaPropertyColumn Property="@(employee => employee.Name)" />
<FormaPropertyColumn Property="@(employee => employee.StartDate)" Format="d" />
<FormaTemplateColumn Title="Actions">
@if (_grid?.IsEditing(context) == true)
{
<FormaButton OnClick="() => _grid!.SaveEditAsync()">Save</FormaButton>
<FormaButton OnClick="() => _grid!.CancelEditAsync()">Cancel</FormaButton>
}
else
{
<FormaButton OnClick="() => _grid!.BeginEdit(context)">Edit</FormaButton>
}
</FormaTemplateColumn>
</Columns>
</FormaDataGrid>
</FormaDataView>
@code {
private FormaDataGrid<Employee>? _grid;
}
Reading from a database
A queryable backed by a database is counted and read through the registered IDataViewQueryExecutor
when it Supports the query, so the work runs in the database asynchronously. With Entity Framework
Core:
using Forma.Blazor.Components.DataView;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query;
public sealed class EntityFrameworkQueryExecutor : IDataViewQueryExecutor
{
public bool Supports<TItem>(IQueryable<TItem> query)
=> query.Provider is IAsyncQueryProvider;
public async ValueTask<int> CountAsync<TItem>(IQueryable<TItem> query, CancellationToken cancellationToken)
=> await query.CountAsync(cancellationToken);
public async ValueTask<TItem[]> ToArrayAsync<TItem>(IQueryable<TItem> query, CancellationToken cancellationToken)
=> await query.ToArrayAsync(cancellationToken);
}
builder.Services.AddSingleton<IDataViewQueryExecutor, EntityFrameworkQueryExecutor>();
builder.Services.AddFormaDataViewServices();
The data view's own strings are localized through the library's locale packs. The design document describes the engine, its views and the rules a view keeps.
License
Apache License 2.0, under the repository's LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- formaui-net.Blazor (= 1.0.0-preview.27)
- formaui-net.Framework.Browser (= 1.0.0-preview.27)
- formaui-net.Framework.Browser.Interop (= 1.0.0-preview.27)
- formaui-net.Framework.Css (= 1.0.0-preview.27)
- formaui-net.Framework.Culture (= 1.0.0-preview.27)
- formaui-net.Framework.Events (= 1.0.0-preview.27)
- formaui-net.Framework.Icons (= 1.0.0-preview.27)
- formaui-net.Framework.Input.Interop (= 1.0.0-preview.27)
- formaui-net.Framework.JavaScript.Interop (= 1.0.0-preview.27)
- formaui-net.Framework.Localization (= 1.0.0-preview.27)
- Microsoft.AspNetCore.Components (>= 11.0.0)
- Microsoft.AspNetCore.Components.Forms (>= 11.0.0)
- Microsoft.AspNetCore.Components.Web (>= 11.0.0)
- Microsoft.AspNetCore.WebUtilities (>= 11.0.0)
- Microsoft.JSInterop (>= 11.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on formaui-net.Blazor.DataView:
| Package | Downloads |
|---|---|
|
formaui-net.Blazor.Explorer
FormaExplorer, a file manager for the Forma component library over items and folders the host already holds: a folder tree, an address bar with history and breadcrumbs, thumbnail, details and list views, search, sorting and grouping, selection, drag and drop between folders, upload, and a preview of any item. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-preview.27 | 45 | 12/3/2026 |
| 1.0.0-preview.26 | 55 | 12/3/2026 |
| 1.0.0-preview.25 | 53 | 12/2/2026 |
| 1.0.0-preview.24 | 60 | 12/1/2026 |
| 1.0.0-preview.23 | 71 | 11/30/2026 |
| 1.0.0-preview.22 | 68 | 11/30/2026 |
| 1.0.0-preview.21 | 77 | 11/29/2026 |
| 1.0.0-preview.20 | 79 | 11/26/2026 |
| 1.0.0-preview.19 | 76 | 11/26/2026 |
| 1.0.0-preview.18 | 83 | 11/26/2026 |
| 1.0.0-preview.17 | 73 | 11/26/2026 |
| 1.0.0-preview.16 | 68 | 11/24/2026 |
| 1.0.0-preview.15 | 66 | 11/23/2026 |
| 1.0.0-preview.14 | 64 | 11/23/2026 |
| 1.0.0-preview.13 | 70 | 11/21/2026 |
| 1.0.0-preview.12 | 73 | 11/20/2026 |
| 1.0.0-preview.11 | 78 | 11/18/2026 |
| 1.0.0-preview.10 | 78 | 11/17/2026 |
| 1.0.0-preview.9 | 104 | 11/17/2026 |
| 1.0.0-preview.8 | 78 | 11/17/2026 |
What this release changed is in Forma's changelog: https://github.com/FormaUI/Forma/blob/v1.0.0-preview.27/CHANGELOG.md