Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Core/Components/DataGrid/FluentDataGrid.razor
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
{
@if (Virtualize)
{
if (_internalGridContext.TotalItemCount == 0)
if (_internalGridContext.TotalItemCount == 0 && _virtualizeComponent is not null)
{
@_renderEmptyContent
}
Expand Down
45 changes: 38 additions & 7 deletions src/Core/Components/DataGrid/FluentDataGrid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1302,19 +1302,34 @@ public async Task RefreshDataAsync(bool force = false)

// Same as RefreshDataAsync, except without forcing a re-render. We use this from OnParametersSetAsync
// because in that case there's going to be a re-render anyway.
[SuppressMessage("Design", "MA0051:Method is too long", Justification = "Not going to do artificial optimization because of some random arbitrary determined line count number")]
private async Task RefreshDataCoreAsync()
{
// Move into a "loading" state, cancelling any earlier-but-still-pending load
_pendingDataLoadCancellationTokenSource?.CancelAsync();
var thisLoadCts = _pendingDataLoadCancellationTokenSource = new CancellationTokenSource();

if (_virtualizeComponent is not null)
if (Virtualize)
{
// 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();
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
// ProvideVirtualizedItemsAsync updates _internalGridContext.Items and fires ItemsChanged,
// so no second query is needed here.
await _virtualizeComponent.RefreshDataAsync();
_pendingDataLoadCancellationTokenSource = null;
return;
}
// If Virtualize is true but we don't have a reference to the component yet,
// it means we're still in the first render. The Virtualize component will call us when it's ready,
// so we can just wait for that instead of trying to load data now.
_pendingDataLoadCancellationTokenSource = null;
thisLoadCts.Dispose();
Loading = false;
StateHasChanged();
return;
}

// If we're not using Virtualize, we build and execute a request against the items provider directly
Expand Down Expand Up @@ -1365,6 +1380,7 @@ private async Task RefreshDataCoreAsync()

// Gets called both by RefreshDataCoreAsync and directly by the Virtualize child component during scrolling
[ExcludeFromCodeCoverage(Justification = "This method requires Virtualiztion which cannot be tested with bunit.")]
[SuppressMessage("Design", "MA0051:Method is too long", Justification = "Not going to do artificial optimization because of some random arbitrary determined line count number")]
private async ValueTask<ItemsProviderResult<(int, TGridItem)>> ProvideVirtualizedItemsAsync(ItemsProviderRequest request)
{
_lastRefreshedPaginationState = Pagination;
Expand All @@ -1375,7 +1391,14 @@ private async Task RefreshDataCoreAsync()
}
else
{
await Task.Delay(20);
try
{
await Task.Delay(20, request.CancellationToken);
}
catch (TaskCanceledException)
{
return default;
}
}

if (request.CancellationToken.IsCancellationRequested)
Expand Down Expand Up @@ -1467,8 +1490,16 @@ private async ValueTask<GridItemsProviderResult<TGridItem>> ResolveItemsRequestA
if (_asyncQueryExecutor is not null)
{
await OnItemsLoading.InvokeAsync(true);

var resultArray = Array.Empty<TGridItem>();
var totalItemCount = await _asyncQueryExecutor.CountAsync(Items, request.CancellationToken);
var resultArray = await _asyncQueryExecutor.ToArrayAsync(result, request.CancellationToken);
request.CancellationToken.ThrowIfCancellationRequested();

if (!request.Count.HasValue || request.Count.Value > 0)
{
resultArray = await _asyncQueryExecutor.ToArrayAsync(result, request.CancellationToken);
request.CancellationToken.ThrowIfCancellationRequested();
}
Comment thread
miguelhasse marked this conversation as resolved.

Loading = false;
_asyncQueryExecuted = true;
Expand Down
2 changes: 1 addition & 1 deletion tests/Core/Components/DataGrid/FluentDataGridTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@
var rows = cut.FindComponents<FluentDataGridRow<Customer>>();

Assert.NotEmpty(rows); // Asserting that there are rows present
Assert.Equal(2, rows.Count); //In bUnit the actual height of the grid can't be determined, so we just check that at least one row is rendered.
Assert.True(rows.Count >= 1); //In bUnit the actual height of the grid can't be determined, so we just check that at least one row is rendered.
}

private async Task<GridItemsProviderResult<Customer>> RefreshItemsAsync(GridItemsProviderRequest<Customer> req)
Expand Down