MudBlazor DataGrid Grouping by MudSwitch

I’m trying to toggle the column that is grouped in my MudDataGrid by toggling the MudSwitch. By default it is grouped by Entity and a count of items is shown. I want to be able to toggle it to show the count by Agency. Changing the toggle doesn’t do anything. dataGrid.GroupItems() doesn’t do anything. The “hidden” columns I have set toggle appropriately, but that’s it.

I would like to be able to click the switch and toggle columns

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><MudDataGrid @ref="dataGrid" T="Incident" Items="@incidentList" Bordered="true"
FixedHeader="true" Dense="true" SortMode="SortMode.None" Filterable="false"
Groupable="true" ShowColumnOptions="false">
<ToolBarContent>
<MudText Typo="Typo.h5">Investigative Tracker</MudText>
<MudSpacer />
<MudTextField @bind-Value="_searchString" Placeholder="Search" Adornment="Adornment.Start" Immediate="true" Class="mb-4 ml-3 pr-5"
AdornmentIcon="@Icons.Material.Filled.Search" Style="color: #ffffff;" IconSize="Size.Medium"></MudTextField>
</ToolBarContent>
<Columns>
<PropertyColumn Property="x => x.AgencyMember.Entity.ToString()" Title="Full Name" Hidden="@groupValue" Grouping="@groupValue" Groupable="true" >
<GroupTemplate>
<span style="font-weight: bold;">
<MudChip Variant="Variant.Text" Style="background-color: transparent;" Color="Color.Tertiary" Size="Size.Small">
<table><td style="width: 250px;">@context.Grouping.Key</td> <td style="width: fit-content;">Count: @context.Grouping.Count()</td></table>
</MudChip>
</span>
</GroupTemplate>
</PropertyColumn>
<PropertyColumn Property="x => x.AgencyMember.Agency.Code" Title="Agency" Hidden="@(!groupValue)" Grouping="@(!groupValue)" Groupable="true">
<GroupTemplate>
<span style="font-weight: bold;">
<MudChip Variant="Variant.Text" Style="background-color: transparent;" Color="Color.Tertiary" Size="Size.Small">
<table><td style="width: 250px;">@context.Grouping.Key</td> <td style="width: fit-content;">Count: @context.Grouping.Count()</td></table>
</MudChip>
</span>
</GroupTemplate>
</PropertyColumn>
<PropertyColumn Property="x => x.AgencyMember.Agency.Description" Title="Description" />
<PropertyColumn Property="x => x.ReceivedDateTime" Title="Created" />
<PropertyColumn Property="x => x.LastUpdateTimeStamp" Title="Last Update" />
</Columns>
</MudDataGrid>
</code>
<code><MudDataGrid @ref="dataGrid" T="Incident" Items="@incidentList" Bordered="true" FixedHeader="true" Dense="true" SortMode="SortMode.None" Filterable="false" Groupable="true" ShowColumnOptions="false"> <ToolBarContent> <MudText Typo="Typo.h5">Investigative Tracker</MudText> <MudSpacer /> <MudTextField @bind-Value="_searchString" Placeholder="Search" Adornment="Adornment.Start" Immediate="true" Class="mb-4 ml-3 pr-5" AdornmentIcon="@Icons.Material.Filled.Search" Style="color: #ffffff;" IconSize="Size.Medium"></MudTextField> </ToolBarContent> <Columns> <PropertyColumn Property="x => x.AgencyMember.Entity.ToString()" Title="Full Name" Hidden="@groupValue" Grouping="@groupValue" Groupable="true" > <GroupTemplate> <span style="font-weight: bold;"> <MudChip Variant="Variant.Text" Style="background-color: transparent;" Color="Color.Tertiary" Size="Size.Small"> <table><td style="width: 250px;">@context.Grouping.Key</td> <td style="width: fit-content;">Count: @context.Grouping.Count()</td></table> </MudChip> </span> </GroupTemplate> </PropertyColumn> <PropertyColumn Property="x => x.AgencyMember.Agency.Code" Title="Agency" Hidden="@(!groupValue)" Grouping="@(!groupValue)" Groupable="true"> <GroupTemplate> <span style="font-weight: bold;"> <MudChip Variant="Variant.Text" Style="background-color: transparent;" Color="Color.Tertiary" Size="Size.Small"> <table><td style="width: 250px;">@context.Grouping.Key</td> <td style="width: fit-content;">Count: @context.Grouping.Count()</td></table> </MudChip> </span> </GroupTemplate> </PropertyColumn> <PropertyColumn Property="x => x.AgencyMember.Agency.Description" Title="Description" /> <PropertyColumn Property="x => x.ReceivedDateTime" Title="Created" /> <PropertyColumn Property="x => x.LastUpdateTimeStamp" Title="Last Update" /> </Columns> </MudDataGrid> </code>
<MudDataGrid @ref="dataGrid" T="Incident" Items="@incidentList"  Bordered="true"
             FixedHeader="true" Dense="true" SortMode="SortMode.None" Filterable="false" 
             Groupable="true" ShowColumnOptions="false">
    <ToolBarContent>
        <MudText Typo="Typo.h5">Investigative Tracker</MudText>     
        <MudSpacer />
        <MudTextField @bind-Value="_searchString" Placeholder="Search" Adornment="Adornment.Start" Immediate="true" Class="mb-4 ml-3 pr-5"
                      AdornmentIcon="@Icons.Material.Filled.Search" Style="color: #ffffff;" IconSize="Size.Medium"></MudTextField>
    </ToolBarContent>   
    <Columns>
        <PropertyColumn Property="x => x.AgencyMember.Entity.ToString()" Title="Full Name" Hidden="@groupValue" Grouping="@groupValue" Groupable="true" >
            <GroupTemplate>
                <span style="font-weight: bold;">
                    <MudChip Variant="Variant.Text" Style="background-color: transparent;" Color="Color.Tertiary" Size="Size.Small">
                        <table><td style="width: 250px;">@context.Grouping.Key</td> <td style="width: fit-content;">Count: @context.Grouping.Count()</td></table>
                    </MudChip>
                </span>
            </GroupTemplate>
        </PropertyColumn>
        <PropertyColumn Property="x => x.AgencyMember.Agency.Code" Title="Agency" Hidden="@(!groupValue)" Grouping="@(!groupValue)" Groupable="true">
            <GroupTemplate>
                <span style="font-weight: bold;">
                    <MudChip Variant="Variant.Text" Style="background-color: transparent;" Color="Color.Tertiary" Size="Size.Small">
                        <table><td style="width: 250px;">@context.Grouping.Key</td> <td style="width: fit-content;">Count: @context.Grouping.Count()</td></table>
                    </MudChip>
                </span>
            </GroupTemplate>
        </PropertyColumn>
        <PropertyColumn Property="x => x.AgencyMember.Agency.Description" Title="Description" />
        <PropertyColumn Property="x => x.ReceivedDateTime" Title="Created" />
        <PropertyColumn Property="x => x.LastUpdateTimeStamp" Title="Last Update" />        
    </Columns>
