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

2 posts, 0 answers
  1. Vivido
    Vivido avatar
    3 posts
    Member since:
    Jan 2015

    Posted 09 Jan 2015 Link to this post

    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?

  2. Daniel
    Admin
    Daniel avatar
    2231 posts

    Posted 13 Jan 2015 Link to this post

    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.

     
Back to Top