@@ -314,38 +314,40 @@ public async Task RefreshDataAsync()
314314 private async Task RefreshDataCoreAsync ( )
315315 {
316316 // First render of Virtualize component will handle the data load itself.
317- if ( ! ( _firstRefreshDataAsync && Virtualize ) )
317+ if ( _firstRefreshDataAsync && Virtualize )
318318 {
319- // Move into a "loading" state, cancelling any earlier-but-still-pending load
320- _pendingDataLoadCancellationTokenSource ? . Cancel ( ) ;
321- var thisLoadCts = _pendingDataLoadCancellationTokenSource = new CancellationTokenSource ( ) ;
319+ _firstRefreshDataAsync = false ;
320+ return ;
321+ }
322+
323+ // Move into a "loading" state, cancelling any earlier-but-still-pending load
324+ _pendingDataLoadCancellationTokenSource ? . Cancel ( ) ;
325+ var thisLoadCts = _pendingDataLoadCancellationTokenSource = new CancellationTokenSource ( ) ;
322326
323- if ( _virtualizeComponent is not null )
327+ if ( _virtualizeComponent is not null )
328+ {
329+ // If we're using Virtualize, we have to go through its RefreshDataAsync API otherwise:
330+ // (1) It won't know to update its own internal state if the provider output has changed
331+ // (2) We won't know what slice of data to query for
332+ await _virtualizeComponent . RefreshDataAsync ( ) ;
333+ _pendingDataLoadCancellationTokenSource = null ;
334+ }
335+ else
336+ {
337+ // If we're not using Virtualize, we build and execute a request against the items provider directly
338+ _lastRefreshedPaginationStateHash = Pagination ? . GetHashCode ( ) ;
339+ var startIndex = Pagination is null ? 0 : ( Pagination . CurrentPageIndex * Pagination . ItemsPerPage ) ;
340+ var request = new GridItemsProviderRequest < TGridItem > (
341+ startIndex , Pagination ? . ItemsPerPage , _sortByColumn , _sortByAscending , thisLoadCts . Token ) ;
342+ var result = await ResolveItemsRequestAsync ( request ) ;
343+ if ( ! thisLoadCts . IsCancellationRequested )
324344 {
325- // If we're using Virtualize, we have to go through its RefreshDataAsync API otherwise:
326- // (1) It won't know to update its own internal state if the provider output has changed
327- // (2) We won't know what slice of data to query for
328- await _virtualizeComponent . RefreshDataAsync ( ) ;
345+ _currentNonVirtualizedViewItems = result . Items ;
346+ _ariaBodyRowCount = _currentNonVirtualizedViewItems . Count ;
347+ Pagination ? . SetTotalItemCountAsync ( result . TotalItemCount ) ;
329348 _pendingDataLoadCancellationTokenSource = null ;
330349 }
331- else
332- {
333- // If we're not using Virtualize, we build and execute a request against the items provider directly
334- _lastRefreshedPaginationStateHash = Pagination ? . GetHashCode ( ) ;
335- var startIndex = Pagination is null ? 0 : ( Pagination . CurrentPageIndex * Pagination . ItemsPerPage ) ;
336- var request = new GridItemsProviderRequest < TGridItem > (
337- startIndex , Pagination ? . ItemsPerPage , _sortByColumn , _sortByAscending , thisLoadCts . Token ) ;
338- var result = await ResolveItemsRequestAsync ( request ) ;
339- if ( ! thisLoadCts . IsCancellationRequested )
340- {
341- _currentNonVirtualizedViewItems = result . Items ;
342- _ariaBodyRowCount = _currentNonVirtualizedViewItems . Count ;
343- Pagination ? . SetTotalItemCountAsync ( result . TotalItemCount ) ;
344- _pendingDataLoadCancellationTokenSource = null ;
345- }
346- }
347350 }
348- _firstRefreshDataAsync = false ;
349351 }
350352
351353 // Gets called both by RefreshDataCoreAsync and directly by the Virtualize child component during scrolling
0 commit comments