How to display a running total of an amount entered into the table?
How to display a running total of an amount entered into the table?
Glyndwr
Posts: 128Questions: 35Answers: 1
http://live.datatables.net/dalogaci/1/edit
I have an amount of money to be dispersed. I want to provide a running total of the amount entered into the table please so I can warn when the total to be dispersed has been reached or passed.
Kind regards,
Glyn
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You would use
column().data()
whenever the value is changed, and just add up the values in theinput
elements. I suspect that would work.Colin
Thanks Colin,
This is what I did:
var sum = 0.0;
// this gets each node (cell) in the final column:
memDispTable.columns(4).nodes().to$()[0].forEach(function (item) {
// see if the display value is a number (i.e. not blank):
var amt = parseFloat($('input', item ).val());
if (!isNaN(amt)) {
sum += amt;
}
How would I populate another column with a calculated amount please? Foe example populate column 6 with column 4 divided by 2. I tried:
In my original:
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
http://live.datatables.net/kinikaje/1/edit
I have tied to get something like my code in the above.
I am iterating through rows of a DataTable to pickup the name of each person and the total that has been populated into the Total column (i.e., is a calculated field based on Amount entered and hours if they are entered, if no hours are entered then it is the same as the Amount entered). When I iterate through each row the Total column is not being returned for the correct row. An when I sort the Total is applied to a different row in the iteration (the amount is still on the correct row i.e., it stays with the correct person and does not move to a different person on the page).
This is my code as it stand now:
Thanks for the test case, can you give steps on what to do, and what you would expect to happen,
Colin