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

Calculate value for each radgrid row

4 Answers 334 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 10 Dec 2010, 06:13 PM
I have a dynamically built radgrid which outputs a list of products and their unit price. 
I have also created a template column for the grid which puts a textbox on each row so that a user can enter a quantity.

What I need to do is have some javascript so that when a user enters the quantity into the textbox for a given row, the cost of the unit price multiplied by the quantity is displayed on the row in another column, under the header text "Line Total", and the total of these for all of the rows is displayed at the bottom of the grid.

I also need to be able to have several of these grids on the same page and have the total for all grids displayed at the bottom of the page.

I have managed to get the grids all built ok and have the textboxes output but am really stumped as to how to proceed.

ANY help would be appreciated...

Thanks in advance,
Karl

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 Dec 2010, 10:43 AM
Hello Karl,

Check out the following forum post which is almost similar to your requirement. Attch 'onblur' client event to TextBox and find out the cell value for corresponding column with the same logic in that forum.
 RadGrid CalculatedColumn based on TemplateColumn

In order to find the total for that column, in that same event('onblur') loops through each grid row and find out the sum for that column and set it in footer. And also save the total to display it at the bottom of the page.

Thanks,
Princy.
0
Karl
Top achievements
Rank 1
answered on 13 Dec 2010, 01:09 PM
Thanks Princy, Once again you've come up trumps! :)

However, because I have a dynamic number of grids on my page, once I edit a value in my quantity/amount textboxes and the calculated column updates, I also need to do a page total, which should reflect the total of all the grids calculated columns.

I think the best place to do this is immediatly after the javascript call made in your example, but how do I itterate through all the grids on my page and retrieve the totals so I can add them all up and display them at the bottom of my page outside any of the grids?

0
Marin
Telerik team
answered on 15 Dec 2010, 05:04 PM
Hi Karl,

You can find all the grids on the page by iterating on the Sys.Application.getComponents() collection and checking whether they are of type RadGrid:
var components = Sys.Application.getComponents();
  
for (var i = 0; i < components.length; i++) {
  
     if (components[i] instanceof Telerik.Web.UI.RadGrid) {
  
           alert("grid");
     }
}

Feel free to ask if you have other questions.

Best wishes,
Marin
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Karl
Top achievements
Rank 1
answered on 16 Dec 2010, 12:17 PM
Thanks Marin, this has worked exactly as I had hoped.

Karl
Tags
Grid
Asked by
Karl
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Karl
Top achievements
Rank 1
Marin
Telerik team
Share this question
or