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

Sum different column in aggregate header

1 Answer 97 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.
Martin
Top achievements
Rank 1
Martin asked on 25 Mar 2011, 03:50 PM
Using the MVC Grid is it possible to aggregate by 1 column, say project, and in the group header show the sum of a different column. So, in the example code below, we are grouping by 3 fields, the first being project. In the header of each group we want to show the total of the JobValues for the children of that group. There's a screen shot attached as well, in the screenshot the headers for "Project: Test 1616", "Language" and "Task Type" would each display the totals for their children.

<%= Html.Telerik().Grid<InvoiceLines>()

        .Name("Quotes")

        .Columns(columns =>

        {

            columns.Bound(c => c.ExternalDescription);

 

            columns.Bound(o => o.JobValue)

                .HeaderTemplate(h => { return "Value"; })

                .Aggregate(a => a.Sum())

                .ClientGroupFooterTemplate("<#=Sum#>")

                .Format("{0:C}")                                

                .Width(0);

 

            columns.Bound(o => o.InvoiceLineValue)

                .HeaderTemplate(h => { return "Value"; })                

                .Aggregate(a => a.Count())

                .ClientGroupFooterTemplate("<#=Sum#>")

                .Format("{0:C}")

                .Width(0);

 

            columns.Bound(o => o.SubmissionInvoiceLineValue)

                .HeaderTemplate(h => { return "Value"; })

                .Aggregate(a => a.Sum())

                .ClientGroupFooterTemplate("<#=Sum#>")

                .Format("{0:C}")

                .Width(0);

        })

        .DetailView(detailView => detailView.ClientTemplate(

                ""

        ))

        .DataBinding(dataBinding => dataBinding.Ajax()

            .Select("_GetInvoiceLines""Quotes"new { quoteId = Model.Quote.QuoteId }))

            .Groupable(settings =>

                settings.Groups(groups =>

                {

                    groups.Add(g => g.Project);

                    groups.Add(g => g.Language);

                    groups.Add(g => g.TaskType);

                })

                .Visible(false))

%>

The idea is that you can see the total of the children without having to expand the group. Placing the values in the footer doesn't work as the footer is only visible when the group is expanded.

Thanks for any help offered

1 Answer, 1 is accepted

Sort by
0
SEAN
Top achievements
Rank 1
answered on 31 Oct 2011, 12:43 AM
Any update on this? I'd also like to use the aggregate values in a calculation in the group header, for example if I grouped by a product category I'd like to get the sum of a price column and the sum of a units column, and then in the group header I'd like to show the sum of the prices divided by the sum of the units.

Sean
Tags
Grid
Asked by
Martin
Top achievements
Rank 1
Answers by
SEAN
Top achievements
Rank 1
Share this question
or