5 Answers, 1 is accepted
The attached project demonstrates how to create a custom aggregate function and use it in RadGridView.
For your needs you will need to modify MyAggregateMethod. Within the method you have access to the items in RadGridView and may write a few lines of code to return the distinct total.
Let me know in case you need further assistance.
Sincerely yours,
Pavel Pavlov
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.
I am afraid that it is not possible to pass parameter to the method this way . However I think we can find an alternative way - we can make a custom EnumerableSelectorAggregateFunction instead. This one has the SourceFiled property.
I will prepare a small sample , but I will need to know the data type of the property you will make distinct count on.
All the best,
Pavel Pavlov
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.
public class CountDistinctFunction : EnumerableSelectorAggregateFunction
{
protected override string AggregateMethodName
{
get
{
return "CountDistinct";
}
}
protected override Type ExtensionMethodsType
{
get
{
return typeof(CountDistinctAggregates);
}
}
}
public static class CountDistinctAggregates
{
public static int CountDistinct<TSource>(IEnumerable<TSource> source, Func<TSource, float> selector)
{
if (!source.Any<TSource>())
return 0;
else
return source.Select(selector).Distinct().Count();
}
public static int CountDistinct<TSource, TResult>(IEnumerable<TSource> source, Func<TSource, TResult> selector)
{
if (!source.Any<TSource>())
return 0;
else
{
IEnumerable<string> values = from i in source select Convert.ToString(selector(i)).ToLower();
var result = values.Distinct().Count();
return result;
}
}
public static int CountDistinct<TSource>(IEnumerable<TSource> source, Func<TSource, int> selector)
{
if (!source.Any<TSource>())
return 0;
else
return source.Select(selector).Distinct().Count();
}
}
col.AggregateFunctions.Add(new CountDistinctFunction { SourceField = columnName });