Telerik MVC Grid - 仅当行数 > 时才显示客户端页脚模板0
我在我的 asp.net MVC3 应用程序中使用 Telerik 2011 Q2 MVC Grid。在我的一个页面中,我有一个网格,我试图在网格上显示页脚。网格以 Ajax 模式绑定。这是我正在使用的代码
@(Html.Telerik().Grid<MatrixDetail>()
.Name("tlkLocalityMatrixGrid")
.DataBinding(db => db.Ajax().Select("_LocalityMatrix", "Matrix"))
.Columns(col => {
col.Bound(m => m.Name).Title("Locality/BloodGroup").Width(200)
.Sortable(false);
col.Bound(m => m.A_PositiveCount).Title("A+ve")
.Sortable(false);
...
col.Bound(m => m.Total).Title("Total").Width(100).Aggregate(aggr => aggr.Sum())
.ClientFooterTemplate("<# if(Count > 0) { $.telerik.formatString('{0:n}', Sum); } #>")
.Format("{0:n}");}))
从代码中可以看出,我尝试使用客户端页脚模板显示聚合(总计)。我的要求是仅当网格的行数大于 0 时才显示总计。否则页脚中的总计应为空白。所以我使用“计数”和“求和”来实现该功能。当我第一次加载网格时,它是空的,并且“总计”页脚按预期显示为空白。然而,在用户进行一些更改后,我用数据重新加载网格,但 JQuery 抱怨 “ReferenceError:未定义计数”
如何让 ClientFooterTemplate 显示页脚(在本例中为“总计”)仅当网格有一些行时。如果我仅在 ClientFooterTemplate 中指定“<#= Sum #>
”,则如果网格没有行,页脚仍显示 0。
I am using Telerik 2011 Q2 MVC Grid in my asp.net MVC3 application. In one of my pages I have a Grid and I am trying to display Footer on the Grid. The Grid is bound in Ajax Mode. Here is the code that I am using
@(Html.Telerik().Grid<MatrixDetail>()
.Name("tlkLocalityMatrixGrid")
.DataBinding(db => db.Ajax().Select("_LocalityMatrix", "Matrix"))
.Columns(col => {
col.Bound(m => m.Name).Title("Locality/BloodGroup").Width(200)
.Sortable(false);
col.Bound(m => m.A_PositiveCount).Title("A+ve")
.Sortable(false);
...
col.Bound(m => m.Total).Title("Total").Width(100).Aggregate(aggr => aggr.Sum())
.ClientFooterTemplate("<# if(Count > 0) { $.telerik.formatString('{0:n}', Sum); } #>")
.Format("{0:n}");}))
As can be seen from the code, I am trying to display aggregate (Total) using Client Footer Template. My requirement is to display the Total only if the row Count of the Grid is greater than 0. Otherwise the Total in the footer should be blank. So I was using the "Count" and "Sum" to achieve the functionality. When I first load the grid it is empty and the "Total" Footer displays blank as expected. However after user makes some changes I reload the grid with data, but the JQuery complains that "ReferenceError: Count is not defined"
How do I get ClientFooterTemplate to display the footer ("Total" in this case) only when the grid has some rows. If I only specify "<#= Sum #>
" in the ClientFooterTemplate, then if the Grid has no rows the Footer still displays 0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了一些问题。首先,需要在 col.Bound(m => m.Total).Title("Total").Width(100).Aggregate(aggr => aggr.Sum()) 处指定 Count 聚合。因此,将上面的行更改为后,
我可以在 javascript 中访问 Count 变量。其次,客户端页脚模板需要如下所示。
一切都运转良好。
问候,
涅槃。
There were a couple of things that I was having problem with. Firstly, the Count aggregate needs to be specified at col.Bound(m => m.Total).Title("Total").Width(100).Aggregate(aggr => aggr.Sum()). So the after changing the above line to
I had Count variable in the javascript accessible. Secondly, the Client footer template needs to be as given below.
and it all works well.
regards,
Nirvan.