@(Html.EJ().Grid<object>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
--------------------
.Columns(col =>
{
col.HeaderText("Button").Commands(command =>
{
command.Type("Commit")
.ButtonOptions(new Syncfusion.JavaScript.Models.ButtonProperties()
{
Text = "Commit",
Width = "100px",
Click = "onClickCommit"
}).Add();
}).Add();
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(130).Add();
col.Field("EmployeeID").HeaderText("Employee Name").AllowEditing(true).ForeignKeyField("EmployeeID")
.ForeignKeyValue("FirstName").DataSource((IEnumerable<object>)ViewBag.dataSource2).EditType(EditingType.Dropdown)
.TextAlign(TextAlign.Left).AllowEditing(false).Width(90).Add();
---------------------
}))
</div>
<script type="text/javascript">
function onClickCommit(args) {
var gridObj = $("#FlatGrid").data("ejGrid");
//getting corresponding record
var data = gridObj.getSelectedRecords()[0].OrderID;
var data1 = gridObj.getSelectedRecords()[0].EmployeeID;
var Foreignkey = gridObj.model.columns[2].dataSource; // get the ForeignKey column datasource in the grid model column.
var dataManager = ej.DataManager(Foreignkey);
var query = ej.Query().select(["EmployeeID", "LastName", "FirstName", "Country"]).where("EmployeeID", "equal", data1); //
var promise = dataManager.executeLocal(query);
var ForeignkeyValue = promise[0].FirstName; // get the ForeignKey value of the selected record in the grid.
$.ajax({
----------------
});
}
</script>
|