Hi,
I am trying to use a hierarchical grid using MVC 5. I am suppose to have three levels of data in the grid - parent , child and grand child.
I am able to bind the parent but not the child using Load on demand from the controller.
--Modelpublic class ParentViewModel{ public int PId {get; set;} public string Name {get; set;} public ICollection ChildDetails}
Public class ChildViewModel{ public int CId {get; set;} public int PId {get; set;} public int CData {get; set;}}
--View@model Infragistics.Web.Mvc.GridModel
(Html.Infragistics().Grid(Model))
--Controller
private GridModel GetGridModel(){
GridModel model = new GridModel(); model.AutoGenerateColumns = false; model.AutoCommit = true; model.PrimaryKey = "PId"; model.AutoGenerateLayouts = false; model.ID = "igGrid";
model.LoadOnDemand = true;
model.Columns.Add(new GridColumn { Key = "PId", Hidden = true, DataType = "number" }); model.Columns.Add(new GridColumn { Key = "Name", HeaderText = "Parent Name ", DataType = "string" }); model.DataSourceUrl = (Url.Action("BindParentDetails"));
GridColumnLayoutModel childModel = new GridColumnLayoutModel(); childModel.Key = "ChildDetails"; childModel.PrimaryKey = "PID"; childModel.ForeignKey = "CId"; childModel.AutoGenerateColumns = false; childModel.Columns.Add(new GridColumn { Key = "CId", HeaderText = "Child ID", DataType = "number" }); childModel.Columns.Add(new GridColumn { Key = "CData", HeaderText = "Child Data", DataType = "number" }); childModel.DataSourceUrl = Url.Action("BindChildDetails");
model.ColumnLayouts.Add(childModel); return model;}
public JsonResult BindParentDetails() { GridModel rModel = GetGridModel();
var p = _service.GetPDetails();
rModel.DataSource = p.AsQueryable(); var res = rModel.GetData(); return res; }
public JsonResult BindChildDetails(string path, string layout) { var pid = path.Substring(path.LastIndexOf(':') + 1);
GridModel grd = GetGridModel();
var p = _service.GetChildDetails(pId); grd.DataSource = p.AsQueryable(); var res = grd.GetData(path, layout); return res; }
When I run the solution it binds the parent grid correctly. On clicking the + icon it goes into BindChildDetails function and breaks on:
var res = grd.GetData(path, layout);
An exception of type 'System.NullReferenceException' occurred in Infragistics.Web.Mvc.dll but was not handled in user code
Additional information: Object reference not set to an instance of an object.
It has correct values in path and layout
grd.DataSource is set correctly with the data from the DB.
The version of Infragistics.Web.Mvc we are using is 5.16.2.2040
Can anyone please help me with this?
Hello Singh,
Thank you for the update. Are you calling the saveChanges method in the saveChanges button’s click event?
Otherwise to save the changes in the grid you should call saveChanges:
https://www.igniteui.com/help/api/2016.2/ui.iggrid#methods:saveChanges
Hi Mike,
The above links were very helpful.
I am able to show the drop downs and textboxes in the child grid but I am now stuck on Saving the data.
I have set the child grid's update URL but still it is not getting called:
Save button on the view :
<input type="submit" id="saveChanges" class="btn btn-block btn-grey" value="Save" />
(Tried with type="button" as well)
In controller
updating.ColumnSettings.Add(new ColumnUpdatingSetting
{
ColumnKey = "StatusValue",
EditorType = ColumnEditorType.Combo,
ComboEditorOptions = new ComboModel { TextKey = "Text", ValueKey = "Value", DataSource = ViewData["Status"], AutoComplete = true }
});
childModel.Features.Add((updating));
childModel.UpdateUrl = (Url.Action("UpdateChildren"));
public ActionResult UpdateChildren()
return View();
}
If I click on the save button it doesn't go into the UpdateChildren
Can you please help me with this?
Regards
S
Thank you for the update. setting up a dropdown and a texbox editor is the same whether you are using load on demand or not. You setup the editorProvider/editorOptions through the Updating feature’s column settings:
editorOptions:https://www.igniteui.com/help/api/2016.2/ui.iggridupdating#options:columnSettings.editorOptions
https://www.igniteui.com/help/infragistics.web.mvc~infragistics.web.mvc.columnupdatingsetting~editoroptions
editorProvider:https://www.igniteui.com/help/api/2016.2/ui.iggridupdating#options:columnSettings.editorProvider
https://www.igniteui.com/help/infragistics.web.mvc~infragistics.web.mvc.columnupdatingsetting~editorprovider
https://www.igniteui.com/grid/basic-editing
https://www.igniteui.com/help/working-with-combo-editor-provider
Specifically for the igCombo (dropdown) you would set the dataSourceUrl for retrieving data for the combo:
https://www.igniteui.com/help/api/2016.2/ui.igcombo#options:dataSourceUrl
I also want to add a dropdown and a textbox in the child row in the same grid.
I am able to find some links that show dropdowns in the hierarchical grid without load on demand but not with it.
Can you please suggest me some links where I can find a working example for the same i.e MVC Load on demand hierarchical grid with dropdowns and textbox in the child row.
Drop down values will be coming from the DB.
I would also need to set the default value of the drop down from the DB and save the value chosen in the DB so I want to access the controls in the controller.
It would be great if you can help me with this
Thank you very much for your help.
It works perfectly now.