Ho to set custom Format string for Custom GridSummaryColumn for TimeSpan type ?

Hi,

I'm not able to corretly set the custom Format string for GridSummaryColumn on a column of type TimeSpan


I've defined the following custom aggregate:


    public class CustomAggregate : ISummaryAggregate
    {
        public Action<IEnumerable, string, PropertyDescriptor> CalculateAggregateFunc()
        {
            return (items, property, pd) =>
            {
                var enumerableItems = items as IEnumerable<NestedPartDTO>;

                if (pd.Name == "TotalTime" && enumerableItems != null)
                {
                    TimeSpan ret = TimeSpan.Zero;
                    foreach (var p in enumerableItems)
                        if (p.TotalSavedTime.HasValue)
                            ret = ret + p.TotalSavedTime.Value;
                        this.TotalTime = ret;
                }
            };
        }


        public TimeSpan TotalTime
        {
            get;
            set;
        } = TimeSpan.Zero;


    }


and I've defined the following GridSummaryColumn:


                        <Syncfusion:SfDataGrid.TableSummaryRows>
                            <Syncfusion:GridTableSummaryRow Position="Bottom"  ShowSummaryInRow="False">

                                <Syncfusion:GridSummaryRow.SummaryColumns>
                                    <Syncfusion:GridSummaryColumn Name="TTotalSavedTime"  MappingName="TotalSavedTime" CustomAggregate="{StaticResource customAggregate}" SummaryType="Custom" Format="'{TotalTime:h:mm:ss}'"/>
                                </Syncfusion:GridSummaryRow.SummaryColumns>

                            </Syncfusion:GridTableSummaryRow>

                        </Syncfusion:SfDataGrid.TableSummaryRows>


Please refer to the bold text.
If I run this example I obtain a FormatException runtime error.
If I insted remove the bold text I don't have runtime errors and the summay TimeSpan is correctly displayed but without formatting (using the default one).

So, I ask you if can suggest me what's the currect format string to put after "TotalTime:": I'd like to have string such as 1:02:13 (1 hour, 2 minutes, 13 seconds).
Can you hekp me ?



1 Reply

JG Jai Ganesh S Syncfusion Team April 11, 2018 05:20 PM UTC

Hi Silvio, 
 
We have checked your query. If you want to display the time span format as 1:02:13 in TableSummary row then you can set the format like Format="'{TotalTime}'". We have prepared a sample for this and please find the sample from the below location, 
 
 
Still if your requirement is not meet by referring the above sample then could you please let us know the details for how you want to display the Time Span value in TableSummaryRow? This would be more helpful for us to proceed further. 
 
Regards, 
Jai Ganesh S

Loader.
Up arrow icon