blazor-docs/knowledge-base/grid-filtering-null-referen...

1.9 KiB

title description type page_title slug position tags ticketid res_type
Null Reference when using filtering in Grid with data coming from a server How to fix a Null Reference exception when using filtering in Grid with data coming from a server? troubleshooting Null Reference when using filtering in Grid grid-kb-filtering-null-reference telerik,blazor,grid,filtering,null,reference,exception 1524399 kb

Environment

Product Grid for Blazor

Description

For our current project, we are grabbing data from the server and using it to dynamically populate a TelerikGrid in Blazor. This is causing an issue with filtering in the Grid.

Error Message

System.NullReferenceException: Object reference not set to an instance of an object.
    at Telerik.Blazor.Components.Common.Filters.FilterList.TelerikFilterList.GetFilterOperators()
    at Telerik.Blazor.Components.Common.Filters.FilterList.TelerikFilterList.InitFilterOperators()
    at Telerik.Blazor.Components.Common.Filters.FilterList.TelerikFilterList.OnInitializedAsync()
    at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

Possible Cause

The possible reason for this error is a missing FieldType from the column that you try to filter.

Solution

The FieldType is required when the Grid can't get its columns type through reflection - when the Grid is bound to an object rather than a real model.

The following sample project in the blazor-ui repository demonstrates an example of filtering in Grid with data coming from a server.

https://github.com/telerik/blazor-ui/tree/master/grid/datasourcerequest-on-server/ServerApp

Additional useful information can be found at our Grid data binding documentation in the following link.

https://docs.telerik.com/blazor-ui/components/grid/columns/bound#grid-bound-column-parameters