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
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.
Maya
the Telerik team
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
Thanks very much. This was helpful.
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
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.