ClientGroupFooterTemplate - Get Aggregate Field Value

5 posts, 0 answers
  1. AP
    AP avatar
    187 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?

    Thanks

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

    Posted 27 Oct 2015 Link to this post

    I've logged a support ticket about this.
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. AP
    AP avatar
    187 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:-

    @(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
        .Name("Grid")
        .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"))
        .Pageable()   
        .Sortable()       
        .DataSource(dataSource => dataSource
            .Ajax()
            .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"))
        )
    )
      
    <script>
        function dataBinding(e) {
            assignGroupName(this.dataSource.view());
        }
      
        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;
                }
      
            }
        }
    </script>

  5. Lee
    Lee avatar
    20 posts
    Member since:
    Jun 2014

    Posted 17 Feb 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.
  6. David
    David avatar
    2 posts
    Member since:
    Sep 2016

    Posted 01 Nov 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] ....

Back to Top
UI for ASP.NET MVC is VS 2017 Ready