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

[Solved] Problem with Count Aggregate in ClientGroupFooterTemplate

6 Answers 56 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.
Zack
Top achievements
Rank 1
Zack asked on 06 Jun 2012, 06:02 PM
I'm having trouble with the ClientGroupFooterTemplate. When I choose a column to group by, it seems that there is some AJAX-related error with resolving the Count aggregate.

@{Html.Telerik().Grid<Inventory>()
              .Name("InventoryGrid")
              .ToolBar(commands => commands
                                       .Custom()
                                       .HtmlAttributes(new { id = "export" })
                                       .Text("Export to CSV")
                                       .Action("ExportCsv", "Order", new { page = 1, orderBy = "~", filter = "~" })
              )
              // bind operations using ajax
              .EnableCustomBinding(true)
              .ClientEvents(events => events.OnDataBinding("onDataBinding"))
              .ClientEvents(events => events.OnDataBound("onDataBindingForCSV"))
              .DataBinding(bind => bind.Ajax().Select("ListInventoryAjax", "Order"))
              .Columns(columns =>
                           {
                               columns.Bound(i => i.Model)
                                   .Title("Model")
                                   .Width(40)
                                   .Aggregate(aggregates => aggregates.Count())
                                   .ClientGroupFooterTemplate("Count: <#= Count #>");   
                               columns.Bound(i => i.RegionId).Title("Region").Width(40);
                               columns.Bound(i => i.DealerName).Title("Dealer").Width(40);               
                               columns.Bound(i => i.Product).Title("Product").Width(40);
                               columns.Bound(i => i.OrderNumber).Title("Order #").Width(40);
                               columns.Bound(i => i.SerialNumber).Title("Serial #").Width(40);
                               columns.Bound(i => i.Detail).Title("Detail").Width(40);
                               columns.Bound(i => i.ShipDate).Title("Shipped").Width(40);
                           })
              .Groupable()
              .Selectable()
              .Sortable()
              .Pageable(paging => paging.PageSize(20))
              .Render();
        }

When I try to drag in a field to group by (Model, for instance), a WebPage error is returned ('Count' is undefined).

The Developer Tools debugger in IE shows the error at line 2 (in bold):

function anonymous(data) {
   var p=[];with(data){p.push('Count: ', Count ,'');}return p.join('');
}

If I use the ClientFooterTemplate instead, it does not error at runtime but it displays the count (although it shows "0" which is incorrect).

6 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 11 Jun 2012, 06:58 AM
Hello Zack, 

This error will be thrown if the parameter is missing from the data. Are the aggregates calculated in your custom binding implementation? If yes, the problem could be caused by the format in which the data is returned from the server.

Regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Zack
Top achievements
Rank 1
answered on 12 Jun 2012, 07:00 PM

To my knowledge, the aggregates are not calculated or changed in the custom binding implementation.

In other words, in the ListInventoryAjax method, nothing is done with the GridCommand command.Aggregates IList<AggregateDescriptor>.

ListInventoryAjax does use the command.GroupDescriptors and command.SortDescriptors, and returns this:

return View(new GridModel
{
    Data = entityGroup,
    Total = total
});
0
Daniel
Telerik team
answered on 14 Jun 2012, 01:03 PM
Hello again Zack,

The aggregates should be implemented along with the other operations in order to use them when custom binding is enabled. The alternative is to disable the custom binding and use the built-in operations.

Kind regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Zack
Top achievements
Rank 1
answered on 14 Jun 2012, 01:21 PM
Thanks for that. I need to use the custom binding in this case. That said, how do I implement the aggregates in this scenario? Can you point me toward some examples or other documentation?
0
Daniel
Telerik team
answered on 15 Jun 2012, 01:22 PM
Hello Zack,

We don't have any official examples and documentation on how to implement aggregates when using custom binding. I attached a sample project to this thread which shows a basic implementation of aggregates and the structure in which the Grid will expect the result. I hope it helps.

All the best,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Zack
Top achievements
Rank 1
answered on 18 Jun 2012, 05:02 PM
Thanks. I looked at the code but still couldn't get it to fit what I was trying to do.

Anyway, for now I've disabled custom binding and I'm able to use the ClientGroupFooterTemplate.
Tags
Grid
Asked by
Zack
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Zack
Top achievements
Rank 1
Share this question
or