Skip to content

Add EmptyContent to Virtualize #38978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Components/Web/src/Virtualization/Virtualize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public sealed class Virtualize<TItem> : ComponentBase, IVirtualizeJsCallbacks, I
private IJSRuntime JSRuntime { get; set; } = default!;

/// <summary>
/// Gets or sets the item template for the list.
/// Gets or sets the child content for the list.
/// </summary>
[Parameter]
public RenderFragment<TItem>? ChildContent { get; set; }
Expand All @@ -66,6 +66,12 @@ public sealed class Virtualize<TItem> : ComponentBase, IVirtualizeJsCallbacks, I
[Parameter]
public RenderFragment<TItem>? ItemContent { get; set; }

/// <summary>
/// Gets or sets the `<see cref="RenderFragment" />` that is used when no items are available.
/// </summary>
[Parameter]
public RenderFragment? EmptyContent { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sir. I missed that part of the instructions.


/// <summary>
/// Gets or sets the template for items that have not yet been loaded in memory.
/// </summary>
Expand Down Expand Up @@ -193,6 +199,11 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)

builder.OpenRegion(3);

if (EmptyContent is not null && _itemCount == 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this show the empty content when the list is still being loaded in the event the data source is an ItemsProvider? That doesn't seem right.

Could we also add some tests for this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it indeed does. I will rectify that and write some tests.

{
EmptyContent(builder);
}

// Render placeholders before the loaded items.
for (; renderIndex < placeholdersBeforeCount; renderIndex++)
{
Expand Down