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

How to hide the column group

4 Answers 296 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gabriel Boulianne
Top achievements
Rank 1
Gabriel Boulianne asked on 02 Jun 2010, 07:53 PM
Hello,

I want hide the column corresponding to the group.

For exemple, I have 3 column :

1    2    3
-------------
x    a    f
y    b    e
x    c    d

And i group by the first column :

1
    1    2    3
    -------------
x
    x    a    f
    x    c    d
y
    y    b    e

The first column is still visible, but not necessary,

is-it possible to hide this colomn, or i have to implements this feature ?

4 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 03 Jun 2010, 09:18 AM
Hello,

I tried following for a similar scenario, for hiding the column when it is grouped and again showing it when ungrouping.

CS:
 
    protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        if (RadGrid1.MasterTableView.GroupByExpressions.Count > 0) 
        { 
            RadGrid1.MasterTableView.GetColumnSafe(RadGrid1.MasterTableView.GroupByExpressions[0].GroupByFields[0].FieldName).Display = false
        } 
        else 
        { 
            foreach(GridColumn col in RadGrid1.MasterTableView.RenderColumns ) 
            { 
                col.Display = true
            } 
        } 
    } 
Feel free to modify the code based on your requirement.

I hope this would help you also.
Shinu.
0
Gabriel Boulianne
Top achievements
Rank 1
answered on 03 Jun 2010, 02:11 PM
Thanks Shinu,

The grouping is executed on client side, how to force a postback on grouping ?

Thanks,

Gabriel Boulianne
0
Gabriel Boulianne
Top achievements
Rank 1
answered on 03 Jun 2010, 03:08 PM
What i say ? Sorry, i need coffee... The event is raised on server it's ok !

I just have a small error in generated jscript code :

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: La référence d'objet n'est pas définie à une instance d'un objet.

Thanks for your help !

Gabriel Boulianne
0
Gabriel Boulianne
Top achievements
Rank 1
answered on 03 Jun 2010, 03:32 PM
Ok thanks Shinu, i have modified your method :

protected void radGrid_PreRender(object sender, EventArgs e)  
        {  
            foreach (TelerikUI.GridBoundColumn col in radGrid.Columns)  
            {  
                col.Display = true;  
            }  
 
            foreach (TelerikUI.GridGroupByExpression groupByExp in radGrid.MasterTableView.GroupByExpressions)  
            {  
                string fieldName = groupByExp.GroupByFields[0].FieldName;  
 
                foreach (TelerikUI.GridBoundColumn column in radGrid.Columns)  
                {  
                    if (column.DataField == fieldName)  
                    {  
                        column.Display = false;  
                        break;  
                    }  
                }  
            }  
        } 

That's work correctly !
Tags
Grid
Asked by
Gabriel Boulianne
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Gabriel Boulianne
Top achievements
Rank 1
Share this question
or