Hi,
I am trying to add a multi column header in my application dynamically based on the data. I am facing an issue where once i add the multi column headers using group options the Header is not visible in the grid.
GridModel ConsolidatedMargin = new GridModel();var lstDistinctHeader = lstConsolidated.Select(x => x.txtHeader).Distinct().AsEnumerable();
foreach (var item in lstDistinctHeader) { int count = 0; GridColumn grpCol = new GridColumn(); grpCol.HeaderText = item; var lstconsolidatedFiltered = lstConsolidated.Where(a => a.txtHeader == item).ToList(); foreach (var item1 in lstconsolidatedFiltered) { string headerName = GetUntilOrEmpty(item1.txtHeader); if (headerName == string.Empty) { headerName = AppConstants.Total + AppConstants.DASH + counter; } else { headerName = AppConstants.Pricing + AppConstants.DASH + counter + AppConstants.DASH + headerName; } counter++;
if (count == 0) { col = new GridColumn() { HeaderText = item, Key = headerName, Hidden = false }; col.GroupOptions.Hidden = CollapsibleGroupHidden.ParentExpanded; grpCol.Group.Add(col); } count++; col = new GridColumn() { HeaderText = item, Key = headerName, Hidden = false }; col.GroupOptions.Hidden = CollapsibleGroupHidden.ParentCollapsed; grpCol.Group.Add(col); } grpCol.GroupOptions.AllowGroupCollapsing = true; grpCol.GroupOptions.Expanded = false; SampleGrid.Columns.Add(grpCol); } SampleGrid.PrimaryKey = "AssignedFor"; SampleGrid.AutoCommit = true; SampleGrid.DataSource = dynamicLstForConsolidated.OrderBy(a => a.OrderBy).AsQueryable(); SampleGrid.AutoGenerateColumns = false; SampleGrid.DefaultColumnWidth = "240px"; SampleGrid.Width = "100%";
Hello Udayakumar,
Thank you for posting in our forum.
Please make sure that the Multi-ColumnHeaders feature is added to the Grid Model features list, for example:
GridMultiColumnHeaders f = new GridMultiColumnHeaders();
SampleGrid.Features.Add(f);
If the feature is not added then the multi-column headers will not render.
I have attached a small sample for your reference with a similar setup to the code you have shared.
Please refer to it and let me know if you’re aiming to achieve something similar.
4722.MCH_Grid.zip
Regards,
Maya Kirova