Suppose you have this sample's OrderDetails.cs:
https://blazor.syncfusion.com/documentation/datagrid/foreignkey-column?cs-save-lang=1&cs-lang=razor#binding-local-data
and then the following Index.razor code, where Args.Data can be used for performing CRUD in the Orders table. The problem is: how to use Args.Data to know which row of the Employees table to delete, update, insert, if the employee name column in the grid is edited, and assume one employee at most handles one order?
@using Syncfusion.Blazor.Grids
<SfGrid DataSource="@Orders" Height="315">
<GridEvents OnActionBegin="ActionBegin" TValue="GanttSegClass"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(OrderDetails.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridForeignColumn Field=@nameof(OrderDetails.EmployeeID) HeaderText="Employee Name" ForeignKeyValue="FirstName" ForeignDataSource="@Employees" Width="150"></GridForeignColumn>
<GridColumn Field=@nameof(OrderDetails.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(OrderDetails.ShipCity) HeaderText="Ship City" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
@code {
public List<OrderDetails> Orders { get; set; }
public List<EmployeeDetails> Employees { get; set; }
protected override void OnInitialized()
{
Orders = OrderDetails.GetAllRecords();
Employees = EmployeeDetails.GetAllRecords();
}
public void ActionBegin(Syncfusion.Blazor.Grids.ActionEventArgs<OrderDetails> Args)
{
if (Args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Save)){
if (Args.Action == "Add"){
//add Args.Data
}
else{
//update Args.Data
}
}
if (Args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Delete)){
//delete Args.Data
}
}
}