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

How to Change Total Values in Master /Child Grids as users are Adding/Changing Values before post back.

3 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 28 Mar 2014, 12:56 AM
Hi all,

Using VS 2010 with UI for ASP.NET AJAX Q1 2014. I am using Grid - Form Template Edit Form like this for both Master/Child Records:

http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/form-template-update/defaultcs.aspx

My question is it possible as users are typing the values in attached, total values gets changed accordingly for Master/Child Grids, not after post back but as
they are entering/changing values.

Thanks for any help.

3 Answers, 1 is accepted

Sort by
0
gc_0620
Top achievements
Rank 1
answered on 29 Mar 2014, 10:29 PM
Telerik/Shinu/Princy/Joyesh,

No solution for above? Thanks

gc_0620
0
Accepted
Konstantin Dikov
Telerik team
answered on 01 Apr 2014, 11:13 AM
Hello Ghulam,

There is no built-in functionality that could be used for your requirement. Please note that the aggregates are calculated on server-side and will be extremely difficult to update those values on client-side.

Nevertheless, following is a simple example of one possible approach that could be used:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function incomeValueChanged(sender, args) {
            var grid = $find("<%=RadGrid1.ClientID%>");
            var footer = grid.MasterTableView.get_element().getElementsByTagName("tfoot")[0].firstElementChild;
            var cellIndex = grid.MasterTableView._getCellIndexByColumnUniqueNameFromTableRowElement(footer, "Income");
            var oldIncome = footer.cells[cellIndex].innerHTML.replace("Sum : ", "");
            footer.cells[cellIndex].innerHTML = "Sum : " + (args.get_newValue() - args.get_oldValue() + parseFloat(oldIncome));
        }
    </script>
</telerik:RadCodeBlock>
 
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource">
    <MasterTableView AutoGenerateColumns="false" ShowFooter="true">
        <Columns>
            <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn>
            <telerik:GridBoundColumn DataField="ID"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="FirstName"></telerik:GridBoundColumn>
            <telerik:GridNumericColumn DataField="Income" Aggregate="Sum"></telerik:GridNumericColumn>
        </Columns>
        <EditFormSettings EditFormType="Template">
            <FormTemplate>
                Income:
                <telerik:RadTextBox runat="server" ID="RadTextBox1" Text='<%# Bind("Income") %>' ClientEvents-OnValueChanged="incomeValueChanged"></telerik:RadTextBox>
            </FormTemplate>
        </EditFormSettings>
    </MasterTableView>
</telerik:RadGrid>

And the code-behind:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable table = new DataTable();
    table.Columns.Add("ID", typeof(int));
    table.Columns.Add("FirstName", typeof(string));
    table.Columns.Add("LastName", typeof(string));
    table.Columns.Add("Age", typeof(int));
    table.Columns.Add("Income", typeof(decimal));
    for (int i = 0; i < 5; i++)
    {
        table.Rows.Add(i, "FirstName" + i, "LastName" + i, 20 + i, 205.20);
    }
 
    (sender as RadGrid).DataSource = table;
}

As you could notice, we are handling the client-side OnValueChanged event of the RadTextBox control. Then, we are getting reference to the TD element holding the aggregate value and we are changing its innerHTML.

The same approach should be used with hierarchical grid.

Hope that helps.


Regards,
Konstantin Dikov
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
gc_0620
Top achievements
Rank 1
answered on 03 Apr 2014, 11:53 PM
Thanks so much Konstantin for your help.

gc_0620.
Tags
Grid
Asked by
gc_0620
Top achievements
Rank 1
Answers by
gc_0620
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or