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

Grid Templet column with Total,summary

6 Answers 182 Views
Grid
This is a migrated thread and some comments may be shown as answers.
NA
Top achievements
Rank 1
NA asked on 06 Mar 2014, 12:32 PM
I using GridTemplateColumn RadNumericTextBox when i enter Amount in textbox automatically add  to Total ,sample code in  client side and server side

6 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 07 Mar 2014, 09:36 AM
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
0
Princy
Top achievements
Rank 2
answered on 07 Mar 2014, 09:46 AM
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
0
Ramey
Top achievements
Rank 1
answered on 24 Feb 2016, 07:41 PM

Hello,

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

Ramey

0
Eyup
Telerik team
answered on 25 Feb 2016, 02:33 PM
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
0
Ramey
Top achievements
Rank 1
answered on 25 Feb 2016, 03:09 PM

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

0
Eyup
Telerik team
answered on 01 Mar 2016, 01:04 PM
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
Tags
Grid
Asked by
NA
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Ramey
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or