@Grid
@(Html.EJ().Grid<OrdersView>("Grid")
. . .
.AllowPaging()
.Columns(col =>
{
col.Field(p => p.EmployeeID).ForeignKeyField("EmployeeID").ForeignKeyValue("FirstName").DataSource(ds => ds.URL(@Url.Action("ForeignData"))).HeaderText("FirstName").Add();
})
)
@Server side
public ActionResult ForeignData(DataManager dm)
{
IEnumerable data = EmployeeData;
int count = data.Cast<EmployeeView>().Count();
return Json(dm.RequiresCounts ? new { result = data, count = count } : data as object, JsonRequestBehavior.AllowGet);
} |
Hi,
thank you for the support.
I've used a "mixed solution" but I still encounter some problems.
the ActionComplete event is triggered and this is the javascript function:
<script type="text/javascript">
function complete(args) {
if (args.requestType == "beginedit" || args.requestType == "add") {
var locationId = args.rowData.LocationId;
if (args.requestType == "beginedit") {
$.ajax({
url: '../../Work/GetUsageValues',
type: 'GET',
async: false,
data: { "LocationId": locationId },
dataType: 'json',
success: function (result)
{
$("#LocationsGridUsageValueCode").ejDropDownList({ dataSource: result });//assign the filtered dataSource obtained from serverSide
}
})
}
}
}
</script>
below is the controller method:
public ActionResult GetUsageValues(int LocationId)
{
var location = db.Locations.Find(LocationId);
Equipment equipment = null;
if (location != null)
{
equipment = db.Equipments.FirstOrDefault(i => i.EquipmentId == location.LocationEquipmentId);
}
var eq = db.Equipments.FirstOrDefault(i => i.EquipmentId == location.LocationEquipmentId);
var usageValues = db.UsageValues.Where(uv => uv.IsCapture == eq.IsCapture).ToList();
return Json(usageValues, JsonRequestBehavior.AllowGet);
}
PROBLEM: the controller method is correclty called and it returns the correct datasourse. But in the dropdownlist I see the correct number of items but the description for all the items is "undefined". So I see <undefined<,<undefined>,... as text of the dropdownlist items.
Claudio
$("#LocationsGridUsageValueCode").ejDropDownList({ dataSource: result, fields: { text: "Field is shown for Display purpose", value: "This field value is foreignkey field" } });//assign the filtered dataSource obtained from serverSide
//For example we have foreign key field is EmployeeID and foreign key value is FirstName
$('#EmployeeID').ejDropDownList({
dataSource: result,
fields: { text: "FirstName", value: "EmployeeID" }, //here we have mentioned text as FirstName and value as EmployeeID
}); |