Kendo UI网格聚合使用组和Razor语法获取'sum'是未定义的错误

时间:2015-07-03 05:58:35

标签: c# asp.net-mvc razor telerik-mvc

我有一个用于telerik的父网格,其下有聚合网格作为子网格,这是我的代码 这里是父网格

@(Html.Kendo().Grid<ClaimListbyCompanyUserId1_Result>()
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(e => e.chkbox)
                .HeaderTemplate("<input type='checkbox' id='chkAllClaim' class='chkAll'/>")
                .ClientTemplate("<input type='checkbox' class='clsClaim'/>")
                .HtmlAttributes(new { style = "text-align: center" })
                .HeaderHtmlAttributes(new { style = "text-align: center" })
                .Filterable(false)
                .Sortable(false)
                .Groupable(false)
                .Width(50);
            columns.Bound(e => e.Name)
                //.Filterable(filterable => filterable.UI("claimType"))
                .Title(@objFieldNameList["Name"])
                .Width(80);
            columns.Bound(e => e.Description)
                .Width(120)
                .Title(@objFieldNameList["Description"]);
            columns.Bound(e => e.Amount).Template(@<text></text>).ClientTemplate(@clsExtensions.ToCurrencyFormat(Convert.ToString("#=decimalAmount#"), ProjectSession.CurrencySign, ProjectSession.CurrencyCode_ISO3, ProjectSession.CurrencyFormat, ProjectSession.DisplayPlaceCurrencyFormat))
                .Width(100).Title(@objFieldNameList["Amount"]);
            columns.Bound(e => e.PayableAmount).Template(@<text></text>).ClientTemplate(@clsExtensions.ToCurrencyFormat(Convert.ToString("#=decimalAmount#"), ProjectSession.CurrencySign, ProjectSession.CurrencyCode_ISO3, ProjectSession.CurrencyFormat, ProjectSession.DisplayPlaceCurrencyFormat))
                .Width(100).Title(@objFieldNameList["Payable Amount"]);
            columns.Bound(e => e.Status).Filterable(filterable => filterable.UI("status")).ClientTemplate("#=GetStatus(Status)#").Width(100).Title(@objFieldNameList["Status"]);
            columns.Bound(e => e.DATE).Format("{0:" + ProjectSession.DateFormat + "}")
                    .Title(@objFieldNameList["Last Modified"])
                    .Width(130);
            columns.Bound(e => e.TotalApprovals)
        .Width(120)
        .Title(@objFieldNameList["Approvals"]);

            columns.Template(@<text></text>).ClientTemplate(
        @Html.ViewLink("View Comment", "javascript:", null, null, new { datahref = Url.Action("_ViewClaimComment", "Home", new { Data = "#=ClaimId#" }), @class = "clsView" }).ToHtmlString())
        .Title(@objFieldNameList["Comment"])
        .Width(60);

            columns.Template(@<text></text>).ClientTemplate(
        @Html.EditLink("Edit", "ExpenseGroupDetails", "ExpenseGroup1", new { Data = "#=ClaimId#" }) + "&nbsp;" +
        @Html.DeleteLink("Delete", "javascript:", null, null, new { Data = "#=ClaimId#", @class = "clsDelete", @datahref = Url.Action("Delete", "ExpenseGroup1") }) + "&nbsp;" +
        @Html.PrintLink("Receipt", "DownloadClaimReport", "ExpenseGroup1", new { Data = "#=ClaimId#" }))
        .Title(@objFieldNameList["Action"])
        .Width(60);
        })
        .Sortable()
        .Pageable()
    //.Scrollable()
        .ClientDetailTemplateId("template")
        .Scrollable(a => a.Height("auto"))
        .Filterable()
        .DataSource(dataSource => dataSource
                        .Ajax().Read(read => read.Action("claimCompanyUserList", "ExpenseGroup1")).PageSize(10)
        )
        .Events(events => events.DataBound("dataBound"))

这里是子网格作为聚合网格 -

<script id="template" type="text/kendo-tmpl">
@(Html.Kendo().Grid<ClaimListbyCompanyUserId1_Result>()
            .Name("grid_#=ClaimId#")
            .Pageable(p => p.Enabled(false))
          .Sortable(s => s.Enabled(false))
          .Groupable(g => g.Enabled(true))
          .Scrollable(s => s.Enabled(false))
        //.Groupable(groupable => groupable.Enabled(true))
            .Columns(columns =>
            {
                columns.Bound(o => o.ItemDescription)
                    .Width(110)
                    .Title(@objFieldNameList["Description"]);

                columns.Bound(e => e.ItemAmount)
                .Title(@objFieldNameList["Amount"])
                .ClientGroupFooterTemplate("Total Amount: #=sum#")
                .Width(100);

                columns.Bound(e => e.CountryName)
                .Title(@objFieldNameList["Country"])
                .ClientGroupFooterTemplate("Count: #=count#")
                .Width(80);

            }).Events(e => e.DataBound("ChildGridDatabound"))
        .DataSource(dataSource => dataSource.Ajax()
        .Aggregates(aggregates =>
    {
        aggregates.Add(p => p.CountryName).Count();
        aggregates.Add(p => p.ItemAmount).Sum();
    })
    .Group(groups => groups.Add(p => p.ClaimTypeId))
    .Read(read => read.Action("GetClaimInnerGridByClaimId", "ExpenseGroup1", new { ClaimId = "#=ClaimId#" }))).ToClientTemplate())

错误:Javascript运行时错误,'sum'未定义
尝试了所有可能的解决方案,但它给出了同样的错误 如果有人有解决方案,请帮忙 提前致谢

2 个答案:

答案 0 :(得分:0)

您的HTML代码:

columns.Bound(e => e.ItemAmount)
            .Title(@objFieldNameList["Amount"])
            .ClientGroupFooterTemplate("Total Amount: #=sum#")
            .Width(100);

将以上HTML代码替换为:

 columns.Bound(e => e.ItemAmount)
            .Title(@objFieldNameList["Amount"])
            .ClientGroupFooterTemplate("Total Amount: #= kendo.toString(sum,'c')")
            .Width(100);

答案 1 :(得分:0)

necropost(: 你的代码

...
.ClientGroupFooterTemplate("Total Amount: #=sum#")
.ClientGroupFooterTemplate("Count: #=count#")
...

您可以使用双反斜杠转义哈希字符 将以上HTML代码替换为:

...
.ClientGroupFooterTemplate("Total Amount: \\#=sum\\#")
.ClientGroupFooterTemplate("Count: \\#=count\\#")
...