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

Client API internals

5 Answers 37 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.
SEAN
Top achievements
Rank 1
SEAN asked on 03 Nov 2011, 03:33 AM
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

5 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 03 Nov 2011, 03:53 PM
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
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
0
Accepted
Georgi Tunev
Telerik team
answered on 04 Nov 2011, 03:09 PM
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:

<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
0
Georgi Tunev
Telerik team
answered on 09 Nov 2011, 01:29 PM
Hi Sean,

Basically, currently you can use only the public API that is already documented. We may expose richer API in the future.

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
Tags
Grid
Asked by
SEAN
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
SEAN
Top achievements
Rank 1
Share this question
or