DataGrid object is null

I'm attempting to filter my DataGrid on component load, but I'm having issues as the C# object doesn't seem be representing the Blazor component, so looking for columns etc doesn't work.

<RadzenGrid @ref="inProgressGrid" AllowPaging="true" AllowSorting="true" AllowFiltering="true"
                    Data="inProgressRequests" TItem="FullRequestDTO">

And in the code section:

private List<FullRequestDTO> inProgressRequests;
private string currentUser;
RadzenGrid<FullRequestDTO> inProgressGrid;

But any subsequent use of inProgressGrid fails, as its null.
It's probably something basic, but I can't see it....and as I was double checking things, found it! But in case this trips someone else up:

My <RadzenGrid> definition was in a @if block checking that I had data...this seemed to be preventing Blazor from populating the object passed to the @ref parameter.

Refs in Blazor are populated at later stage in the lifecycle:

" A component reference is only populated after the component is rendered and its output includes ReferenceChild 's element. Until the component is rendered, there's nothing to reference."

1 Like