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

Radgrid Template Columns Total

13 Answers 209 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Kavya
Top achievements
Rank 2
Kavya asked on 07 Jul 2011, 05:27 PM
Hi

I am trying to get Template columns Total to be updated on Footer  and Label outside the Grid

Here is my scenario

i have qty,price,discount and total(which is calculated client side). So when the user enters the qty and selects the price and
 discounts(if any)  i calculate the total on client side.
As user can select multiple items, total is calculated accordingly. But i want the Sum of total in the footer and also label which is outside the grid. Can we show the sum in the footer  and also  in the label using client side functions

Please suggest

Thank you
Kavya

13 Answers, 1 is accepted

Sort by
0
Genti
Telerik team
answered on 12 Jul 2011, 02:59 PM
Hello Kavya ,

In this case you can get the footer element in the following way:
var footer = grid.get_masterTableViewFooter().get_element();
footer.rows[0].cells[1].innerHTML = 'Something'; // Set the footer text

Also, you can print something outside by injecting JavaScript node of text or overriding the text of a node that already exists in the DOM.
I.e
//get some existing element
document.getElementById("elementID").innerText = "Something";
//or create a new node and append it to a container
var txt = document.createTextNode(" This text was added to the DIV.");
document.getElementById('myDiv').appendChild(txt);

Hope this helps.

Regards,
Genti
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Kavya
Top achievements
Rank 2
answered on 12 Jul 2011, 03:22 PM
Hi Genti

Thank you for the update

var footer = grid.get_masterTableViewFooter().get_element();
footer.rows[0].cells[1].innerHTML = 'Something';

How  can i show Total from Template columns in place of 'Something'.

And how can get the sum of total in a Label outside Grid


0
Genti
Telerik team
answered on 12 Jul 2011, 04:32 PM
Hello Kavya ,

Well in such case you can do the following:
-Declare a global  variable called total.
-Then update the total each time someone enters quantity and price for a row.

Greetings,
Genti
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Kavya
Top achievements
Rank 2
answered on 12 Jul 2011, 05:44 PM
Genti

I am using Javascript to Update Total in Template Column using OnChange . So the when user enters qty and selects the price the total is calculated using Javascript and shows on the Template column. I can show that total in the Label. However if there are multiple products they select i want the sum to be shown in the Label. Below is sample of code i use

qty_txt.Attributes.Add("onchange", "calc_disc(" + tot_txt.ClientID + "," + disc_fee.ClientID + "," + qty_txt.ClientID + "," + disc_list.ClientID + "," + cpt_grid.ClientID + ")")
             
I am sending all client id for each item and calculating and showing it in tot_txt
If do lbl1.value = lbl1.value + tot_txt.value its working fine until the user goes back and changes the value for one item
Then i don't know how to show it in the lb1.value (which is outside the grid).
I tried using

 

function get_tot(sender,args)

 

{

 

 

var masterTable = sender.MasterTableView(); //reference MasterTableView's client bbject

 

 

var items = masterTable.get_dataItems(); //retrieve all data items in the table

 

 

 

var grandTotal = 0;

 

 

 

for(var i = 0; i < items.length; i++) //loop through the items

 

{

 

var total = parseFloat(items[i].findElement("tot_txt").innerHTML);

 

 

grandTotal += total;

}

 

lb1.value = parse.

float(grandTotal);

 

}

Gives me error at  sender.MasterTableView its not recognizing the grid

Thank you

0
Genti
Telerik team
answered on 13 Jul 2011, 02:21 PM
Hello Kavya ,

You can make us of a delegate function that handle the Blur event of each of the row quantity and price fields.
So, after a user has moved the focus away from those fields you have to update the total.

Greetings,
Genti
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Kavya
Top achievements
Rank 2
answered on 18 Jul 2011, 05:40 PM
Hi Genti

Can you send me an example

