-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
area-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor Componentsfeature-blazor-quickgridinvestigate
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
In the method RefreshDataCoreAsync, add _lastRefreshedPaginationStateHash = Pagination?.GetHashCode(); after Pagination?.SetTotalItemCountAsync(result.TotalItemCount); to avoid calling RefreshDataCoreAsync() again in OnParametersSetAsync() when ItemsProvider return a different TotalItemCount.
This happen, for example, when an event handler on the page changes a filter, reset the page to 0 SetCurrentPageIndexAsync(0), ItemsProvider returns a different TotalItemCount because of different filter, the _lastRefreshedPaginationStateHash is not updated with the new TotalItemCount , and Pagination?.GetHashCode() is different because Pagination.TotalItemCount is different.
private async Task RefreshDataCoreAsync()
{
// Move into a "loading" state, cancelling any earlier-but-still-pending load
_pendingDataLoadCancellationTokenSource?.Cancel();
var thisLoadCts = _pendingDataLoadCancellationTokenSource = new CancellationTokenSource();
if (_virtualizeComponent is not null)
{
// If we're using Virtualize, we have to go through its RefreshDataAsync API otherwise:
// (1) It won't know to update its own internal state if the provider output has changed
// (2) We won't know what slice of data to query for
await _virtualizeComponent.RefreshDataAsync();
_pendingDataLoadCancellationTokenSource = null;
}
else
{
// If we're not using Virtualize, we build and execute a request against the items provider directly
_lastRefreshedPaginationStateHash = Pagination?.GetHashCode();
var startIndex = Pagination is null ? 0 : (Pagination.CurrentPageIndex * Pagination.ItemsPerPage);
var request = new GridItemsProviderRequest<TGridItem>(
startIndex, Pagination?.ItemsPerPage, _sortByColumn, _sortByAscending, thisLoadCts.Token);
var result = await ResolveItemsRequestAsync(request);
if (!thisLoadCts.IsCancellationRequested)
{
_currentNonVirtualizedViewItems = result.Items;
_ariaBodyRowCount = _currentNonVirtualizedViewItems.Count;
Pagination?.SetTotalItemCountAsync(result.TotalItemCount);
_pendingDataLoadCancellationTokenSource = null;
}
}
}
/// <inheritdoc />
protected override Task OnParametersSetAsync()
{
// The associated pagination state may have been added/removed/replaced
_currentPageItemsChanged.SubscribeOrMove(Pagination?.CurrentPageItemsChanged);
if (Items is not null && ItemsProvider is not null)
{
throw new InvalidOperationException($"{nameof(QuickGrid)} requires one of {nameof(Items)} or {nameof(ItemsProvider)}, but both were specified.");
}
// Perform a re-query only if the data source or something else has changed
var _newItemsOrItemsProvider = Items ?? (object?)ItemsProvider;
var dataSourceHasChanged = _newItemsOrItemsProvider != _lastAssignedItemsOrProvider;
if (dataSourceHasChanged)
{
_lastAssignedItemsOrProvider = _newItemsOrItemsProvider;
_asyncQueryExecutor = AsyncQueryExecutorSupplier.GetAsyncQueryExecutor(Services, Items);
}
var mustRefreshData = dataSourceHasChanged
|| (Pagination?.GetHashCode() != _lastRefreshedPaginationStateHash);
// We don't want to trigger the first data load until we've collected the initial set of columns,
// because they might perform some action like setting the default sort order, so it would be wasteful
// to have to re-query immediately
return (_columns.Count > 0 && mustRefreshData) ? RefreshDataCoreAsync() : Task.CompletedTask;
}
Expected Behavior
``
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
No response
Anything else?
No response
Metadata
Metadata
Assignees
Labels
area-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor Componentsfeature-blazor-quickgridinvestigate