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

Displaying group name in the group footer

6 Answers 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 18 Jan 2013, 04:21 PM
I've got a RadGrid with group by by two fields and subtotals shown in the group by  footers. The grouping is by Strategy and then by Manager. However, the out-of-the-box group footer display is a bit confusing because it's unclear whether the footer is for Strategy or for Manager (1st level group of 2nd level group). Please see the attached pic on how it is displayed currently.

 1) I need the footer to clarify what is the subtotal for like follows:
>Strategy: [StrategyName]
  >Manager: [ManagerName1]
.............row.........................
.............row........................
..............row.......................
>Number of portfolios for manager [ManagerNames1] : 3 Total TNA: $100
> Manager: [ManagerName2]
  ...............row.....................
...............row.....................
>Number of portfolios for manager [ManagerNames2] 2: Total TNA: $200
>Number of portfolios for strategy [StrategyName]  5 Total TNA: $500

I looked at your group footer templates, but couldn't figure out how to get what I need from the samples or documentation. 

2) Another issue is that my "Total TNA" in the footer displays just the amount, but the words "Total TNA" are not displayed.

Here is the mark-up:
<telerik:RadGrid runat="server" ID="TrackersRadGrid" OnNeedDataSource="TrackersRadGrid_NeedDataSource"
           AutoGenerateColumns="False" CellSpacing="0" GridLines="None" ShowFooter="true">
           <MasterTableView ShowGroupFooter="true">
               <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
               <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
               </RowIndicatorColumn>
               <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
               </ExpandCollapseColumn>
               <Columns>
                   <telerik:GridBoundColumn DataField="Strategy" HeaderText="Strategy" />
                   <telerik:GridBoundColumn DataField="PortfolioNumber" UniqueName="PortfolioNumber"
                       Aggregate="Count" FooterText="Number of Porfolios: " HeaderText="Portfolio Number">
                       <ItemStyle CssClass="portfolioNumber" />
                   </telerik:GridBoundColumn>
                   <telerik:GridHyperLinkColumn DataNavigateUrlFields="PortfolioNumber" UniqueName="PortfolioName"
                       HeaderText="Portfolio Name" AllowFiltering="false" DataNavigateUrlFormatString="./equitygrid/tracker.aspx?portfolio={0}"
                       DataTextField="PortfolioName">
                   </telerik:GridHyperLinkColumn>
                   <telerik:GridBoundColumn DataField="TNA" DataFormatString="{0:c}" UniqueName="TNA"
                       Aggregate="Sum" FooterText="Total TNA: " HeaderText="TNA" >
                       <ItemStyle CssClass="numeric tna" />
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="InternationalRevenuePercent" HeaderText="Intl %"
                       UniqueName="InternationalRevenuePercent">
                       <ItemStyle CssClass="numeric intlRevPct" />
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="InternationalRevenue" HeaderText="International Assests"
                       UniqueName="InternationalRevenue">
                       <ItemStyle CssClass="numeric intlRev" />
                   </telerik:GridBoundColumn>
                   <telerik:GridBoundColumn DataField="PortfolioManagers" HeaderText="Managers" UniqueName="PortfolioManagers">
                       <ItemStyle CssClass="portfolioManagers" />
                   </telerik:GridBoundColumn>
               </Columns>
               <GroupByExpressions>
                   <telerik:GridGroupByExpression>
                       <GroupByFields>
                           <telerik:GridGroupByField FieldAlias="Strategy" FieldName="Strategy" />
                       </GroupByFields>
                       <SelectFields>
                           <telerik:GridGroupByField FieldAlias="Strategy" FieldName="Strategy" />
                       </SelectFields>
                   </telerik:GridGroupByExpression>
                   <telerik:GridGroupByExpression>
                       <GroupByFields>
                           <telerik:GridGroupByField FieldAlias="PortfolioManagers" FieldName="PortfolioManagers" />
                       </GroupByFields>
                       <SelectFields>
                           <telerik:GridGroupByField FieldAlias="PortfolioManagers" FieldName="PortfolioManagers"
                               FormatString="" HeaderText="Manager" />
                       </SelectFields>
                   </telerik:GridGroupByExpression>
               </GroupByExpressions>
               <EditFormSettings>
                   <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                   </EditColumn>
               </EditFormSettings>
           </MasterTableView>
           <FilterMenu EnableImageSprites="False">
           </FilterMenu>
       </telerik:RadGrid>


