-
Notifications
You must be signed in to change notification settings - Fork 9.9k
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
Virtualize component Placeholder has no effect #57929
Comments
Hi, @AndrewBorst. Until the items provider returns its first In your repro app, the first If you change the When loading data asynchronously, it's not super common to know the total item count before the initial items are fetched, which is why the API is designed this way. If you want some kind of loading experience for the initial set of items, you could render a separate loading indicator until the first set of items are fetched. This is what we would recommend. However, if you really want to render some hard-coded number of initial placeholders, despite this being possibly different from the actual item count, you could make the first Example<Virtualize ItemsProvider="LoadForecastsAsync" @ref="_virtualize">
@* ... *@
</Virtualize>
@code {
private const int InitialPlaceholderCount = 10;
private Virtualize<WeatherForecast> _virtualize = null!;
private bool _hasProvidedInitialPlaceholders;
private async ValueTask<ItemsProviderResult<WeatherForecast>> LoadForecastsAsync(ItemsProviderRequest request)
{
if (!_hasProvidedInitialPlaceholders)
{
_hasProvidedInitialPlaceholders = true;
_ = LoadActualItemsAsync();
return new(items: [], totalItemCount: InitialPlaceholderCount);
async Task LoadActualItemsAsync()
{
await Task.Yield(); // Defer the call to 'RefreshDataAsync()` to avoid cancelling the current request
await _virtualize.RefreshDataAsync(); // Refresh the data, which will call 'LoadForecastsAsync()' again
StateHasChanged(); // Re-render the component
}
}
// ... load the actual items ...
return new(actualItems, actualItemCount);
}
} Could you please let us know if this addresses your concerns? We'll close out this issue if there's not a framework problem here. Thanks! |
@MackinnonBuck Thank you for the explanation and sample code, it makes sense now that the Placeholder is at the item-level and not the component-level. Please close out the issue. |
Is there an existing issue for this?
Describe the bug
Adding the Placeholder tag to the Virtualize component has no effect. I could not make a working example or find any code online that worked. I tried testing locally on two different machines and neither worked. I also tried the EmptyContent and that didn't work either. In older issue, somebody pointed out this only works with ItemsProvider which I am trying to use.
Expected Behavior
How it should work:
Steps To Reproduce
So a minimal example is on the FetchData page of Repo. On the main branch, I have a working alternative for showing a message while waiting for the items to load.
Exceptions (if any)
No response
.NET Version
8.0.108
Anything else?
No response
The text was updated successfully, but these errors were encountered: