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

Custom Aggregate

3 Answers 311 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aaron Spilman
Top achievements
Rank 1
Aaron Spilman asked on 14 Apr 2010, 12:37 AM
I am tring to add a custom aggregate to a group footer. I need to step throught all the data in the grid for that group. I just can't seem to find the values.
Please tell me how to change this.

Thanks,

Protected Sub dgrPartnerTransactions_CustomAggregate(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridCustomAggregateEventArgs) Handles dgrPartnerTransactions.CustomAggregate  
        Dim items As GridItem() = Me.dgrPartnerTransactions.MasterTableView.GetItems(GridItemType.Item)  
        Dim Amount As Int32 = 0  
        For Each index As GridDataItem In items  
            Amount = Amount + CType(index.GetDataKeyValue("TransactionAmount"), Int32)  
        Next 
        e.Result = Amount.ToString()  
    End Sub 

<telerik:RadGrid PageSize="100" ID="dgrPartnerTransactions" ShowGroupPanel="true" 
                    runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" 
                    Skin="Office2007" GridLines="None" Width="99%" ShowFooter="true">  
                    <PagerStyle Mode="NextPrevNumericAndAdvanced" /> 
                    <MasterTableView TableLayout="Fixed" ShowGroupFooter="true">  
                        <RowIndicatorColumn> 
                            <HeaderStyle Width="20px"></HeaderStyle> 
                        </RowIndicatorColumn> 
                        <ExpandCollapseColumn> 
                            <HeaderStyle Width="20px"></HeaderStyle> 
                        </ExpandCollapseColumn> 
                        <Columns> 
                          
                            <telerik:GridTemplateColumn HeaderText="" UniqueName="DeleteThis" Groupable="false">  
                                <HeaderStyle HorizontalAlign="Center" Width="30px"></HeaderStyle> 
                                <ItemStyle HorizontalAlign="Center" Width="30px"></ItemStyle> 
                                <ItemTemplate> 
                                    <asp:CheckBox ID="DeleteThis" runat="server" /> 
                                    <asp:Label runat="server" Visible="False" ID="lblPartnerTransactionID" Text='<%#DataBinder.Eval(Container, "DataItem.PartnerTransactionID")%>'></asp:Label> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
              
                            <telerik:GridTemplateColumn UniqueName="TemplateEditColumn" Groupable="false">  
                                <HeaderStyle HorizontalAlign="Center" Width="30px"></HeaderStyle> 
                                <ItemStyle HorizontalAlign="Center" Width="30px"></ItemStyle> 
                                <ItemTemplate> 
                                    <asp:HyperLink ID="hypEditLink" runat="server" Text="Edit" NavigateUrl="#" OnClick='<%# getEditWindowURL( DataBinder.Eval(Container, "DataItem.PartnerTransactionID") ) %>'></asp:HyperLink> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn>                  
                                
                            <telerik:GridTemplateColumn HeaderText="Transaction Type" UniqueName="PartnerTransactionType" 
                                Groupable="false" DataField="PartnerTransactionType" SortExpression="PartnerTransactionType" 
                                GroupByExpression="PartnerTransactionType Group By PartnerTransactionType">  
                                <HeaderStyle HorizontalAlign="Left"></HeaderStyle> 
                                <ItemStyle HorizontalAlign="Left"></ItemStyle> 
                                <ItemTemplate> 
                                    <%#DataBinder.Eval(Container, "DataItem.PartnerTransactionType")%>&nbsp;  
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                  
                            <telerik:GridTemplateColumn HeaderText="Date" UniqueName="TransactionDate" Groupable="false" 
                                DataField="TransactionDate" SortExpression="TransactionDate" GroupByExpression="TransactionDate Group By TransactionAmount">  
                                <HeaderStyle HorizontalAlign="Center"></HeaderStyle> 
                                <ItemStyle HorizontalAlign="Center"></ItemStyle> 
                                <ItemTemplate> 
                                    <%#DataBinder.Eval(Container, "DataItem.TransactionDate", "{0:d}")%>&nbsp;  
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                  
                            <telerik:GridTemplateColumn HeaderText="Amount" UniqueName="TransactionAmount" Groupable="false" 
                                DataField="TransactionAmount" SortExpression="TransactionAmount" Aggregate="Custom">  
                                <HeaderStyle HorizontalAlign="Center"></HeaderStyle> 
                                <ItemStyle HorizontalAlign="Center"></ItemStyle> 
                                <ItemTemplate> 
                                    <%#DataBinder.Eval(Container, "DataItem.TransactionAmount", "{0:C}")%>&nbsp;  
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                  
                            <telerik:GridTemplateColumn HeaderText="Check Number" UniqueName="CheckNumber" Groupable="false" 
                                DataField="CheckNumber" SortExpression="CheckNumber" GroupByExpression="CheckNumber Group By CheckNumber">  
                                <HeaderStyle HorizontalAlign="Left"></HeaderStyle> 
                                <ItemStyle HorizontalAlign="Left"></ItemStyle> 
                                <ItemTemplate> 
                                    <%#DataBinder.Eval(Container, "DataItem.CheckNumber")%>&nbsp;  
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                  
                            <telerik:GridTemplateColumn HeaderText="Paid Out of Escrow?" UniqueName="PaidOutOfEscrow" 
                                Groupable="false" DataField="PaidOutOfEscrow" SortExpression="PaidOutOfEscrow" 
                                GroupByExpression="PaidOutOfEscrow Group By PaidOutOfEscrow">  
                                <HeaderStyle HorizontalAlign="Left"></HeaderStyle> 
                                <ItemStyle HorizontalAlign="Left"></ItemStyle> 
                                <ItemTemplate> 
                                    <%#FormatYesNo(DataBinder.Eval(Container, "DataItem.PaidOutOfEscrow"))%>&nbsp;  
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn>                 
                                    
                            <telerik:GridTemplateColumn HeaderText="Property" UniqueName="PropertyAddress" DataField="PropertyAddress" 
                                SortExpression="PropertyAddress" GroupByExpression="PropertyAddress Group By PropertyAddress">  
                                <HeaderStyle HorizontalAlign="Left"></HeaderStyle> 
                                <ItemStyle HorizontalAlign="Left"></ItemStyle> 
                                <ItemTemplate> 
                                    <href='PropertyDetails.aspx?PropertyID=<%#DataBinder.Eval(Container, "DataItem.PropertyID")%>' 
                                        target="_blank">  
                                        <%#DataBinder.Eval(Container, "DataItem.PropertyAddress")%></a>&nbsp;  
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn>                 
              
                            <telerik:GridTemplateColumn HeaderText="Transaction Note" UniqueName="TransactionNote" 
                                Groupable="false" DataField="TransactionNote" SortExpression="TransactionNote" 
                                GroupByExpression="TransactionNote Group By TransactionNote">  
                                <HeaderStyle HorizontalAlign="Left"></HeaderStyle> 
                                <ItemStyle HorizontalAlign="Left"></ItemStyle> 
                                <ItemTemplate> 
                                    <%#DataBinder.Eval(Container, "DataItem.TransactionNote")%>&nbsp;  
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                  
                            <telerik:GridTemplateColumn HeaderText="Document" UniqueName="PropertyID" Groupable="false">  
                                <ItemTemplate> 
                                    <%#getDocumentURL(DataBinder.Eval(Container, "DataItem.DocumentName"), DataBinder.Eval(Container, "DataItem.DocumentLocation"))%>&nbsp;  
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn>   
               
                 
                            <telerik:GridTemplateColumn HeaderText="Balance" UniqueName="Balance" Groupable="false" 
                                DataField="Balance" SortExpression="Balance"   
                                GroupByExpression="Balance Group By Balance">  
                                <HeaderStyle HorizontalAlign="Center"></HeaderStyle> 
                                <ItemStyle HorizontalAlign="Right"></ItemStyle> 
                                <ItemTemplate> 
                                    <%#DataBinder.Eval(Container, "DataItem.Balance", "{0:C}")%>&nbsp;  
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
               
                  
                        </Columns> 
                        <GroupByExpressions> 
                            <telerik:GridGroupByExpression> 
                                <GroupByFields> 
                                    <telerik:GridGroupByField FieldName="PropertyID" /> 
                                </GroupByFields> 
                                <SelectFields> 
                                    <telerik:GridGroupByField FieldName="TransactionAmount" HeaderText="TransactionAmount" /> 
                                </SelectFields> 
                            </telerik:GridGroupByExpression> 
                        </GroupByExpressions> 
              
                    </MasterTableView> 
                      
                    <ClientSettings AllowDragToGroup="false" AllowGroupExpandCollapse="true" AllowColumnsReorder="true">  
                        <Scrolling AllowScroll="False" UseStaticHeaders="True" SaveScrollPosition="true" 
                            FrozenColumnsCount="1"></Scrolling> 
                    </ClientSettings> 
                      
                    <FilterMenu EnableTheming="True">  
                        <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
                    </FilterMenu> 
                </telerik:RadGrid> 

