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

Radgrid grouping

6 Answers 369 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ali Akbar
Top achievements
Rank 1
Ali Akbar asked on 04 Aug 2009, 11:18 AM
 Below is the code which is grouping the data based on name field, i also want one more level above the name field ex: category how do i do it?


Thanks a million in advance.









 <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceI="SqlDataSource1" 
   GridLines="None" 
   AllowPaging="false" PageSize="25" 
   Skin="Outlook" DataSourceID="SqlDataSource1">  
 
 
 <MasterTableView DataSourceID="SqlDataSource1">  
   <GroupByExpressions> 
         <telerik:GridGroupByExpression  > 
         <SelectFields> 
          <telerik:GridGroupByField  
            FieldName="name" HeaderText=""/>  
         </SelectFields> 
           <GroupByFields> 
              <telerik:GridGroupByField  
                 FieldName="name" /> 
               </GroupByFields> 
         </telerik:GridGroupByExpression> 
   </GroupByExpressions> 
    </MasterTableView> 
    <ClientSettings ReorderColumnsOnClient="True" AllowDragToGroup="false" AllowColumnsReorder="false">  
                <Selecting AllowRowSelect="false"></Selecting> 
                            </ClientSettings> 
   
</telerik:RadGrid> 

6 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 04 Aug 2009, 11:38 AM
Hello Ali,

You can add another groupbyexpression as shown below:
aspx:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceI="SqlDataSource1"  
   GridLines="None" AllowPaging="false" PageSize="25" Skin="Outlook" >    
  <MasterTableView DataSourceID="SqlDataSource1">   
    <GroupByExpressions>  
       <telerik:GridGroupByExpression>          
         <GroupByFields>  
              <telerik:GridGroupByField FieldName="category" />  
         </GroupByFields>  
         <SelectFields>  
          <telerik:GridGroupByField FieldName="category"/>   
         </SelectFields>  
       </telerik:GridGroupByExpression>  
    </GroupByExpressions> 
    <GroupByExpressions>  
       <telerik:GridGroupByExpression>  
         <SelectFields>  
          <telerik:GridGroupByField FieldName="name" HeaderText=""/>   
         </SelectFields>  
         <GroupByFields>  
              <telerik:GridGroupByField FieldName="name" />  
         </GroupByFields>  
       </telerik:GridGroupByExpression>  
   </GroupByExpressions>    
 </MasterTableView>  
    .... 

Thanks
Princy.
0
Ali Akbar
Top achievements
Rank 1
answered on 04 Aug 2009, 11:46 AM
Thanks a lot for writing it worked.


0
Kevin McGinnis
Top achievements
Rank 1
answered on 28 Aug 2009, 09:31 PM

Is it possible to add multiple GroupByExpressions programatically (C#)?

I tried:

GridGroupByExpression expression = GridGroupByExpression.Parse("fld1, COUNT(fld1) Total GROUP BY fld1");
RadGrid1.MasterTableView.GroupByExpressions.Add(expression);

GridGroupByExpression expression2 = GridGroupByExpression.Parse("fld2,, SUM(fld2) Total GROUP BY fld2");
RadGrid1.MasterTableView.GroupByExpressions.Add(expression2);

And it appears that only the second expression applies, resulting in a grid with only one level.  Editing the ASPX direclty, as shown in the previous post, results in two levels, at least proving that my data is valid.

Thanks!

0
Princy
Top achievements
Rank 2
answered on 29 Aug 2009, 04:34 AM
Hi,

Try dynamically setting the Grouping for Grid as shown below.

CS:
 
GridGroupByExpression expression = new GridGroupByExpression(); 
 
GridGroupByField gridGroupByField = new GridGroupByField(); 
// SelectFields values (appear in header) 
gridGroupByField = new GridGroupByField(); 
gridGroupByField.FieldName = "EmployeeID"
gridGroupByField.HeaderText = "Employee"
gridGroupByField.HeaderValueSeparator = " for current group: "
gridGroupByField.FormatString = "<strong>{0}</strong>"
expression.SelectFields.Add( gridGroupByField ); 
 
gridGroupByField = new GridGroupByField(); 
gridGroupByField.FieldName = "Freight"
gridGroupByField.HeaderText = "Total shipping cost is "
gridGroupByField.HeaderValueSeparator = ""
gridGroupByField.FormatString = "<strong>{0:0.00}</strong>"
gridGroupByField.Aggregate = GridAggregateFunction.Sum; 
expression.SelectFields.Add( gridGroupByField ); 
//GroupByFields values (group data) 
gridGroupByField = new GridGroupByField(); 
gridGroupByField.FieldName = "EmployeeID"
expression.GroupByFields.Add( gridGroupByField ); 
 
tableViewOrders.GroupByExpressions.Add( expression ); 


You can also refer the following help artcle for getting more details.
Programmatic definition

Thanks
Princy


0
Kiara
Top achievements
Rank 1
answered on 08 Sep 2016, 02:30 PM

 

I have written the same code but this is not working for Sum Aggregate function.In the gridgroupheaderitem the header text is not generating the sum of the values of the specified column---

Code:
GridGroupByExpression expression = new GridGroupByExpression(); 

 

GridGroupByField gridGroupByField = new GridGroupByField(); 

//GroupByFields values (group data) 
gridGroupByField = new GridGroupByField(); 
gridGroupByField.FieldName = "EmployeeID"; 
expression.GroupByFields.Add( gridGroupByField ); 

 

// SelectFields values (appear in header) 
gridGroupByField = new GridGroupByField(); 
gridGroupByField.FieldName = "EmployeeID"; 
gridGroupByField.HeaderText = "Employee"; 
gridGroupByField.HeaderValueSeparator = " for current group: "; 
gridGroupByField.FormatString = "<strong>{0}</strong>"; 
expression.SelectFields.Add( gridGroupByField ); 

gridGroupByField = new GridGroupByField(); 
gridGroupByField.FieldName = "Freight"; 
gridGroupByField.HeaderText = "Total shipping cost is "; 
gridGroupByField.HeaderValueSeparator = ""; 
gridGroupByField.FormatString = "<strong>{0:0.00}</strong>"; 
gridGroupByField.Aggregate = GridAggregateFunction.Sum; 
expression.SelectFields.Add( gridGroupByField ); 

tableViewOrders.GroupByExpressions.Add( expression ); 

 

Can anyone help...??

0
Maria Ilieva
Telerik team
answered on 13 Sep 2016, 12:17 PM
Hi Ali,

Can you please share the entire page markup and related code behind so that we can revise your code locally and advise you further?

Regards,
Maria Ilieva
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Ali Akbar
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ali Akbar
Top achievements
Rank 1
Kevin McGinnis
Top achievements
Rank 1
Kiara
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or