This is a migrated thread and some comments may be shown as answers.

Accesing column name on which aggregate function was applied

5 Answers 63 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Manoj
Top achievements
Rank 1
Manoj asked on 04 Mar 2015, 12:21 PM
Hi,

I have a custome aggregate function defined as follows. I would like to access the column name on which this particular function is being called from so that the function can act on that particular column. How can that be done? Currently I have hard-coded the column name('Score') which I do not want to do.

class Summation : AggregateFunction<BindableDynamicDictionary, int>
    {
        public Summation()
        {
            this.AggregationExpression = items => FindSum(items);
             
        }
 
        private int FindSum(IEnumerable<BindableDynamicDictionary> source)
        {
 
            var itemCount = source.Count();
            int sum = 0;
            if (itemCount >= 1)
            {
                var values = source.Select(i => i["Score"]);
                 
                foreach (int str in values)
                {
                    sum = sum + str;
                }
            }
 
            return sum;
        }
    }



Thanks

5 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 04 Mar 2015, 04:04 PM
Hello,

I am afraid the generic aggregate function does not hold a reference on what the invoking column is and such an information is not available.

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Manoj
Top achievements
Rank 1
answered on 04 Mar 2015, 04:59 PM
Is there any other Aggregate function available which holds this reference?
Your documentation to generic aggregate functions returns a 404 page not found error :
http://docs.telerik.com/devtools/wpf/api/html/allmembers_t_telerik_windows_data_aggregatefunction_2.htm

Thanks.
0
Dimitrina
Telerik team
answered on 04 Mar 2015, 05:23 PM
Hello,

I apologize for this invalid link presented in our documentation after the recent migration of the help. I will resolve it, meanwhile the correct link is:
http://docs.telerik.com/devtools/wpf/api/html/t_telerik_windows_data_aggregatefunction_2.htm

As it turns out, there is not such a function, all the built-in ones inherit from AggregateFunction.

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Manoj
Top achievements
Rank 1
answered on 04 Mar 2015, 05:47 PM
I am lost now. As I mentioned, all the columns and the type of aggregation are determined by the user at run-time.
I cannot hard code the column value on the aggregate functions.
Is there any other way I can achieve this functionality? Also curious how the inbuilt functions like count or average work without predetermined column name.
Any help would be appreciated!

Thanks!
0
Dimitrina
Telerik team
answered on 05 Mar 2015, 02:54 PM
Hello,

You can also refer to our Source Code available for download from your account. The aggregate functions are presented under path ..\\Core\Data.

As to the question on how the AverageFunction knows the property to calculate on, it will be done based on the DataMemberBinding specified. This is the respective code involved:

private void SetSourceFieldToAggregateFunctionsIfNeeded()
{
    foreach (var selectorFunction in this.AggregateFunctions.OfType<EnumerableSelectorAggregateFunction>()
                                         .Where(f => f.SourceField == null))
    {
        selectorFunction.SourceField = this.GetDataMemberName();
    }
}
- - - -
public static string GetDataMemberName(this IDataFieldDescriptor descriptor)
{
    var name = string.Empty;
    if (descriptor != null)
    {
        var dataBinding = descriptor.DataMemberBinding;
  
        name = BindingToExpressionHelper.ExtractNameFromBinding(dataBinding, descriptor.ItemType);
        if (string.IsNullOrEmpty(name))
        {
            name = ExtractNameFromUniqueName(descriptor);
        }
    }
  
    return name;
}


Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Manoj
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Manoj
Top achievements
Rank 1
Share this question
or