New to Telerik UI for WinUI? Download free 30-day trial

PropertyAggregateDescriptor

The PropertyAggregateDescriptor allows you to define a property and function that is applied over the property values. This accumulates an aggregated result based on the RadDataGrid's data.

To setup the descriptor use the following properties:

  • PropertyName: Defines the name of the property that is used to compute the aggregate value.
  • Function: Defines a KnownFunction value to be applied to the aggregate. See the known functions listed in the Aggregates Overview article.
  • Caption: Defines the caption of the aggregate. This can be used to display text in the UI when set the AggregatesTemplate.
  • Format: Defines the string format that will be applied over the aggregated value.

To display the aggregates, set the AggregatesTemplate property of the RadDataGrid's column that should display the value. The data context in the template is a collection with AggregateResult objects. Each AggregateResult contains the Caption of the aggregate, the aggregated value and the value with the Format applied.

The following example shows how to add a PropertyAggregateDescriptor to a RadDataGrid. It will take the values from a Value property of the row model and the result will be the Sum value.

<telerikGrid:RadDataGrid ItemsSource="{Binding Items}" AutoGenerateColumns="False">
    <telerikGrid:RadDataGrid.Columns>
        <telerikGrid:DataGridTextColumn PropertyName="Value">
            <telerikGrid:DataGridTextColumn.AggregatesTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                        <TextBlock Text="{Binding [0].Caption}" />
                        <TextBlock Text="{Binding [0].FormattedValue}" Margin="5 0 0 0" />
                    </StackPanel>
                </DataTemplate>
            </telerikGrid:DataGridTextColumn.AggregatesTemplate>
        </telerikGrid:DataGridTextColumn>
    </telerikGrid:RadDataGrid.Columns>
    <telerikGrid:RadDataGrid.AggregateDescriptors>
        <telerikData:PropertyAggregateDescriptor PropertyName="Value" Function="Sum" Caption = "Total: " Format = "C" />
    </telerikGrid:RadDataGrid.AggregateDescriptors>
</telerikGrid:RadDataGrid>

This example uses the following namespaces:

xmlns:telerikGrid="using:Telerik.UI.Xaml.Controls.Grid"
xmlns:telerikCore="using:Telerik.Data.Core"

You can get the aggregate value/s through the GetAggregateValue and GetAggregateValues methods of the IDataView interface.

In this article
Not finding the help you need?