Sort with Aggregates

4 posts, 1 answers
  1. Scott Buchanan
    Scott Buchanan avatar
    38 posts
    Member since:
    Dec 2008

    Posted 25 Jul 2015 Link to this post

    Greetings!  I have an MVC 5 app using Telerik UI for MVC 2015.2.624.  The key aspects of the grid layout are

    @(Html.Kendo().Grid(Model.IssueReportRows.ToList())
        .Name("grid")
        .HtmlAttributes(new { @class = "suppress-borders sticky-table-header clickable-rows" })
        .Pageable(pageable => pageable
            .Enabled(ViewData["RenderMode"] != "PDF")
            .ButtonCount(ConfigVars.GridPagerButtonCount)
            .PageSizes(ChartHelpers.GetPagerChoices(Model.IssueReportRows.Count()))
            )
        .Sortable(sortable => sortable.AllowUnsort(false))
        .Selectable()
        .Events(events => events
            .DataBound("OnDataBound_Issues")
            .Change("OnRowClick")
            )
        .DataSource(dataSource => dataSource
            .Ajax()
            .Sort(sort =>
                {
                    sort.Add("ProcedureCategoryName").Ascending();
                    sort.Add("Sequence").Ascending();
                })
            .Group(groups => groups.Add(t => t.AuditIssueDescription))
            .Aggregates (aggregates =>
                {
                    aggregates.Add(t => t.ProviderName).Count();
                    aggregates.Add(t => t.ChartsReviewed).Sum();
                    aggregates.Add(t => t.IssuesFound).Sum();
                })
            .ServerOperation(false)
            .PageSize(ViewData["RenderMode"] == "PDF" ? Model.IssueReportRows.Count() : ChartHelpers.GetPageSize(Model.IssueReportRows.Count()))
            )
        .Columns(columns =>
        {
            columns
                .Bound(t => t.AuditIssueDescription)
            columns
                .Bound(t => t.ProcedureCategoryName)
            columns
                .Bound(t => t.SpecialtyCode)
            columns
                .Bound(t => t.ProviderName)
                .ClientGroupFooterTemplate("Providers: #=count#");
            columns
                .Bound(t => t.ChartsReviewed)
                .ClientGroupFooterTemplate("<div class='code-cell suppress-borders'>#=sum#</div>");
            columns
                .Bound(t => t.IssuesFound)
                .ClientGroupFooterTemplate("<div class='code-cell'>#=sum#</div>");
        })
    )

    My issue is that I need the grid sorted by ProcedureCategoryName + Sequence.  This worked fine until I added the Group and Aggregates - now it sorts by whatever column is specified in Group().  This is a great default, but I have not been able to override the behavior.  I have considered creating an extra column that contains a concatenation of ProcedureCategory and Sequence, but I'm hoping there is a better way.  If not, please let me know how to put the AuditIssueDescription in the Group Header - that seems challenging as well.

    Thanks,
    Scott

     

  2. Answer
    Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 29 Jul 2015 Link to this post

    Hello Scott Buchanan,

    Indeed when grouping is set the it will sort only by whatever column is specified in Group(). 

    Regarding your second question - you can use the #= value # expression in the group header template as shown in Grid / Aggregates demo. Please note that the grid is grouped by UnitsInStock column and the group header template definition looks like: 

    { field: "UnitsInStock", title: "Units In Stock", aggregates: ["min", "max", "count"], footerTemplate: "<div>Min: #= min #</div><div>Max: #= max #</div>", groupHeaderTemplate: "Units In Stock: #= value # (Count: #= count#)" }

    Regards,
    Boyan Dimitrov
    Telerik
    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
  4. Scott Buchanan
    Scott Buchanan avatar
    38 posts
    Member since:
    Dec 2008

    Posted 06 Aug 2015 in reply to Scott Buchanan Link to this post

    Boyan,

    Thank you.  I've added a column for sorting, used that in Group(), and parsed the sort column to display the portion that makes sense.

    Can I remove the borders in the footer?  As you can see above, the grid'sHtmlAttributes includes the class suppress-borders, which is defined as border-width: 0px !important.  But the footer does not honor this attribute.  I tried adding this class to ClientGroupFooterTemplate, but no joy.

    Thanks,

    Scott

     

     
     
     
     
  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 10 Aug 2015 Link to this post

    Hello Scott Buchanan,

    Border styles are not inherited, while the supress-borders class is applied to the Grid <div>. As a result, the border styles of descendant table cells are not affected. You can use:

    .suppress-borders .k-group-footer td,
    .suppress-borders .k-grid-footer td
    {
       border-width: 0;
    }

    Regards,
    Boyan Dimitrov
    Telerik
    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready