.NET MAUI DataGrid Property Aggregate Descriptor
The PropertyAggregateDescriptor
allows you to define a property and a function that are applied over the property values of the .NET MAUI DataGrid, which accumulates an aggregated result based on the component data.
To set up the PropertyAggregateDescriptor
, use the following properties:
-
PropertyName
—Defines the name of the property that is used to compute the aggregate value. -
Function
—Defines aKnownFunction
value that will be applied to the aggregate. -
Caption
—Defines the caption of the aggregate. You can useCaption
to display text in the UI. -
Format
—Defines the string format that will be applied over the aggregated value.
The PropertyAggregateDescriptor
supports the following KnownFunction
aggregates:
-
Sum
—TheSum
function summarizes all values in the column. -
Min
—TheMinimum
value of the cells in the column. -
Max
—TheMaximum
value of the cells in the column. -
Average
—TheAverage
value of the cells in the column. -
Count
—TheCOUNT
function counts the items in the column. -
Product
—ThePRODUCT
function multiplies all the numbers given as arguments and returns the product. -
StdDev
—TheStandard Deviation
is a measure of how widely values are dispersed from the average value, based on a sample function. -
StdDevP
—TheStandard Deviation
is a measure of how widely values are dispersed from the average value, based on the entire population function. -
Var
—TheVariance
is a measure of dispersion, based on a sample function. -
VarP
—TheVariance
is a measure of dispersion, based on the entire population function.
The following example shows how to add a PropertyAggregateDescriptor
to the DataGrid's Columns. It will take the values from the Name
, Price
, DeliveryPrice
and Quantity
properties of the row model and the result will be the Min
and Max
prices as well as Average
price for delivery and the Count
of the listed items.
<telerik:RadDataGrid x:Name="dataGrid"
UserGroupMode="Disabled"
AutoGenerateColumns="False"
UserEditMode="Cell"
ShowColumnFooters="True">
<telerik:RadDataGrid.Columns>
<telerik:DataGridTextColumn PropertyName="Name">
<telerik:DataGridTextColumn.AggregateDescriptors>
<telerik:PropertyAggregateDescriptor PropertyName="Name"
Function="Count"
Caption="Total count: " />
</telerik:DataGridTextColumn.AggregateDescriptors>
</telerik:DataGridTextColumn>
<telerik:DataGridNumericalColumn PropertyName="Price"
CellContentFormat="{}{0:C}">
<telerik:DataGridNumericalColumn.AggregateDescriptors>
<telerik:PropertyAggregateDescriptor PropertyName="Price"
Function="Min"
Format="C"
Caption="Cheapest item: " />
<telerik:PropertyAggregateDescriptor PropertyName="Price"
Function="Max"
Format="C"
Caption="Priciest item: " />
</telerik:DataGridNumericalColumn.AggregateDescriptors>
</telerik:DataGridNumericalColumn>
<telerik:DataGridNumericalColumn PropertyName="DeliveryPrice"
HeaderText="Delivery Price"
CellContentFormat="{}{0:C}">
<telerik:DataGridNumericalColumn.AggregateDescriptors>
<telerik:PropertyAggregateDescriptor PropertyName="DeliveryPrice"
Function="Average"
Format="C"
Caption="Average: " />
</telerik:DataGridNumericalColumn.AggregateDescriptors>
</telerik:DataGridNumericalColumn>
<telerik:DataGridNumericalColumn PropertyName="Quantity">
<telerik:DataGridNumericalColumn.AggregateDescriptors>
<telerik:PropertyAggregateDescriptor PropertyName="Quantity"
Function="Sum"
Caption="Total amount: " />
</telerik:DataGridNumericalColumn.AggregateDescriptors>
</telerik:DataGridNumericalColumn>
</telerik:RadDataGrid.Columns>
</telerik:RadDataGrid>
The following image shows the end result.