Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ public partial class QuickGrid<TGridItem> : IAsyncDisposable
// If the QuickGrid is disposed while the JS module is being loaded, we need to avoid calling JS methods
private bool _wasDisposed;

private bool _firstRefreshDataAsync = true;
Copy link
Member

@ilonatommy ilonatommy Sep 11, 2025

Choose a reason for hiding this comment

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

"Added a _firstRefreshDataAsync flag to the QuickGrid class to track whether the initial data load has occurred."

Can we simplify it to _shouldSkipDataLoad? Or _shouldSkipDataRefresh.

Suggested change
private bool _firstRefreshDataAsync = true;
private bool _shouldSkipDataLoad = true;


/// <summary>
/// Constructs an instance of <see cref="QuickGrid{TGridItem}"/>.
/// </summary>
Expand Down Expand Up @@ -311,6 +313,13 @@ public async Task RefreshDataAsync()
// because in that case there's going to be a re-render anyway.
private async Task RefreshDataCoreAsync()
{
// First render of Virtualize component will handle the data load itself.
if (_firstRefreshDataAsync && Virtualize)
{
_firstRefreshDataAsync = false;
return;
}

// Move into a "loading" state, cancelling any earlier-but-still-pending load
_pendingDataLoadCancellationTokenSource?.Cancel();
var thisLoadCts = _pendingDataLoadCancellationTokenSource = new CancellationTokenSource();
Expand Down
9 changes: 8 additions & 1 deletion src/Components/test/E2ETest/Tests/QuickGridTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void RowStyleApplied()
const p = document.querySelector('tbody > tr:first-child > td:nth-child(5)');
return p ? getComputedStyle(p).textAlign : null;"));
}

[Fact]
public void CanOpenColumnOptions()
{
Expand Down Expand Up @@ -208,4 +208,11 @@ public void CanCloseColumnOptionsByHideColumnOptionsAsync()
var firstNameSearchSelector = "#grid > table > thead > tr > th:nth-child(2) input[type=search]";
Browser.DoesNotExist(By.CssSelector(firstNameSearchSelector));
}

[Fact]
public void ItemsProviderCalledOnceWithVirtualize()
{
app = Browser.MountTestComponent<QuickGridVirtualizeComponent>();
Browser.Equal("1", () => app.FindElement(By.Id("items-provider-call-count")).Text);
}
}
1 change: 1 addition & 0 deletions src/Components/test/testassets/BasicTestApp/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<option value="@GetTestServerProjectComponent("Components.TestServer.ProtectedBrowserStorageUsageComponent")">Protected browser storage usage</option>
<option value="@GetTestServerProjectComponent("Components.TestServer.ProtectedBrowserStorageInjectionComponent")">Protected browser storage injection</option>
<option value="BasicTestApp.QuickGridTest.SampleQuickGridComponent">QuickGrid Example</option>
<option value="BasicTestApp.QuickGridTest.QuickGridVirtualizeComponent">QuickGrid with Virtualize Example</option>
<option value="BasicTestApp.RazorTemplates">Razor Templates</option>
<option value="BasicTestApp.Reconnection.ReconnectionComponent">Reconnection server-side blazor</option>
<option value="BasicTestApp.RedTextComponent">Red text</option>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@using Microsoft.AspNetCore.Components.QuickGrid
@using System.Linq

<p id="items-provider-call-count">@ItemsProviderCallCount</p>

<div id="grid" style="height: 200px; overflow: auto">
<QuickGrid ItemsProvider="@itemsProvider" Virtualize="true" ItemSize="50">
<PropertyColumn Property="@(p => p.Id)" />
<PropertyColumn Property="@(p => p.Name)" />
</QuickGrid>
</div>

@code {
internal class Person
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
}

private GridItemsProvider<Person> itemsProvider = default!;

int ItemsProviderCallCount = 0;

protected override void OnInitialized()
{
itemsProvider = async request =>
{
await Task.CompletedTask;
Interlocked.Increment(ref ItemsProviderCallCount);
StateHasChanged();
return GridItemsProviderResult.From(
items: Enumerable.Range(1, 100).Select(i => new Person { Id = i, Name = $"Person {i}" }).ToList(),
totalItemCount: 100);
};
}
}
Loading