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

Show/Hide GridGroupHeaderItem client-side

4 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
bern
Top achievements
Rank 1
bern asked on 28 Jun 2009, 04:29 PM

In the code-behind in the grid_ItemDataBound event I have this code to hide a particular GridGroupHeaderItem.  Now I want to show it later in the client-side based on some condition.  I can't figure out how to do this please help.

 

if

 

(e.Item is GridGroupHeaderItem)

 

{

 

GridGroupHeaderItem groupHeaderItem = (GridGroupHeaderItem)e.Item;

 

 

DataRowView groupDataRow = (DataRowView)e.Item.DataItem;

 

 

if (String.IsNullOrEmpty(groupDataRow["TRCategoryLabel"].ToString()))

 

{

 

groupHeaderItem.Display =

false;

 

}

 

else

 

{

 

if (groupDataRow["TRCategoryLabel"].ToString() == "OnCall Time Worked")

 

groupHeaderItem.Display =

false;

 

 

else

 

groupHeaderItem.DataCell.Text =

"<b>" + groupDataRow["TRCategoryLabel"].ToString() + "</b>";

 

}

Thanks,
Bernard

4 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 01 Jul 2009, 02:03 PM
Hello Bern,

You can set a custom class to the group header, which will hide it. Then on the client you can find those items depending on the assigned custom class with jQuery and to remove it. Thus you will show the hidden group items.

Sincerely yours,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
bern
Top achievements
Rank 1
answered on 01 Jul 2009, 03:08 PM
Thanks but can you show me an example?  That would help very much.

-bn
0
Georgi Krustev
Telerik team
answered on 06 Jul 2009, 11:24 AM
Hello Bern,

To achieve your goal you need to wire the ItemCreated event and apply your custom css class in order to hide the group header depending on some condition. Here is a code snippet showing how to achieve this:

C#:
    protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridGroupHeaderItem)  
        { 
            e.Item.CssClass = "hideGroupHeader"
        } 
    } 

CSS class:
    <style type="text/css"
        .hideGroupHeader 
        { 
            displaynone
        } 
    </style> 


JavaScript:
            function ShowGroupHeader() { 
                var result = $telerik.$(".hideGroupHeader"); 
                for (var i = 0; i < result.length; i++)  
                { 
                    result[i].className = "rgGroupHeader"
                } 
            } 

As you maybe noticed I have used in the ShowGroupHeader item jQuery to find all group header rows which have the custom CSS class applied.

Below is a code excerpts which shows how to register jQuery:
<telerik:RadScriptManager runat="server" ID="RadScriptManager1" > 
    <Scripts> 
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" /> 
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" /> 
    </Scripts> 
</telerik:RadScriptManager> 

Regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
bern
Top achievements
Rank 1
answered on 09 Jul 2009, 10:47 PM
Thank you very much.  That makes sense now.  I will try that out right now.

Bernard
Tags
Grid
Asked by
bern
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
bern
Top achievements
Rank 1
Share this question
or