I am struggling to hide some columns in the child rows of a hierarchical grid bound to a dataset with two tables, with a parent:child relationship.
I am looking at the hierarchical grid data set binding sample that came with NetAdvantage and I am trying to hide the CategoryID column in the child rows since it is merely repeating the same value in the parent row.
Here is the grid definition from the MVC View (dataset-binding.cshtml), with my additions in bold.:
@(Html.Infragistics().Grid<Category>() .ID("grid1") .Height("500px") .AutoGenerateColumns(true) .AutoGenerateLayouts(true) .RenderCheckboxes(true) .EnableUTCDates(true) .Features(features => { features.Sorting().Type(OpType.Local).Mode(SortingMode.Single).Inherit(true); features.Paging().PageSize(5).Type(OpType.Remote).Inherit(false); features.Filtering().Type(OpType.Local).Inherit(true); features.Selection().Mode(SelectionMode.Row).MultipleSelection(true); features.RowSelectors().Inherit(true); features.GroupBy().Type(OpType.Local).Inherit(true); features.Hiding().Inherit(true); features.Resizing().Inherit(true); features.Tooltips().Visibility(TooltipsVisibility.Always).Inherit(true); features.ColumnMoving().Inherit(true).Mode(MovingMode.Immediate).MoveType(MovingType.Dom); features.CellMerging().InitialState(CellMergingInitialState.Merged); }) .ColumnLayouts(layouts => { layouts.For(x => x.Products) .PrimaryKey("CategoryID") .ForeignKey("ProductID").Columns(column => { column.For(x => x.CategoryID).DataType("numeric").Hidden(true); column.For(x => x.ID).DataType("numeric"); column.For(x => x.ProductName).DataType("string"); column.For(x => x.UnitPrice).DataType("numeric"); column.For(x => x.UnitsInStock).DataType("numeric"); column.For(x => x.Discontinued).DataType("bool"); }) ; }) .DataSource(Model) .DataSourceUrl(Url.Action("dataset-binding")) .DataBind() .Render() )
When I run the sample up I get a KeyNotFoundException with the message "The given key was not present in the dictionary".
Stack trace:
at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at Infragistics.Web.Mvc.GridModel.RenderHierarchicalQueryableRecursive(IQueryable queryable, WrappedGridResponse response, GridModel baseLayout) at Infragistics.Web.Mvc.GridModel.RenderHierarchicalQueryableRecursive(IQueryable queryable, WrappedGridResponse response, GridModel baseLayout) at Infragistics.Web.Mvc.GridModel.RenderHierarchicalQueryable(IQueryable queryable) at Infragistics.Web.Mvc.GridModel.DataBind() at Infragistics.Web.Mvc.Grid`1.DataBind() at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at ASP._Page_Views_hierarchicalgrid_dataset_binding_cshtml.Execute() in c:\Users\Public\Documents\Infragistics\IgniteUI 2013.1\Samples\IgniteUI.SamplesBrowser\Views\HierarchicalGrid\dataset-binding.cshtml:line 26 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.Mvc.WebViewPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1a.b__17() at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
I have tried all sorts of variations but my gut feeling is that it boils down to this bit: layouts.For(x => x.Products).
I don't know what the right name is for the child collection. There is not much else I can choose for the value, but all the column names are correct so I suspect that this needs to be something else.
Regards,
Graeme
Forgot to mention that this is using NetAdvantage v13.1
Hello Graeme,
Please refer to the following link for this:
http://help.infragistics.com/Doc/jquery/2013.1/CLR4.0/?page=igGrid_Configure_Column_Hiding.html.
The code should be something like this, you can alter it if needed for your own needs:\
features.Hiding().ColumnSettings(settings => settings.ColumnSetting()
.ColumnKey("ID")
.AllowHiding(true)
.Hidden(true));
Please note that you need to specify the column by its key, make sure that it is the right one.
Please feel free to let me know if a question about our tool set comes up on your mind.