</MudDataGrid>

My @Code block

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@code {
private string _searchString = string.Empty;
private List<Incident> incidentList = [];
private MudDataGrid<Incident> dataGrid = default!;
private MudSwitch<bool> groupBySwitch = default!;
private bool groupValue = true;
protected async override Task OnInitializedAsync()
{
incidentList = await _trackerRepo.GetIncidentsAsync();
groupBySwitch.Value = true;
}
// Toggle Group By
private async Task GroupByChanged(bool isChecked)
{
if (isChecked)
{
groupValue = true;
}
else
{
groupValue = false;
}
dataGrid.GroupItems();
}
// happens everytime a row is edited, added
private async Task CommittedItemChanges(Incident item)
{
}
// quick filter - filter globally across multiple columns with the same input
private Func<Incident, bool> _quickFilter => x =>
{
if (string.IsNullOrWhiteSpace(_searchString))
return true;
return false;
};
}
</code>
<code>@code { private string _searchString = string.Empty; private List<Incident> incidentList = []; private MudDataGrid<Incident> dataGrid = default!; private MudSwitch<bool> groupBySwitch = default!; private bool groupValue = true; protected async override Task OnInitializedAsync() { incidentList = await _trackerRepo.GetIncidentsAsync(); groupBySwitch.Value = true; } // Toggle Group By private async Task GroupByChanged(bool isChecked) { if (isChecked) { groupValue = true; } else { groupValue = false; } dataGrid.GroupItems(); } // happens everytime a row is edited, added private async Task CommittedItemChanges(Incident item) { } // quick filter - filter globally across multiple columns with the same input private Func<Incident, bool> _quickFilter => x => { if (string.IsNullOrWhiteSpace(_searchString)) return true; return false; }; } </code>
@code {
    private string _searchString = string.Empty;
    private List<Incident> incidentList = [];
    private MudDataGrid<Incident> dataGrid = default!;
    private MudSwitch<bool> groupBySwitch = default!; 
    private bool groupValue = true;

    protected async override Task OnInitializedAsync()
    {
        incidentList = await _trackerRepo.GetIncidentsAsync();
        groupBySwitch.Value = true;
    }

    // Toggle Group By
    private async Task GroupByChanged(bool isChecked)
    {
        if (isChecked)
        {
            groupValue = true;
        }
        else
        {
            groupValue = false;
        }
        dataGrid.GroupItems();
    }

    // happens everytime a row is edited, added
    private async Task CommittedItemChanges(Incident item)
    {

    }

    // quick filter - filter globally across multiple columns with the same input
    private Func<Incident, bool> _quickFilter => x =>
    {
        if (string.IsNullOrWhiteSpace(_searchString))
            return true;

        return false;
    };
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật