0

我有一个 Telerik 网格,并希望以这样的方式自定义页脚模板,使计数正好在总和之下,如下所示:

总计:$XXXXXXX 计数:XXXX

@model 列表

@(Html.Telerik().Grid(Model).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" })

)

谢谢你的帮助。

4

1 回答 1

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);     
})
于 2012-11-12T16:11:19.460 回答