Get the sum of a column with two values in their cells
Get the sum of a column with two values in their cells
fedegiro
Posts: 10Questions: 5Answers: 0
I have column that have cells with two values like this:
<td><span class="first-value">1200</span> / <span class="second-value">2000</span></td>
<td><span class="first-value">800</span> / <span class="second-value">3200</span></td>
<td><span class="first-value">500</span> / <span class="second-value">1400</span></td>
(Here's the JSFiddle)
I've already checked the examples https://datatables.net/reference/api/column().footer() and https://datatables.net/reference/option/footerCallback, to get the sum of both values of the column (ej. 2500 / 6600) in the footer. But i can't get it to work when the cells have two values.
Any help would be appreciated.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
nobody?
Perhaps the easiest way is to use the
pluck()
method to get the data from the rows -table.rows().data().pluck( 'first_value' );
will give you an array of the data that containsfirst_value
. Then usereduce()
like in my demo to calculate the sum from that array.Do likewise for the
second_value
.Allan