Search code examples
c#asp.net-mvckendo-uirazorengine

Round off kendo ui grid aggregate to the nearest whole number


I've been trying to find a solution on this but haven't had much luck.

I have a grid with a client footer template that shows the average of the column, now my problem is that I want the average to be a whole number.

Here is my code

@(Html.Kendo().Grid<LearnerAssessmentModel>()
.Name("LearnerAssessmentListGrid")
        .Columns(column =>
        {
            column.Bound(c => c.AssessmentId).Hidden();
            column.Bound(c => c.AssessmentTitle).ClientTemplate(
                "<a href='" + Url.Action("Index", "ConductAssessment", new { area = "Assessments" }) + "?assessmentId=#= AssessmentId #'" +
                ">#= AssessmentTitle #</a>");
            column.Bound(c => c.TotalCredits);
            column.Bound(c => c.RemainingCredits);
            column.Bound(c => c.LastSaveDate).Title("Latest Assessment Date").Format("{0:dd/MM/yyyy}");
            column.Bound(c => c.AssessorProfileId).Hidden();
            column.Bound(c => c.Assessor).ClientTemplate(
                "<a href='" + Url.Action("DisplayProfile", "EmployeeProfile", new { area = "EmployeeInfo" }) + "?id=#= AssessorProfileId #'" +
                ">#= Assessor #</a>"
                );
            column.Bound(c => c.AchievedPercentage).Format("{0} %").HtmlAttributes(new { style = "text-align: center;" }).HeaderHtmlAttributes(new { style = "text-align: center;", title = "Assessment Progress" }).ClientFooterTemplate("Overall: #=average#%");
        })
        .DataSource(ds => ds
            .Ajax()
            .Read(read => read.Action("ReadLearnerAssessments", "LearnerHome", new { area = "Home" }))
            .Aggregates(aggregates =>
                    {
                        aggregates.Add(p => p.AchievedPercentage).Average();
                    })

        )
        .Sortable())

Thanks in advance.


Solution

  • I found an alternative solution to my question, I used the kendo.toString() method to format the footerTemplate

    column.Bound(c => c.AchievedPercentage).Format("{0} %").HtmlAttributes(new { style = "text-align: center;" }).HeaderHtmlAttributes(new { style = "text-align: center;", title = "Assessment Progress" }).ClientFooterTemplate("Overall: #= kendo.toString(average, '0') #%");