Loading data
Since 0.1.0-alpha.20Static server-side rendering: no circuit, no WebAssembly.
Give the list its items with Items, or load them a page at a time with an ItemsProvider, which works as it does in Table (see Table's Loading data page). Numbered pages and DataPaging.NextPrevious work as in Table too; this page shows the two paging styles that suit a list.
Load more
A Load more button after the last item adds the next page with each press. Set PageSize and Paging to DataPaging.LoadMore. To make the list scroll inside its box, set MaxHeight; the button scrolls with the items. The page is kept in the URL, so give each list on a page its own QueryPrefix.
Preview
- Notification 17 minutes ago
- Notification 214 minutes ago
- Notification 321 minutes ago
- Notification 428 minutes ago
Code
@* PageSize with Paging="DataPaging.LoadMore": the first page, and a button after it that adds
the next, scrolling with the items in a box as tall as MaxHeight. On static pages and with
JavaScript off, the button is a link to the same list with one more page. *@
<ListView Items="_events" ItemKey="e => e.Id" ItemText="e => e.Title" ItemDescription="e => e.When"
ItemIcon="_ => Lucide.Bell" PageSize="4" Paging="DataPaging.LoadMore" QueryPrefix="events-"
MaxHeight="16.Rem" Bordered AriaLabel="Notifications" MaxWidth="28.Rem" Grow />
{
private readonly Event[] _events = Enumerable.Range(1, 11)
.Select(i => new Event(i.ToString(System.Globalization.CultureInfo.InvariantCulture), $"Notification {i}", $"{i * 7} minutes ago"))
.ToArray();
}Static: Load more is a link. The list updates without a full reload, and focus moves to the first new item.
Loading on scroll
The list can load the next page when the last item scrolls into view. Set Paging to DataPaging.LoadOnScroll, with a MaxHeight. A Load more button stays for keyboard users, hidden until it has focus.
Preview
- Message 13 minutes ago
- Message 26 minutes ago
- Message 39 minutes ago
- Message 412 minutes ago
- Message 515 minutes ago
- Message 618 minutes ago
- Message 721 minutes ago
- Message 824 minutes ago
Code
@* PageSize with Paging="DataPaging.LoadOnScroll" and a MaxHeight: the next page loads as the
last item scrolls into view, on interactive pages. *@
<ListView Items="_messages" ItemKey="m => m.Id" ItemText="m => m.Title" ItemDescription="m => m.When"
ItemIcon="_ => Lucide.MessageSquare" PageSize="8" Paging="DataPaging.LoadOnScroll" QueryPrefix="feed-"
MaxHeight="18.Rem" Bordered AriaLabel="Messages" MaxWidth="28.Rem" Grow />
{
private readonly Message[] _messages = Enumerable.Range(1, 40)
.Select(i => new Message(i.ToString(System.Globalization.CultureInfo.InvariantCulture), $"Message {i}", $"{i * 3} minutes ago"))
.ToArray();
}Static: Scroll the list: the next page loads as the last item comes into view, without a full reload, and the scroll position is kept.