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

Grouping by 3 columns, but showing sum of another columsn only once

1 Answer 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vivido
Top achievements
Rank 1
Vivido asked on 09 Jan 2015, 02:08 PM
Hi all,
I'm building a grid where I group my data by 3 columns, but I show the sum of another column as ClientGroupFooterTemplate. Here some code snippet
Inside data source:
                .Group(gr =>
                    {
                        gr.Add(p=> p.Finality);
                        gr.Add(p=> p.Task);
                        gr.Add(p=> p.Session);
                    }
                )
                .Aggregates(aggr =>
                    {
                        aggr.Add(p => p.Duration).Sum();
                    })

Inside .Columns
//previous columns code
columns.Bound(c => c.Duration).Title("Duration (h)").Width(150).ClientGroupFooterTemplate("Sum: #=sum#");
//following columns code

but when grid displays the data it shows the Sum at the end of every grouping (Finality, Task and Session)
I want to diplay it only for Session, how can I accomplish that?

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 13 Jan 2015, 02:08 PM
Hello,

This is not supported by the grid. The template will be rendered for each group. It should be possible to use a condition that checks if the template is rendered for the Session group and show the value only in this case. If you are using server side operations then this can be achieved by checking the template item parent e.g.
.ClientGroupFooterTemplate("#: sessionFooter(data)#")
function sessionFooter(data) {   
    if (data.parent().field == "Session") {
        return "Sum: " + data.Duration.sum;
    }
 
    return "";
}

For client-side operations you will need to iterate over the summary group items in the dataSource change or in the grid dataBinding events and set a a field that indicates whether the value should be rendered to the Duration aggregates.

Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Vivido
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or