Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model state not updated in MudTable when using an IEnumerable and server-side data-retrieval #8885

Open
1 of 2 tasks
nullpainter opened this issue May 5, 2024 · 2 comments

Comments

@nullpainter
Copy link

nullpainter commented May 5, 2024

Bug type

Component

Component name

MudTable

What happened?

Summary

If TableData<T>.Items is an IEnumerable<T>, context state cannot be modified.

Background
I have a MudTable which receives data from my server. Each row has a button which expands or collapses the row.

This was working perfectly until I performed client-side transformation of the table data prior to population in the MudTable - and critically, not converting the resultant IEnumerable<T> to a List<T> in my ServerData callback when setting TableData<T>.Items.

The resultant behaviour was that the table rendered fine, however the context passed to my row expander was the original model state - i.e., any changes to the model in code (i.e., toggling an expanded state boolean on my model) - weren't reflected.

Expected behavior

If the ServerData function sets an IEnumerable<T> on TableData<T>.Items, the MudTable should still work fully.

Reproduction link

Can write if required - I believe the context of the bug report is hopefully sufficient

Reproduction steps

<MudTable ServerData="@(new Func<TableState, Task<TableData<ClientMessageSummary>>>(SearchAsync))" @ref="_table">
   ...
private async Task<TableData<ClientMessageSummary>> SearchAsync(TableState state) 
{
    // Retrival code removed for clarity

    return new TableData<ClientMessageSummary>
    {
        Items = response.Messages.Select(ModelMapper.Map),  // BUG - IEnumerable due to `Select()`
        TotalItems = response.NumMessages
    };
}

Relevant log output

No response

Version (bug)

6.15.0

Version (working)

No response

What browsers are you seeing the problem on?

Edge

On which operating systems are you experiencing the issue?

Windows

Pull Request

  • I would like to do a Pull Request

Code of Conduct

  • I agree to follow this project's Code of Conduct
@henon henon removed the triage label May 7, 2024
@Conman-123
Copy link
Contributor

Please create a trymudblazor recreating this. I could not recreate the issue and it doesn't sound like an issue with using IEnumerable instead of List (unless MudBlazor was somehow and for some reason creating deep copies of your objects).

@nullpainter
Copy link
Author

Of course, I will do. The only other thing of note is that my models are records, not classes. Not sure if that's of any consequence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants