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

GridView Group Aggregates Not Showing

8 Answers 220 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David Cronin
Top achievements
Rank 1
David Cronin asked on 16 Mar 2011, 09:08 PM
Telerik Team,

I am having an issue with my GridView control. My goal is to group a grid by a column called "Category", but not show that column in the grid. I then want to show sum aggregates for each group on only certain rows (the number rows). Lastly, I want to show custom numbers in the column footer of my grid (a total sum and a margin calculation).

The problem is that my group aggregates are not appearing.

Here is my GridView code:

<telerik:RadGridView HeaderRowStyle="{StaticResource GridViewHeaderRowStyle1}" Name="radGridView1" ShowGroupPanel="False" Grid.Row="1" ShowColumnFooters="True" AutoExpandGroups="True" ShowGroupFooters="True">
            <telerik:RadGridView.GroupRowStyle>
                <Style TargetType="telerik:GridViewGroupRow">
                    <Setter Value="False" Property="ShowHeaderAggregates"/>
                </Style>
            </telerik:RadGridView.GroupRowStyle>
            <telerik:RadGridView.GroupDescriptors>
                <telerik:GroupDescriptor Member="Category" SortDirection="Descending">
                    <telerik:GroupDescriptor.AggregateFunctions>
                        <telerik:SumFunction SourceField="OriginalBudget" ResultFormatString="{}{0:c}"/>
                    </telerik:GroupDescriptor.AggregateFunctions>
                </telerik:GroupDescriptor>
            </telerik:RadGridView.GroupDescriptors>
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding CostType}" Header="Cost Type" TextAlignment="Center" HeaderCellStyle="{StaticResource CustomGridHeaderStyle}"/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding CostTypeDesc}" Header="Cost Desc" HeaderCellStyle="{StaticResource CustomGridHeaderStyle}"/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding OriginalBudget}" Header="Orig. Budget" DataFormatString="{}{0:c}" TextAlignment="right" FooterTextAlignment="right" HeaderCellStyle="{StaticResource CustomGridHeaderStyle}" UniqueName="origBudget">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction SourceField="OriginalBudget" ResultFormatString="{}{0:c}"/>
                    </telerik:GridViewDataColumn.AggregateFunctions>
                    <telerik:GridViewDataColumn.Footer>
                        <StackPanel>
                            <TextBlock Text="Subtotal"/>
                            <TextBlock Text="Margin" HorizontalAlignment="Right"/>
                        </StackPanel>
                    </telerik:GridViewDataColumn.Footer>
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding CurrentBudget}" Header="Curr. Budget" DataFormatString="{}{0:c}" TextAlignment="right" FooterTextAlignment="right" HeaderCellStyle="{StaticResource CustomGridHeaderStyle}" UniqueName="currBudget">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction SourceField="CurrentBudget" ResultFormatString="{}{0:c}"/>
                    </telerik:GridViewDataColumn.AggregateFunctions>
                    <telerik:GridViewDataColumn.Footer>
                        <StackPanel>
                            <TextBlock Text="Subtotal"/>
                            <TextBlock Text="Margin" HorizontalAlignment="Right"/>
                        </StackPanel>
                    </telerik:GridViewDataColumn.Footer>
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding PreviousPeriodActual}" Header="Actual - Previous" DataFormatString="{}{0:c}" TextAlignment="right" FooterTextAlignment="right" HeaderCellStyle="{StaticResource CustomGridHeaderStyle}" UniqueName="prevActual" Width="100">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction SourceField="PreviousPeriodActual" ResultFormatString="{}{0:c}"/>
                    </telerik:GridViewDataColumn.AggregateFunctions>
                    <telerik:GridViewDataColumn.Footer>
                        <StackPanel>
                            <TextBlock Text="Subtotal"/>
                            <TextBlock Text="Margin" HorizontalAlignment="Right"/>
                        </StackPanel>
                    </telerik:GridViewDataColumn.Footer>
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding CurrentPeriodActual}" Header="Actual - Current" DataFormatString="{}{0:c}" TextAlignment="right" FooterTextAlignment="right" UniqueName="curActual" Width="100">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction SourceField="CurrentPeriodActual" ResultFormatString="{}{0:c}"/>
                    </telerik:GridViewDataColumn.AggregateFunctions>
                    <telerik:GridViewDataColumn.Footer>
                        <StackPanel>
                            <TextBlock Text="Subtotal"/>
                            <TextBlock Text="Margin" HorizontalAlignment="Right"/>
                        </StackPanel>
                    </telerik:GridViewDataColumn.Footer>
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding DTCAmount}" Header="DTC Amount" DataFormatString="{}{0:c}">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction SourceField="DTCAmount" ResultFormatString="{}{0:c}"/>
                    </telerik:GridViewDataColumn.AggregateFunctions>
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding PeriodCosts}" Header="Period Costs" DataFormatString="{}{0:c}" TextAlignment="right" FooterTextAlignment="right" HeaderCellStyle="{StaticResource CustomGridHeaderStyle}">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction SourceField="PeriodCosts" ResultFormatString="{}{0:c}"/>
                    </telerik:GridViewDataColumn.AggregateFunctions>
                </telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

