DataGrid Element Reference Is Empty

I'm trying to pass the element reference of my DataGrid into my JS function when a user presses a certain key, but the ElementReference property on my referenced variable is empty. When I pass it to my JS function, it's blowing up. Am I doing something wrong here?

FYI, it doesn't seem to make a difference if I add an "id" attribute to the grid itself.

<RadzenDataGrid  @ref="_loadsGrid"
                            @onkeypress="@(e => KeyPressed(e))"

@code {

    private RadzenDataGrid<LoadEdit> _loadsGrid;

    private async void KeyPressed(Microsoft.AspNetCore.Components.Web.KeyboardEventArgs e)
        bool hotKeyShortcut = e.AltKey || e.CtrlKey || e.ShiftKey;

        if (hotKeyShortcut)
            bool saveEdit = new string[] { "Enter", "NumpadEnter" }.Contains(e.Code);
            if (saveEdit)
                // _loadsGrid.Element.Id && _loadsGrid.Element.Context are both null.
                await JSRuntime.InvokeVoidAsync("manuallyTriggerChangeEvents", _loadsGrid.Element);

I now see where I can access the id via the attributes property on the grid reference. So now my question is, shouldn't I be able to pass in the element reference into my JS function and things be groovy, or am I misunderstanding that Element property?

Hi @beeterry,

It seems we haven't set the Element reference of the RadzenDataGrid. We will address that with the next release.

1 Like