how to have two attributes in a columns to display data, and calculate sum of one attribute
how to have two attributes in a columns to display data, and calculate sum of one attribute
anujgakhar
Posts: 3Questions: 0Answers: 0
I am having two attributes in a single column of a row of a table. i want to calculate sum of one attribute in the footer. I am using data table 1.9. can anyone tell me how to do it
example
my jsp code looks like this
<th>revenue (r.percentage)</th>
<td>${a.revenue} (${a.percentage}%)</td>
<td>${a.revenue} (${a.percentage}%)</td>
page
10,000(20%)
20,000(40%)
..............................
**30,000 **
i want to calculate 30,000 at the footer
This discussion has been closed.
Replies
Take a look at this please:
https://datatables.net/examples/advanced_init/footer_callback.html
Thanks for the reply rf1234 but the problem isnt solved with the solution provided, that is a single column of a row contain 2 attributes here for instance i have 2 products a,b
A B
<tr>
<td>${a} ${(aPercentage)}</td> <td>${b} ${(bPercentage)}</td>
</tr>
<tr>
<td>${a} ${(aPercentage)}</td> <td>${b} ${(bPercentage)}</td>
</tr>
<tr>
<td>${a} ${(aPercentage)}</td> <td>${b} ${(bPercentage)}</td>
</tr>
<tr>
<td>${a} ${(aPercentage)}</td> <td>${b} ${(bPercentage)}</td>
</tr>
...................................................................................................................
sum(a) sum(b)
sum a doensnt include a percentage
so how to fetch value of 'a' only as of now it recives 'a(aPercentage)' in my datatable inside data
Thanks for the reply rf1234 but the problem with the solution provided is that single column of a row doesnt contain 2 attributes here for instance i have 2 products a,b
A B
<tr><td>${a} ${(aPercentage)}</td> <td>${b} ${(bPercentage)}</td></tr>
<tr><td>${a} ${(aPercentage)}</td> <td>${b} ${(bPercentage)}</td></tr>
<tr><td>${a} ${(aPercentage)}</td> <td>${b} ${(bPercentage)}</td></tr>
<tr><td>${a} ${(aPercentage)}</td> <td>${b} ${(bPercentage)}</td></tr>
...................................................................................................................
sum(a) sum(b)
sum a doensnt include a percentage
so how to fetch value of 'a' only as of now it recives 'a(aPercentage)' in my datatable inside data
You could define a reducer that only addresses your first td element in each tr.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce
https://stackoverflow.com/questions/16668094/jquery-selector-first-td-of-each-row