This is a migrated thread and some comments may be shown as answers.

Grid Aggregate Doesn't Work

3 Answers 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kevin
Top achievements
Rank 1
Kevin asked on 21 Jul 2011, 07:29 PM
I have looked at lot of examples of how to do a aggregate summary for a grid.  Unfortunately, none the examples I tried to implement, work for me.  One of the them comes close.  For like $5000 in sales, I get a aggregate sum of $50.  Why that's happening, I have no idea.  Here is the code I have:

columns.Bound(j => j.TotalValue).Width(100).Format("{0:c}").HeaderHtmlAttributes(new { style = "text-align: right;" }).HtmlAttributes(new { style = "text-align: right;" })
       .Aggregate(aggregates => aggregates.Sum())
       //.ClientFooterTemplate("<div>Total Price: <#= Sum#></div>");
       //FooterTemplate(@<text>Total: @item.Sum.Format("{0:c}")</text>);         
       //.ClientFooterTemplate("<div>Total Price: <#= $.telerik.formatString('{0:0.0000}', Sum * 1000)#></div>");
       .ClientFooterTemplate("<div>Total Price: <#= $.telerik.formatString('{0:c}', Sum)#></div>");

I'm out of ideas here.  Any help would be greatly appreciated.  I am using John DeVight's code to build dynamic tabs with partial views:
Telerik MVC : jQuery.ajax, Partial View and the Telerik Grid:
http://www.aspnetwiki.com/page:jquery-ajax-partial-view-and-the-telerik-grid

Steve

3 Answers, 1 is accepted

Sort by
0
John DeVight
Top achievements
Rank 1
answered on 22 Jul 2011, 03:20 PM
Hey Steve,

I haven't been able to figure out any problems with your code.  Attached is a sample project based on the Telerik MVC : jQuery.ajax, Partial View and the Telerik Grid article.  A partial view is retrieved from the server using jQuery.ajax and rendered into a Tab that is dynamically added to the TabView.  The Partial View contains a Grid that loads the data via Ajax and has a client footer template.  Maybe take a look at it and see if you can find any differences between the sample project and what you are doing.  Sorry I couldn't do more =(

Regards,

John
0
Kevin
Top achievements
Rank 1
answered on 04 Aug 2011, 07:57 PM
John, 
I am having all kinds of issues with grid aggregates.  Your example works, however, when you remove all items from your grid:

private IList<WikiPage> GetWikiPageList()
{
    IList<WikiPage> list = new List<WikiPage>();
    //list.Add(new WikiPage { Id = 1, Title = "Telerik MVC : Creating an \"ExtJS border-layout\" with Splitters", Url = "http://aspnet.wikidot.com/telerik-mvc:creating-an-extjs-border-layout-with-splitters", PageViews = 100, DateCreated = new DateTime(2011, 5, 11) });
    //list.Add(new WikiPage { Id = 2, Title = "Telerik MVC : Resizing Controls Within Splitter Panes", Url = "http://aspnet.wikidot.com/telerik-mvc:resizing-controls-within-splitter-panes", PageViews = 200, DateCreated = new DateTime(2011, 5, 12) });
    //list.Add(new WikiPage { Id = 3, Title = "Telerik MVC : Dynamically Add a Tab to the TabStrip", Url = "http://aspnet.wikidot.com/telerik-mvc:dynamically-add-a-tab-to-the-tabstrip", PageViews = 300, DateCreated = new DateTime(2011, 5, 12) });
    //list.Add(new WikiPage { Id = 4, Title = "Telerik MVC : jQuery.ajax, Partial View and the Telerik Grid", Url = "http://aspnet.wikidot.com/telerik-mvc:jquery-ajax-partial-view-and-the-telerik-grid", PageViews = 400, DateCreated = new DateTime(2011, 5, 14) });
    //list.Add(new WikiPage { Id = 5, Title = "Telerik MVC : Creating Standard MessageBox Dialogs", Url = "http://aspnet.wikidot.com/telerik-mvc:creating-generic-messagebox-dialogs", PageViews = 500, DateCreated = new DateTime(2011, 5, 11) });
    //list.Add(new WikiPage { Id = 6, Title = "Telerik MVC : Extending the Telerik Extensions for ASP.NET MVC", Url = "http://aspnet.wikidot.com/telerik-mvc:extending-the-telerik-extensions-for-asp-net-mvc", PageViews = 600, DateCreated = new DateTime(2011, 5, 11) });
    return list;
}

Your grid will get an "Microsoft JScript runtime error: Object required". 

I am getting the exact same error in my project when I have zero records in my grid.  I have not been able to find a work around for this.

Steve
0
Kevin
Top achievements
Rank 1
answered on 04 Aug 2011, 10:25 PM
John, 
There was a bug with the grid footer aggregate functions with empty grids.  It was fixed in the Q2 release.

http://www.telerik.com/community/forums/aspnet-mvc/grid/empty-collection-causes-jscript-exception-when-using-ajax-binding-with-aggregate.aspx


Steve
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
John DeVight
Top achievements
Rank 1
Kevin
Top achievements
Rank 1
Share this question
or