Skip to content

fix: Loading value is not set in DataGrid when using Items parameter #3261

@TekMechanic

Description

@TekMechanic

🐛 Bug Report

After changes made in PR #2998, when using the Items parameter as a data feed and not ItemsProvider, the Loading boolean is never set and is always null. This results in the Items IQueryable being enumerated whenever OnParametersSetAsync is called.

💻 Repro or Code Sample

@using System.Linq.Expressions
@using Microsoft.FluentUI.AspNetCore.Components

<FluentDataGrid
    Style="@_style"
    Items="@_queryable">
    <PropertyColumn Title="ID" Property="@(c => c)" />
</FluentDataGrid>

<FluentButton OnClick="OnButtonClick">Update Parameters</FluentButton>

<p>Number of queryable executions: <strong>@_numExecutions</strong></p>

@code {
    IQueryable<string>? _queryable;
    int? _numExecutions;
    private string _style = "";

    protected override Task OnInitializedAsync()
    {
        _queryable = new LoggingQueryable(["foo", "bar"], () => _numExecutions += 1);

        // Display the number of executions just for information. This is completely separate from the grid.
        _numExecutions = 1;
        return Task.CompletedTask;
    }

    private class LoggingQueryable(List<string> list, Action fetchCounter) : EnumerableQuery<string>(list), IQueryProvider
    {
        private readonly IQueryable<string> _list = list.AsQueryable();

        object? IQueryProvider.Execute(Expression expression)
        {
            fetchCounter();
            return (_list as IQueryProvider)!.Execute(expression);
        }

        TElement IQueryProvider.Execute<TElement>(Expression expression)
        {
            fetchCounter();
            return (_list as IQueryProvider)!.Execute<TElement>(expression);
        }
    }

    private void OnButtonClick()
    {
        _style += "";
    }

}

🤔 Expected Behavior

The queryable should not be enumerated unless there is a proper change.

😯 Current Behavior

The queryable is executed anytime a parameter is updated on the data grid.

💁 Possible Solution

The ResolveItemsRequestAsync method needs to set Loading appropriately when the Items parameter is used, similar to how it sets it for when ItemsProvider is used.

🔦 Context

🌍 Your Environment

Fluent UI 4.11.3, Chrome

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs: author feedbackThe author of this issue needs to respond in order for us to continue investigating this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions