1 Header Row per Grid Row?

2 posts, 0 answers
  1. Rob
    Rob avatar
    116 posts
    Member since:
    Aug 2012

    Posted 17 Jul 2015 Link to this post

    This is a very strange request from the user base.

     I have a 3 level hierarchical grid with 100's of rows of data at levels 2 and 3.  All grid rows are expanded by default.  At level 2, the users would like to see a header row for each row of data since they have to scroll down a lot due to the large amount of data.  This sounds weird, but the users can't collapse any of the grid rows, which would really make things look weird, but since the grid is completely expanded, it is easier on the eyes of the user to have 1 header row for each row of data at level 2, so the users tell me.

    Is there any chance a simple solution could be provided how to accomplish this feat?



  2. Konstantin Dikov
    Konstantin Dikov avatar
    2466 posts

    Posted 21 Jul 2015 Link to this post

    Hi Rob,

    Thank you for contacting us.

    I have to say that there is no built-in way for achieving the desired result and I am not sure if it is possible to achieve it with custom implementation as well, because the grid's structure is not designed to allow such layout.

    The only approach that I could think of will require to use DetailItemTemplate for the second hierarchy level and customize it in such manner, so it could simulate a header. However, the DetailItemTemplate will be displayed after the item and could not be displayed above it:
    <telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemDataBound="RadGrid1_ItemDataBound">
        <MasterTableView HierarchyDefaultExpanded="true">
                <telerik:GridTableView Name="Level2" HierarchyDefaultExpanded="true">
                        <telerik:GridTableView Name="Level3"></telerik:GridTableView>

    And the code-behind:
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        DataTable table = new DataTable();
        table.Columns.Add("ID", typeof(int));
        table.Columns.Add("FirstName", typeof(string));
        table.Columns.Add("LastName", typeof(string));
        table.Columns.Add("Age", typeof(int));
        table.Columns.Add("Image", typeof(DateTime));
        table.Columns.Add("BoolValue", typeof(Boolean));
        for (int i = 0; i < 5; i++)
            table.Rows.Add(i, "value" + i, "value" + i, 20 + i, DateTime.Now.AddDays(i), i % 2 == 0);
        (sender as RadGrid).DataSource = table;
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        if (e.Item is GridDataItem)
            GridDataItem item = e.Item as GridDataItem;
            if (item.OwnerTableView.Name == "Level2")
                item.DetailTemplateItemDataCell.ColumnSpan = 1;
                TableRow detailRow = item.DetailTemplateItemDataCell.Parent as TableRow;
                bool isFirst = true;
                foreach (GridColumn column in item.OwnerTableView.RenderColumns)
                    if (column.Visible && column.Display && column.OrderIndex >= 0)
                        if (!isFirst)
                            TableCell nextCell = new TableCell();
                        detailRow.Cells[detailRow.Cells.Count - 1].Text = column.HeaderText;
                        detailRow.Cells[detailRow.Cells.Count - 1].CssClass = "rgHeader";
                        isFirst = false;

    If any questions related to the built-in functionality of the control arise, please feel free to contact us again.

    Konstantin Dikov
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top