TelerikGrid - Click on GridCommandButton does not set selected row

1 Answer 24 Views
Button Grid
Martin Herløv
Top achievements
Rank 2
Bronze
Iron
Iron
Martin Herløv asked on 23 May 2024, 04:45 PM | edited on 23 May 2024, 04:56 PM

I have a GridCommandButton with a custom action.

If I click directly on the button, the select row is not set. How can I get the content of the row when I click the button?

<GridCommandButton Command="SyncWithAD" Icon="@FontIcon.Lock" Title="Sync to Azure" Enabled="CanEdit" OnClick="@ShowSyncUserWithAdDialog"></GridCommandButton>

Use the GridCommandEventArgs.Item

private async Task ShowSyncUserWithAdDialog(GridCommandEventArgs args)
    {
        if(args.Item is not JasminExternalUser user) return;
        
        Progress.Visible = true;
        var props = new JasminUserAdProperties { Email = user.Email, Name = user.Name, Groups = [] };
        AdProperties = await UserService.GetUserAdProperties(props);
        Progress.Visible = false;
    }

1 Answer, 1 is accepted

Sort by
0
Nansi
Telerik team
answered on 28 May 2024, 09:06 AM

Hello Martin,

Thank you for the provided code example.

To access the data of the clicked model item, you need to explicitly cast the item to the model.

JasminExternalUser user = (JasminExternalUser)args.Item;

I have prepared a REPL example that displays some properties of the model when you click the custom command button. 

Regards,
Nansi
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!
Tags
Button Grid
Asked by
Martin Herløv
Top achievements
Rank 2
Bronze
Iron
Iron
Answers by
Nansi
Telerik team
Share this question
or