ClientGroupFooterTemplate - Get Aggregate Field Value

6 posts, 0 answers
  1. AP
    AP avatar
    205 posts
    Member since:
    Apr 2010

    Posted 23 Oct 2015 Link to this post

    I have a grid which displays a summary of data along with totals and subtotals.

    Each cell value has a link that enables a user to 'drill-down' to the individual records , by making a JavaScript call via a ClientTemplate.

    I want to add this drill-down functionality to the sub-total rows, but I need to pass the value of the aggregating field (in my case the patient class field). However, I'm not able to reference this field in the ClientGroupFooterTemplate.

    The ClientTemplate:-


    ClientTemplate("<a href='javascript:showData(\"#= PATCLASS #\",\"#= CONSPEF #\",\"p4p\")'> #= _4p #</a>")


    The ClientGroopFooterTemplate:-

    ClientGroupFooterTemplate("<a href='javascript:showData(\"-X-\",\"-X-\",\"-X-\")'>#= sum  #</a>")

    This works passing a string ("-X-" - which shows all values), but I need to pass the patient class value relating to the sub-total.  How can I do this?


  2. AP
    AP avatar
    205 posts
    Member since:
    Apr 2010

    Posted 27 Oct 2015 Link to this post

    I've logged a support ticket about this.
  3. AP
    AP avatar
    205 posts
    Member since:
    Apr 2010

    Posted 29 Oct 2015 Link to this post

    In case this helps anyone else, I got the solution after raising a support ticket.

    You need to use the DataBinding event, and use a function to set the value:-

        .Columns(columns =>
            columns.Bound(p => p.ProductName)
                .ClientFooterTemplate("Total Count: #=count#")
                .ClientGroupFooterTemplate("Value: #:groupField#");       
            columns.Bound(p => p.UnitPrice).Format("{0:C}");
            columns.Bound(p => p.UnitsOnOrder)
                .ClientFooterTemplate("Average: #=average#")
                .ClientGroupFooterTemplate("Average: #=average#");
            columns.Bound(p => p.UnitsInStock)
                .ClientGroupHeaderTemplate("Units In Stock: #= value # (Count: #= count#)")
                .ClientFooterTemplate("<div>Min: #= min #</div><div>Max: #= max #</div>");
        .Events(ev => ev.DataBinding("dataBinding"))
        .DataSource(dataSource => dataSource
            .Aggregates(aggregates =>
                aggregates.Add(p => p.UnitsInStock).Min().Max().Count();
                aggregates.Add(p => p.UnitsOnOrder).Average();
                aggregates.Add(p => p.ProductName).Count();
                aggregates.Add(p => p.UnitPrice).Sum();
            .Group(groups => groups.Add(p => p.UnitsInStock))
            .Read(read => read.Action("Aggregates_Read", "Grid"))
        function dataBinding(e) {
        function assignGroupName(view) {
            var item;
            for (var i = 0; i < view.length; i++) {
                item = view[i];
                for (var field in item.aggregates) {
                    item.aggregates[field].groupField = item.value;

  4. Lee
    Lee avatar
    25 posts
    Member since:
    Jun 2014

    Posted 17 Feb 2016 in reply to AP Link to this post

    Thanks so much for posting this!!!  I was trying to create a custom Aggregate for my ClientGroupFooterTemplate so I had created a function but couldn't figure out how to get the value that was being grouped to pass to my function.  This got me past that hurdle.
  5. David
    David avatar
    2 posts
    Member since:
    Sep 2016

    Posted 01 Nov 2016 in reply to AP Link to this post

    This is incredibly helpful. However, after implementing this solution and i try to export the data to excel, i get the following error:

    Uncaught ReferenceError: groupField is not defined
        at Object.eval [as groupFooterTemplate] ....

  6. Jared
    Jared avatar
    13 posts
    Member since:
    Oct 2015

    Posted 15 Apr Link to this post

    Here is an easier way to access the grid's aggregates:

    var grid = $('#shakeoutGrid').data('kendoGrid');
    var aggregates = grid.dataSource.aggregates();
Back to Top