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

Show the total in the column footer for a calculated column

6 Answers 358 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Satrajit
Top achievements
Rank 1
Satrajit asked on 30 Jul 2010, 02:30 PM

I am unable to show the total in the footer of the calculated column.

If I try to show the revenue total of this column in the footer using the aggregate functions as shown below then
I get an exception.This is because the YIELD_REVENUE does not exist in the Items List.Please let me know how I can do so?

<grid:GridViewDataColumn Header="Yield Revenue" DataMemberBinding="{Binding Converter={StaticResource CalculatingConverter},ConverterParameter='YIELD_REVENUE'}" IsReadOnly="True" HeaderTextAlignment="Center" UniqueName="YIELD_REVENUE" DisplayIndex="25">

                            

<grid:GridViewDataColumn.AggregateFunctions>

 
<data:SumFunction Caption="Sum (In LCY): "  SourceField="YIELD_REVENUE"/>

                            
</grid:GridViewDataColumn.AggregateFunctions>

</grid:GridViewDataColumn>

6 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 30 Jul 2010, 05:01 PM
Hi Satrajit,

 
In order to provide you with a possible solution for your exact scenario, we would need more details about your project, the converter you are using and the type of data you are setting as a ItemsSource for the grid.
However, I may suggest you to take a look at this blog post, where you will find both explanations and updated example for developing a Calculated Column. You can test the sample project and add the aggregate function you want in the last column.  

All the best,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mark
Top achievements
Rank 1
answered on 01 Apr 2011, 05:30 PM
It would be useful if the demo showed how to get a sum of a calculated column like the original post / request.
0
Maya
Telerik team
answered on 04 Apr 2011, 09:15 AM
Hello Mark,

There should be no problem to get the sum of the values in the calculated column. Once you define the aggregate function and set the ShowColumnFooters property of the grid to "True", you will be able to see the corresponding sum:

<telerik:RadGridView x:Name="gridView"  AutoGenerateColumns="False" ShowColumnFooters="True">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Count}" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Price}" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Total}"  >
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction Caption="Total: "/>
                    </telerik:GridViewDataColumn.AggregateFunctions>
                </telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

Furthermore, now you may use the GridViewExpressionColumn instead. 

Regards,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mark
Top achievements
Rank 1
answered on 04 Apr 2011, 01:52 PM
Hi Maya,

Thanks very much.  This was helpful.
0
Leos
Top achievements
Rank 1
answered on 07 Apr 2011, 09:31 AM
Sorry Maya,
not for me. It is working fine with normal column. Not with Converter or Expression.

So from zero with Converter:

Converter:
public class WeightEnergyConverter : IValueConverter
 {
     public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
     {
         decimal result = 0;
         Item o = (Item) value;
         if (o.FoodTypeEntity!=null)
         {
             result = o.Weight * o.FoodTypeEntity.Energy/100;   // Energy is in kJ/100g
         }
         return result;
     }
 
     public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
     {
         throw new NotImplementedException();
     }
 }


And Column definition:
<telerik:GridViewDataColumn Header="SumE"
Width="120" TextAlignment="Right" DataFormatString="###0.00"
DataMemberBinding="{Binding Converter={StaticResource cnvWeightEnergy}}" >                              
<!-- commented block
 <telerik:GridViewDataColumn.AggregateFunctions>
    <telerik:SumFunction Caption="Sum:" />
  </telerik:GridViewDataColumn.AggregateFunctions>                               
-->
</telerik:GridViewDataColumn>

If AggregateFunctions is commented, then it works fine and shows data with calculated energy for specified weight. Of course no total sum in footer is displayed.
When uncommented, no data are displayed (probably occures some error in background).

Thank you very much.
Leos
0
Leos
Top achievements
Rank 1
answered on 07 Apr 2011, 10:19 AM
And workaround:
1) Add calculated property to entity on client (= bypass calculation in Grid):
public partial class Item : Entity
   {
       public decimal WeightEnergy
       {
           get
           {
               decimal result = 0;
               if (FoodTypeEntity != null)
               {
                   result = Weight * FoodTypeEntity.Energy / 100;
               };               
               return result;
           }
       }
       partial void OnWeightChanged()
       {           
           this.RaisePropertyChanged("WeightEnergy");
       }
       partial void OnFoodTypeIdChanged()
       {
           this.RaisePropertyChanged("WeightEnergy");
       }
   }

2) use added property as typical DataColumn:
<telerik:GridViewDataColumn Header="WeightEnergy"
 Width="120" TextAlignment="Right" DataFormatString="###0.00"
 DataMemberBinding="{Binding WeightEnergy}">
 <telerik:GridViewDataColumn.AggregateFunctions>
    <telerik:SumFunction Caption="Sum:" />
 </telerik:GridViewDataColumn.AggregateFunctions>                                                               
</telerik:GridViewDataColumn>

3) now is all working fine - value in row is calculated and summary in footer is displayed.
Tags
GridView
Asked by
Satrajit
Top achievements
Rank 1
Answers by
Maya
Telerik team
Mark
Top achievements
Rank 1
Leos
Top achievements
Rank 1
Share this question
or