How to do custom aggregate functions?

5 posts, 0 answers
  1. Dom
    Dom avatar
    7 posts
    Member since:
    Jun 2011

    Posted 05 Sep 2012 Link to this post

    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
  2. Dom
    Dom avatar
    7 posts
    Member since:
    Jun 2011

    Posted 05 Sep 2012 Link to this post

    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 */) #" }
          ],
  3. Kendo UI is VS 2017 Ready
  4. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 10 Sep 2012 Link to this post

    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!
  5. Geoff
    Geoff avatar
    2 posts
    Member since:
    Nov 2014

    Posted 16 Dec 2014 in reply to Alexander Valchev Link to this post

    Is this still the most up to date answer?
  6. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 17 Dec 2014 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready