Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

Server data

Since 0.1.0-alpha.20
Rows, groups and totals load from your database a page at a time, or as the user scrolls.

Loading from a database

To load rows from a database, set ItemsProvider. It gets a DataRequest with the page, sort and filters, and request.ToResultAsync runs them as one query. For grouping and footer totals, add a GroupsProvider, which DataGroupRequest.ToResultAsync answers the same way.

Static

Code

ServerData.razor
@* Rows, groups and the footer's total, each asked of the data source in its own query: the provider
   loads one page of orders, and the groups provider counts and totals the groups the user opens. *@
@using IzzyBlazor.Site.Examples.Table
<DataGrid TItem="Order" ItemsProvider="LoadAsync" GroupsProvider="GroupAsync" ItemKey="o => o.Number.ToString()"
          Caption="Orders from the database" PageSize="5" Groupable InitialGroup="status" QueryPrefix="db-" Grow>
    <Columns>
        <PropertyColumn Property="o => o.Number" Title="Order" Align="CellAlign.Start" Width="7.Rem" Sortable />
        <PropertyColumn Property="o => o.Customer" Sortable Filterable />
        <PropertyColumn Property="o => o.Status" Filterable Width="9.Rem" />
        <PropertyColumn Property="o => o.Date" Format="MMM d" Sortable Width="8.Rem" />
        <PropertyColumn Property="o => o.Total" Format="C" Sortable Width="9.Rem" Aggregate="DataAggregate.Sum" />
    </Columns>
</DataGrid>

@code {
    // Stands in for a DbSet: with EF Core, pass db.Orders and call ToResultAsync.
    private static IQueryable<Order> Database => Orders.All.AsQueryable();

    private ValueTask<DataResult<Order>> LoadAsync(DataRequest<Order> request) =>
        ValueTask.FromResult(request.ToResult(Database));

    private ValueTask<DataGroupResult> GroupAsync(DataGroupRequest<Order> request) =>
        ValueTask.FromResult(request.ToResult(Database));
}

To skip the providers, pass an EF Core IQueryable as Items; the grid builds the same queries. Table's Loading data page covers the request in full, including rows from an API.

Virtual rows

Virtual rows render only the rows in view, so 100,000 rows scroll as easily as 100. Set Virtualize, which works on interactive pages.

Static

Preview

Every order
SelectNumber CustomerTotal
1Katherine Johnson$108.00
2Grace Hopper$149.75
3Barbara Liskov$191.50
4Linus Torvalds$233.25
5Alan Turing$275.00
6Ada Lovelace$316.75
7Margaret Hamilton$358.50
8Katherine Johnson$400.25
9Grace Hopper$442.00
10Barbara Liskov$483.75
11Linus Torvalds$65.50
12Alan Turing$107.25
13Ada Lovelace$149.00
14Margaret Hamilton$190.75
15Katherine Johnson$232.50
16Grace Hopper$274.25
17Barbara Liskov$316.00
18Linus Torvalds$357.75
19Alan Turing$399.50
20Ada Lovelace$441.25
1–20 of 100,000

Code

VirtualRows.razor
@* 100,000 rows, of which only those in view are drawn, each window read as a database would be. Switch
   this page to Interactive to see it; a static page loads more on scroll instead. *@
@using IzzyBlazor.Site.Examples.Table
<DataGrid TItem="Order" ItemsProvider="LoadAsync" ItemKey="o => o.Number.ToString()" Caption="Every order" Virtualize RowHeight="40" MaxHeight="24.Rem" PageSize="20" SelectionMode="SelectionMode.Multiple" SelectionName="every" QueryPrefix="every-" Grow>
    <Columns>
        <PropertyColumn Property="o => o.Number" Sortable Align="CellAlign.Start" Width="8.Rem" />
        <PropertyColumn Property="o => o.Customer" />
        <PropertyColumn Property="o => o.Total" Format="C" Width="8.Rem" />
    </Columns>
</DataGrid>

@code {
    private static readonly IReadOnlyList<Order> Many = Enumerable.Range(1, 100_000)
        .Select(i => Orders.All[i % Orders.All.Count] with { Number = i })
        .ToList();

    private async ValueTask<DataResult<Order>> LoadAsync(DataRequest<Order> request)
    {
        // As long as a query takes, so you can see rows on their way.
        if (RendererInfo.IsInteractive)
        {
            await Task.Delay(150, request.CancellationToken);
        }

        return request.ToResult(Many.AsQueryable());
    }
}

It needs a MaxHeight, and each row must fit one line of RowHeight. On static pages the same grid loads more rows as the user scrolls.

This example is static unless you switch the page to Interactive.

Connection lost

Rejoining the server…