将kendo ui网格聚合到最接近的整数

时间:2014-08-11 14:26:43

标签: c# asp.net-mvc kendo-ui razorengine

我一直试图找到解决方案,但是没有多少运气。

我有一个带有客户端页脚模板的网格,显示列的平均值,现在我的问题是我希望平均值是整数。

这是我的代码

@(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())

提前致谢。

2 个答案:

答案 0 :(得分:0)

我找到了一个替代解决方案,我使用了kendo.toString()方法来格式化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') #%");

答案 1 :(得分:-1)

您是否尝试过更改

aggregates.Add(p => p.AchievedPercentage).Average();

aggregates.Add(Math.Round(p => p.AchievedPercentage).Average());