Hi,
from
documentation I know that we can bound foreign key column in grid to remote DataSource (in doc used OData remote service). I tried to connect to my Web API via URL Adapter, but have got error:
ej.web.all.min.js:10 Uncaught TypeError: s.filter is not a function
at _foreignKeyBinding (ej.web.all.min.js:10)
at r (jsrender.js:371)
at Function.eval [as fn] (eval at P (jsrender.js:2103), <anonymous>:11:29)
at N (jsrender.js:1454)
at Function.E [as render] (jsrender.js:1323)
at Object.dgDevices_JSONTemplate (jsrender.js:905)
at Object.sendDataRenderingRequest (ej.web.all.min.js:10)
at Object._renderGridContent (ej.web.all.min.js:10)
at Object.render (ej.web.all.min.js:10)
at Object._initGridRender (ej.web.all.min.js:10)
While local datasource binding for foreign key column is working as expected. Is UrlAdaptor can be used to implement the required task?
Below are excerpts from my code. My entities are DeviceType (DeviceTypeID [pk]) and Device (DeviceID [pk], DeviceTypeID [fk]).
1. Device.cshtml
@{Html.EJ().Grid<object>("dgDevices")
.Datasource(ds => ds.URL("/api/device/datasource")
.InsertURL("/api/device/insert")
.UpdateURL("/api/device/update")
.RemoveURL("/api/device/delete")
.Adaptor(AdaptorType.UrlAdaptor))
.EditSettings(edit => { edit.AllowAdding().AllowEditing().AllowDeleting().AllowEditOnDblClick().EditMode(EditMode.Normal); })
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Add);
items.AddTool(ToolBarItems.Edit);
items.AddTool(ToolBarItems.Delete);
items.AddTool(ToolBarItems.Update);
items.AddTool(ToolBarItems.Cancel);
});
})
.AllowPaging()
.AllowSorting()
.Columns(col =>
{
col.Field("DeviceID").HeaderText("ID").Width(30).IsPrimaryKey(true).AllowEditing(true).Add();
col.Field("DeviceTypeID").HeaderText("Type")
.ForeignKeyField("DeviceTypeID").ForeignKeyValue("DeviceType1")
@*.DataSource((IEnumerable<object>)ViewBag.dsDeviceTypes)*@ @* <--this works *@
.DataSource(ds =>
ds.URL("/api/devicetype/datasource")
.Adaptor(AdaptorType.UrlAdaptor))
.Width(150).Add();
}).Render();
2. DeviceController.cs
// GET: Device
public ActionResult Device([FromServices] IDeviceTypeService pService)
{
// preparing local data source
var ds = pService.Get(0, 12).ToList();
ViewBag.dsDeviceTypes = ds;
return View();
}
3. DeviceTypeApiController.cs
[HttpPost]
[EnableQuery]
[Route("datasource")]
public ActionResult DataSource([FromServices] IDeviceTypeService pService, [FromBody] DataManager dm)
{
var data = pService.Get(dm.Skip, dm.Take,
pInclude: dm.Select);
return Json(new { result = data, count = data.Count() });
}
Attachment:
Screenshots_ea6e709f.zip