<telerik:RadGridView DockPanel.Dock="Top" x:Name="grdAccrual" ItemsSource="{Binding EnterpriseAllocationRecords}" AutoGenerateColumns="False" IsFilteringAllowed="False" ShowGroupPanel="False" SelectionMode="Extended" ShowInsertRow="False" ActionOnLostFocus="CommitEdit" CanUserInsertRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" IsReadOnly="False" CanUserFreezeColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False" RowIndicatorVisibility="Collapsed" AutoExpandGroups="True" EditTriggers="F2,CellClick" ScrollViewer.VerticalScrollBarVisibility="Auto" RowEditEnded="grdAccrual_RowEditEnded" RowHeight="27"> <telerik:RadGridView.Columns> <!--<telerik:GridViewDataColumn Header="ATIG" CellStyle="{StaticResource LeftAlignCell}" DataMemberBinding="{Binding TransactionCode}" Width="65" IsReadOnly="True"></telerik:GridViewDataColumn> <telerik:GridViewDataColumn Header="Description" CellStyle="{StaticResource LeftAlignCell}" DataMemberBinding="{Binding TransactionDescription}" IsReadOnly="True" Width="*" />--> <telerik:GridViewDataColumn Header="Ent" CellStyle="{StaticResource LeftAlignCell}" DataMemberBinding="{Binding EnterpriseCode}" IsFilterable="False" IsReadOnly="True" Width="50" /> <telerik:GridViewDataColumn Header="Ent Desc" CellStyle="{StaticResource LeftAlignCell}" DataMemberBinding="{Binding EnterpriseDescription}" IsFilterable="False" IsReadOnly="True" Width="350" /> <telerik:GridViewDataColumn Header="Cash/Inv" DataMemberBinding="{Binding SuggestedAccrualAmount}" DataFormatString="{}{0:f2}" IsFilterable="False" IsReadOnly="True" Width="70" > <!--<telerik:GridViewDataColumn.Header> <TextBlock Text="Cash/Inv Accrual" TextWrapping="Wrap" /> </telerik:GridViewDataColumn.Header>--> </telerik:GridViewDataColumn> <telerik:GridViewDataColumn Header="%" DataMemberBinding="{Binding AllocationPercent}" DataFormatString="{}{0:p2}" IsFilterable="False" Width="60"> <telerik:GridViewDataColumn.CellEditTemplate> <DataTemplate> <telerikInput:RadMaskedNumericInput x:Name="txtAllocationPercent" Mask="p3.2" SpinMode="None" IsClearButtonVisible="False" SelectionOnFocus="SelectAll" KeyboardNavigation.TabNavigation="Local" TextMode="PlainText" Validation.ErrorTemplate="{StaticResource TextBoxErrorTemplate}" > <telerikInput:RadMaskedNumericInput.Value> <Binding Path="AllocationPercent" Mode="TwoWay" UpdateSourceTrigger="LostFocus"> <Binding.ValidationRules> <imKASHelper:PercentValidationRule Min="-100.00" Max="100.00" /> </Binding.ValidationRules> </Binding> </telerikInput:RadMaskedNumericInput.Value> </telerikInput:RadMaskedNumericInput> </DataTemplate> </telerik:GridViewDataColumn.CellEditTemplate> </telerik:GridViewDataColumn> <telerik:GridViewDataColumn Header="Units" DataMemberBinding="{Binding Units}" DataFormatString="{}{0:f2}" IsFilterable="False" IsReadOnly="True" Width="70" ></telerik:GridViewDataColumn> <telerik:GridViewDataColumn Header="Weight" DataMemberBinding="{Binding Weight}" DataFormatString="{}{0:f2}" IsFilterable="False" IsReadOnly="True" Width="70" ></telerik:GridViewDataColumn> <telerik:GridViewDataColumn DataMemberBinding="{Binding Amount}" DataFormatString="{}{0:f2}" IsFilterable="False" Width="70" > <telerik:GridViewDataColumn.Header> <TextBlock Text="Amount" TextWrapping="Wrap" /> </telerik:GridViewDataColumn.Header> <telerik:GridViewDataColumn.CellEditTemplate> <DataTemplate> <telerikInput:RadMaskedNumericInput x:Name="txtAmount" Mask="#11.2" SpinMode="None" IsClearButtonVisible="False" SelectionOnFocus="SelectAll" KeyboardNavigation.TabNavigation="Local" TextMode="PlainText" Validation.ErrorTemplate="{StaticResource TextBoxErrorTemplate}" > <telerikInput:RadMaskedNumericInput.Value> <Binding Path="Amount" Mode="TwoWay" UpdateSourceTrigger="LostFocus"> <Binding.ValidationRules> <imKASHelper:DoubleValidationRule Min="-10000000000.00" Max="10000000000.00" /> </Binding.ValidationRules> </Binding> </telerikInput:RadMaskedNumericInput.Value> </telerikInput:RadMaskedNumericInput> </DataTemplate> </telerik:GridViewDataColumn.CellEditTemplate> </telerik:GridViewDataColumn> </telerik:RadGridView.Columns> <telerik:RadGridView.GroupRowStyle> <Style TargetType="telerik:GridViewGroupRow"> <Setter Property="ShowHeaderAggregates" Value="False"></Setter> </Style> </telerik:RadGridView.GroupRowStyle> <telerik:RadGridView.GroupHeaderTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" Margin="0,0" Height="45"> <TextBlock Text="{Binding Group.Key}" Margin="0,0,0,2" Width="200" /> <telerik:AggregateResultsList ItemsSource="{Binding AggregateResults}" VerticalAlignment="Center"> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation="Vertical" VerticalAlignment="Center"> <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Caption}" Width="90" /> <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding FormattedValue}" Width="90" Style="{StaticResource EnterpriseStatusStyle}" /> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </telerik:AggregateResultsList> </StackPanel> </DataTemplate> </telerik:RadGridView.GroupHeaderTemplate> <telerik:RadGridView.GroupDescriptors> <telerik:GroupDescriptor x:Name="TransactionGroup" Member="TransactionGroup" SortDirection="Ascending" > <telerik:GroupDescriptor.AggregateFunctions> <telerik:MinFunction Caption="Cash" SourceField="CashTotal" ResultFormatString="{}{0:0.00}" /> <telerik:MinFunction Caption="Beg Inv" SourceField="BegInvTotal" ResultFormatString="{}{0:0.00}" /> <telerik:MinFunction Caption="End Inv" SourceField="EndInvTotal" ResultFormatString="{}{0:0.00}" /> <telerik:MinFunction Caption="Beg Acc" SourceField="BegAccruedTotal" ResultFormatString="{}{0:0.00}" /> <telerik:MinFunction Caption="End Acc" SourceField="EndAccruedTotal" ResultFormatString="{}{0:0.00}" /> <telerik:MinFunction Caption="Accrual" SourceField="AccrualAmount" ResultFormatString="{}{0:c2}" /> <telerik:SumFunction Caption="Ent Amt" SourceField="Amount" ResultFormatString="{}{0:c2}" /> <local:EnterpriseDifferenceFunction Caption="Diff" ResultFormatString="{}{0:0.00}" /> </telerik:GroupDescriptor.AggregateFunctions> </telerik:GroupDescriptor> </telerik:RadGridView.GroupDescriptors> </telerik:RadGridView>
Hi,
I want to have a footer in one of my gridview columns that has two rows: one containing a textbox bound to a field in model view, and the second row displays the sum of items in that column.
---------------------------------
Total: {text box}
<sum>
---------------------------------
I have followed the suggestion from another thread to have a style for the footer to set the binding, and then reference that style on the column.
<Style x:Key="SalesTotalStyle" TargetType="telerik:GridViewFooterCell"> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <Grid> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <TextBlock Grid.Row="0" Width="75" TextAlignment="Right" FontWeight="Bold" Text="{Binding Path=DataContext.SalesSum, RelativeSource={RelativeSource AncestorType=telerik:GridView}}" /> <TextBox Grid.Row="1" Text="{Binding Path=DataContext.ExpetedSalesTotal, RelativeSource={RelativeSource AncestorType=telerik:GridView}}" Width="75" TextAlignment="Right"/> </Grid> </DataTemplate> </Setter.Value> </Setter> </Style>
This works great and it does display y the data properly in the textbox. However, how can I add an aggregate function in the style section??
I undetstand aggregate functions will not show if the footer is set. I have also tried to create a sum property (SalesSum) that reruns the sum of underlying data, whoever it doesn’t get refreshed in the grid as the user enters items in the column. Any suggestion?