Weird bug in datagrid: column with property "Parent" breaks sorting and filtering

<RadzenDataGridColumn TItem="RdtoLocation" Property="Parent" Title="Parent">
   <Template Context="data">
      <RadzenLink Path="@($"/location/{data?.ParentId}")" Text="@(data?.Parent ?? "")" class="rz-text-wrap" />
   </Template>
</RadzenDataGridColumn>

This column causes error when I try to sort or filter. I am not using datagrid "LoadData", so all data is loaded once on initialization and passed to the datagrid component. All sorting and filtering is client side. Weirdly, the error goes away if I change the property name in RdtoLocation from Parent to something else.

This is the error message I get in the browser:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: No 'parent' is in scope
No 'parent' is in scope (at index 0)

Worth mentioning that some entries in the column may be null or empty strings.

Without actual code demonstrating the exception we will unable to help.

AarmBlazor.zip (243.5 KB)

@enchev Sorry for the late reply. I have attached a demo. It is a Blazor hosted project in a zip. You can login with a@b.c and password Abcd@1234 or you can register a new dummy user.

The Location entity is self-referencing / hierarchical. I cannot sort or filter using the field named "Parent" but the same server-side field, if mapped to a DTO field called "NotNamedParent" works okay.

I would be grateful if you could take a look.

Hi @sohaib,

Debugging customers projects is part of our paid services - you can check our pricing page for reference. If you want to receive quick help you might need to provide a simplified version of your code (a self contained code snippet with just the DataGrid) that can be executed easily. Other possibility is to attach the source code of Radzen.Blazor to your project to debug your entire application.

<RadzenDataGrid Data="@Data"
    AllowMultiColumnSorting="true" ShowMultiColumnSortingIndex="true" AllowColumnResize="true" AllowSorting="true"
    AllowFiltering="true" AllowPaging="true" PageSize="25" PagerHorizontalAlign="HorizontalAlign.Center"
    PagerPosition="PagerPosition.Bottom" FilterMode="FilterMode.SimpleWithMenu" TItem="RdtoLocation" ColumnWidth="200px"
    SelectionMode="DataGridSelectionMode.Multiple"
    AllowRowSelectOnRowClick="true" @bind-Value="@selectedLocations"
    FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" >
    <HeaderTemplate>
        @*redacted because irrelevant*@
    </HeaderTemplate>
    <Columns>
        <RadzenDataGridColumn TItem="RdtoLocation" Width="50px" Sortable="false" Filterable="false">
            <HeaderTemplate>
                <RadzenCheckBox TriState="false" TValue="bool"
                    Value="@(Data?.Any(i => selectedLocations != null && selectedLocations.Contains(i)) ?? false)"
                    Change="@(args => selectedLocations = args ? Data?.ToList() : null)" />
            </HeaderTemplate>
            <Template Context="data">
                <RadzenCheckBox TriState="false" Value="@(selectedLocations != null && selectedLocations.Contains(data))"
                    TValue="bool" Change=@(args => { if(!allowRowSelectOnRowClick) { grid?.SelectRow(data); }}) />
            </Template>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn TItem="RdtoLocation" Property="Name"
            Title="Name" Frozen="true">
            <Template Context="data">
                <RadzenLink Path="@($"/location/{data?.Id}")" Text="@data?.Name" class="rz-text-wrap" />
            </Template>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn TItem="RdtoLocation" Property="Parent"
            Title="Parent">
            <Template Context="data">
                <RadzenLink Path="@($"/location/{data?.ParentId}")" Text="@data?.Parent" class="rz-text-wrap" />
            </Template>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn TItem="RdtoLocation" Property="NotNamedParent"
            Title="NotNamedParent">
            <Template Context="data">
                <RadzenLink Path="@($"/location/{data?.NotNamedParentId}")" Text="@data?.NotNamedParent" class="rz-text-wrap" />
            </Template>
        </RadzenDataGridColumn>
    </Columns>
</RadzenDataGrid>

Above is the datagrid. Following is RdtoLocation

public class RdtoLocation
    {
        public int Id { get; set; }

        public string Name { get; set; } = string.Empty;

        public int? ParentId { get; set; }

        public string Parent { get; set; } = string.Empty;

        public int? NotNamedParentId { get; set; }

        public string NotNamedParent { get; set; } = string.Empty;

        public IEnumerable<RdtoLocation> Children { get; set; } = new HashSet<RdtoLocation>();
    }

Both Parent and NotNamedParent are derived using Automapper from the database entity as follows:


CreateMap<Location, RdtoLocation>()
                .ForMember(d => d.Parent, opt => opt.MapFrom(s => s.Parent == null ? "" : s.Parent.Name))
                .ForMember(d => d.NotNamedParent, opt => opt.MapFrom(s => s.Parent == null ? "" : s.Parent.Name))
                .ForMember(d => d.NotNamedParentId, opt => opt.MapFrom(s => s.ParentId))
                .ForMember(d => d.CountOfChildren, opt => opt.MapFrom(s => s.Children.Count));

Datagrid works fine in case of server side sorting and filtering but causes error when using the built-in client side sorting and filtering with column named Parent.