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

how can I add a Converter class to an Aggregate function

13 Answers 211 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Brian Graves
Top achievements
Rank 1
Brian Graves asked on 22 May 2010, 01:33 AM
My aggregate function returns a decimal number representing the number of minutes.  However, I want to use a Converter data binding class on this result to make it into a D H M (days, hours, minutes) format.  My converter class works fine on my column data but, unfortunately, I have no way of applying it to my column aggregate function.  How can I do this (apart from calling the convert method directly from my aggregate method)?

13 Answers, 1 is accepted

Sort by
0
Stefan Dobrev
Telerik team
answered on 26 May 2010, 03:25 PM
Hi Brian Graves,

My suggestion is to use an aggregate function that returns a TimeSpan. Then you can use the ResultFormatString to format the time span to match your requirements.

Greetings,
Stefan Dobrev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Brian Graves
Top achievements
Rank 1
answered on 26 May 2010, 05:10 PM
Thanks but I can't get my ResultFormatString to output my timespan correctly.  For example, I want my output to look like:
19 D 8 H 14 M

If I set my ResultFormatString to "{0:dd} D {0:hh} H {0:mm} M", I get the following result:
19.08.14:00 D 19.08.14:00 H 19.08.14:00 M

How can I output this correctly?
0
Pavel Pavlov
Telerik team
answered on 31 May 2010, 01:31 PM
Hello Brian Graves,
<telerik:GridViewDataColumn DataMemberBinding="{Binding Minutes}" >
    <telerik:GridViewDataColumn.Footer>
        <telerik:AggregateResultsList ItemsSource="{Binding}">
            <telerik:AggregateResultsList.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="{Binding Converter={StaticResource MyConverter}}" />
                    </StackPanel>
                </DataTemplate>
            </telerik:AggregateResultsList.ItemTemplate>
        </telerik:AggregateResultsList>
    </telerik:GridViewDataColumn.Footer>
</telerik:GridViewDataColumn>

The XAML above demonstrates a way to use a converter with the aggregate results.

Regards,
Pavel Pavlov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Siew Fai Hoy
Top achievements
Rank 1
answered on 16 Jul 2010, 02:31 AM
Hi,

This does the job in formatting the aggregate result value in the footer, what if I would like to achieve the same thing in the group header panel  (i.e. using a converter to format the value of aggregate result) ?

Regards,
Siew Fai Hoy
0
Pavel Pavlov
Telerik team
answered on 21 Jul 2010, 08:53 AM
Hi Siew Fai Hoy,

You may use exactly the same approach , but you can use a global style targeting aggregate results list.
This way it will affect all aggregate results list , including those in the headers.

Regards,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
MiddleTommy
Top achievements
Rank 1
answered on 23 Jan 2012, 04:58 PM
Could you go into more detail as to how this would be done? If I target global AggregateResultsList then wouldnt it use the converter for all columns and not just the one I need special formatting?
0
Pavel Pavlov
Telerik team
answered on 23 Jan 2012, 05:03 PM
Hello Tommy ,

Indeed in case you need it applied to specific elements only , the global style will not work . You will need to take care individually with explicit styles.

Kind regards,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
MiddleTommy
Top achievements
Rank 1
answered on 23 Jan 2012, 05:38 PM
Where would I apply the style to? In the column Definition somewhere? I have my footer formatted correctly with a Binding and Converter. but the Aggregate value in the group header is not correct.
<Style x:Key="LengthAggregateStyle" TargetType="t:AggregateResultsList">
                <Setter Property="ItemTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock Text="{Binding Value, Converter={StaticResource LengthConverter}}" />
                            </StackPanel>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

<t:GridViewDataColumn DataMemberBinding="{Binding length, Converter={StaticResource LengthConverter}}"
                                      IsReadOnly="True"
                                      Header="length">
                    <t:GridViewDataColumn.AggregateFunctions>
                        <t:SumFunction SourceField="TotalLength" FunctionName="TotalLengthSum"/>
                    </t:GridViewDataColumn.AggregateFunctions>
                     
                     
                    <t:GridViewDataColumn.Footer>
                        <t:AggregateResultsList ItemsSource="{Binding}" Style="{StaticResource LengthAggregateStyle}"/>
                    </t:GridViewDataColumn.Footer>
                    <t:GridViewDataColumn.GroupHeaderTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Value, Converter={StaticResource LengthConverter}}" />
                        </DataTemplate>
                    </t:GridViewDataColumn.GroupHeaderTemplate>
 
                </t:GridViewDataColumn>
0
MiddleTommy
Top achievements
Rank 1
answered on 23 Jan 2012, 05:43 PM
See my screen shot just so I know we are on the same page
0
Vlad
Telerik team
answered on 24 Jan 2012, 10:14 AM
Hi,

 Have you tried implicit style? Please remove the x:Key setting from your style definition. 

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
MiddleTommy
Top achievements
Rank 1
answered on 24 Jan 2012, 02:20 PM
Implicit styling does not work. It styles all the footer cells (some incorrectly) and none of the group Headers. See the attached picture.
0
Pavel Pavlov
Telerik team
answered on 30 Jan 2012, 11:03 AM
Hello Tommy ,

Indeed applying the template to the aggregate results in the group header is a bit tricky.
I believe for your specific case there is a lighter solution without styling and retemplating.
We can place the converting /formatting logic in the aggregate function itself as demonstrated in the sample project attached. 

Here we have both the group aggregates and the common aggregates displaying the right formatting.

All the best,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
MiddleTommy
Top achievements
Rank 1
answered on 30 Jan 2012, 04:36 PM
Thanks Pavel. That example worked great. I even turned it into an AttachedProperty so I can add it to columns easily and still follow MVVM.
Tags
GridView
Asked by
Brian Graves
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Brian Graves
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Siew Fai Hoy
Top achievements
Rank 1
MiddleTommy
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or