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

Custom Format for Grid Footer

8 Answers 280 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Randall Nelson
Top achievements
Rank 1
Randall Nelson asked on 04 Mar 2010, 09:05 PM
I have a grid in which one of the columns displays a duration of minutes.  I have a footer on this grid which displays the total number of minutes.  Instead of just displaying the total number of minutes, I would really like to show it in hours and minutes - for example "10 hrs 5 mins" instead of "605 Minutes".  I don't want to display this special formatting in the grid because generally the miinutes for individual rows are under an hour.

I can create an IValueConverter class to turn minutes into hours and minutes, but I don't see how to hook it up to the SumFunction for the grid footer.

Is there a way to get this custom formatting in the grid footer?  Thanks.

8 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 05 Mar 2010, 07:11 AM
Hi,

You can create your own custom Footer/GroupFooter similar to this demo:
http://demos.telerik.com/silverlight/#GridView/Totals

Sincerely yours,
Vlad
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
Randall Nelson
Top achievements
Rank 1
answered on 05 Mar 2010, 02:32 PM
Thanks for your response.  In the example, all of the aggregates appear to be shown with standard formatting (such as standard date formatting and currency formatting).  I don't see custom formatting applied to any of the aggregate values.  So I still don't see how I would take the sum of minutes and display it as as hours and minutes.  I may be missing something obvious though. 
0
Vlad
Telerik team
answered on 05 Mar 2010, 02:43 PM
Hello,

You can declare AggregateResultsList in the footer similar to the posted example and set desired IValueConverter for FormattedValue Binding:

                     <grid:GridViewDataColumn.Footer>
                                <StackPanel Orientation="Vertical" Margin="5,0">
                                    <TextBlock Text="Custom footer with aggregates:" Margin="0,0,0,2" />
                                    <gridView:AggregateResultsList ItemsSource="{Binding}" VerticalAlignment="Center">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                                    <TextBlock VerticalAlignment="Center" Text="{Binding Caption}" />
                                                    <TextBlock VerticalAlignment="Center" Text="{Binding FormattedValue}" />
                                                </StackPanel>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                        <ItemsControl.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <StackPanel Orientation="Vertical" />
                                            </ItemsPanelTemplate>
                                        </ItemsControl.ItemsPanel>
                                    </gridView:AggregateResultsList>
                                </StackPanel>
                            </grid:GridViewDataColumn.Footer>


Sincerely yours,
Vlad
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
Randall Nelson
Top achievements
Rank 1
answered on 09 Mar 2010, 12:23 AM
Thanks.  For a variety of reasons, my application sets up columns on the grids dynamically.  I have the aggregate function working as follows (although just to get it started, I just have standard formatting in the footer):

            Telerik.Windows.Data.SumFunction f = new Telerik.Windows.Data.SumFunction();  
            f.SourceField = "TotalMinutes";  
            f.Caption = "Total: ";  
            f.ResultFormatString = "{0:d}";  
            MyGrid.Columns["TotalMinutes"].AggregateFunctions.Add(f);  
 

My IValueConverter class is called HourMinuteConverter. Can you tell me how I would implement the converter when setting up the footer dynamically?
0
Accepted
Vlad
Telerik team
answered on 09 Mar 2010, 08:46 AM
Hello,

In this case it will be better if you create your own custom aggregate function - you can check this demo for more info on how to do this.

Best wishes,
Vlad
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
Randall Nelson
Top achievements
Rank 1
answered on 09 Mar 2010, 08:10 PM
Thanks.  That did the trick.
0
Wasif Jahangir
Top achievements
Rank 1
answered on 13 Jul 2010, 06:36 AM
Hi,
Is there any way to call Converter for Footer. i.e. i want to calc grand total of a field who is itself calculated by IValueConverter
here sample code:
<telerik:GridViewDataColumn Width="120" DataMemberBinding="{Binding Path=., Converter={StaticResource ResourceKey=TotalConverter}, Mode=TwoWay}" Header="Total">
                            <telerik:GridViewDataColumn.Footer>
                                <StackPanel>
                                    <TextBlock VerticalAlignment="Center" Text="{Binding Path=.,Converter={StaticResource ResourceKey=GrandTotalConverter}, Mode=TwoWay}" />
                                </StackPanel>
                            </telerik:GridViewDataColumn.Footer>
                        </telerik:GridViewDataColumn>

but it is not working.

for my case reference Post is:
http://www.telerik.com/community/forums/wpf/gridview/calculate-grand-total-of-column-which-is-calculated-through-ivalueconverter.aspx
0
David
Top achievements
Rank 1
answered on 13 Aug 2019, 06:24 PM

I was able to use an `IValueConverter` in the footer with code like this:

    <telerik:GridViewDataColumn Header="Size"
          DataMemberBinding="{Binding SizeInBytes, Converter={x:Static local:ByteCountToStringConverter.Instance}}"  >
        <telerik:GridViewDataColumn.AggregateFunctions>
            <telerik:SumFunction/>
        </telerik:GridViewDataColumn.AggregateFunctions>
        <telerik:GridViewDataColumn.Footer>
            <telerik:AggregateResultsList ItemsSource="{Binding}" VerticalAlignment="Center">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding FormattedValue, Converter={x:Static local:ByteCountToStringConverter.Instance}}" />
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </telerik:AggregateResultsList>
        </telerik:GridViewDataColumn.Footer>
    </telerik:GridViewDataColumn>


Tags
GridView
Asked by
Randall Nelson
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Randall Nelson
Top achievements
Rank 1
Wasif Jahangir
Top achievements
Rank 1
David
Top achievements
Rank 1
Share this question
or