Server aggregates wrong

2 posts, 0 answers
  1. Jaesoon
    Jaesoon avatar
    51 posts
    Member since:
    Oct 2012

    Posted 19 Jul Link to this post

    Hi,

    I'm having a problem with the aggregates on my server-bound grid. Here's my code:

    @(Html.Kendo().Grid(Model[j].BusinessUnitTimesheets)
        .Name("BU_Time" + j)
            .DataSource(d => d
                .Server()
                .Aggregates(ag =>
                {
                    ag.Add(a => a.Amount).Sum();
                    ag.Add(a => a.Hours).Sum();
                })
            )
        .Columns(columns =>
        {
            columns.Bound(c => c.BusinessUnitId)
                .Hidden();
            columns.Bound(c => c.BusinessUnitCodeAndName)
                .Title("Business Unit")
                .ClientFooterTemplate("Total");
            columns.Bound(c => c.Hours)
                .Format("{0:N2}")
                .HtmlAttributes(new { style = "text-align:right;" })
                .ClientFooterTemplate("#=sum#")
                .FooterHtmlAttributes(new { style = "text-align:right;" });
            columns.Bound(c => c.Amount)
                .Width(100).Format("{0:N2}")
                .HtmlAttributes(new { style = "text-align:right;" })
                .ClientFooterTemplate("#=kendo.toString(sum,'N2')#")
                .FooterHtmlAttributes(new { style = "text-align:right;" });
        })
        .DetailTemplate(
            @<text>
            @(Html.Kendo().Grid(item.UserTime)
                .Name(string.Format("BU_U_Time{0}_{1}", j, item.BusinessUnitId))
                .DataSource(d => d
                    .Server()
                    .Aggregates(ag =>
                    {
                        ag.Add(a => a.Hours).Sum();
                        ag.Add(a => a.Amount).Sum();
                    })
                )
                .Events(e => e.DataBinding("splitBound"))
                .Columns(columns =>
                {
                    columns.Bound(c => c.UserName)
                        .Title("User");
                    columns.Bound(c => c.Hours)
                        .Format("{0:N2}")
                        .HtmlAttributes(new { style = "text-align:right;" })
                        .ClientFooterTemplate("#=sum#")
                        .FooterHtmlAttributes(new { style = "text-align:right;" });
                    columns.Bound(c => c.Amount)
                        .Width(100)
                        .Format("{0:N2}")
                        .HtmlAttributes(new { style = "text-align:right;" })
                        .ClientFooterTemplate("#=kendo.toString(sum,'N2')#")
                        .FooterHtmlAttributes(new { style = "text-align:right;" });
                })
            )
            </text>
        )
    )

     

    I've attached a screenshot of the rendered grid. The totals are in the wrong columns for the parent grid, and both parent and child have sums that are zero.

     

    Thanks

  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 21 Jul Link to this post

    Hi,

    When using a client template in a detail template the "#" character needs to be escaped with a backslash as below:
    .ClientFooterTemplate("\\#=sum\\#")

    Another possible reason would be problem with data binding.
     
    Regards,
    Pavlina
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top