DeepWorks Studios Blazor Component Library

Demo user Administrator ยท Blazor Server Library 20261206222504-6e8ff32.dirty

DwsInfiniteScrolling

Obsolete - now a wrapper over DwsVirtualize. DwsInfiniteScrolling keeps its root element (.dws-infinite-scrolling, with its id, classes and inline style) and renders a DwsVirtualize inside it: the scroll container, the items' layout, the “Load more” button, the loading, empty, end and error blocks and the live region are DwsVirtualize's (.dws-virtualize…). Every parameter, event and method on this page keeps its meaning; the examples below run through the wrapper. Using the type in C# gives compiler warning CS0618, and the component logs one warning per application.

For new code use DwsVirtualize: Items, HasMoreItems (default false there), OnLoadMoreItems, LoadMoreDistance (this component's Threshold), LoadMoreMode / LoadMoreText, IsEnabled (Virtualize), LoadingMoreContent / EmptyContent / EndContent / ShowEndMessage, OnError (OnLoadError).

DwsVirtualize: load more button, end of the list, group headers

A scrollable list that asks for more items when it is scrolled near its end. Scrolling is watched in the browser, so only reaching the end costs a round trip.

API Reference

Basic

OnLoadMore is awaited: a loading indicator shows until it completes, and no second request starts meanwhile. Setting HasMoreItems to false stops the requests; ShowEndMessage then marks the end of the list.

Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9
Item 10
Item 11
Item 12
Item 13
Item 14
Item 15
Item 16
Item 17
Item 18
Item 19
Item 20

20 of 100 items loaded.

Show Code
InfiniteScrolling.razor
<DwsInfiniteScrolling Name="InfiniteScrollingDemo_Basic" Items="@_basicItems" OnLoadMore="LoadBasicAsync"
                      HasMoreItems="@(_basicItems.Count < BasicMaxItems)" ShowEndMessage="true" Height="300">
    <ItemTemplate Context="item">
        <div class="border-bottom px-3 py-2">@item</div>
    </ItemTemplate>
</DwsInfiniteScrolling>
<DwsTypography Name="InfiniteScrollingDemo_Text04" Typography="DwsTypographyType.Paragraph" Class="small text-muted mt-2 mb-0" FontSize="0.875em">@_basicItems.Count of @BasicMaxItems items loaded.</DwsTypography>
InfiniteScrolling.razor.cs
private const int PageSize = 20;
private const int BasicMaxItems = 100;
private readonly List<string> _basicItems = Enumerable.Range(1, 20).Select(i => $"Item {i}").ToList();

private async Task LoadBasicAsync()
{
    await Task.Delay(600); // e.g. a web API call
    _basicItems.AddRange(Enumerable.Range(_basicItems.Count + 1, PageSize).Select(i => $"Item {i}"));
}

Loading and end templates

LoadingTemplate and EndTemplate replace the default loading indicator and end text.

#1 Article number 1
#2 Article number 2
#3 Article number 3
#4 Article number 4
#5 Article number 5
#6 Article number 6
#7 Article number 7
#8 Article number 8
#9 Article number 9
#10 Article number 10
#11 Article number 11
#12 Article number 12
#13 Article number 13
#14 Article number 14
#15 Article number 15
#16 Article number 16
#17 Article number 17
#18 Article number 18
#19 Article number 19
#20 Article number 20
#21 Article number 21
#22 Article number 22
#23 Article number 23
#24 Article number 24
#25 Article number 25
#26 Article number 26
#27 Article number 27
#28 Article number 28
#29 Article number 29
#30 Article number 30
#31 Article number 31
#32 Article number 32
#33 Article number 33
#34 Article number 34
#35 Article number 35
#36 Article number 36
#37 Article number 37
#38 Article number 38
#39 Article number 39
#40 Article number 40
Show Code
InfiniteScrolling.razor
<DwsInfiniteScrolling Name="InfiniteScrollingDemo_Templates" Items="@_templateItems" OnLoadMore="LoadTemplatesAsync"
                      HasMoreItems="@(_templateItems.Count < TemplateMaxItems)" Height="300">
    <ItemTemplate Context="item">
        <div class="d-flex align-items-center gap-2 border-bottom px-3 py-2">
            <span class="badge bg-secondary">#@item.Id</span>
            <span>@item.Title</span>
        </div>
    </ItemTemplate>
    <LoadingTemplate>
        <em>Fetching the next @PageSize articles…</em>
    </LoadingTemplate>
    <EndTemplate>
        <strong>That's all @TemplateMaxItems articles.</strong>
    </EndTemplate>
</DwsInfiniteScrolling>
InfiniteScrolling.razor.cs
private const int PageSize = 20;
private const int TemplateMaxItems = 80;
private sealed record Article(int Id, string Title);
private readonly List<Article> _templateItems = Enumerable.Range(1, 20).Select(i => new Article(i, $"Article number {i}")).ToList();

private async Task LoadTemplatesAsync()
{
    await Task.Delay(600);
    int start = _templateItems.Count + 1;
    _templateItems.AddRange(Enumerable.Range(start, PageSize).Select(i => new Article(i, $"Article number {i}")));
}

Horizontal scrolling

Orientation Horizontal lays the items out in a row and loads more at its right end.

Card 1

Scroll sideways

Card 2

Scroll sideways

Card 3

Scroll sideways

Card 4

Scroll sideways

Card 5

Scroll sideways

Card 6

Scroll sideways

Card 7

Scroll sideways

Card 8

Scroll sideways

Card 9

Scroll sideways

Card 10

Scroll sideways

Card 11

Scroll sideways

Card 12

Scroll sideways

Card 13

Scroll sideways

Card 14

Scroll sideways

Card 15

Scroll sideways

Card 16

Scroll sideways

Card 17

Scroll sideways

Card 18

Scroll sideways

Card 19

Scroll sideways

Card 20

Scroll sideways

Show Code
InfiniteScrolling.razor
<DwsInfiniteScrolling Name="InfiniteScrollingDemo_Horizontal" Items="@_horizontalItems" OnLoadMore="LoadHorizontalAsync"
                      HasMoreItems="@(_horizontalItems.Count < HorizontalMaxItems)"
                      Orientation="DwsLayoutOrientation.Horizontal" ShowEndMessage="true">
    <ItemTemplate Context="item">
        <div class="card m-2" style="width: 160px;">
            <div class="card-body">
                <h6 class="card-title mb-1">Card @item</h6>
                <p class="card-text small text-muted mb-0">Scroll sideways</p>
            </div>
        </div>
    </ItemTemplate>
</DwsInfiniteScrolling>
InfiniteScrolling.razor.cs
private const int PageSize = 20;
private const int HorizontalMaxItems = 60;
private readonly List<int> _horizontalItems = Enumerable.Range(1, 20).ToList();

private async Task LoadHorizontalAsync()
{
    await Task.Delay(600);
    _horizontalItems.AddRange(Enumerable.Range(_horizontalItems.Count + 1, PageSize));
}

Theming

Color themes the loading indicator, the retry button and the focus ring; BackgroundColor the list's background.

Item 1
Item 2
Item 3
Item 4
Item 5
Item 6
Item 7
Item 8
Item 9
Item 10
Item 11
Item 12
Item 13
Item 14
Item 15
Item 16
Item 17
Item 18
Item 19
Item 20
Item 21
Item 22
Item 23
Item 24
Item 25
Item 26
Item 27
Item 28
Item 29
Item 30
Item 31
Item 32
Item 33
Item 34
Item 35
Item 36
Item 37
Item 38
Item 39
Item 40
Item 41
Item 42
Item 43
Item 44
Item 45
Item 46
Item 47
Item 48
Item 49
Item 50
Item 51
Item 52
Item 53
Item 54
Item 55
Item 56
Item 57
Item 58
Item 59
Item 60
Show Code
InfiniteScrolling.razor
<DwsInfiniteScrolling Name="InfiniteScrollingDemo_ThemingList" Items="@_themeItems" OnLoadMore="LoadThemeAsync"
                      HasMoreItems="@(_themeItems.Count < 100)"
                      Color="DwsColor.Success" BackgroundColor="DwsColor.Light" ShowEndMessage="true" Height="250">
    <ItemTemplate Context="item">
        <div class="border-bottom px-3 py-2">@item</div>
    </ItemTemplate>
</DwsInfiniteScrolling>
InfiniteScrolling.razor.cs
private const int PageSize = 20;
private readonly List<string> _themeItems = Enumerable.Range(1, 20).Select(i => $"Item {i}").ToList();

private async Task LoadThemeAsync()
{
    await Task.Delay(600);
    _themeItems.AddRange(Enumerable.Range(_themeItems.Count + 1, PageSize).Select(i => $"Item {i}"));
}

Empty state

With no items and nothing loading, the list shows a default text, or EmptyTemplate.

No items to display.
Your inbox is empty.
Show Code
InfiniteScrolling.razor
<DwsInfiniteScrolling Name="InfiniteScrollingDemo_EmptyDefault" Items="@_emptyItems" HasMoreItems="false" Height="120">
    <ItemTemplate Context="item"><div>@item</div></ItemTemplate>
</DwsInfiniteScrolling>

<DwsInfiniteScrolling Name="InfiniteScrollingDemo_EmptyTemplate" Items="@_emptyItems" HasMoreItems="false" Height="120">
    <ItemTemplate Context="item"><div>@item</div></ItemTemplate>
    <EmptyTemplate>
        <div>
            <DwsIcon Name="InfiniteScrollingDemo_EmptyIcon" Icon="@Icons.BS.Inbox" Color="DwsColor.Undefined" Size="DwsSize.Large" Class="d-block" />
            Your inbox is empty.
        </div>
    </EmptyTemplate>
</DwsInfiniteScrolling>
InfiniteScrolling.razor.cs
private readonly List<string> _emptyItems = [];

Load more button

LoadMode Button shows a “Load more” button after the last item instead of loading while scrolling: the user decides when the next page is fetched, and whatever follows the list stays reachable by keyboard and screen reader. The button stays (as a busy button) while its request runs, so the focus is not lost and Enter loads page after page; a polite live region says how many items arrived. At the end the button leaves and the list itself takes the focus. An empty list still loads its first page by itself. LoadMoreText replaces the button's text.

Message 1
Message 2
Message 3
Message 4
Message 5
Message 6
Message 7
Message 8
Message 9
Message 10
Message 11
Message 12
Message 13
Message 14
Message 15
Message 16
Message 17
Message 18
Message 19
Message 20

20 of 60 items loaded.

Show Code
InfiniteScrolling.razor
<DwsInfiniteScrolling Name="InfiniteScrollingDemo_Button" Items="@_buttonItems" OnLoadMore="LoadButtonAsync"
                      HasMoreItems="@(_buttonItems.Count < ButtonMaxItems)"
                      LoadMode="DwsInfiniteScrollingLoadMode.Button" ShowEndMessage="true" Height="300">
    <ItemTemplate Context="item">
        <div class="border-bottom px-3 py-2">@item</div>
    </ItemTemplate>
</DwsInfiniteScrolling>
<DwsTypography Name="InfiniteScrollingDemo_Text07" Typography="DwsTypographyType.Paragraph" Class="small text-muted mt-2 mb-0" FontSize="0.875em">@_buttonItems.Count of @ButtonMaxItems items loaded.</DwsTypography>
InfiniteScrolling.razor.cs
private const int PageSize = 20;
private const int ButtonMaxItems = 60;
private readonly List<string> _buttonItems = [];   // may start empty: the first page is loaded without a click

private async Task LoadButtonAsync()
{
    await Task.Delay(600); // e.g. a web API call
    _buttonItems.AddRange(Enumerable.Range(_buttonItems.Count + 1, PageSize).Select(i => $"Message {i}"));
}

On a static page (no circuit)

Rendered as static SSR nothing scrolls into a handler, so the list ends with a Load more link instead, whatever LoadMode says. The link adds a step to the address (?StaticSsr_Feed-more=1, 2, ...; LoadMoreQueryParameter, by default the Name followed by -more), and that request raises OnLoadMore once per step during its one render - the same handler that appends interactively, no extra code. A list that starts empty loads its first page by itself, as it does interactively. Bounded by 50 steps and StaticItemLimit (500 items).

Show Code
StaticSsrProbe.razor

@* Static page: ?StaticSsr_Feed-more=2 raises OnLoadMore twice in the one render; the list ends with a link to step 3. *@
<DwsInfiniteScrolling TItem="string" Name="StaticSsr_Feed" Items="@FeedItems" HasMoreItems="@(FeedItems.Count < FeedTotal)"
                      OnLoadMore="LoadMoreFeed" MaxHeight="240">
    <ItemTemplate Context="item"><div class="py-1">@item</div></ItemTemplate>
</DwsInfiniteScrolling>
StaticSsrProbe.razor.cs

private const int FeedTotal = 25;

private List<string> FeedItems { get; } = [.. Enumerable.Range(1, 10).Select(i => $"Post {i:00}")];

// The same handler serves the interactive list and every static step.
private Task LoadMoreFeed()
{
    int start = FeedItems.Count + 1;
    FeedItems.AddRange(Enumerable.Range(start, Math.Min(10, FeedTotal - FeedItems.Count)).Select(i => $"Post {i:00}"));
    return Task.CompletedTask;
}

Interface-Description

Name Typ Parameters Description
LoadMoreAsync Task Requests more items now, as reaching the end does. Does nothing while a request runs, while disabled, once HasMoreItems is false or after a failed request.
RetryAsync Task Clears a failed request and asks for the items again.
ScrollToStartAsync Task Scrolls the list back to its first item.
Name Typ Default Description
Items IEnumerable<TItem>? null The items shown in the list. Append to it in OnLoadMore. A List or array is used as it is; any other sequence is copied once per parameter update.
ItemTemplate RenderFragment<TItem>? null Renders one item. Without a template the item's ToString() is shown.
LoadingTemplate RenderFragment? null Replaces the default loading indicator (spinner and text) shown while OnLoadMore runs.
EmptyTemplate RenderFragment? null Replaces the default text shown when there are no items and nothing is loading.
EndTemplate RenderFragment? null Shown after the last item once HasMoreItems is false.
ShowEndMessage bool false Shows a default "end of the list" text once HasMoreItems is false and no EndTemplate is set.
HasMoreItems bool true Whether there is more to load. Set it to false once the source is exhausted: the list then stops asking for more.
LoadMode DwsInfiniteScrollingLoadMode Scroll How more items are asked for. Scroll: when the list is scrolled near its end. Button: by a "Load more" button after the last item; nothing loads by scrolling, an empty list loads its first page itself.
LoadMoreText string? null Text of the "Load more" button (LoadMode Button). Null: the localized default.
LoadMoreQueryParameter string? null (Name-more) Static SSR only: the address parameter counting the "Load more" steps (?feed-more=2). Rendered statically, the list raises OnLoadMore once per step during its one render - your handler appends as usual - and ends with a "Load more" link to the next step, whatever LoadMode says.
Threshold int 100 Distance in px from the end of the content at which more items are requested. Negative values fall back to 100.
Orientation DwsLayoutOrientation DwsLayoutOrientation.Vertical Scroll axis. Horizontal lays the items out in a row and loads more at its right end.
Virtualize bool false Renders only the items in view (plus OverscanCount on each side) through Blazor's Virtualize, for long lists. Vertical lists only.
ItemSize float 50 Estimated item height in px for Virtualize; the real height is measured once items render.
OverscanCount int 3 Items rendered beyond the visible ones on each side while Virtualize is on.
Height int? null Height in px. Null: 400px for a vertical list, the content's height for a horizontal one.
MaxHeight int? null Maximum height in px.
Width int? null Width in px. Null fills the parent.
Color DwsColor DwsColor.Primary Theme colour of the loading indicator, the retry button and the focus ring.
BackgroundColor DwsColor DwsColor.Undefined Theme colour of the list's background. Undefined leaves it transparent.
Name Typ Description
OnLoadMore EventCallback Requested when the list is scrolled within Threshold of its end, and after a render that leaves the end in view. Awaited: the loading indicator shows until it completes and no second request starts meanwhile. Not requested while disabled, once HasMoreItems is false, or after a failed request until it is retried.
OnLoadError EventCallback<Exception> Raised when OnLoadMore throws. The error is logged and a retry button is shown.
OnScrollStart EventCallback<DwsInfiniteScrollingScrollEventArgs> Raised when the user starts scrolling the list (Offset, ScrollSize, ClientSize, RemainingDistance in px).
OnScrollEnd EventCallback<DwsInfiniteScrollingScrollEventArgs> Raised when scrolling has stopped for 150ms.
OnItemsRendered EventCallback<int> Raised after a render in which the number of items changed, with the new count.
Name Typ Default Description
Element ElementReference The associated web component. May be null if accessed before the component is rendered.
ComponentGuid Guid Unique identifier for the component.
TypeString string The name of the component type, obtained from reflection.
Authorized_RegisterEnabled bool false Indicates whether this component is enabled through a permission registry.
Authorized_RegisterSelected bool false Indicates whether this component is selected in permission selection mode.
GetInitializedState bool false Returns whether the component is initialized.
GetRenderModeState DwsRenderMode Returns the current render mode.
GetComponentState DwsComponentStateType Returns the current component state.
GetIsInteractiveState bool false Returns whether the component is interactive.
GetIsPrerenderingState bool false Returns whether the component is prerendering.
GetComponentLoadingState bool false Returns whether the component is loading.
IsFormBusy bool false Whether the DwsForm (or DwsFormBusyRegion) around the component is locked because its submit handler is running. The state itself is the cascaded FormBusyState (IDwsFormBusyState).
Name Typ Parameters Description
DebugInfo void Logs debug information about the component.
UpdateState void Updates the component's state and triggers StateHasChanged.
UpdateStateAsync Task Asynchronously updates the component's state and triggers StateHasChanged.
Dispose void Disposes the component and releases resources.
FocusAsync ValueTask bool containedInScrollableList Sets focus to the component's element.
Name Typ Default Description
Name string Required unique identifier for the component within its container.
Visible bool true Determines if the component is visible in the UI.
Disabled bool false Disables the form control, ensuring it doesn't participate in form submission.
ComponentNameSpace string The namespace for permission-based access control.
PermissionKey string? null A stable key that takes the place of Name in the generated permission namespace (Page.PermissionKey): the stored permission survives a rename, and components that share a key share one permission entry. Null: keyed by Name. Read once, when the component registers; an explicit ComponentNameSpace wins.
Class string Optional CSS class names.
Style string Optional in-line styles.
Tag object An optional user-defined object to store any additional data with the component.
BackReference DwsReference A reference to the enclosing component.
ID string The HTML ID attribute for the component.
AdditionalAttributes Dictionary<string, object> Additional HTML attributes for the component's root element.
IgnorePermissionChecks bool false Bypasses all permission checks for this component.
IgnorePermissionSelection bool false Ignore permission selection mode for this component.
IgnoreFormBusy bool false Takes the component out of the submit lock of the DwsForm (or DwsFormBusyRegion) around it: IsFormBusy stays false for it.
Name Typ Description
OnInitializedCallbackStarted EventCallback Callback when OnInitialized starts.
OnInitializedCallback EventCallback Callback during OnInitialized.
OnInitializedCallbackCompleted EventCallback Callback when OnInitialized completes.
OnInitializedAsyncCallbackStarted EventCallback Callback when OnInitializedAsync starts.
OnInitializedAsyncCallback EventCallback Callback during OnInitializedAsync.
OnInitializedAsyncCallbackCompleted EventCallback Callback when OnInitializedAsync completes.
OnIsComponentLoadingChanged EventCallback<bool> Callback when IsComponentLoading changes.
OnCurrentRenderModeChanged EventCallback<DwsRenderMode> Callback when CurrentRenderMode changes.
OnComponentStateChanged EventCallback<DwsComponentStateType> Callback when ComponentState changes.
An error has occurred. This app may no longer respond until reloaded.