I am using a MudTable with a custom Group By function to display a list of tickets for each department. Each ticket has a single category hence the grouping is done by Category Name. I also display the number of tickets for each category in the Group Name by getting the count of Tickets
in Category
entity
I want to sort these groups in the descending of number of tickets. Category with highest tickets should be displayed at the top. But I realized MudTable does not provide much options for sorting whereas MudDataGrid does. But I still can't figure out how to achieve it.
P.S: I understand MudTable & MudDataGrid could be 2 separate questions but I am trying to get it working with either.
The MudTable
<MudTable Hover="true" Breakpoint="Breakpoint.Sm" FixedHeader="true" Items="@votes" GroupBy="@_groupDefinition" GroupHeaderStyle="background-color:var(--mud-palette-background-grey)" MultiSelection="false" SortLabel="Sort By"><GroupHeaderTemplate><MudTh Class="mud-table-cell-custom-group" colspan="6">@($"{context.GroupName}: {context.Key} - ") <span style="font-weight: bold">(@context.Items.Where(v => v.CreatedAt != null).Count()) Tickets</span></MudTh></GroupHeaderTemplate><RowTemplate><MudTd DataLabel="Id">ID: @context.Id</MudTd><MudTd DataLabel="Name">Subject: @context.Name</MudTd><MudTd DataLabel="Email">Email: @context.Email</MudTd></RowTemplate><PagerContent><MudTablePager /></PagerContent><NoRecordsContent><MudText>No tickets found for this department</MudText></NoRecordsContent></MudTable>
The Group By Function
private TableGroupDefinition<Ticket> _groupDefinition = new TableGroupDefinition<Ticket>() { GroupName = "Category", Expandable = true, Indentation = false, IsInitiallyExpanded = false, Selector = (e) => e.Category };
Category-Ticket relationship
Category
public virtual ICollection<Ticket> Tickets { get; } = new List<Ticket>();
Ticket
public int CategoryId { get; set; }public Category Category { get; set; } = null!;
Any help would be appreciated! TIA!