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

Can't format my group footers and grid footers properly

8 Answers 250 Views
Grid
This is a migrated thread and some comments may be shown as answers.
andieje
Top achievements
Rank 1
andieje asked on 29 Jun 2009, 05:41 PM
Hi

My grid has a column called DistanceTravelled. I have a sum aggregate on this field. My grid is also grouped on another field. This means that there is a Sum of DistanceTravelled per group and for the entire grid.

<

 

telerik:GridGroupByField FieldAlias="Total" Aggregate="Sum" FieldName="DistanceTravelled" />

 

<

 

telerik:GridBoundColumn DataField="DistanceTravelled" HeaderText="Distance Travelled (miles)" UniqueName="DistanceTravelled" Aggregate="Sum"  DataFormatString="{0:F2}" FooterText="Total: "

 

 

 

 

></telerik:GridBoundColumn>

 


I can't format my grid and group footers properly.

Firstly I format the DistanceTravelled column as a whole to 2 decimal places uses a DataFormatString in the bound column. It seems to me that this overrides anything specified in the FooterText property of the bound column or the FormatString property of the aggregate field. With the example above, both the group and grid footers are simply shown as a number to 2dp - the word "Total" is not displayed. If I remove the DataFormatString property I get the FooterText "Total" output in the group/grid footers but the number after it is not shown to 2 decimal places

This is what i would like but i don't know how to achieve it:

1) The column formatted to 2 decimal places
2) The group footer to say Total for group: x.xx where x.xx is the number to 2 decimal places
3)The grid footer to say Total: x.xx

Many thanks in advance

8 Answers, 1 is accepted

Sort by
0
andieje
Top achievements
Rank 1
answered on 30 Jun 2009, 12:05 PM
I have got a little bit further with this

<

 

telerik:GridBoundColumn DataField="DistanceTravelled" DataFormatString="{0:F2}" HeaderText="Distance Travelled (miles)" UniqueName="DistanceTravelled" Aggregate="Sum" FooterAggregateFormatString="Total miles: {0:F2}"></telerik:GridBoundColumn>

 


This formats the column throughout the grid to 2dp with the DataFormatString. The footer aggregate format string also now displays what I want in the grid footer. However now the text in the FooterAggregateFormatString is overriding anything i specify for the group footer like so

 

 

<

 

telerik:GridGroupByField FieldAlias="Total" Aggregate="Sum" FieldName="DistanceTravelled" FormatString="Total for day: {0:F2}" />

 

 

 

 

In other words, the group footer also displays "Total miles" like the grid footer instead of "Total for the day"

 

0
andieje
Top achievements
Rank 1
answered on 01 Jul 2009, 08:04 PM
Hi

I would really appreciate it if someone from tech support could look at this question as I notice other questions posted after this one have already been answered.

Many thanks in advance
0
Shinu
Top achievements
Rank 1
answered on 02 Jul 2009, 11:22 AM
Hello Andieje,

I tried setting GroupFooter text from code behind as shown below. Give a try with this and see whether it is working fine as expected

C#:
 
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    foreach (GridGroupFooterItem groupFooter in RadGrid1.MasterTableView.GetItems(GridItemType.GroupFooter)) 
    { 
        groupFooter["Number"].Text = "ToTal Number :"+ groupFooter["Number"].Text.ToString().Split(':')[1].ToString(); 
    } 

-Shinu.
0
andieje
Top achievements
Rank 1
answered on 03 Jul 2009, 12:10 AM
Hi

Thanks for your reply. I was also able to set the group footer programmatically but i wanted to know how to do it declaratively as I've got a lot of grids in my site!

andrea
0
andieje
Top achievements
Rank 1
answered on 05 Jul 2009, 12:19 AM
but on the subject of setting group footers programatically....

I didn't fully understand what you were trying to achieve in your code sample but i don't understand how it works.

when I try and set my grid group footers programmatically it's a total pain because you cannot index the grid footer columns by column name

      ElseIf TypeOf e.Item Is GridGroupFooterItem Then
                Dim item As GridGroupFooterItem = CType(e.Item, GridGroupFooterItem)
                item("DistanceTravelled").text = "hello" <------------ this will not compile

yet you could do this

 groupFooter["Number"].Text



 
I have read a post where someone complained that you could not use unique column names to index grid group footers so perhaps this issue has been remedied in the new release. I am using q3 2008

But that aside i would like to format my group footers declaratively if possible using the format string for the group.

many thanks
0
Sebastian
Telerik team
answered on 06 Jul 2009, 08:04 AM
Hello andieje,

Indeed with the Q2 2009 release of RadGrid for ASP.NET AJAX you can access the group footer cells using the unique names of the corresponding columns as you will do with header, data or regular footer items.

If you prefer to apply format string for the group footer aggregate results declaratively, utilize the FooterAggregateFormatString property of the columns as illustrates on these demos of the product:

http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/aggregates/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplate/defaultcs.aspx

Best,
Sebastian
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
andieje
Top achievements
Rank 1
answered on 07 Jul 2009, 10:15 PM
Hello Sebastien

Thank-you for your reply. However it does not solve my problem. The 2 examples you have given me display aggregates in the grid footers. I am not having a problem with displaying aggregates in the grid footers. The problem that I am having, as described in my original question, is that the FooterAggregateFormatString  which I am using to format the grid footer is OVERRIDING the FormatString property i am setting in the GridGroupByField for the group footers.

so to reiterate I am setting the group footer declaratively like so

<telerik:GridGroupByField FieldAlias="Total" Aggregate="Sum" FieldName="DistanceTravelled" FormatString="Total for day: {0:F2}" />

but the text in the group footer is not "total for day" but the text from the footeraggregateformatstring which you can see here

 

<

 

telerik:GridBoundColumn DataField="DistanceTravelled" DataFormatString="{0:F2}" HeaderText="Distance Travelled (miles)" UniqueName="DistanceTravelled" Aggregate="Sum" FooterAggregateFormatString="Total miles: {0:F2}"></telerik:GridBoundColumn>

Shinu very kindly advised me how I can set my display group aggregates in teh group footer programmatically. However I do already know how to do this. I want to set the group footers declaratively using the FormatString property of the group footer because this should be possible.

I am using q3 2008.

 

0
Sebastian
Telerik team
answered on 08 Jul 2009, 07:56 AM
Hello andieje,

The FormatString property of GridGroupByField can be used to format the aggregate result that will be displayed in the grid group header as explained in this help topic. Hence it is not applicable for group footers.

Therefore, you may consider the approaches suggested by me and Shinu in this forum thread.

Kind regards,
Sebastian
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.
Tags
Grid
Asked by
andieje
Top achievements
Rank 1
Answers by
andieje
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or