Hi,
I have a DataGrid with a GridForeignColumn. Within my GridForeignColumn, I have an "EditTemplate" with a SfDropDownList component.
The problem I am having is displaying the same values from the ForeignKeyValue from my GridForeignColumn to the SfDropDownList in the EditTemplate.
I want to be able to bind the ForeignKeyValue to the '@bind-Value' attribute in SfDropDownList component as shown in the attached screenshot. However, this breaks the program because currently '@bind-Value' can only bind to the 'Field' attribute and not the ' ForeignKeyValue' in the GridForeignColumn.
Is there another way around this? Why is there no 'ForeignKeyValue' attribute for SfDropDownList ?
Thanks,
Kenney
|
<SfGrid DataSource="@Orders" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">
<GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="@EditMode.Normal"></GridEditSettings>
<GridEvents OnActionBegin="ActionBegin" TValue="Order"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridForeignColumn Field=@nameof(Order.GeoFenceListID) HeaderText="Employee Name" ForeignKeyValue="LocTypeID" ForeignDataSource="@Employees" Width="150">
<Template>
@{
var ord = context as Order;
var geofence = Employees.SingleOrDefault(x => x.GeoFenceListID == ord.GeoFenceListID);
if (geofence != null)
{
var loctype = LocationTypes.SingleOrDefault(x => x.LocTypeID == geofence.LocTypeID);
<div>@loctype.LocType</div>
}
}
</Template>
<EditTemplate>
@{
var ord = context as Order;
var geofence = Employees.SingleOrDefault(x => x.GeoFenceListID == ord.GeoFenceListID);
<SfDropDownList @ref="Ddl" ID="GeoFenceListID" TItem="NameList" TValue="int?" Value="@geofence.LocTypeID" DataSource="@LocationTypes">
<DropDownListFieldSettings Text="LocType" Value="LocTypeID"></DropDownListFieldSettings>
</SfDropDownList>
}
</EditTemplate>
</GridForeignColumn>
<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>
</SfGrid>
@code{
public List<Order> Orders { get; set; }
public List<EmployeeData> Employees { get; set; }
public List<NameList> LocationTypes { get; set; }
SfDropDownList<int?, NameList> Ddl { get; set; }
public void ActionBegin(ActionEventArgs<Order> Args)
{
if (Args.RequestType == Syncfusion.Blazor.Grids.Action.Save)
{
var GeoFenceId = Employees.SingleOrDefault(x=>x.LocTypeID == Ddl?.Value).GeoFenceListID;
Args.Data.GeoFenceListID = GeoFenceId;
}
}
|