1) If there is no primaryKey column in the Grid. If you missed the IsPrimaryKey for the corresponding column, enable it.
2) If the server returns PrimaryKey column as null. So we suggest to ensure whether the Grid InsertURL method returns a proper object as shown in the below code example or not.
@(Html.EJ().Grid<EmployeeView>("HierarchyGrid") .Datasource(ds => ds.Json(ViewBag.datasource)) . . . . . . .ChildGrid(child => { child.Datasource(ds => ds.URL("/Home/DataSource").UpdateURL("/Home/Update").InsertURL("/Home/Insert").RemoveURL("/Home/Delete") .Adaptor(AdaptorType.UrlAdaptor)) .QueryString("EmployeeID")
. . . . . . . . )
public ActionResult Insert(EditableOrder value) { OrderRepository.Add(value); var data = OrderRepository.GetAllRecords(); return Json(value, JsonRequestBehavior.AllowGet); |
We have prepared a sample that can be downloaded from the following location.
Sample: http://www.syncfusion.com/downloads/support/forum/123604/ze/HierarchyURL27626282
If you are still facing any difficulty, please share the following information to analyze the issue and provide a solution as early as possible.
1) Code example of Grid and code behind
2) You have quoted that the you have got a sample from the forum. Please share the forum ID or sample.
3) If possible, modify the attached sample and replicate the issue
4) Whether you are using any public methods of Grid like updateRecord ?
Regards,
Seeni Sakthi Kumar S.
Can you show me an example of how to set that up, because I am not able to get it to work. When I set this up like my code snippet below, and I expand a row in the main grid, the child grid does not load any child-related records. The only way I was able to get the child grid to load records was to use a datasource like:
child.Datasource(ds => ds.URL(@Url.Action("ChildDataSource"))...
Are you saying this as an issue and quoted that refreshing action(calling URL again) only repopulates the Grid with the updated record? Or apart from this behavior, you are manually calling any of the Grid’s public methods to repopulate the Grid?
@(Html.EJ().Grid<EmployeeView>("HierarchyGrid") .Datasource(ds => ds.Json(ViewBag.datasource).Adaptor(AdaptorType.RemoteSaveAdaptor)) . . . . . .ChildGrid(child => { child.Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.childData) .InsertURL(@Url.Action("Insert")) .UpdateURL(@Url.Action("Update")) .RemoveURL(@Url.Action("Delete")) .Adaptor(AdaptorType.RemoteSaveAdaptor)) .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); }) .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); }); }) .QueryString("EmployeeID") . . . . . }) |
namespace MvcApplication66.Controllers { public class HomeController : Controller { public ActionResult Index(){ ViewBag.datasource = new NorthwindDataContext().EmployeeViews.ToList(); ViewBag.childData = OrderRepository.GetAllRecords(); return View(); } . . . . . . // We can use either void as return type // or not mandatory to return an updated record //public ActionResult Update(EditableOrder value) //{ // OrderRepository.Update(value); // var data = OrderRepository.GetAllRecords(); // return Json(new {success = success}, JsonRequestBehavior.AllowGet); //} public void Update(EditableOrder value) { OrderRepository.Update(value); var data = OrderRepository.GetAllRecords(); }
public void Insert(EditableOrder value) { OrderRepository.Add(value); var data = OrderRepository.GetAllRecords(); }
public void Delete(int key) { OrderRepository.Delete(key); var data = OrderRepository.GetAllRecords(); } } |
OK, as far as getting the grid to refresh with the newly added record, even when using the UrlAdaptor, I see that returning the value rather than then entire datasource, was part of the problem. (That, and making sure the new row has the proper primary key specified.)The other night, I could not find any examples for what is to be returned from each of the Urls (in Json format) for each of the editing functions. I have determined that they should each return the following:
- InsertURL - returns the inserted data object with the updated primary key value (return Json(value, JsonRequestBehavior.AllowGet))
- UpdateURL - returns the updated data object, just like the InsertURL does (please confirm that this is correct)
- RemoveURL - I am not sure what this is supposed to return???
So basically none of these return the Json structure that the datasource URL is supposed to return (with the result and count properties.)I also found out that after each of these URL returns, the grid does a refresh by calling the datasource URL, so that's how it gets the latest data.Could you please confirm my assumptions listed above and answer what the RemoveURL is supposed to return?Thank you,Cindy