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
Hello Phong,
Thank you for posting in our community.
In order to address the root cause of your issue and provide you with better and more accurate support I will need an isolated working sample where the issue is reproducible. This will help me debug on my side and investigate further and find what is causing this behavior.
Additionally, a sample project illustrating Load on Demand functionality in igHierarchicalGrid could be found at the following link:
http://igniteui.com/hierarchical-grid/load-on-demand
Please have a look at this sample and if you still have any questions or concerns afterwards please fell free to get back to me with your isolated sample.
Looking forward to hearing from you.
Hello Vasya,
Thank you for getting back to me.
Yes, I did follow the Load On Demand Example.Here is what I am trying to do. Our database has over Million records. We want to take the advantage of SQL Server paging and Load On Demand, so we get the Total Count, then the first 10 records to display. Everything is working so far. However, I have a requirement to display data in Hierarchy, a Parent record would have two or more GridColumnLayoutModels.I attached the code sample. Please help
Thank you for providing me your sample.
I spent some time investigating and debugging your project further. What I noticed is that there is no Keys set for the child layout and I set them. This is important because when using GetData method for child layouts path and layout parameters should be defined in order to match the correct layout. If there is no key set for the layout it is being returned as "undefined".
GridColumnLayoutModel layout = new GridColumnLayoutModel(); layout.AutoGenerateColumns = false; layout.Key = "Histories";
GridColumnLayoutModel layout = new GridColumnLayoutModel();
layout.AutoGenerateColumns = false;
layout.Key = "Histories";
Additionally, there is no ForeignKey set for the child layout. Having ForeignKey set is essential for mapping the data for parent and child level. This is necessary in order to set the correct data for corresponding child level. I added a property in your model, in the ProductHistory class, named ProductID. This property is used to make the connection with the parent level. Since I believe this is just a sample data and in your actual data soure you have a field that could act as a foreign this is what I can recommend to ensure that the child levels are correctly loaded. For example:
public class ProductHistory { public int ProductID { get; set; } public string Something { get; set; } } . . . 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.DataSourceUrl = string.Format("/Home/GetChildren?ajaxUpdateTarget={0}", "History"); layout.Width = "100%"; gridModel.ColumnLayouts.Add(layout);
public class ProductHistory
{
public int ProductID { get; set; }
public string Something { get; set; }
}
.
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.DataSourceUrl = string.Format("/Home/GetChildren?ajaxUpdateTarget={0}", "History");
layout.Width = "100%";
gridModel.ColumnLayouts.Add(layout);
I am attaching my modified sample for your reference.
Please have a look at the provided sample and let me know if you need any further assistance with this matter.
The example that you provided is working great. However, We don't have to show the Foreign Key (ProductID) to the end user. So I attempted to remove the ProductID from the grid, then it stop working.
Can you please look into it? I am evaluating the Infragistics Product, and it's critical for me to get this working.
Thank you
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 }} });
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.