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

[Solved] Displaying percentage value of total using aggregates

1 Answer 28 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.
Carlos
Top achievements
Rank 1
Carlos asked on 22 Mar 2012, 04:09 PM
I'm trying to configure a grid to group my data based on a column and using aggregates to display the count of items for each group. I'm also showing the total count in the grid footer. I got that part working, but now I would like to show on the group footer what percentage of the total the current group count represents. So, for example, if the total count displayed in the grid footer shows that there are four records and I have a group that shows on its group footer that there are two records, I would like to show the value 50% next to the item.count for that group. 

Is this even possible? Has anyone achieved this? Any ideas would be greatly appreciated.

Below is the code I'm using to declare my grid:

@(Html.Telerik().Grid(Model)
    .Name("ReportGrid")
    .Columns(columns =>
    {
        columns.Bound(t => t.MainID);
        columns.Bound(t => t.Problem.ProblemTitle)
            .Aggregate(aggregates => aggregates.Count())
            .GroupFooterTemplate(@<text>Count: @item.Count (<<calculate the percentage value here>>% of total)</text>)
            .FooterTemplate(@<text>Count: @item.Count</text>);
    
        columns.Bound(t => t.ProblemSubCategory.ProblemSubCategoryTitle);
        columns.Bound(t => t.DateOpen);
        columns.Bound(t => t.DateClosed);
    })
    .Sortable()
    .Groupable(settings => 
    {
        settings.Groups(groups => 
        {
            groups.Add(t => t.Problem.ProblemTitle);
        })
        .Visible(true);
    })
    .Filterable()
)

Thanks,
Carlos.


1 Answer, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 27 Mar 2012, 02:46 PM
Hello Carlos,

This is not supported and there is no access to the total count in the GroupFooterTemplate as it is calculated later. You could use the OnLoad client-side event to calculate the percentage and replace the text e.g.
columns.Bound(t => t.Problem.ProblemTitle).Aggregate(agg=>agg.Count())
.FooterTemplate(@<text>Total :<span class='totalCount'>@item.Count</span></text>)
.GroupFooterTemplate(@<text> Count :<span class='count'>@item.Count</span></text>);
function onLoad() {
    var totalElement = $(this).find('.totalCount');       
    if (totalElement.length > 0) {
        var total = parseInt(totalElement.text());
        $('.count').each(function () {
            $(this).text(parseInt($(this).text()) / total);
        });
    }
}


All the best,
Daniel
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
Carlos
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or