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.

Hey @enchev if you paste this code in the DataGrid Self Referencing Hierarchy demo on your website, you can easily reproduce the bug. Trying to sort the column with property "Parent" and title "Sort Me" leads to the error.

@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore

@inherits DbContextPage

<RadzenDataGrid @ref="grid" AllowFiltering="true" AllowSorting="true" AllowColumnResize="true" ExpandMode="DataGridExpandMode.Single"
                Data="@employees" TItem="MyEmployee" RowRender="@RowRender" LoadChildData="@LoadChildData" 
                RowCollapse="@(args => grid.ColumnsCollection.ToList().ForEach(c => c.ClearFilters()))">
    <Columns>
        <RadzenDataGridColumn TItem="MyEmployee" Title="Employee" Frozen="true" Sortable="false" Filterable="false" Width="300px">
            <Template Context="data">
                <strong>@data.TitleOfCourtesy @data.FirstName @data.LastName</strong>
            </Template>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn TItem="MyEmployee" Property="Parent" Title="Sort Me" Width="240px" />
        <RadzenDataGridColumn TItem="MyEmployee" Property="Title" Title="Job Title" Width="240px" />
        <RadzenDataGridColumn TItem="MyEmployee" Property="HireDate" Title="Hire Date" FormatString="{0:d}" Width="160px" />
        <RadzenDataGridColumn TItem="MyEmployee" Property="City" Title="City" Width="200px" />
        <RadzenDataGridColumn TItem="MyEmployee" Property="HomePhone" Title="Home Phone" Width="200px" />
        <RadzenDataGridColumn TItem="MyEmployee" Property="Extension" Title="Extension" />
    </Columns>
</RadzenDataGrid>

@code {
    IEnumerable<MyEmployee> employees;
    RadzenDataGrid<MyEmployee> grid;

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        employees = dbContext.Employees.Where(e => e.ReportsTo == null)
            .Select(e => new MyEmployee{
                EmployeeID = e.EmployeeID,
                TitleOfCourtesy = e.TitleOfCourtesy,
                FirstName = e.FirstName,
                LastName = e.LastName,
                Title = e.Title,
                HireDate = e.HireDate,
                City = e.City,
                HomePhone = e.HomePhone,
                Extension = e.Extension,
                Parent = e.ReportsTo,
            });
    }

    void RowRender(RowRenderEventArgs<MyEmployee> args)
    {
        args.Expandable = dbContext.Employees.Where(e => e.ReportsTo == args.Data.EmployeeID).Any();
    }

    void LoadChildData(DataGridLoadChildDataEventArgs<MyEmployee> args)
    {
        args.Data = dbContext.Employees.Where(e => e.ReportsTo == args.Item.EmployeeID)
            .Select(e => new MyEmployee{
                EmployeeID = e.EmployeeID,
                TitleOfCourtesy = e.TitleOfCourtesy,
                FirstName = e.FirstName,
                LastName = e.LastName,
                Title = e.Title,
                HireDate = e.HireDate,
                City = e.City,
                HomePhone = e.HomePhone,
                Extension = e.Extension,
                Parent = e.ReportsTo,
            });
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        base.OnAfterRender(firstRender);

        if (firstRender)
        {
            await grid.ExpandRow(employees.FirstOrDefault());
        }
    }
    
    public class MyEmployee{
    	public int EmployeeID {get; set;}
        public string TitleOfCourtesy {get; set;}
        public string FirstName {get; set;}
        public string LastName {get; set;}
        public string Title {get; set;}
        public DateTime? HireDate {get; set;}
        public string City {get; set;}
        public string HomePhone {get; set;}
        public string Extension {get; set;}
        public int? Parent {get; set;}
    }
}

There are reserved words in Dynamic LINQ used internally to sort and filter data:

You can change your property name to something different.