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

AggregateExpression cast SUM(minutes) to TimeSpan

1 Answer 377 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Troy
Top achievements
Rank 1
Troy asked on 19 Sep 2014, 08:55 PM
Hi all,
I've got a column containing Minutes as an integer.  I'm trying to sum this and format it as a Time Span like hh:mm (no seconds or days).
I'm not too familiar with the AggregateExpression strings.
Is there a way to cast that aggregate into a timespan, either during or after the sum from within the expression?

I've got a group summary and a grand total that this needs to appear on.

 
summaryItem.Name = "TimeWorked"
summaryItem.AggregateExpression = "SUM(MinutesWorked)"
summaryItem.FormatString = "{0:hh}:{0:mm} = {0}"

TimeWorked column - string value formatted by database in hh:mm format
MinutesWorked column - integer value  - need Timespan.FromMinutes(...)
FormatString - the ' = {0}' at the end is for checking the value of the sum.

Currently, for example:     hh:mm = 2239
Hoping for:                        37:19 = 2239

Or is tackling this in the expression not possible? 
Or maybe as it loads into the column?
I've tried/am trying events also but hoping the 3 lines of code is do-able...

Thanks

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 24 Sep 2014, 12:58 PM
Hello Troy,

Thank you for writing.

In this case you should use the GroupSummaryEvaluate event and convert the sum to time span manually:
void radGridView1_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
{
    if (e.SummaryItem.Name == "TimeWorked")
    {
        TimeSpan span = TimeSpan.FromMinutes((long)e.Value);
        e.FormatString = String.Format("{0}:{1}", span.Hours, span.Minutes);
         
    }
}

Let me know if you have additional questions.
 
Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Troy
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or