群聚集
当你使用程序化的分组,可以向组行添加聚合函数。这些函数允许您显示关于组中数据的信息,如第一项、最后一项、项数等。
有两种主要类型的聚合函数可用,它们可以作为具体实现的基础。
EnumerableAggregateFunction中提供的聚合扩展方法的AggregateFunction可列举的.
CountFunction:返回所有项目数量在列中。
FirstFunction:返回第一个元素在列中按当前顺序排序。
LastFunction:返回最后一个元素在列中按当前顺序排序。
EnumerableSelectorAggregateFunction中提供的聚合扩展方法的AggregateFunction可列举的并使用它SourceField属性作为成员选择器。属性未显式设置SourceField属性,则为DataMemberBinding将使用列的。
AverageFunction:返回平均列中的值。
MaxFunction:返回最大列中单元格值的值。
MinFunction:返回最低列中单元格值的值。
SumFunction:返回总和列中的所有单元格值。
您还可以通过继承来创建自己的自定义函数Telerik.Windows.Data.EnumerableAggregateFunction或EnumerableSelectorAggregateFunction类。一个例子可以在自定义聚合函数RadGridView的例子演示.
每个聚合函数都有一个标题和一个结果,显示在组标题旁边。
例1:用AggregateFunction定义GroupDescriptor
…< / telerik: RadGridView >
例2:用AggregateFunction编程定义GroupDescriptor
CountFunction f = new CountFunction();f.Caption = "Entries Count: ";GroupDescriptor countryDescriptor = new GroupDescriptor();countryDescriptor。成员= "国家";countryDescriptor。SortDirection = ListSortDirection.Ascending;countryDescriptor.AggregateFunctions。加上(f);this.radGridView.GroupDescriptors。添加(countryDescriptor);
Dim As New CountFunction() f. caption = "Entries Count: " Dim countryDescriptor As New GroupDescriptor() countryDescriptor。成员= "国家"国家描述符。SortDirection = ListSortDirection。递增countryDescriptor. aggregatefunctions . add (f) . radgridview . groupdescriptors . add (countryDescriptor)
图1:带有组聚合的RadGridView
方法中可以添加多个函数AggregateFunctions收集,它们将一个接一个地可视化。
例3:定义具有多个aggregatefunction的GroupDescriptor
...
例4:以编程方式定义具有多个aggregatefunction的GroupDescriptor
CountFunction f = new CountFunction();f.Caption = "Entries Count: ";FirstFunction f1 = new FirstFunction();f.Caption = "FirstEntry: ";GroupDescriptor countryDescriptor = new GroupDescriptor();countryDescriptor。成员= "国家";countryDescriptor。SortDirection = ListSortDirection.Ascending;countryDescriptor.AggregateFunctions。加上(f); countryDescriptor.AggregateFunctions.Add( f1 ); this.radGridView.GroupDescriptors.Add( countryDescriptor );
Dim f As New CountFunction() f. caption = "Entries Count: " Dim f1 As New FirstFunction() f. caption = "FirstEntry: " Dim countryDescriptor As New GroupDescriptor() countryDescriptor。成员= "国家"国家描述符。SortDirection = ListSortDirection。递增countryDescriptor. aggregatefunctions . add (f) countryDescriptor. aggregatefunctions . add (f1) Me.radGridView.GroupDescriptors.Add(countryDescriptor)
图2:定义了GroupDescriptor和AggregateFunctions的RadGridView
的FirstFunction将显示由ToString ()业务对象的方法。
显示组头聚合
您还可以添加在列级上聚合函数.
例5:列级上的聚合函数
< telerik: RadGridView。> < / telerik: RadGridView >
可以通过应用控件来控制此特性风格针对GroupHeaderRow并设置ShowGroupHeaderColumnAggregates财产真正的.由于GroupHeaderRow仅用于平GroupRenderMode控件的,此特性仅在此模式下可用。
例6:设置GroupHeaderRow的showgroupheadercolumnaggregate属性
.
图3:与列对齐的聚合
该行的类型为GridViewGroupFooterRow时所显示的相同ShowGroupFooters将RadGridView控件的值设置为真正的.这些细胞依次是GridViewGroupFooterCell类型。
在使用此特性时,很可能不再需要显示默认组行聚合。属性可以隐藏它们ShowHeaderAggregates属性的GroupHeaderRow到假.
例7:设置GroupHeaderRow的showheaderaggregate属性为False
.
图4:设置showheaderaggregate为False的RadGridView
在GroupHeaderRow中对齐聚合
默认情况下,聚合结果显示在组键的右侧。通过ColumnAggregatesAlignment属性的RadGridView,你可以把结果放在他们定义的列下面。该属性有以下可能的值:
NoAlignment:聚合结果不按列对齐。
BelowGroupKey:聚合结果与列对齐,并置于组键的下方。
NextToGroupKey:聚合结果与列对齐,并与组键放在同一行。