This is a migrated thread and some comments may be shown as answers.
How to do custom aggregate functions?
4 Answers 582 Views
This is a migrated thread and some comments may be shown as answers.
Dom
Top achievements
Rank 1
Dom asked on 05 Sep 2012, 06:16 PM
I've looked over documentation but was not able to find an example on how to implement custom aggregate function for a data source. Is that possible? Can someone post simple example?

Thanks,
Dominik

4 Answers, 1 is accepted

Sort by
0
Dom
Top achievements
Rank 1
answered on 05 Sep 2012, 06:40 PM
Is it possible to get a value of the group on so that I can pass it to a function and use it in the template? Like this:

columns: [
//some other column definitions go here
        { field: "ValueAmount", title: "Modifier Value", format: "{0:N2}", groupFooterTemplate: "#= ValueAmountBalance(/* groupId */) #" },
        { field: "OverrideAmount", title: "Override", format: "{0:N2}", groupFooterTemplate: "#= OverrideAmountBalance(/* groupId */) #" }
      ],
0
Alexander Valchev
Telerik team
answered on 10 Sep 2012, 05:47 AM
Hi Dom,

I have already replied to your question in the support ticket that you submitted on the same subject. For convenience I will paste my reply here, so the other users who follow this thread could read it.

I am afraid that the dataSource does not support custom aggregate functions. By default the groupFooterTemplate contains information about current group aggregates, but not the "group by" field and value. As a workaround I can suggest to retrieve this information through thegroupHeaderTemplate (groupHeaderTemplate is executed before groupFooterTemplate). As an example:
{ field: "category", groupHeaderTemplate: "# getGroupInfo(data) #" },
{ field: "amount", groupFooterTemplate: "#= calculateAggregate(groupByField, groupByValue) #" }
  
function getGroupInfo(data) {
    groupByField = data.field;
    groupByValue = data.value;
};
//where groupByField and groupByValue are global variables
  
function calculateAggregate(field, value) {
    return field + " " + value;
}

Alternatively you may consider using the dataSource.view() which contains information about the group field, value and items. The order of view objects matches the order of displayed items(groups) in the grid. 

To avoid any further duplication I would like to ask you to continue our conversation in the support ticket.
Thank you in advance.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Geoff
Top achievements
Rank 1
answered on 16 Dec 2014, 06:54 PM
Is this still the most up to date answer?
0
Alexander Valchev
Telerik team
answered on 17 Dec 2014, 03:31 PM
Hello Geoff,

The previous answer is still valid.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Asked by
Dom
Top achievements
Rank 1
Answers by
Dom
Top achievements
Rank 1
Alexander Valchev
Telerik team
Geoff
Top achievements
Rank 1
Share this question
or