fluentui-blazor
fluentui-blazor copied to clipboard
fix: Using virtualization causes two data requests in FluentDataGrid
🐛 Bug Report
Using virtualization causes RefreshDataCoreAsync, and by proxy all code that calls it, to request new data from ItemsProvider twice.
💻 Repro or Code Sample
<div style="height: 400px; max-width: 800px; overflow-y: scroll;">
<FluentDataGrid @ref="_grid"
ItemsProvider="_itemsProvider"
Virtualize="true"
DisplayMode="DataGridDisplayMode.Table"
Style="width: 100%;"
ItemSize="54"
GenerateHeader="@GenerateHeaderOption.Sticky">
<PropertyColumn Property="@(c => c.Item)" />
</FluentDataGrid>
</div>
<br />
<FluentButton OnClick="Refresh">Force refresh</FluentButton>
@code {
FluentDataGrid<SampleGridData>? _grid;
public record SampleGridData(string Item);
GridItemsProvider<SampleGridData>? _itemsProvider;
int _fetchCounter;
protected override void OnInitialized()
{
_itemsProvider = req =>
{
DemoLogger.WriteLine($"{_fetchCounter++,3}. Fetching values {req.StartIndex} - {req.StartIndex + req.Count}");
if (req.Count is null)
return Result([]);
return Result(Enumerable
.Range(req.StartIndex, req.Count.Value)
.Select(i => new SampleGridData($"value {i}"))
.ToList());
ValueTask<GridItemsProviderResult<SampleGridData>> Result(ICollection<SampleGridData> data)
=> ValueTask.FromResult(GridItemsProviderResult.From(data, 50_000));
};
}
async Task Refresh()
{
if (_grid is not null)
{
DemoLogger.WriteLine("Refresh requested");
await _grid.RefreshDataAsync();
}
}
}
🤔 Expected Behavior
Refreshing the grid should request data once.
😯 Current Behavior
Refreshing requests data twice.
💁 Possible Solution
It looks like there is a missing return here. Otherwise the code continues and calls ResolveItemsRequestAsync.
🌍 Your Environment
- Windows on PC
- Browser Microsoft Edge
- .NET 10 and Fluent UI Blazor 4.13.2
Duplicate. See https://github.com/microsoft/fluentui-blazor/issues/1066#issuecomment-2076548798