How to fetch the Entire row data After clicking context menu in Sync Fusion Grid?

199 Views Asked by At

I 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.

enter image description here

1

There are 1 best solutions below

0
On

You can utilize a custom context menu item and use the contextMenuItem event arguments in the rowInfo to fetch the row data. You can refer to the code snippet below: Documentation: https://blazor.syncfusion.com/documentation/datagrid/context-menu#custom-context-menu-items https://blazor.syncfusion.com/documentation/datagrid/events#contextmenuitemclicked

<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>
<GridPageSettings PageSize="8"></GridPageSettings>
<GridColumns>
    <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120" IsPrimaryKey="true"></GridColumn>
    <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>
    <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
    <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
@code {
public List<Order> Orders { get; set; }
private Order rowData { get; set; }


private SfGrid<Order> DefaultGrid;

protected override void OnInitialized()
{
    Orders = Enumerable.Range(1, 75).Select(x => new Order()
        {
            OrderID = 1000 + x,
            CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],
            Freight = 2.1 * x,
            OrderDate = DateTime.Now.AddDays(-x),
        }).ToList();
}

public class Order
{
    public int? OrderID { get; set; }
    public string CustomerID { get; set; }
    public DateTime? OrderDate { get; set; }
    public double? Freight { get; set; }
}



public void OnContextMenuClick(ContextMenuClickEventArgs<Order> args)
{
    if (args.Item.Id == "fetch data")
    {
        rowData = args.RowInfo.RowData;
 
       

    }
}

}