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("grid").DataSource((IEnumerable<object>)ViewBag.DataSource).Height("348px").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.EmployeeData).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()
{
ViewBag.DataSource = OrdersDetails.GetAllRecords();
ViewBag.EmployeeData = EmployeeView.GetAllRecords();
return View();
}