This question is locked. New answers and comments are not allowed.
I want to get at some of the aggregates in a grid to use them in calculations on my page and I have found that there are two arrays dataSource._data and dataSource._view in the grid object that have all the data including the group aggregates. Is there any reason why I should not get the values from one of them - they are not in any documentation that I've found. I can't tell what the difference is between them, so can anyone provide some guidance as to which one to use and why?
If it is not recommended to use that array to get the group level aggregates, what should I do to get them?
Thanks
Sean
If it is not recommended to use that array to get the group level aggregates, what should I do to get them?
Thanks
Sean
5 Answers, 1 is accepted
0
Hello Sean,
_data and _view are reserved for internal use only and should not be used. Could you please provide more details on what exactly you want to achieve and what is your real scenario?
Best wishes,
Georgi Tunev
the Telerik team
_data and _view are reserved for internal use only and should not be used. Could you please provide more details on what exactly you want to achieve and what is your real scenario?
Best wishes,
Georgi Tunev
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

SEAN
Top achievements
Rank 1
answered on 04 Nov 2011, 12:19 AM
What I want to do is create an expression using the group aggregates - so for example in the MVC Grid Demos, in the Ajax Aggregates demo, how would I display the average Unit Price multiplied by the average Units On Order in the group header or footer and the grid footer.
Thanks
Sean
Thanks
Sean
0
Accepted
Hello Sean,
Grid does not support that out of the box and it is a bit complicated to achieve. Here is one way to do it:
Kind regards,
Georgi Tunev
the Telerik team
Grid does not support that out of the box and it is a bit complicated to achieve. Here is one way to do it:
<
asp:Content
ContentPlaceHolderID
=
"maincontent"
runat
=
"server"
>
<%= Html.Telerik().Grid<
Product
>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(o => o.ProductName)
.Aggregate(aggregates => aggregates.Count())
.ClientFooterTemplate("Total Count: <#= Count #>")
.ClientGroupFooterTemplate("Count: <#= Count #>");
columns.Bound(o => o.UnitPrice)
.Width(200)
.Aggregate(aggreages => aggreages.Sum().Average())
.Format("{0:c}")
.ClientFooterTemplate("Total Sum: <#= $.telerik.formatString('{0:c}', Sum) #>")
.ClientGroupFooterTemplate("Sum: <#= $.telerik.formatString('{0:c}', Sum) #>");
columns.Bound(o => o.UnitsOnOrder)
.Width(200)
.Aggregate(aggregates => aggregates.Average())
.ClientFooterTemplate("Average: <#= Average #>")
.ClientGroupFooterTemplate("Average: <#= Average #>");
columns.Bound(o => o.UnitsInStock)
.Width(100)
.Aggregate(aggregates => aggregates.Count().Min().Max())
.ClientFooterTemplate(
"<
div
>Min: <#= Min #></
div
>" +
"<
div
>Max: <#= Max #></
div
>"
)
.ClientGroupHeaderTemplate("<#var value = calcTemplate();#> <#= value#>");
})
.DataBinding(dataBinding => dataBinding.Ajax().Select("AggregatesAjax_Select", "Grid"))
.Sortable()
.Pageable()
.Groupable(settings => settings.Groups(groups => groups.Add(o => o.UnitsInStock)).Visible(false))
.ClientEvents(events=>events.OnDataBound("grid_bound"))
%>
<
script
>
var counter = 0;
function grid_bound() {
counter = 0;
}
function calcTemplate() {
var gridData = $("#Grid").data("tGrid").dataSource.data(),
aggregates = gridData[counter++].aggregates;
return aggregates["UnitPrice"]["Average"] * aggregates["UnitsOnOrder"]["Average"];
}
</
script
>
Kind regards,
Georgi Tunev
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

SEAN
Top achievements
Rank 1
answered on 07 Nov 2011, 12:51 AM
Thanks Georgi,
That's pretty much what I was thinking and you filled in the blanks for me :-) Very helpful because I can use that to get any aggregate value from the data and use it in the group header or footer however I want to.
I found that in the group header I could also use the Key as a parameter to the function and then use it to filter the data array to get the group (rather than maintaining the counter) - it would be very handy to have the group index available in the header and footer client templates like the Key, and is there any reason why Key is only available in the group header.
One more thing, is there documentation of the client side dataSource property - it seems like it is very rich in functionality?
Sean
That's pretty much what I was thinking and you filled in the blanks for me :-) Very helpful because I can use that to get any aggregate value from the data and use it in the group header or footer however I want to.
I found that in the group header I could also use the Key as a parameter to the function and then use it to filter the data array to get the group (rather than maintaining the counter) - it would be very handy to have the group index available in the header and footer client templates like the Key, and is there any reason why Key is only available in the group header.
One more thing, is there documentation of the client side dataSource property - it seems like it is very rich in functionality?
Sean
0
Hi Sean,
Georgi Tunev
the Telerik team
Basically, currently you can use only the public API that is already documented. We may expose richer API in the future.
Georgi Tunev
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