Error when loading/saving RadzenDataGrid Settings, where there are filterable columns without Property #918

Open
opened 2026-01-29 17:46:20 +00:00 by claunia · 0 comments
Owner

Originally created by @lulikin on GitHub (Jul 13, 2023).

I have a class which inherit from RadzenDataGridColumn and override GetColumnODataFilter.

        protected override string GetColumnODataFilter(object filterValue, FilterOperator filterOperator)
        {
            var property = GetFilterProperty().Replace('.', '/');

            return $"{property}/any(x: x/Value eq '{filterValue}' and x/CustomPropertyId eq {CustomPropertyId})";
        }

Then I use this in my Grid like

                   <ContactCustomPropertyGridColumn FilterProperty="@nameof(Flegis.Model.Contact.ContactCustomProperties)" TItem="Flegis.Model.Contact" CustomPropertyId="@(customProperty.Id)" Title="@customProperty.Name" Frozen="false" Sortable="false" Filterable="true" Width="100px" TextAlign="TextAlign.Left">
                       <Template Context="data">
                           @switch (customProperty.AnswerType)
                           {
                               case Model.AnswerType.Note:
                               case Model.AnswerType.Text:
                                   @(data.ContactCustomProperties.Any(a => a.CustomPropertyId == customProperty.Id) ? data.ContactCustomProperties.First(a => a.CustomPropertyId == customProperty.Id).Value : "")
                                   break;
                               case Model.AnswerType.Bool:
                                   <RadzenCheckBox TriState="true" TValue="bool?" Value="@(data.ContactCustomProperties.Any(a => a.CustomPropertyId == customProperty.Id) ? data.ContactCustomProperties.First(a => a.CustomPropertyId == customProperty.Id).IntValue==1 : null)" />
                                   break;
                               case Model.AnswerType.ChooseMany:
                                   break;
                               case Model.AnswerType.ChooseOne:
                                   if (data.ContactCustomProperties.Any(a => a.CustomPropertyId == customProperty.Id))
                                   {
                                       var value = data.ContactCustomProperties.First(a => a.CustomPropertyId == customProperty.Id);
                                       if (value.IntValue.HasValue)
                                       {
                                           <p>@customProperty.CustomPropertyAnswers.First(f => f.Value  == value.IntValue.Value).Title</p>
                                       }
                                   }
                                   else
                                   {
                                   }
                                   break;
                           }
                       </Template>
                   </ContactCustomPropertyGridColumn>

When page load I get this error

blazor.webassembly.js:1  crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Radzen.PropertyAccess.Getter[Contact,Object](String propertyName, Type type)
   at Radzen.Blazor.RadzenDataGridColumn`1[[Flegis.Model.Contact, Flegis.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnInitialized()
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
   at Radzen.Blazor.RadzenDataGridColumn`1.<SetParametersAsync>d__192[[Flegis.Model.Contact, Flegis.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()

Filtering works like it should. If I remove that column I don't get any error. If I remove binding for settings from grid error also disappear.

My line for Grid:
<RadzenDataGrid @ref="_CustomersGrid" @bind-Settings="GridSettings" IsLoading="@isLoading" Count="@_TotalResults" Data="@_Customers" LoadData="@LoadData" FilterPopupRenderMode="PopupRenderMode.OnDemand" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterMode="FilterMode.SimpleWithMenu" AllowSorting="true" AllowFiltering="!CustomFilter" AllowPaging="true" PageSize="_PageSize" PagerHorizontalAlign="HorizontalAlign.Center" TItem="Customer" ColumnWidth="200px" AllowColumnPicking="true" AllowColumnResize="true" AllowColumnReorder="true">

Like you see, I get values for the column from related List. If I add Property="..." to the column error tells me, that Property does not exists for my class. Which is correct.

I suspect, that error saving settings use Property for key, but I cannot set it, because Property does not exists for my class. Solution could be adding new Parameter to RadzenDataGridColumn, which will be used for saving settings.

Originally created by @lulikin on GitHub (Jul 13, 2023). I have a class which inherit from RadzenDataGridColumn<TItem> and override GetColumnODataFilter. ``` protected override string GetColumnODataFilter(object filterValue, FilterOperator filterOperator) { var property = GetFilterProperty().Replace('.', '/'); return $"{property}/any(x: x/Value eq '{filterValue}' and x/CustomPropertyId eq {CustomPropertyId})"; } ``` Then I use this in my Grid like ``` <ContactCustomPropertyGridColumn FilterProperty="@nameof(Flegis.Model.Contact.ContactCustomProperties)" TItem="Flegis.Model.Contact" CustomPropertyId="@(customProperty.Id)" Title="@customProperty.Name" Frozen="false" Sortable="false" Filterable="true" Width="100px" TextAlign="TextAlign.Left"> <Template Context="data"> @switch (customProperty.AnswerType) { case Model.AnswerType.Note: case Model.AnswerType.Text: @(data.ContactCustomProperties.Any(a => a.CustomPropertyId == customProperty.Id) ? data.ContactCustomProperties.First(a => a.CustomPropertyId == customProperty.Id).Value : "") break; case Model.AnswerType.Bool: <RadzenCheckBox TriState="true" TValue="bool?" Value="@(data.ContactCustomProperties.Any(a => a.CustomPropertyId == customProperty.Id) ? data.ContactCustomProperties.First(a => a.CustomPropertyId == customProperty.Id).IntValue==1 : null)" /> break; case Model.AnswerType.ChooseMany: break; case Model.AnswerType.ChooseOne: if (data.ContactCustomProperties.Any(a => a.CustomPropertyId == customProperty.Id)) { var value = data.ContactCustomProperties.First(a => a.CustomPropertyId == customProperty.Id); if (value.IntValue.HasValue) { <p>@customProperty.CustomPropertyAnswers.First(f => f.Value == value.IntValue.Value).Title</p> } } else { } break; } </Template> </ContactCustomPropertyGridColumn> ``` When page load I get this error ``` blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object. at Radzen.PropertyAccess.Getter[Contact,Object](String propertyName, Type type) at Radzen.Blazor.RadzenDataGridColumn`1[[Flegis.Model.Contact, Flegis.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnInitialized() at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync() at Radzen.Blazor.RadzenDataGridColumn`1.<SetParametersAsync>d__192[[Flegis.Model.Contact, Flegis.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() ``` Filtering works like it should. If I remove that column I don't get any error. If I remove binding for settings from grid error also disappear. My line for Grid: ` <RadzenDataGrid @ref="_CustomersGrid" @bind-Settings="GridSettings" IsLoading="@isLoading" Count="@_TotalResults" Data="@_Customers" LoadData="@LoadData" FilterPopupRenderMode="PopupRenderMode.OnDemand" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterMode="FilterMode.SimpleWithMenu" AllowSorting="true" AllowFiltering="!CustomFilter" AllowPaging="true" PageSize="_PageSize" PagerHorizontalAlign="HorizontalAlign.Center" TItem="Customer" ColumnWidth="200px" AllowColumnPicking="true" AllowColumnResize="true" AllowColumnReorder="true">` Like you see, I get values for the column from related List. If I add Property="..." to the column error tells me, that Property does not exists for my class. Which is correct. I suspect, that error saving settings use Property for key, but I cannot set it, because Property does not exists for my class. Solution could be adding new Parameter to RadzenDataGridColumn, which will be used for saving settings.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#918