Grid Templet column with Total,summary

7 posts, 0 answers
  1. NA
    NA avatar
    39 posts
    Member since:
    Aug 2013

    Posted 06 Mar 2014 Link to this post

    I using GridTemplateColumn RadNumericTextBox when i enter Amount in textbox automatically add  to Total ,sample code in  client side and server side

  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 07 Mar 2014 in reply to NA Link to this post

    Hello,

    Please check the below link. In this link you can able to find server and client side code.

    Accessing and validating controls client-side inside a hierarchical RadGrid

    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 Mar 2014 in reply to NA Link to this post

    Hi,

    Please take a look at the following code snippet.

    ASPX:
    <telerik:GridTemplateColumn HeaderText="Number">
        <ItemTemplate>
            <telerik:RadNumericTextBox ID="ValueTxt" runat="server" AutoPostBack="true" Value="0" OnTextChanged="ValueTxt_TextChanged">
            </telerik:RadNumericTextBox>
        </ItemTemplate>
        <FooterTemplate>
            <telerik:RadNumericTextBox ID="TotalTxtBox" runat="server">
            </telerik:RadNumericTextBox>
        </FooterTemplate>
    </telerik:GridTemplateColumn>

    From ServerSide:
    C#:
    int total;
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item=(GridDataItem)e.Item;
            RadNumericTextBox txt=(RadNumericTextBox)item.FindControl("ValueTxt");
            int fieldValue = int.Parse(txt.Text);
            total += fieldValue;
        }
        if (e.Item is GridFooterItem)
        {
            GridFooterItem footerItem = e.Item as GridFooterItem;
            RadNumericTextBox footertxt = (RadNumericTextBox)footerItem.FindControl("TotalTxtBox");
            footertxt.Text = total.ToString();
        }
    }
    protected void ValueTxt_TextChanged(object sender, EventArgs e)
    {
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
        {
            RadNumericTextBox txt = (RadNumericTextBox)item.FindControl("ValueTxt");
            int fieldValue = int.Parse(txt.Text);
            total += fieldValue;
        }
     
        foreach (GridFooterItem footerItem in RadGrid1.MasterTableView.GetItems(GridItemType.Footer))
        {
            RadNumericTextBox footertxt = (RadNumericTextBox)footerItem.FindControl("TotalTxtBox");
            footertxt.Text = total.ToString();
        }
    }

    For doing it from client you can use the ClientEvents-OnValueChanged="OnValueChanged" event for the ItemTemplate RadNumericTextBox 'ValueTxt'.
    From ClientSide:

    JS:
    <script type="text/javascript">
        function OnValueChanged(sender, args) {
            var grid = $find("<%=RadGrid1.ClientID %>");
            var totalAmount = 0;
            if (grid) {
                var MasterTable = grid.get_masterTableView();
     
                var Rows = MasterTable.get_dataItems();
                for (var i = 0; i < Rows.length; i++) {
     
                    var row = Rows[i];
                    var txtQuntity1 = row.findControl("ValueTxt");
                    totalAmount = totalAmount + txtQuntity1.get_value();
     
                }
            }
            var footerTextBox = '<%= ((GridFooterItem)RadGrid1.MasterTableView.GetItems(GridItemType.Footer)[0]).FindControl("TotalTxtBox").ClientID %>';
            var TextBox = document.getElementById(footerLabelID);
            TextBox.control.set_value(totalAmount);
        }
    </script>

    Thanks,
    Princy
  5. Ramey
    Ramey avatar
    19 posts
    Member since:
    Feb 2016

    Posted 24 Feb in reply to Princy Link to this post

    Hello,

    Where are you getting footerLabelID from?  I was trying to implement this into my project.

    Ramey

  6. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 25 Feb Link to this post

    Hi Ramey,

    You can check the following articles:
    http://www.telerik.com/help/aspnet-ajax/grid-totals-with-numerictextbox.html
    http://www.telerik.com/help/aspnet-ajax/grid-totals-in-footers.html
    http://www.telerik.com/help/aspnet-ajax/grid-using-getitems-getcolumn-methods.html


    These posts, too:
    http://www.telerik.com/forums/radgrid-group-footer-dynamic-calculation
    http://www.telerik.com/forums/how-to-change-keypress-event-in-telerik-grid
    http://www.telerik.com/forums/how-to-changes-telerik-grid-running-total-footer-template

    I am also attaching another web site sample for reference.

    I hope these resources will prove helpful.


    Regards,
    Eyup
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  7. Ramey
    Ramey avatar
    19 posts
    Member since:
    Feb 2016

    Posted 25 Feb in reply to Eyup Link to this post

    Hi Eyup,

    Thank you for you quick response.  Currently my grid is using batch edit mode and I've implemented Telerik's batchmanagerextentions.js to handle multiple radcomboboxes using tooltips.  I have one GridBoundColumn and I need to calculate the sum for all of those values client side so it will be a live updated value.  I haven't figured out how to use aggregates since the datatype is a varchar.  If I use a template column once I click on a cell for it to enter into batch edit mode the values aren't saved after entered. So this is basically where I am at currently.  I wanted to see if there was a way to add up all work percents in my column and total it in the footer but if one changes then change the footer total accordingly.  I haven't been able to find any solutions thus far.  If you know of any way it would be very helpful.

    Thanks,

    Ramey

  8. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 01 Mar Link to this post

    Hello Ramey,

    I suggest that you continue your conversation on the following forum thread and leverage the approach suggested by my colleague:
    http://marketplace.telerik.com/forums/footer-total-in-batch-edit-mode

    Regards,
    Eyup
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017