0

I am using a MudBlazor MudTable. I cannot get the OnRowClick Event to work. I tried using the pattern from their documentation, but keep getting an error message. [using .Net 8.0, MudBlazor 8.12]
Pattern suggested in documentation samples: (Visit1 is the model)

   <MudTable Items="@Vis1List" OnRowClick="RowClickEvent"> </MudTable>
    
    @code {
    .
    .
    private void RowClickEvent(TableRowClickEventArgs<Visit1> tableRowClickEventArgs)
        {
            clickedEvents.Add("Row has been clicked");
        }        
    }

VS2022 gives error on the OnRowClick="RowClickEvent". Error message is

 "CS1503: Argument2: cannot convert from 'method group' to Microsoft.AspNetCore.Components.EventCallback"

What is the correct format to use in this case?

1 Answer 1

2

You are nearly there! Here is how I use it:

<MudTable T="Client" Items="@clientsPotentiels" OnRowClick="OnTblRowClicked"> </MudTable>
@code {

    private void OnTblRowClicked(TableRowClickEventArgs<Client> tableEvent)
    {
        //doing some stuff
    }
}

Notice the T parameter: you need to give it the Type used by the Items collection (Mine is Client).

Your code should work by adding it:

<MudTable T="Visit1" Items="@Vis1List" OnRowClick="RowClickEvent"> </MudTable>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks so much - worked perfectly! This makes me realize that I need to ALWAYS include the "T" parameter when using the MudTable... and probably any other component that asks for it.
No problem! Lots of times I had the same error with MudDataGrid. When a MudBlazor component needs a collection (MudDataGrid, MudTable, MudSelect, MudAutocomplete, MudList...), it's safe to assume that it will also require the Type of your collection, since some parameters could use it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.