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

Setting individual column header styles in GridGroupHeaderItem

2 Answers 154 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ed
Top achievements
Rank 1
Ed asked on 17 Apr 2009, 01:38 PM
Hi,

I think I am close to finding an answer on this - but it is so far elluding me.  I have an app that supports drag to group.  In my app, I can canfigure it to have custom CssClass for a column header as well as for individual row and alt row cells, but I only know at runtime (not at compile time) what the column names will be.  It is all fine for displaying without grouping - my column headers and column rows and alt rows get the right classes on them (both can get set in PreRender, except if I want a special class on a row or alt row cell based on the cell content value in which case I do it in ItemDataBound.)

However, when Grouping, I find that I seem also to have a need to separately set the CssClass for the column in the GridGroupheaderItem.  In order to know what CssClass i want to set, i need to be able to find the right column cell in the GridGroupColumnItem based on column name.  But it is not apparent to me how I can get at the column names for that in ItemDataBound (which seems to me to be the right event to do it in - since I do get that event called for these.) 

Any ideas on how to identify the right cell by column name for the GridGroupheaderItem in the ItemDataBound event?

Thanks,

Ed Hinton

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Apr 2009, 10:56 AM
Hello Ed,

I suppose you would want to set  a css class for the grouped column and set it back to the initial styles when ungrouped. If that is the case you can access the column UniqueName and then set its css class i the prerender event where in you can pass the unique names using globally accessible variables. To understand better try out the following code:
c#:
    string groupstrtxt;  
    string ungroupstrtxt;  
    protected void RadGrid1_GroupsChanging(object source, GridGroupsChangingEventArgs e)  
    {  
        if ((e.Action == GridGroupsChangingAction.Group))  
        {  
            groupstrtxt = e.Expression.GroupByFields[0].FieldName;  
        }  
        else if ((e.Action == GridGroupsChangingAction.Ungroup))  
        {  
            ungroupstrtxt = e.Expression.GroupByFields[0].FieldName;  
        }   
         
    }  
 
 
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
 
        foreach (GridDataItem item in RadGrid1.Items) 
        { 
            if (groupstrtxt != null
            { 
                item[groupstrtxt].CssClass = "GroupedColumn"
            } 
            if (ungroupstrtxt != null
            { 
                item[ungroupstrtxt].CssClass = "UnGroupedColumn"
            } 
        } 
    } 

css:
<style type="text/css">   
    .GroupedColumn 
    { 
      color:Purple !important; 
      background-color:Pink !important; 
    } 
    .UnGroupedColumn 
    { 
      color:Empty !important; 
      background-color:Empty !important; 
    }  
</style> 

Thanks
Princy.
0
Ed
Top achievements
Rank 1
answered on 20 Apr 2009, 01:04 PM
This does give me some ideas to try, but it also raises some questions:
1) Does this mean I can only set CssClass for the group header item rows on columns that are in the GroupBy expression?  In my case, I can configure my app to specify a CssClass for a column (header, Row, and AltRow) by column name, but I didn;t explicitly make all columns part of the GroupBy.

2) I seem to have gotten by the issue with some other changes, but I am not clear how they are interacting.  Basically, if I set TableLayout to Auto and Scrolling.UseStaticHeader to False, (or set to Fixed and set static headers to True) it seems to be ok.  When I had Table Layout set to Auto and static headers set to True I was having the problem but only when Grouping - not otherwise..

-Ed
Tags
Grid
Asked by
Ed
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ed
Top achievements
Rank 1
Share this question
or