I should mention that the data source for this GridView is a collection of POCOs

8 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 18 Mar 2011, 01:30 PM
Hello David Cronin,

 
The group aggregates are not showing because you have created a GirdViewGroupRow's style and set the ShowHeaderAggregates property to False, this is the reason by which the aggregates are not showing. Just remove this style from RadGridView's definition and the issue shoule be resolved.

If you need any further assistance please let me know.

Regards,
Vanya Pavlova
the Telerik team
0
David Cronin
Top achievements
Rank 1
answered on 23 Mar 2011, 10:14 PM
Looking back, my response was not clear. After implementing your solution, the group aggregates are showing. However, they are on the header of the group and not on each group footer. Not only do I want to remove the aggregates from the group header, I want to show in the footer of each group.
0
Vanya Pavlova
Telerik team
answered on 24 Mar 2011, 01:20 PM
Hi David,

 
In this case you may specifty GroupFooterTemplate in a similar way as it is implemented in our Totals demo.

Kind regards,
Vanya Pavlova
the Telerik team
0
David Cronin
Top achievements
Rank 1
answered on 28 Mar 2011, 05:20 PM

I implemented your suggestion on a column to see if it worked, and it did not. I used the following code:

<telerik:GridViewDataColumn.GroupFooterTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Vertical">
                                <TextBlock Text="Some Text"/>
                                <telerik:AggregateResultsList ItemsSource="{Binding}" VerticalAlignment="Center">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock VerticalAlignment="Center" Text="{Binding FormattedValue}"/>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <StackPanel Orientation="Vertical"/>
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                </telerik:AggregateResultsList>
                            </StackPanel>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.GroupFooterTemplate>


What I can see is "Some text" in my group footer, but no numbers. What steps should I take next?

0
Vanya Pavlova
Telerik team
answered on 29 Mar 2011, 03:54 PM
Hi David,

Thank you for sharing this snippet to us. I have prepared an example for you using this markup, however everything works fine by my side (please refer to the attached picture). May you please check the attached project and let me know how it differs from yours? Feel free to modify it and sent it back to us in a new support ticket where we can see what is going on.



Greetings,
Vanya Pavlova
the Telerik team
0
David Cronin
Top achievements
Rank 1
answered on 29 Mar 2011, 09:39 PM
Replicating the issue required the addition of a GroupDescriptor. I am using the GroupDescriptor to add a default grouping. In this case, when I add the GroupDescriptor, I no longer see the group footer content.
0
Accepted
Vanya Pavlova
Telerik team
answered on 30 Mar 2011, 02:29 PM
Hello,

 
Thank you for sharing this information to us. It seems that you have hit a known bug in RadGridView, related to the GroupDescriptors whey they are defined before the columns in RadGridView. I hope it is not a problem for you to define the GroupDescriptor after the definition of the columns, thus you will be able to see the aggregates correctly.
Please follow the markup below:

<telerik:RadGridView  AutoExpandGroups="True" ShowColumnFooters="True" AutoGenerateColumns="False" ShowGroupFooters="True" ItemsSource="{Binding Collection}">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="ID" DataMemberBinding="{Binding Property1}">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:CountFunction Caption="Total:"/>
                        </telerik:GridViewDataColumn.AggregateFunctions>
                    <telerik:GridViewDataColumn.GroupFooterTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Vertical">
                                <TextBlock Text="Some Text"/>
                                <telerik:AggregateResultsList ItemsSource="{Binding}" VerticalAlignment="Center">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock VerticalAlignment="Center" Text="{Binding FormattedValue}"/>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <StackPanel Orientation="Vertical"/>
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                </telerik:AggregateResultsList>
                            </StackPanel>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.GroupFooterTemplate>
                    </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn Header="IsTrue" DataMemberBinding="{Binding Property2}"/>
                <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Property3}"/>
                <telerik:GridViewDataColumn Header="CompanyName" DataMemberBinding="{Binding Property4}"/>
                </telerik:RadGridView.Columns>
            <telerik:RadGridView.GroupDescriptors>
                <telerik:GroupDescriptor Member="Property1"/>
            </telerik:RadGridView.GroupDescriptors>
        </telerik:RadGridView>



On the other hand you can use ColumnGroupDescriptor instead to avoid such problems. 

Kind regards,
Vanya Pavlova
the Telerik team
0
David Cronin
Top achievements
Rank 1
answered on 30 Mar 2011, 05:59 PM
It works! I'm happy it was just that and not having to write 100 lines of XAML :)

Thank you for all your help! Always a pleasure
Tags
GridView
Asked by
David Cronin
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
David Cronin
Top achievements
Rank 1
Share this question
or