How to fetch the row data once clicked on the Context menu in the Grid?

have scenario where there is a SyncFusion grid with 6 columns. Once user click on the ContextMenu for the a row, i need to fetch all the Row data. how to do the same? Reference grid & context menu as shown below.




4 Replies

PS Prathap Senthil Syncfusion Team May 25, 2023 08:29 AM UTC

Hi Lokanath,


We understand that you have a scenario where you need to retrieve all the row data when a user clicks on the Context Menu for a specific row. To achieve this, we recommend using a custom context menu item and utilizing the contextMenuItem event arguments in the rowInfo to fetch the row data. Kindly refer to the below code snippet and sample for your reference,

<SfGrid @ref="DefaultGrid" DataSource="@Orders" AllowPaging="true" ContextMenuItems="@(new List<ContextMenuItemModel>() { new ContextMenuItemModel { Text = "fetch data", Id = "fetch data" } })">

    <GridEvents ContextMenuItemClicked="OnContextMenuClick" TValue="Order"></GridEvents>

   

</SfGrid>

 

@code {

   

    private Order rowData { get; set; }

 

    public void OnContextMenuClick(ContextMenuClickEventArgs<Order> args)

    {

        if (args.Item.Id == "fetch data")

        {

            rowData = args.RowInfo.RowData;

    

           

 

        }

    }

}



Documentation: https://blazor.syncfusion.com/documentation/datagrid/context-menu#custom-context-menu-items

                             https://blazor.syncfusion.com/documentation/datagrid/events#contextmenuitemclicked


Regards,
Prathap S


Attachment: DataGrid_85bae72b.zip


LD lokanath das May 26, 2023 11:15 AM UTC

Thanks for the reply. In my case the  TValue="ExpandoObject". i.e., from System.Dynamic name space. As this is a Gneric grid, so the same grid will render in multiple model data. trying with the fllowing code



Protected void OnContextMenuItemClicked(ContextMenuClickEventArgs<ExpandoObject>? row)

{

 var result= row.RowInfo?.RowData;  //here it's not returning the row data info.

}



MS Monisha Saravanan Syncfusion Team May 29, 2023 10:18 AM UTC

Hi Lokanath,


We have prepared an simple sample as per your shared requirement. But we could not able to replicate the reported issue at our end. Kindly check the below attached code snippet and sample for your reference.



If you still face difficulties then kindly share below the details to validate the issue further from our side.


  • Share us the entire Grid code snippet.
  • Share us the Nuget version used at your end.
  • Share us the video demonstration of the issue.
  • If possible share us simple issue reproducing sample or try to reproduce the reported issue on the below attached sample. So that we will validate and we will check the reported issue in the provided sample.


The above provided details will be very helpful for us to validate the reported query at our end and provide the solution as early as possible also Kindy get back to us if you need further assistance


Regards,

Monisha



MS Monisha Saravanan Syncfusion Team May 29, 2023 10:23 AM UTC

Hi Lokanath,


Please find the sample below


Attachment: BlazorApp1_20257902.zip

Loader.
Up arrow icon