Hi,
I have a need to display multiple ColumnLayouts using LoadOnDemand. Currently everything is working as expecting except the Children ColumnLayouts displayed a empty Grid.
GridModel gridModel = this.GetGridModel(ajaxUpdateTarget, 0); GridUIHelper.ApplyLayout(ref gridModel, vm); gridModel.DataSource = resultSet.Result.AsQueryable(); return gridModel.GetData();Thank you
Yes, I will start a new thread next time. The reason I appended to this thread because the feature I need is related to this solution pattern.
Anyway, based on the example I provided. I am looking for a way to get the Selected Row so I can get the data to Query the data for Children grids.
Currently, I have to do:
1. Get the Primary Key of the Parent Row
2. Query the Parent data based on the Primary Key
3. Query the Child data based on the Parent data
You can see there is a lot of step if I have another nested Grid in a Child grid. So I am looking for the way get the Selected Row of the expanding row.
This is another important feature that I need to complete the requirement.
Thank you very much
Hello Phong,
I am glad that you find my suggestion helpful.
I just want to let you know that in order to ensure all your issues are addressed correctly we handle single issue per forum thread. This helps our customers find what they are looking for easily. I can suggest you next time when you have a question which is not directly related to the initially discussed to start a new thread in our forum.
Regarding your additional question I will need some more information. Could you please be more specific for what you are trying to achieve when you click the expanding button? Any details are going to be highly appreciated and will help me find a way for achieving your requirement.
Looking forward to hearing from you.
Hello Vasya,
This is exactly what I need for my requirement. I have another question based on this same structure/Grid setup that I will need soon. How can I get the Row of Data (Selected Data Object) and post back to the server when user click on "+" icon?
This is perfect.
Thank you
Thank you for getting back to me.
In case that you have a field that you could use as a foreign key however you do not like to show in the grid you could hide it completely (even do not show it in the column chooser of Hiding feature) as following:
GridColumnLayoutModel layout = new GridColumnLayoutModel(); layout.AutoGenerateColumns = false; layout.Key = "Histories"; layout.ForeignKey = "ProductID"; layout.Columns.Add(new GridColumn() { HeaderText = "Something", Key = "Something", DataType = "string" }); layout.Columns.Add(new GridColumn() { HeaderText = "ProductID", Key = "ProductID", DataType = "number" }); layout.LoadOnDemand = false; layout.Features.Add(new GridHiding() { Inherit = true, ColumnSettings = new List<ColumnHidingSetting>() { new ColumnHidingSetting(){ColumnKey = "ProductID",AllowHiding= false, Hidden=true }} });
GridColumnLayoutModel layout = new GridColumnLayoutModel();
layout.AutoGenerateColumns = false;
layout.Key = "Histories";
layout.ForeignKey = "ProductID";
layout.Columns.Add(new GridColumn() { HeaderText = "Something", Key = "Something", DataType = "string" });
layout.Columns.Add(new GridColumn() { HeaderText = "ProductID", Key = "ProductID", DataType = "number" });
layout.LoadOnDemand = false;
layout.Features.Add(new GridHiding() { Inherit = true, ColumnSettings = new List<ColumnHidingSetting>() {
new ColumnHidingSetting(){ColumnKey = "ProductID",AllowHiding= false, Hidden=true }}
});
If there is no column in your underlying data source that you could use as foreign key you could use a custom implementation of load on demand. Infragistics GetData method used to retrieve the data for child layout requires this foreign key. This means that for if you choose to use a custom approach this method could not be used. Alternative approach could be to use WrappedGridResponse to send the data for your child layouts. WrappedGridResponse is a class that wraps the response in a particular way suitable for the igHierarchicalGrid. It takes data and grid model as parameters. For example in your GetChildren method you could do the following:
public JsonResult GetChildren(string ajaxUpdateTarget, string path, string layout) { if (ajaxUpdateTarget == "History") { var histories = new List<ProductHistory>(); histories.Add(new ProductHistory() { ProductID = 0, Something = "What" }); GridModel gridModel = this.GetGridModel(ajaxUpdateTarget, 0); //gridModel.DataSource = histories.AsQueryable(); WrappedGridResponse response; response = new WrappedGridResponse(histories, null); return Json(response, JsonRequestBehavior.AllowGet); // return gridModel.GetData(path, layout); } . .
public JsonResult GetChildren(string ajaxUpdateTarget, string path, string layout)
{
if (ajaxUpdateTarget == "History")
var histories = new List<ProductHistory>();
histories.Add(new ProductHistory() { ProductID = 0, Something = "What" });
GridModel gridModel = this.GetGridModel(ajaxUpdateTarget, 0);
//gridModel.DataSource = histories.AsQueryable();
WrappedGridResponse response;
response = new WrappedGridResponse(histories, null);
return Json(response, JsonRequestBehavior.AllowGet);
// return gridModel.GetData(path, layout);
}
.
Please keep in mind that you will have to check the parent which is calling the method and you will have to filter the data by yourself in order to map corresponding data to its parent for each level. Additionally, GetData uses its internal techniques to handle all grid features enabled. Since every other approach is considered a custom implementation you will have to take care of how all the features are implemented manually.
I modified the provided sample with an illustration of my suggestion and I am attaching it for your reference. Please note that the data added for all child levels is the same because it has no foreign key defined and you will have your own relation to the parent and child to represent the correct data for each level.
I modified your sample
I hope you find my information helpful.
Please let me know if you need any further assistance with this matter.