This is a migrated thread and some comments may be shown as answers.

Colspan Override For GridGroupHeaderItem

3 Answers 174 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jason Divis
Top achievements
Rank 1
Jason Divis asked on 08 Mar 2010, 03:27 PM
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.

3 Answers, 1 is accepted

Sort by
0
Accepted
Veli
Telerik team
answered on 10 Mar 2010, 03:40 PM
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.
0
Jason Divis
Top achievements
Rank 1
answered on 12 Mar 2010, 03:36 PM
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!
0
Neha
Top achievements
Rank 1
answered on 10 Jun 2016, 11:18 AM

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;
}

Tags
Grid
Asked by
Jason Divis
Top achievements
Rank 1
Answers by
Veli
Telerik team
Jason Divis
Top achievements
Rank 1
Neha
Top achievements
Rank 1
Share this question
or