This is a migrated thread and some comments may be shown as answers.

Sort with Aggregates

3 Answers 206 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott Buchanan
Top achievements
Rank 1
Scott Buchanan asked on 26 Jul 2015, 02:47 AM

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

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Boyan Dimitrov
Telerik team
answered on 29 Jul 2015, 07:56 AM

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
0
Scott Buchanan
Top achievements
Rank 1
answered on 06 Aug 2015, 03:30 PM

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

 

 
 
 
 
0
Boyan Dimitrov
Telerik team
answered on 10 Aug 2015, 01:28 PM

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
Tags
Grid
Asked by
Scott Buchanan
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Scott Buchanan
Top achievements
Rank 1
Share this question
or