<Grid>
@(Html.EJ().Grid<InlineFormtemplate.OrdersView>("ForeignKey")
.Datasource((IEnumerable<object>)ViewBag.dataSource1)
. . .
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.InlineFormTemplate).InlineFormTemplateID("#Inlineform"); })
. . .
.Columns(col =>
{
. . .
col.Field("EmployeeID").HeaderText("Employee Name").ForeignKeyField("EmployeeID")
.ForeignKeyValue("FirstName").DataSource((IEnumerable<object>)ViewBag.dataSource2)
.TextAlign(TextAlign.Left).Width(90).Add();
. . .
}).ClientSideEvents(eve =>
{
eve.ActionComplete("actionComplete");
})
)
<InlineForm template>
<script id="Inlineform" type="text/template">
<b>Order Details</b>
<table cellspacing="10">
<tr>
<td style="text-align: right;">
EmployeeID
</td>
<td style="text-align: left">
<select id="EmployeeID" name="EmployeeID">
<option value=1>Nancy</option>
<option value=2>Andrew</option>
<option value=3>Janet</option>
<option value=4>Margaret</option>
<option value=5>Robert</option>
<option value=6>Michael</option>
<option value=7>Steven</option>
<option value=8>Laura</option>
<option value=9>Anne</option>
</select>
</td>
</tr>
</table>
</script>
<ActionComplete event>
<script type="text/javascript">
function actionComplete(args) {
if ((args.requestType == "beginedit" || args.requestType == "add") && args.model.editSettings.editMode == "inlineformtemplate") {
$("#ShipCountry").ejDropDownList({ width: '116px' });
$("#EmployeeID").ejDropDownList({ width: '116px' });
if (args.requestType == "beginedit") {
$("#OrderID").attr("disabled", "disabled");
var rowIndex = args.rowIndex; //Get the Row index
var ForeignKeyValue = args.model.currentViewData[rowIndex]["EmployeeID"]; // Get the EmployeeID value
$("#ShipCountry").ejDropDownList("setSelectedValue", args.row.children().eq(4).text());
$("#EmployeeID").ejDropDownList("setSelectedValue", ForeignKeyValue); // Set the Foreignkey value for dropdown list
}
$(".e-field").css({ 'width': '116px', 'text-align': 'left' });
}
}
</script> |
<ej-grid id="FlatGrid" allow-paging="true" datasource="@ViewBag.DataSource1">
<e-edit-settings allow-editing="true" allow-adding="true" allow-editing="true" />
<e-columns>
<e-column field="OrderID" is-primary-key="true"></e-column>
<e-column field="EmployeeID" header-text="first Name" foreign-key-field="EmployeeID" foreign-key-value="FirstName" datasource="@ViewBag.DataSource2"></e-column>
<e-column field="CustomerID"></e-column>
<e-column field="Freight"></e-column>
<e-column field="ShipCity"></e-column>
</e-columns>
</ej-grid> |