Colspan Override For GridGroupHeaderItem

4 posts, 1 answers
  1. Jason Divis
    Jason Divis avatar
    8 posts
    Member since:
    Feb 2010

    Posted 08 Mar 2010 Link to this post

    Trying to follow ManniAT's Colspan override... thread, but instead of changing the colspan on a nested view item, I am trying to change the colspan on a gridgroupheader item. In my case, I just want to get rid of the colspan altogether. I've tried a number of variations, including accessing the colspan attribute from the itemCreated as well as the prerender events, and changing the colspan value to "0" as well as trying grh.DataCell.Attributes.Remove("colspan").

    Protected Sub RadGrid3_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGrid3.ItemCreated
            If TypeOf e.Item Is GridGroupHeaderItem Then
                CType(e.Item, GridGroupHeaderItem).DataCell.Attributes("colspan") = 0
            End If
        End Sub

    Protected Sub RadGrid3_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles RadGrid3.PreRender
            For Each grh As GridGroupHeaderItem In CType(sender, RadGrid).MasterTableView.GetItems(GridItemType.GroupHeader)
                grh.DataCell.Attributes.Remove("colspan")
            Next
        End Sub

    Neither of these seem to work. When I try to change the colspans value to 0, I end up with duplicate colspan attributes for the TD (<td colspan="0" colspan="3"><p>R.V.'S</p></td>), and when I try to remove it, I still see the original colspan="3" attribute. (<td colspan="3"><p>R.V.'S</p></td>

    An
    y help will be appreciated.

    Thank you,

    -J.
  2. Answer
    Veli
    Admin
    Veli avatar
    2002 posts

    Posted 10 Mar 2010 Link to this post

    Hello Jason,

    The column span of the group header's data cell is set very late (on Render) and is basically unmodifiable. What you can do is entirely hide the data cell and show another cell in its place, copying whatever text the data cell contains. You can do this on PreRender:

    C#
    protected void Page_PreRender(object sender, EventArgs e)
    {
        GridItem[] groupHeaders = RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader);
        foreach (GridItem item in groupHeaders)
        {
            GridGroupHeaderItem header = (GridGroupHeaderItem)item;
            header.DataCell.Visible = false;
            GridTableCell cell = new GridTableCell();
            header.Cells.Add(cell);
            cell.Text = header.DataCell.Text;
        }
    }

    VB.NET
    Protected Sub Page_PreRender(sender As Object, e As EventArgs)
        Dim groupHeaders As GridItem() = RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader)
        For Each item As GridItem In groupHeaders
            Dim header As GridGroupHeaderItem = DirectCast(item, GridGroupHeaderItem)
            header.DataCell.Visible = False
            Dim cell As New GridTableCell()
            header.Cells.Add(cell)
            cell.Text = header.DataCell.Text
        Next
    End Sub


    Kind regards,
    Veli
    the Telerik team

    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 Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jason Divis
    Jason Divis avatar
    8 posts
    Member since:
    Feb 2010

    Posted 12 Mar 2010 Link to this post

    That is a very good workaround that you have provided Veli.

    I am pleased that when the Telerik components can't do something someone wants them to do, it seems like the Telerik folks find a way to do it. Many posts I have come across have solutions provided by Telerik Admins.

    Thank you!
  5. Neha
    Neha avatar
    1 posts
    Member since:
    Jun 2016

    Posted 10 Jun Link to this post

    Thank you Veli. This post was helpful in resolving Bug in the application.

    I have added the code in the PreRender method and it fixed my issue.

    GridItem[] groupHeaders = radGridClientList.MasterTableView.GetItems(GridItemType.GroupHeader);
    foreach (GridItem item in groupHeaders)
    {
    GridGroupHeaderItem header = (GridGroupHeaderItem)item;
    header.Visible = false;
    }

Back to Top