Summary of "time" column
Hello,
how to make summary of column which contains time in format HH:mm:ss?
Time is formatted through SQL query as result of some calculations.
SIGN IN To post a reply.
7 Replies
SN
Sindhu Nagarajan
Syncfusion Team
June 27, 2018 12:50 PM UTC
Hi Josip,
Thanks for your interest in Syncfusion products.
We are able to understand your requirement. By default, GridGroupingControl does not have direct support to calculate summary (aggregate functions) for DateTime values. However, the reported scenario can be achieved by writing custom summary inherited from SummaryBase class. We have prepared a simple sample as per your requirement. In the attached sample, we have added summary to calculate the total time of the column. Please refer to the below code and sample,
Code Snippet
|
class DateTimeSummary : SummaryBase
{
public static ITreeTableSummary CreateSummaryMethod(SummaryDescriptor summaryDescriptor, Record record)
{
object obj = summaryDescriptor.GetValue(record);
bool isNull = (obj == null || obj is DBNull);
if (isNull)
return Empty;
else
{
return new DateTimeSummary(obj.ToString());
}
}
public DateTimeSummary Combine(DateTimeSummary other)
{
TimeSpan s1;
TimeSpan s2;
TimeSpan.TryParse(this.Total, out s1);
TimeSpan.TryParse(other.Total, out s2);
TimeSpan s3 = s1.Add(s2);
return new DateTimeSummary(s3.ToString());
}
}
private void GridGroupingControl1_QueryCustomSummary(object sender, GridQueryCustomSummaryEventArgs e)
{
if( e.SummaryColumn.Name== "TotalTimeSpan")
{
e.SummaryDescriptor.CreateSummaryMethod = new CreateSummaryDelegate(DateTimeSummary.CreateSummaryMethod);
}
} |
Please let us know if you have any other queries.
Regards,
Sindhu
Hi Josip,
Thanks for your interest in Syncfusion products.
We are able to understand your requirement. By default, GridGroupingControl does not have direct support to calculate summary (aggregate functions) for DateTime values. However, the reported scenario can be achieved by writing custom summary inherited from SummaryBase class. We have prepared a simple sample as per your requirement. In the attached sample, we have added summary to calculate the total time of the column. Please refer to the below code and sample,
Code Snippet
class DateTimeSummary : SummaryBase{public static ITreeTableSummary CreateSummaryMethod(SummaryDescriptor summaryDescriptor, Record record){object obj = summaryDescriptor.GetValue(record);bool isNull = (obj == null || obj is DBNull);if (isNull)return Empty;else{return new DateTimeSummary(obj.ToString());}}public DateTimeSummary Combine(DateTimeSummary other){TimeSpan s1;TimeSpan s2;TimeSpan.TryParse(this.Total, out s1);TimeSpan.TryParse(other.Total, out s2);TimeSpan s3 = s1.Add(s2);return new DateTimeSummary(s3.ToString());}}private void GridGroupingControl1_QueryCustomSummary(object sender, GridQueryCustomSummaryEventArgs e){if( e.SummaryColumn.Name== "TotalTimeSpan"){e.SummaryDescriptor.CreateSummaryMethod = new CreateSummaryDelegate(DateTimeSummary.CreateSummaryMethod);}}
Please let us know if you have any other queries.
Regards,Sindhu
Colud you check sample link, I have problem with downloding it.
SN
Sindhu Nagarajan
Syncfusion Team
June 28, 2018 05:00 AM UTC
Hi Josip,
Sorry for the inconvenience caused.
Please find the sample from the below link,
Sample Link: GridGroupingControlSample
Regards,
Sindhu
Hi Josip,
Sorry for the inconvenience caused.
Please find the sample from the below link,
Sample Link: GridGroupingControlSample
Regards,Sindhu
Thank you! It's working now.
Just one more question; I'm trying to convert result in format to show only hours minutes and seconds on this way:
TimeSpan s1;
TimeSpan s2;
TimeSpan.TryParse(this.Total, out s1);
TimeSpan.TryParse(other.Total, out s2);
TimeSpan s3 = s1.Add(s2);
string retVal = string.Format("{0}hr {1}mn {2}sec",
(int)s3.TotalHours,
s3.Minutes,
s3.Seconds);
TimeSpan s2;
TimeSpan.TryParse(this.Total, out s1);
TimeSpan.TryParse(other.Total, out s2);
TimeSpan s3 = s1.Add(s2);
string retVal = string.Format("{0}hr {1}mn {2}sec",
(int)s3.TotalHours,
s3.Minutes,
s3.Seconds);
return new DateTimeSummary(retVal);
But as result I get only 00:00:00
So if the result is two day I want to show as 48:00:00
MG
Mohanraj Gunasekaran
Syncfusion Team
July 3, 2018 01:13 PM UTC
Hi Josip,
Thanks for your update.
In order to display the total hours instead of days in summary cell, you can use the QueryCellStyleInfo event to make this kind of changes. Please refer to the below code example and the sample,
Code example
|
this.gridGroupingControl1.QueryCellStyleInfo += GridGroupingControl1_QueryCellStyleInfo;
private void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
if (e.Style.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.Summary && e.Style.TableCellIdentity.SummaryColumn != null && e.Style.TableCellIdentity.SummaryColumn.DisplayColumn == "Date")
{
TimeSpan time;
if (TimeSpan.TryParse(e.Style.CellValue.ToString(), out time))
{
e.Style.CellValue = String.Format("{0}:{1}:{2}", Convert.ToInt16(time.TotalHours), time.Minutes, time.Seconds);
}
}
} |
Sample link: GridGroupingControl
Regards,
Mohanraj G
JO
Josip
July 4, 2018 07:00 PM UTC
This is it! Thank you very much!
MG
Mohanraj Gunasekaran
Syncfusion Team
July 5, 2018 04:15 AM UTC
Hi Josip,
Thanks for your update.
We are glad to know that your reported problem has resolved.
Please let us know if you have any concerns.
Regards,
Mohanraj G
SIGN IN To post a reply.
- 7 Replies
- 3 Participants
-
JO Josip
- Jun 26, 2018 09:56 PM UTC
- Jul 5, 2018 04:15 AM UTC