3 Answers, 1 is accepted

Sort by
0
Accepted
Martin
Telerik team
answered on 16 Apr 2010, 01:43 PM
Hello Aaron Spilman,

Could you please verify whether the following modifications work in your scenario:

<telerik:RadGrid ID="dgrPartnerTransactions" runat="server" ... > 
         <MasterTableView ... DataKeyNames="TransactionAmount"
....
         </MasterTableView>
</telerik:RadGrid>

Code behind:

Protected Sub dgrPartnerTransactions_CustomAggregate(sender As Object, e As Telerik.Web.UI.GridCustomAggregateEventArgs) Handles dgrPartnerTransactions.CustomAggregate
    Dim Amount As Int32 = 0
    For Each index As GridDataItem In dgrPartnerTransactions.MasterTableView.Items
        Amount = Amount + DirectCast(index.GetDataKeyValue("TransactionAmount"), Int32)
    Next
    e.Result = Amount.ToString()
End Sub

I hope this helps
Martin
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
Aaron Spilman
Top achievements
Rank 1
answered on 16 Apr 2010, 04:55 PM
Yes that worked.

Am I able to look up more then one value that way? I would also like to get the value of "Balance".
0
Aaron Spilman
Top achievements
Rank 1
answered on 16 Apr 2010, 06:07 PM

I figured it out. I just need to add them to the DataKeyNames seperated by a comma.

<telerik:RadGrid ID="dgrPartnerTransactions" runat="server" ... >    
         <MasterTableView ... DataKeyNames="TransactionAmount,Balance">    
....  
         </MasterTableView> 
</telerik:RadGrid> 

Tags
Grid
Asked by
Aaron Spilman
Top achievements
Rank 1
Answers by
Martin
Telerik team
Aaron Spilman
Top achievements
Rank 1
Share this question
or