【问题标题】:Kendo Grid Aggregation for Footer页脚的 Kendo 网格聚合
【发布时间】:2013-12-07 09:49:53
【问题描述】:

我正在尝试将列的总和显示为页脚。按照官方的剑道 UI 演示,我的代码如下:

@(Html.Kendo().Grid<ORMIModel.Content.ContentPurchase.CheckoutListModel>()
.Name("grid")
.Columns(columns =>
{
    columns.Bound(p => p.ContentId).ClientTemplate("<a href='javascript:void(0);' onclick='RemoveFromCart(#=ContentId#)'>#=CategoryName#</a>").Width(50).Sortable(true);
    columns.Bound(p => p.CategoryName).Width(140).Sortable(true);
    columns.Bound(p => p.ModelYear).Width(100).Sortable(true);
    columns.Bound(p => p.PurchasePeriod).Width(100).Sortable(true);
    columns.Bound(p => p.PurchasePeriodCount).Width(50).Sortable(true);
    columns.Bound(p => p.FeeFormatted).Width(50).Sortable(true).ClientFooterTemplate("#=sum#");
})
.Sortable()
.ClientDetailTemplateId("detailTemplate")
.Events(v => v.DetailExpand("detailExpand"))
.DataSource(dataSource => dataSource
    .Ajax()
            .Aggregates(v => { v.Add(p => p.Fee).Sum(); })
    .Read(read => read.Action("ListContentForCheckout", "Content"))                   
)

如上所示,我正确定义了聚合字段,并将其作为 #=sum# 应用到我最后一列的 clientFooterTemplate。

但是,我收到“未捕获的 ReferenceError:未定义总和”的错误

我的数据源也有费用属性。知道我做错了什么吗?

【问题讨论】:

    标签: asp.net-mvc-4 kendo-ui kendo-grid


    【解决方案1】:

    我相信这是您的专栏造成的:

    columns.Bound(p => p.FeeFormatted).Width(50).Sortable(true).ClientFooterTemplate("#=sum#");
    

    FeeFormatted 属性为目标,但总和聚合是针对 p.Fee 属性进行处理的。

    尝试更改列

        columns.Bound(p => p.FeeFormatted).Width(50).Sortable(true).ClientFooterTemplate("#=sum#");
    

        columns.Bound(p => p.Fee).Width(50).Sortable(true).ClientFooterTemplate("#=sum#");
    

    看看它是否有效。然后使用网格列 .Format 属性引入所需的费用值格式

    【讨论】:

    • 您好 Ancalagon,感谢您的回复。我已经按照您的建议进行了更改,现在它可以工作了。没想到我需要将页脚准确地放置在聚合字段中。但是现在还有另一个奇怪的问题,假设我只有 1 行,它的费用值为 5.00。但是我的页脚(费用总和)显示 0(零)。有什么想法吗?
    【解决方案2】:

     .Aggregates(aggregates =>
                                {
                                    aggregates.Add(c => c.MrcPerUnit).Sum();
    
                                })
    
    // it works with my own application

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多