Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
435
Hierarchy Grid with Multiple Layouts using LoadOnDemand feature
posted

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
Parents Reply
  • 17590
    Verified Answer
    Offline posted in reply to Phong Nguyen

    Hello Phong,

    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 }}

    });

    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);

    }

    .

    .

    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.

    igHierarchicalgridCustomLoadOnDemand.zip
Children