Set complex column as Foreignkey column

17 Feb 20221 minute to read

The following example shows how to set the complex column as foreign key column.

In the following example, Employee.EmployeeID is a complex column and also declared as a foreign column which shows FirstName column from foreign data.

@Html.EJS().Grid("ForeignKey").DataSource((IEnumerable<object>)ViewBag.DataSource).Columns(col =>
{
  col.Field("OrderID").HeaderText("Order ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
  col.Field("Employee.EmployeeID").ForeignKeyField("EmployeeID").ForeignKeyValue("FirstName").DataSource((IEnumerable<object>)ViewBag.foreign).HeaderText("Employee Name").Width("150").Add();
  col.Field("Freight").HeaderText("Freight").Width("120").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
  col.Field("ShipName").HeaderText("Ship Name").Width("150").Add();

}).Render()
public IActionResult DefaultExporting()
{
    var order = OrdersDetails.GetAllRecords();
    ViewBag.DataSource = order;

    var emp = EmployeeView.GetAllRecords();
    ViewBag.foreign = emp;
    return View();
}