Is it possible to sum like Ms Excel on html with jquery? And how about if there is a string inside like this <td>USD 7.50</td>
, is it possible?
Sorry for my english btw.
Is it possible to sum like Ms Excel on html with jquery? And how about if there is a string inside like this <td>USD 7.50</td>
, is it possible?
Sorry for my english btw.
You can make sum with a each of columns
var count=0;
$(".number").each(function(){
count=count+parseInt($(this).html().replace("USD","").trim());
});
$(".footer-table tr td:last").html(count);
If your column might have other text besides USD or possibly comas, you might consider a regex to replace everything that is not a number or a period.
Note that something like G6 900.18
, would be seen as 6900.18 so be aware of that.
var count=0;
$(".number").each(function(){
count = count + $(this).html().replace(/[^.\d]/g,'') * 1000;
});
$(".grand-total").html((count / 1000).toFixed(2));