Telerik MVC网格页脚模板

时间:2012-11-06 21:51:42

标签: telerik-grid

我有一个telerik网格,并希望自定义页脚模板,使计数正好在这样的总和下:

总计:$ XXXXXXX 数:XXXXX

@model List

@(Html.Telerik()。网格(模型)     .NAME( “GRD”)     .NoRecordsTemplate(“”)

.Resizable(resizing => resizing.Columns(false))
.Scrollable(c => c.Enabled(true).Height(300))

.Footer(false)
.Columns(columns =>
{
columns.Bound(o => o.Number)
    .Aggregate(ag => ag.Count());

columns.Bound(o => o.TotalCost)
    .Aggregate(ag => ag.Sum())
    .ClientFooterTemplate(
        "<div>Total: <#= $.telerik.formatString('{0:c}', Sum) #></div>" 
    );
})
.DataBinding(db => db.Ajax().Select("getList", "Home"))
.Pageable()
.Scrollable()
.Footer(true)

.HtmlAttributes(new { @class = ".t-grid .t-status" })

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您可以尝试以下方法。请注意,这是未经测试的:

.Resizable(resizing => resizing.Columns(false))
.Scrollable(c => c.Enabled(true).Height(300))
.DataBinding(db => db.Ajax().Select("getList", "Home"))
.Pageable()
.Columns(columns =>
{
columns.Bound(o => o.Number)
    .Aggregate(ag => ag.Count())
    .FooterTemplate(result => (result.Count == null ? "0" : result.Count.Format("{0:N0}")));

columns.Bound(o => o.TotalCost)
    .Aggregate(ag => ag.Sum())  
    .FooterTemplate(result => (result.Sum == null ? "0.00" : result.Sum.Format("{0:N2}")));
})

如果您希望在同一列下方的页脚上看到Sum和Count:

.NoRecordsTemplate("No records available!")
.Resizable(resizing => resizing.Columns(false))
.Scrollable(c => c.Enabled(true).Height("auto"))
.DataBinding(db => db.Ajax().Select("getList", "Home"))
.Pageable()
.Columns(columns =>
{       
    columns.Bound(o => o.TotalCost)
        .HtmlAttributes(new { style = "text-align:right" })
        .Format("{0:N2}")
        .Aggregate(ag => ag.Sum().Count())
        .FooterHtmlAttributes(new { style = "text-align:right" })
        .FooterTemplate(result => string.Format("Total: ${0:N2}, Count: {1:N0}", result.Sum , result.Count))
        .Width(60);     
})