Thanks,
Alex

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 21 Jan 2013, 05:49 AM
Hi,

When using DataFormatString and aggregates, you should specify the footer text in the FooterAggregateFormatString as shown below.
aspx:
<telerik:GridBoundColumn FooterAggregateFormatString="TotalTNA: {0:c}"  DataField="TNA" UniqueName="TNA" Aggregate="Sum" HeaderText="TNA" >
<ItemStyle CssClass="numeric tna" />
</telerik:GridBoundColumn>

Thanks,
Shinu
0
Alex
Top achievements
Rank 1
answered on 22 Jan 2013, 02:46 PM
Thanks for the reply. It answers my second question, but the first one remains unanswered: how do I distinguish what a footer subtotal is for? Please refer to the description for more details.

0
Alex
Top achievements
Rank 1
answered on 24 Jan 2013, 03:13 PM
With help of Daniel from Telerik, this is what I ended up doing:
protected void TrackersRadGrid_ItemDataBound(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridGroupFooterItem)
           {
               //get the footer cell:
               var portfolioNumberCell = (e.Item as GridGroupFooterItem)["PortfolioName"];
               //find the group header for the current group:
               var headerItem = TrackersRadGrid.MasterTableView.GetItems(GridItemType.GroupHeader)
                   .Where(i => i.GroupIndex == e.Item.GroupIndex).First() as GridGroupHeaderItem;
 
               string groupHeaderText = headerItem.DataCell.Text;
               //get just the left part - only group level but not the actual value:
               string groupLevel = groupHeaderText.Substring(0, groupHeaderText.IndexOf(':'));
               //add group level to the text in the footer:
               portfolioNumberCell.Text = string.Format("{0} {1}", groupLevel, portfolioNumberCell.Text);
}
0
D
Top achievements
Rank 1
answered on 17 Jun 2013, 05:54 PM
Can someone convert the posted c# code to VB .Net. I have the same exact requirement but I can't get the equivalent code in VB specifically the following line

var headerItem = TrackersRadGrid.MasterTableView.GetItems(GridItemType.GroupHeader)
                   .Where(i => i.GroupIndex == e.Item.GroupIndex).First() as GridGroupHeaderItem;

0
Princy
Top achievements
Rank 1
answered on 18 Jun 2013, 06:15 AM
Hi,

Here is the code in VB.Hope this helps.

VB:
If TypeOf e.Item Is GridGroupFooterItem Then
    'get the footer cell:
    Dim portfolioNumberCell = TryCast(e.Item, GridGroupFooterItem)("PortfolioName")
    'find the group header for the current group:
    Dim headerItem = TryCast(TrackersRadGrid.MasterTableView.GetItems(GridItemType.GroupHeader).Where(Function(i) i.GroupIndex = e.Item.GroupIndex).First(), GridGroupHeaderItem)
 
    Dim groupHeaderText As String = headerItem.DataCell.Text
    'get just the left part - only group level but not the actual value:
    Dim groupLevel As String = groupHeaderText.Substring(0, groupHeaderText.IndexOf(":"C))
    'add group level to the text in the footer:
    portfolioNumberCell.Text = String.Format("{0} {1}", groupLevel, portfolioNumberCell.Text)
End If

Thanks,
Princy
0
D
Top achievements
Rank 1
answered on 18 Jun 2013, 02:27 PM
The VB code worked perfectly. Thanks Princy.
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Alex
Top achievements
Rank 1
D
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Share this question
or