the way i am trying to do is
<script>
 function calc_disc(totBox,priceBox,qtyBox,discBox,radgrid)
              {
               if (qtyBox.value == "" )
                   {
                     qtyBox.value = 1;
                    }
                if (priceBox.value =="$.00")
                     {
                       priceBox.value = 0;
                     }      
               var totVal = qtyBox.value * priceBox.value - (discBox.value * qtyBox.value * priceBox.value);
               totBox.value = "$" + parseFloat(totVal);
              var tot_cos = document.getElementById("tot_cos");
              if (tot_cos.value == "") 
               {
                tot_cos.value = 0;
               
               
              get_tot(radgrid,tot_cos)
              }
         
         function get_tot(sender,tot_cos)
            {
              
       var masterTable = sender.MasterTableView();     //reference MasterTableView's client bbject
            var items = masterTable.get_dataItems();            //retrieve all data items in the table
              
            var grandTotal = 0;
              
            for(var i = 0; i < items.length; i++)   //loop through the items
            {
                var total = parseFloat(items[i].findElement("tot_txt").innerHTML);
                  
                grandTotal += total;
            }
              
            tot_cos.value = parse.float(grandTotal);
 }
</script>
  
i am calling calc_disc on qty template column and also discount column
                qty_txt.Attributes.Add("onchange", "calc_disc(" + tot_txt.ClientID + "," + disc_fee.ClientID + "," + qty_txt.ClientID + "," + disc_list.ClientID + "," + grid.ClientID + ")")

tot_cos is label outside grid
sender.MasterTableView();     gives me error message
If i use
tot_cos.value = parseFloat(tot_cos.value) + parseFloat(totVal); 

     instead of calling get_tot(radgrid,tot_cos) and if user changes the qty i can only send the current value,then it just goes on adding to the label total       

Hope this is understandable.

Please help Thank you

0
Genti
Telerik team
answered on 19 Jul 2011, 11:50 AM
Hi Kavya ,

I am attaching a solution that illustrates what you are trying to achieve.


All the best,
Genti
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Kavya
Top achievements
Rank 2
answered on 02 Sep 2011, 06:21 PM
Hi Genti

Didn't get chance to work on this issue until now.
I am using Radgrid 5.1 version is there a way to get dataitems of radgrid using javascript.

I ma trying to use

get_masterTableView() and get_dataItems(). It throws error object doesn't support this property.

Please let me know if there is a way to get items in javascript.

Thank you
kavya

0
Bodevain Svensson
Top achievements
Rank 1
answered on 03 Sep 2011, 08:48 AM
When you use the old ASP.NET telerik grid, you can transform the code as follows:
get_masterTableView() and get_dataItems()
 
Here you can find links to the demos and documentation of the classic grid:
http://www.telerik.com/community/forums/aspnet/general-discussions/online-demos-amp-documentation-for-radcontrols-for-asp-net-quot-classic-quot.aspx

Note that these controls are not supported as of Q1 2011, telerik has that stated on their site.

-Bodevain
0
Kavya
Top achievements
Rank 2
answered on 06 Sep 2011, 04:21 PM
Bodevain

I have checked the demos you sent me. They are the regular one's

I was lookign for some way to get the radgrid item values and loop through the values using javascript.

Please let me know if you have any other thoughts

Thank you
kavya
0
Kavya
Top achievements
Rank 2
answered on 08 Sep 2011, 06:00 PM
Can anyone please help me with this issue.


Never mind got it resolved. Thank you everyone' for the help
Kavya
0
Jayesh Goyani
Top achievements
Rank 2
answered on 16 Sep 2011, 01:58 PM
Hello,

try with below thread.

http://www.telerik.com/community/forums/aspnet-ajax/grid/grid-rows-find-in-java-script.aspx

let me know if any concern.

Thanks,
Jayesh Goyani
0
Kavya
Top achievements
Rank 2
answered on 16 Sep 2011, 03:20 PM
Hi Jayesh

Thank you. But i got it resolved by adding

AllowRowHide

 

="true"

 

which i was able to find in only one Thread.
 
Eventhoug i used the same function as you sent before it never worked until i added the above

Thank you for youre' time and like ur avatar its so funny

Kavya
Tags
Ajax
Asked by
Kavya
Top achievements
Rank 2
Answers by
Genti
Telerik team
Kavya
Top achievements
Rank 2
Bodevain Svensson
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or