Blazor Grid how to get clicked/selected cell value

How do I get cell value for a particular row and column.

For example, I need to get value of clicked cell, when user invokes context menu:

        public void ContextMenuItemClicked(ContextMenuClickEventArgs<DeliveryNote> args)
        {
            if (args.Item.Id == "filter_to_this")
            {
                object cellValue = ???;
                this.DataGrid.FilterByColumn(
                    args.Column.Field,
                    "Equal",
                    cellValue 
                    )
            }
        }

3 Replies 1 reply marked as answer

JP Jeevakanth Palaniappan Syncfusion Team November 12, 2020 01:36 PM UTC

Hi Liero, 

Greetings from Syncfusion support. 

We have validated your query and we suggest you to get the cell value based on the rowdata and the column provided in the ContextMenuClickEvent argument. Please find the below code snippet and the sample for your reference. 

    public void ContextMenuItemClickedHandler(ContextMenuClickEventArgs<Order> args) 
    { 
        var cellvalue = args.RowInfo.RowData.GetType().GetProperty(args.Column.Field).GetValue(args.RowInfo.RowData, null); 
        // Here you can customize your code 
    } 


Please get back to us if you have any other queries. 

Regards, 
Jeevakanth SP. 



LI Liero November 13, 2020 08:57 AM UTC

Hi Jeevakanth,
thanks for the suggestion. I hoped there will be something built in, because the field might be a property paths as well, e.g. "Property1.Property2", etc.. I have written my own evaluator, but I would feel better if I could use something more official


JP Jeevakanth Palaniappan Syncfusion Team November 16, 2020 02:20 PM UTC

Hi Liero, 

We suggest you to use the GetObject method of DataUtil class to achieve your requirement. Please refer the below code snippet for your reference. 

    public void ContextMenuItemClickedHandler(ContextMenuClickEventArgs<Order> args) 
    { 
        var cellvalue = Syncfusion.Blazor.Data.DataUtil.GetObject(args.Column.Field, args.RowInfo.RowData); 
    } 

Please get back to us if you have any other queries. 

Regards, 
Jeevakanth SP. 


Marked as answer
Loader.
Up arrow icon