Skip to content

Commit e18df76

Browse files
authored
Fix #4676 for V5 (#4679)
1 parent 39c4132 commit e18df76

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/Core/Components/DataGrid/FluentDataGrid.razor.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public partial class FluentDataGrid<TGridItem> : FluentComponentBase, IHandleEve
5757
private bool? _lastVirtualizationMode;
5858
private GridItemsProvider<TGridItem>? _lastAssignedItemsProvider;
5959
private CancellationTokenSource? _pendingDataLoadCancellationTokenSource;
60+
private bool _isFirstVirtualizeProviderCall = true;
6061
private Exception? _lastError;
6162
private GridItemsProviderRequest<TGridItem>? _lastRequest;
6263
private bool _forceRefreshData;
@@ -443,7 +444,7 @@ public FluentDataGrid(LibraryConfiguration configuration) : base(configuration)
443444

444445
// Returns Loading if set (controlled). If not controlled,
445446
// we assume the grid is loading until the next data load completes
446-
internal bool EffectiveLoadingValue => Loading ?? ItemsProvider is not null;
447+
internal bool EffectiveLoadingValue => Loading ?? (ItemsProvider is not null);
447448

448449
/// <summary>
449450
/// Indicates whether the grid is currently sorted ascending.
@@ -796,7 +797,7 @@ public async Task RemoveSortByColumnAsync(ColumnBase<TGridItem> column)
796797
await OnSortChanged.InvokeAsync(new()
797798
{
798799
Column = _sortByColumn,
799-
SortByAscending = _sortByAscending
800+
SortByAscending = _sortByAscending,
800801
});
801802
}
802803

@@ -994,11 +995,16 @@ private async Task RefreshDataCoreAsync()
994995
private async ValueTask<ItemsProviderResult<(int, TGridItem)>> ProvideVirtualizedItemsAsync(ItemsProviderRequest request)
995996
{
996997
_lastRefreshedPaginationState = Pagination;
998+
// Debounce the requests (except on first call). This eliminates a lot of redundant queries at the cost of slight lag after interactions.
999+
if (_isFirstVirtualizeProviderCall)
1000+
{
1001+
_isFirstVirtualizeProviderCall = false;
1002+
}
1003+
else
1004+
{
1005+
await Task.Delay(20);
1006+
}
9971007

998-
// Debounce the requests. This eliminates a lot of redundant queries at the cost of slight lag after interactions.
999-
// TODO: Consider making this configurable, or smarter (e.g., doesn't delay on first call in a batch, then the amount
1000-
// of delay increases if you rapidly issue repeated requests, such as when scrolling a long way)
1001-
await Task.Delay(20);
10021008
if (request.CancellationToken.IsCancellationRequested)
10031009
{
10041010
return default;

tests/Core/Components/DataGrid/FluentDataGridTests.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@
309309

310310
Assert.NotEmpty(rows); // Asserting that there are rows present
311311
//Assert.Equal(101, 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.
312-
Assert.Single(rows); //In bUnit the actual height of the grid can't be determined, so we just check that at least one row is rendered.
312+
Assert.Equal(21, 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.
313313
314314
}
315315

0 commit comments

Comments
 (0)