I'm trying to make a Hierarchical Grid using my iggrid. My Model is a bit complex, how can I configure my grid to display this model in an hierarchical fashion? Here is my model;
public class RoleRightsModel { public string Module { get; set; } public List<ScreenType> ScreenType { get; set; } }
public class ScreenType { public string ScreenTypeName { get; set; } public List<Screen> Screen{ get; set; } }
public class Screen { public string ScreenName { get; set; } public List<Permission> Permission { get; set; } }
public class Permission { public bool CanAdd { get; set; } public bool CanEdit { get; set; } public bool CanDelete { get; set; } public bool CanPrint { get; set; } }
Basically I want the name of the nodes to be listed once(distinct) in a tree view like structure
For example:
[Module Grid]
(1) -Security Manger [ScreenType Grid]
(1a)-Report [Screen Grid]
(1aa)-Dashboard [Permission Grid]
-CanAdd - CanEdit -CanDelete -CanPrint (checkbox columns)
(1ab)-Screen2 [Permission Grid]
(1b)-Data entry [Screen Grid]
(1ba)-Screen3 [Permission Grid]
(1bb)-Screen4 [Permission Grid]
2 -System Admin [ScreenType Grid]
...
....
Hello,
Thank you for contacting Infragistics!
I have done some looking into this matter and have the following information. This behavior can be achieved by using the igHierarchicalGrid. You will have an igHierarchicalGrid for each main grid you want. Then on the child level you will create a columnLayout for each child grid you want to display. For example the following code would create to child grids. One for each column layout:
.ColumnLayouts(layout => { layout.For(x => x.Products) .ForeignKey("CategoryID") .PrimaryKey("ProductID") .AutoGenerateColumns(false) .DataSourceUrl(Url.Action("BindProduct") .Columns(column => { column.For(x => x.ProductID).HeaderText("ID"); column.For(x => x.ProductName).HeaderText("Name"); column.For(x => x.CategoryID).HeaderText("Category") ; column.For(x => x.UnitPrice).HeaderText("Unit Price"); }); layout.For(x => x.Products2) .ForeignKey("CategoryID") .PrimaryKey("ProductID") .AutoGenerateColumns(false) .DataSourceUrl(Url.Action("BindProduct")) .Columns(column => { column.For(x => x.ProductID).HeaderText("ID"); column.For(x => x.ProductName).HeaderText("Name"); column.For(x => x.CategoryID).HeaderText("Category"); column.For(x => x.UnitPrice).HeaderText("Unit Price"); }); })
.ColumnLayouts(layout =>
{ layout.For(x => x.Products)
.ForeignKey("CategoryID")
.PrimaryKey("ProductID")
.AutoGenerateColumns(false)
.DataSourceUrl(Url.Action("BindProduct")
.Columns(column =>
{
column.For(x => x.ProductID).HeaderText("ID");
column.For(x => x.ProductName).HeaderText("Name");
column.For(x => x.CategoryID).HeaderText("Category")
; column.For(x => x.UnitPrice).HeaderText("Unit Price");
});
layout.For(x => x.Products2)
.DataSourceUrl(Url.Action("BindProduct"))
column.For(x => x.CategoryID).HeaderText("Category");
column.For(x => x.UnitPrice).HeaderText("Unit Price");
})
Please let me know if you have any further questions concerning this matter.
Appreciate your response, but I think I might not have been able to completely clarify what the problem is. As you know at the time of initializing the grid we specify the model type of the grid, so I set the model type as RoleRightsModel and set the grid as follows (Refer the model above in the question);@(Html.Infragistics().Grid<RoleRightsModel>() .ID("RoleRightsGrid") .PrimaryKey("Module") .AutoGenerateColumns(false) .AutoGenerateLayouts(false) .RenderCheckboxes(true) .Height("500px") .Width("700px") .Columns(column => { column.For(x => x.Module).HeaderText("Module").DataType ("string"); }) .ColumnLayouts(layouts => { layouts.For(x => x.ScreenType). AutoGenerateColumns(false). Columns(childcolumn => { childcolumn.For(x => x.ScreenTypeName).HeaderText ("Screen Type").DataType("string"); }); }) //Till the end of the gridThis gives me something like; Module+Module1+Module2On expanding any module i get; Module-Module1 ScreeType Reports+Module2 I want to go furthur down Reports and display all the screens asscoicated with it, in turn showing all the permissions given on that screen. Module-Module1 ScreeType -Reports -UserReport Add Edit Delete +FinancialReport +DI +RF +Module2The problem is that I cannot access the Screen and the Permission models in my grid, so that means I cant do something like;.Columns(column => { column.For(x => x.Module).HeaderText("Module").DataType ("string"); }) .ColumnLayouts(layouts => { layouts.For(x => x.ScreenType). AutoGenerateColumns(false). Columns(childcolumn => { childcolumn.For(x => x.ScreenTypeName).HeaderText ("Screen Type").DataType("string"); }); layouts.For(x => x.Screen). AutoGenerateColumns(false). Columns(childcolumn => { childcolumn.For(x => x.ScreenName).HeaderText ("Screen Name").DataType("string"); }); layouts.For(x => x.Permission). AutoGenerateColumns(false). Columns(childcolumn => { childcolumn.For(x => x.CanAdd).HeaderText ("Screen Type").DataType("string"); }); }) The data that gets passed to the view is something like this;[{"Module":"Security Manager","ScreenType":[{"ScreenTypeName":"RF","Screen":[{"ScreenName":"Dashboard","Permission":[{"CanAdd":true,"CanEdit":true,"CanDelete":false,"CanPrint":false}]},{"ScreenName":"Home","Permission":[{"CanAdd":false,"CanEdit":false,"CanDelete":true,"CanPrint":false}]}]}]},{"Module":"Sys Admin","ScreenType":[{"ScreenTypeName":"RF","Screen":[{"ScreenName":"Sys Admin Screen1","Permission":[{"CanAdd":false,"CanEdit":false,"CanDelete":true,"CanPrint":false}]},{"ScreenName":"Sys Admin Screen2","Permission":[{"CanAdd":false,"CanEdit":false,"CanDelete":true,"CanPrint":false}]}]}]}]I would appreciate any help in this regards