1
votes

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.

1

1 Answers

4
votes

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

col.Bound(m => m.Total).Title("Total").Width(100).Aggregate(aggr => aggr.Sum().Count()) 

I had Count variable in the javascript accessible. Secondly, the Client footer template needs to be as given below.

.ClientFooterTemplate("<# if (Count > 0) {#>" + "<#= $.telerik.formatString('{0:n}', Sum) #>" + "<# } #>")

and it all works well.

regards, Nirvan.