Skip to content

fix: SetTotalItemCountAsync in PaginationState #2479

@vpetit-reimagine

Description

@vpetit-reimagine

🐛 Bug Report

Using FluentDataGrid with PaginationState and a list of items results in the PaginationState using the count of the retrieved Queryable as the TotalItemCount instead of the value assigned via SetTotalItemCountAsync

💻 Repro or Code Sample

@using System.Web
@using Microsoft.FluentUI.AspNetCore.Components


<FluentDataGrid @ref="_myGrid" TGridItem="MyItem" Items="_items" 
                GridTemplateColumns="35px" 
                ResizableColumns="false" Pagination="@_pagination">
        
    <PropertyColumn Property="@(s => s.Id)" Title="ID"></PropertyColumn>
</FluentDataGrid>
    
<FluentPaginator State="@_pagination" CurrentPageIndexChanged="() => LoadItemsWithFiltering()"/>

@code {
    public class MyItem {
        public long Id { get; set; }
    }

    private IQueryable<MyItem> _items;
    
    private int _count;
    
    private PaginationState _pagination = new();
    private FluentDataGrid<SignalOverviewDto> _myGrid;

    protected override void OnInitialized()
    {
        base.OnInitialized();
        
        _pagination.TotalItemCountChanged += (sender, eventArgs) => StateHasChanged();
    }

    protected override async Task OnParametersSetAsync()
    {
        await base.OnParametersSetAsync();

        await LoadItemsWithFiltering();
    }

    private async Task LoadItemsWithFiltering()
    {
        /* API call here, basically looking like: */
        _items = await _myItemService.ListItems(_pagination.CurrentPageIndex * _pagination.ItemsPerPage, _pagination.ItemsPerPage);
        _count = await _myItemService.CountItems();

        // Fails here: The call sets it to 20 but it is then set to the number of items in the IQueryable
        await _pagination.SetTotalItemCountAsync(_count); 
        await InvokeAsync(StateHasChanged);
    }
}

Steps to reproduce:

  1. Load data in the Data Grid with Items="_items"
  2. Manually update the PaginationState with SetTotalItemCountAsync
  3. The TotalItemCount is set to the number of items in the IQueryable

🤔 Expected Behavior

The TotalItemCount should be the value I assign it to, as I currently fetch a small list of items instead of everything

😯 Current Behavior

For some reason, the method SetTotalItemCountAsync just does something strange (probably the callbacks behind that are doing stuff that are not expected).

💁 Possible Solution

Allow the SetTotalItemCountAsync to override the count of the IQueryable

🔦 Context

I'm trying to load the items of a db call with pagination outside of the ItemsProvider because that has way too many other issues to start looking into.

🌍 Your Environment

  • OS & Device: Windows, PC
  • Browser: Firefox Developer Edition
  • .NET 8.0.2, FluentUI Components 4.9.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    docs:apiAdditions, improvements, or fixes to API docsstatus:plannedWork is planned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions