Controlling Group Footer Text

5 posts, 0 answers
  1. Justin
    Justin avatar
    11 posts
    Member since:
    Jul 2012

    Posted 30 May 2013 Link to this post

    I am having difficulty getting the group by Footer Text to have say Subtotal for the groups and then an actual total for everything
    I have tried implementing suggestions listed in other forums but none of them seem to work. Any help would be greatly appreciated. 
    Example what I am trying for is 

    Type: Type 1 - Water Quality
            Data $5
    Data $6
    Data $4
    --Footer Type 1 - Water Quality total sites: 3     $15
    Type: Type 2 - Research
            Data $10
    Data $20
    Data $20
    --Footer Type 2 - Research total Sites sites: 3     $50
    Total sites: 6  $65





    FRONT END
    <
    telerik:RadGrid ID="rgSite" runat="server" AllowSorting="True"  Skin="Silk" OnNeedDataSource="rgSite_NeedDataSource" EnableLinqExpressions="false" OnPreRender="rgSite_PreRender"
                        AutoGenerateColumns="False" AlternatingItemStyle-BackColor="White"  Width="1298px" OnUpdateCommand="rgSite_UpdateCommand" OnInsertCommand="rgSite_InsertCommand">
        <MasterTableView CommandItemDisplay="Top" ShowFooter="true" ShowGroupFooter="true"
                            DataKeyNames="details_site_id">
        <EditFormSettings PopUpSettings-Modal="false" UserControlName="controls/FundedSites.ascx"
                            EditFormType="WebUserControl"/>
        <CommandItemSettings ShowRefreshButton="false" ShowAddNewRecordButton="false"  addnewrecordtext="Add a Site"/>
            <Columns>
                <telerik:GridEditCommandColumn ButtonType="ImageButton" Visible="false" UniqueName="Edit"/>
                <telerik:GridBoundColumn DataField="site_no" SortExpression="site_no" AllowSorting="true"
                                            UniqueName="site_no" visible="false"/>
                <telerik:GridTemplateColumn DataField="site_no_nm" SortExpression="site_no_nm"
                                            UniqueName="site_no_nm" HeaderText="Site Number"
                                            ItemStyle-BorderStyle="Solid" ItemStyle-Bordercolor="Silver" ItemStyle-BorderWidth="0.25"
                                            Aggregate="CountDistinct" FooterText="Total Funded Sites: ">
                    <ItemTemplate>
                        <asp:HyperLink ID="HyperLink1" runat="server"
                            NavigateUrl='<%# string.Format("site.aspx?org_cd={0}&cust_id={1}&agmt_id={2}&site_no={3}",org_cd,cust_id,agmt_id,ProcessMyDataItem(Eval("site_no")))  %>'
                            Text='<%# ProcessMyDataItem(Eval("site_no_nm")) %>'/>
                        <asp:HiddenField runat="server" ID="hfCollectionUnits" Visible="false" Value='<%# ProcessMyDataItem(Eval("data_collection")) %>'/>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn DataField="collection_cd" SortExpression="collection_cd"
                    UniqueName="collection_cd" HeaderText="Code"
                    ItemStyle-BorderStyle="Solid" ItemStyle-Bordercolor="Silver" ItemStyle-BorderWidth="0.25">
                    <ItemTemplate>
                        <a title='<%# ProcessMyDataItem(Eval("collection_desc")) %>' style="color:Black;text-decoration:none;">
                            <%# ProcessMyDataItem(Eval("collection_cd"))%>
                        </a>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="collection_units" SortExpression="collection_units" AllowSorting="true"
                    UniqueName="collection_units" HeaderText="Units"
                    ItemStyle-BorderStyle="Solid" ItemStyle-Bordercolor="Silver" ItemStyle-BorderWidth="0.25"
                    ColumnEditorID="ceUnit"/>
                <telerik:GridBoundColumn DataField="diff_factor" SortExpression="diff_factor" AllowSorting="true"
                    UniqueName="diff_factor" HeaderText="Diff. Factor"
                    ItemStyle-BorderStyle="Solid" ItemStyle-Bordercolor="Silver" ItemStyle-BorderWidth="0.25"
                    ColumnEditorID="ceUnit"/>
                <%--<telerik:GridBoundColumn DataField="data_collection" SortExpression="data_collection"
                    UniqueName="data_collection" HeaderText="Data Collection" Visible="false"
                    ItemStyle-BorderStyle="Solid" ItemStyle-Bordercolor="Silver" ItemStyle-BorderWidth="0.25" />--%>
                <telerik:GridNumericColumn DataField="funding_usgs_cwp" SortExpression="funding_usgs_cwp" AllowSorting="true"
                    UniqueName="funding_usgs_cwp" HeaderText="USGS CWP" DataFormatString="{0:c0}" DataType="System.Decimal"
                    ItemStyle-BorderStyle="Solid" ItemStyle-Bordercolor="Silver" ItemStyle-BorderWidth="0.25"
                    Aggregate="Sum" FooterAggregateFormatString="{0:c0}"
                    ColumnEditorID="ceFunds"/>
                <telerik:GridNumericColumn DataField="funding_customer" SortExpression="funding_customer" AllowSorting="true"
                    UniqueName="funding_customer" HeaderText="Customer" DataFormatString="{0:c0}" DataType="System.Decimal"
                    ItemStyle-BorderStyle="Solid" ItemStyle-Bordercolor="Silver" ItemStyle-BorderWidth="0.25"
                    Aggregate="Sum" FooterAggregateFormatString="{0:c0}"
                    ColumnEditorID="ceFunds"/>
                <telerik:GridBoundColumn DataField="funding_total" SortExpression="funding_total" AllowSorting="true"
                    UniqueName="total" HeaderText="Total" DataFormatString="{0:c0}" DataType="System.Decimal"
                    ItemStyle-BorderStyle="Solid" ItemStyle-Bordercolor="Silver" ItemStyle-BorderWidth="0.25"
                    Aggregate="Sum" FooterAggregateFormatString="{0:c0}" ReadOnly="true"/>
     
                <telerik:GridBoundColumn DataField="remarks" SortExpression="remarks" AllowSorting="true"
                    UniqueName="remarks" HeaderText="Remarks"
                    ItemStyle-BorderStyle="Solid" ItemStyle-Bordercolor="Silver" ItemStyle-BorderWidth="0.25" />
                <telerik:GridButtonColumn ConfirmText="Delete this record?" ConfirmDialogType="RadWindow"
                    confirmtitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                    uniquename="Delete" Visible="false"/>
            </Columns>
            <GroupByExpressions>
                <telerik:GridGroupByExpression>
                    <SelectFields>
                        <telerik:GridGroupByField FieldName="data_collection" FieldAlias="Task"/>
                    </SelectFields>
                    <GroupByFields>
                        <telerik:GridGroupByField FieldName="data_collection" />
                    </GroupByFields>
                </telerik:GridGroupByExpression>
            </GroupByExpressions>
            <ExpandCollapseColumn>

            <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
        </MasterTableView>
    </telerik:RadGrid>

    CODE BEHIND
    protected void rgSite_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        var fundingdb = new fundingdbDataContext();
        rgSite.DataSource = fundingdb.SP_Funding_Agreement_Sites_Details(Convert.ToInt32(agmt_id),Convert.ToInt32(cust_id)).ToList();
    }
    //Removes Repeating values
    protected void rgSite_PreRender(object sender, EventArgs e)
    {
        //The Row Index is the Row above the bottom row, walk up the Grid
        for (int rowIndex = rgSite.Items.Count - 2; rowIndex >= 0; rowIndex += -1)
        {
            //The Current Row is the row index
            GridDataItem row = rgSite.Items[rowIndex];
            //The Previous Row is one below it
            GridDataItem previousRow = rgSite.Items[rowIndex + 1];
            //Grab the ItemTemplate Text values from the Hyperlink of the current and previous row and compare them.
            if ((row["site_no"].FindControl("HyperLink1") as HyperLink).Text == (previousRow["site_no"].FindControl("HyperLink1") as HyperLink).Text && (row["site_no"].FindControl("hfCollectionUnits") as HiddenField).Value == (previousRow["site_no"].FindControl("hfCollectionUnits") as HiddenField).Value)
            {
                //If they are the same set the previous rows Text to blank
                previousRow["site_no_nm"].Text = "";
            }
        }
    }

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 31 May 2013 Link to this post

    Hi Justin,

    I'm not sure if this is what you exactly want,please have a look at the following code.Its is an example i have tried.

    ASPX:
    <telerik:RadGrid ID="Radgrid1" runat="server" AllowSorting="True" Skin="Silk" 
               EnableLinqExpressions="false" OnPreRender="rgSite_PreRender" AutoGenerateColumns="False"
               AlternatingItemStyle-BackColor="White" Width="1298px" DataSourceID="SqlDataSource1">
               <MasterTableView CommandItemDisplay="Top" ShowFooter="true" ShowGroupFooter="true"
                   DataKeyNames="OrderID">
                   <EditFormSettings />
                   <CommandItemSettings ShowRefreshButton="false" ShowAddNewRecordButton="false" AddNewRecordText="Add a Site" />
                   <Columns>
                       <telerik:GridEditCommandColumn ButtonType="ImageButton" Visible="true" UniqueName="Edit" />
                       <telerik:GridBoundColumn SortExpression="OrderID" HeaderText="OrderID" HeaderButtonType="TextButton"
                           DataField="OrderID" UniqueName="OrderID" ReadOnly="true" Aggregate="Count">
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn SortExpression="OrderDate" HeaderText="Date Ordered" HeaderButtonType="TextButton"
                           DataField="OrderDate" UniqueName="OrderDate">
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn SortExpression="ShipPostalCode" HeaderText="ShipPostalCode"
                           HeaderButtonType="TextButton" DataField="ShipPostalCode" UniqueName="ShipPostalCode">
                       </telerik:GridBoundColumn>
                       <telerik:GridBoundColumn SortExpression="EmployeeID" HeaderText="EmployeeID" HeaderButtonType="TextButton"
                           DataField="EmployeeID" UniqueName="EmployeeID" Aggregate="CountDistinct">
                       </telerik:GridBoundColumn>
                   </Columns>
                   <GroupByExpressions>
                       <telerik:GridGroupByExpression>
                           <SelectFields>
                               <telerik:GridGroupByField FieldName="OrderID" FieldAlias="Count" Aggregate="Count"
                                   HeaderText="hello" />
                           </SelectFields>
                           <GroupByFields>
                               <telerik:GridGroupByField FieldName="ShipPostalCode" />
                           </GroupByFields>
                       </telerik:GridGroupByExpression>
                   </GroupByExpressions>
                   <ExpandCollapseColumn>
                       <HeaderStyle Width="20px"></HeaderStyle>
                   </ExpandCollapseColumn>
               </MasterTableView>
           </telerik:RadGrid>

    Thanks
    Princy

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Justin
    Justin avatar
    11 posts
    Member since:
    Jul 2012

    Posted 31 May 2013 Link to this post

    The image down below named current funding shows what the grid currently looks like. I am trying to give custom footer names to the groups while not messing with Total funding section. The desired result is in the desired funding image. 

    Thanks.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Jun 2013 Link to this post

    Hi Justin,

    I have customized the footer,here is the code snippet.Its coded in the ItemDataBound event.If still you find problem,please provide your header code.

    C#:
    protected void Radgrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
      if (e.Item is GridGroupFooterItem)
        {
            GridGroupFooterItem item = (GridGroupFooterItem)e.Item;
            DataRowView groupDataRow = (DataRowView)e.Item.DataItem;
            string val = item["ShipCity"].Text.Split(':')[1].ToString();
            item["ShipCity"].Text = groupDataRow["ShipCity"].ToString() + ":" + val;
        }
     
    }
    Thanks
    Princy
  6. Justin
    Justin avatar
    11 posts
    Member since:
    Jul 2012

    Posted 03 Jun 2013 Link to this post

    The issue would not be resolved in the ItemDataBound event, no matter which solution I used the text would always go back to the default value. So I found a workaround, I added this code to the PreRender Event and it seems to work well. 

    foreach (GridGroupFooterItem item in rgSite.MasterTableView.GetItems(GridItemType.GroupFooter))
    {
        foreach (TableCell cell in item.Cells)
        {
            if (cell.Text.Contains("CountDistinct"))
            {
                string count = Regex.Replace(cell.Text, "[^.0-9]", "");
                cell.Text = string.Format("Funded Sites: {0}", count);
            }
        }
    }
    foreach (GridFooterItem item in rgSite.MasterTableView.GetItems(GridItemType.Footer))
    {
        foreach (TableCell cell in item.Cells)
        {
            if (cell.Text.Contains("CountDistinct"))
            {
                string count = Regex.Replace(cell.Text, "[^.0-9]", "");
                cell.Text = string.Format("Total Funded Sites: {0}", count);
            }
        }
    }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017