|
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);
}
} |
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,
Sorry for the inconvenience caused.
Please find the sample from the below link,
Sample Link: GridGroupingControlSample
Regards,Sindhu
|
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);
}
}
} |