Click here to Skip to main content
15,885,048 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

I need to add items in grid and sum of total in footer.. sum of column is displayed but when i add new row the append field didn't sum the total. please help me

What I have tried:

I tried two methods:
$(document).ready(function () {
var total = 0;
$('.Total').each(function () {
var text = this.innerHTML;
var value = parseFloat(text);
if (!isNaN(value)) { total += value; }
});
$('.total_amount').html(total.toFixed(2));
});

$("table").delegate(".save", "click", function () {
var total = 0;
$('.Total').each(function () {
var text = this.innerHTML;
var value = parseFloat(text);
if (!isNaN(value)) { total += value; }
});
$('.total_amount').html(total.toFixed(2));
});
Posted
Updated 26-Nov-16 2:39am
v2

1 solution

So, two issues. First is DRY, and the second is that the .delegate() method is deprecated.

Move the logic into a function. Call that logic on page load and on column changes (or when you call the save() method).

JavaScript
function sumOfColumn(){
   var total = 0;
   $('.Total').each(function () {
      var text = this.innerHTML;
      var value = parseFloat(text);
      if (!isNaN(value)) { total += value; }
   });
   $('.total_amount').html(total.toFixed(2));
}

$('.Total').change(function(){sumOfColumn();});

$document.ready(function(){sumOfColumn();});
 
Share this answer
 
Comments
Vivek.anand34 27-Nov-16 23:52pm    
No.. its also same.. appended field did't sum...
Nathan Minier 29-Nov-16 7:21am    
Is the appended field being assigned the "Total" class?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900