Get aggregates result in ClientTemplate

4 posts, 1 answers
  1. Ram
    Ram avatar
    5 posts
    Member since:
    Nov 2016

    Posted 22 Feb 2017 Link to this post

    Hi all:

    Can I get aggregates result in ClientTemplate?

    I tried  columns.Bound(c => c.idno).ClientGroupHeaderTemplate("# (Count: #= count#)");

    with DataSource(DataSourceResult from MVC Action)

    added .Aggregates(aggregates => { aggregates.Add(c => c.idno).Count(); }).Group(g => g.Add(c => c.idno))

    The "count" value can be shown in Row.

    But I want to create new a column with "count" value in each row,

    columns.Bound(c => c.idno).ClientTemplate("#= count#"); and columns.Template(e => { }).ClientTemplate("#= count#");

    It will get an error : Uncaught ReferenceError: count is not defined

     

    Is it possibale to get aggregates result in ClientTemplate?

     

    Thanks

  2. Answer
    Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2466 posts

    Posted 24 Feb 2017 Link to this post

    Hi Ram,

    The aggregates are available in the footer and the ClientGroupHeaderTemplate and they are calculated based on the rows in the grid (or in a specific group). There is no concept for aggregates in a single row. However, you can place some HTML element in the ClientTemplate and within the DataBound event of the Grid you can retrieve manually the aggregate that you want to display and placed it in that element.

    Hope this helps.


    Regards,
    Konstantin Dikov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Ram
    Ram avatar
    5 posts
    Member since:
    Nov 2016

    Posted 24 Feb 2017 in reply to Konstantin Dikov Link to this post

    Thanks !!  I will try it.
  4. Ram
    Ram avatar
    5 posts
    Member since:
    Nov 2016

    Posted 24 Feb 2017 in reply to Ram Link to this post

    in grid's datasource

    .Aggregates(aggregates =>  { aggregates.Add(c => c.idno).Count(); })
    .
    Group(g => g.Add(c => c.idno))

    grid's column

    .Columns(columns =>
        {
            columns.Template(e => { }).ClientTemplate("<div class=\"Count#: idno #\">123</div>");
        })

    grid's event

    .Events(a => a.DataBound("bindCount"))

    then script

        function bindCount() {
            var ds = $("#BaseInfo_grid").data("kendoGrid").dataSource;
            for (i = 0 ; i < ds.data().length ; i++) {
                $("div.Count" + ds.data()[i].value).html(ds.data()[i].aggregates.idno.count);
            }
            $(".k-grouping-row").hide();
    }

     

Back to Top