Hi,
i have organization structure that needs to be display in hirachical gird. i do not know the depth. i have seem the example where three level hierarchi is define at code level. is there a way i can do this at runtime.
Hello cmm,
Thank you for posting in our forum.
Do you mean creating the grid model in the controller?
Generally you can create the grid model by creating a new GridModel instance and define the properties and setting you want for example:
GridModel grid = new GridModel();
grid.LoadOnDemand = true;
…
And then you pass that model to the view: @Html.Infragistics().Grid(Model)
To have load on demand in MVC you need to specify a method that returns the required data for each level.There’s more information on how you could do this here: http://help.infragistics.com/Help/Doc/jQuery/2012.2/CLR4.0/HTML/igHierarchicalGrid_Load_on_Demand.html
Specifically the section “Loading data on demand in MVC”.
Let me know if you have any questions or if I’ve misunderstood your question.
Best Regards,
Maya Kirova
Developer Support Engineer
Infragistics, Inc.
www.infragistics.com/support
Hi ,
i undestand this example. but this s for two level Hierarch. but i have n -level Hierarch. e.g.
Org1-->ORG3-->org4-->org5...so on.
ORg2-->org6-->org7
ORg9
in case when i do not know the bindingdepth from the begining how will i do it. cuase all them example requrires, defining column layout or all level upfront.
thank you
Hello cmm ,
I’m just following up to see if you’ve been able to resolve your issue. If you have any questions or concerns or if you need further assistance please let me know.
http://ko.infragistics.com/support
Is There any solution for my issue?
View:
@(Html.Infragistics().Grid(Model))
Controller:
using System.Web.Mvc;using System.Collections.Generic;using Infragistics.Web.Mvc;using Recon.Models;
namespace Recon.Controllers{ public class TestController : Controller { public ActionResult List() { GridModel grid = CreateGridModel(); return View(grid); }
private GridModel CreateGridLoadOnDemand() { GridModel grid = CreateGridModel(); grid.ID = "gridLoadOnDemand"; grid.LoadOnDemand = true; grid.DataSourceUrl = this.Url.Action("BindParent"); grid.ColumnLayouts[0].DataSourceUrl = this.Url.Action("BindChild"); grid.ColumnLayouts[0].ColumnLayouts[0].DataSourceUrl = this.Url.Action("BindInnerChild"); return grid; }
// Take grid creation outside as it will be used in all methods: private GridModel CreateGridModel() { GridModel grid = new GridModel(); // Set up properties and columns: grid.AutoGenerateColumns = false; grid.PrimaryKey = "CustomerID"; grid.Columns = new List<GridColumn>(); grid.Columns.Add(new GridColumn("Customer", "CustomerID", "string", "300px")); grid.Columns.Add(new GridColumn("Company Name", "CompanyName", "string", "150px")); grid.Columns.Add(new GridColumn("Country", "Country", "string", "150px")); grid.AutoGenerateLayouts = false;
// Create child layout GridColumnLayoutModel layout = new GridColumnLayoutModel(); layout.Key = "Orders"; layout.ForeignKey = "CustomerID"; layout.PrimaryKey = "OrderID"; layout.AutoGenerateColumns = false;
layout.Columns = new List<GridColumn>(); layout.Columns.Add(new GridColumn("Order ID", "OrderID", "number", "100px")); layout.Columns.Add(new GridColumn("Customer", "CustomerID", "string", "100px")); layout.Columns.Add(new GridColumn("Order Date", "OrderDate", "date", "150px")); layout.Columns.Add(new GridColumn("Shipped Date", "ShippedDate", "date", "150px")); // Create child layout GridColumnLayoutModel layout2 = new GridColumnLayoutModel(); layout2.Key = "Orders"; layout2.ForeignKey = "OrderID"; layout2.PrimaryKey = "SupplierID"; layout2.AutoGenerateColumns = false;
layout2.Columns = new List<GridColumn>(); layout2.Columns.Add(new GridColumn("Supplier ID", "SupplierID", "number", "100px")); layout2.Columns.Add(new GridColumn("Order ID", "OrderID", "number", "100px")); layout2.Columns.Add(new GridColumn("Supplier Name", "SupplierName", "string", "100px")); //add that layout to the grid layout.ColumnLayouts.Add(layout2); grid.ColumnLayouts.Add(layout);
// Add paging to child layouts (different from the parent's) GridPaging layoutPaging = new GridPaging(); layoutPaging.VisiblePageCount = 2; layoutPaging.PageSize = 5; //layoutPaging.Type = OpType.Remote; layout.Features.Add(layoutPaging);
//And lastly set ID so the client widget can be normally interacted with (see the events in the view) grid.ID = "hierarchicalGrid"; //most importantly turn Load On demand on and define response Urls: grid.LoadOnDemand = true; grid.DataSourceUrl = this.Url.Action("BindParent"); grid.ColumnLayouts[0].DataSourceUrl = this.Url.Action("BindChild"); grid.ColumnLayouts[0].ColumnLayouts[0].DataSourceUrl = this.Url.Action("BindInnerChild");
var dataContext = new NorthwindDataContext(); var dataSource = dataContext.Customers; var ds = dataSource.Take(30); grid.DataSource=ds;
//Add features: GridSorting sorting = new GridSorting(); sorting.Type = OpType.Remote; grid.Features.Add(sorting); GridPaging paging = new GridPaging(); paging.PageSize = 10; paging.Type = OpType.Remote; grid.Features.Add(paging);
// Return the finished model return grid; }
public JsonResult BindParent() { //create a model GridModel grid = CreateGridModel(); //set its data source var dataContext = new NorthwindDataContext(); var dataSource = dataContext.Customers; grid.DataSource = dataSource.Take(30); //and use the GetData() method to return the results return grid.GetData(); }
public JsonResult BindChild(string path, string layout) { //create a model GridModel grid = CreateGridModel(); //set its data source var dataContext = new NorthwindDataContext(); var dataSource = dataContext.Orders; grid.DataSource = dataSource; //and use the GetData() method to return the results return grid.GetData(path, layout); } public JsonResult BindInnerChild(string path, string layout) { //create a model GridModel grid = CreateGridModel(); //set its data source var dataContext = new NorthwindDataContext(); var dataSource = dataContext.Orders; grid.DataSource = dataSource; //and use the GetData() method to return the results return grid.GetData(path, layout); } }
}