admin管理员组文章数量:1333711
I am using datatables. In addition to the regular table set up I am using datatables to add
Row Groups - Outlined here
Column Totals - Using Footer Callbacled Outlined here
I have a working Demo here /
Everything is working fine except my totals are being calculated 1 column off to the right (as you can easily see from demo) I am pretty sure the reason is because of the way groups works and is displayed.
I would like to display the totals under the correct column. i.e. shift all totals 1 column left to line up correctly.
The code used uses the first <td>
in the row to use as the group name so for example
<td>Joe Hammer</td>
is used as a group name.
This is the code I am using to calculate the totals
"fnFooterCallback": function (nRow, aasData, iStart, iEnd, aiDisplay) {
var columnas = [1, 2, 3, 4, 5, 6, 7]; //the columns you wish to add
for (var j in columnas) {
var columnaActual = columnas[j];
var total = 0;
for (var i = iStart; i < iEnd; i++) {
total = total + parseFloat(aasData[aiDisplay[i]][columnaActual]);
}
$($(nRow).children().get(columnaActual)).html(total);
} // end
I am using datatables. In addition to the regular table set up I am using datatables to add
Row Groups - Outlined here
Column Totals - Using Footer Callbacled Outlined here
I have a working Demo here http://jsfiddle/c5UXe/
Everything is working fine except my totals are being calculated 1 column off to the right (as you can easily see from demo) I am pretty sure the reason is because of the way groups works and is displayed.
I would like to display the totals under the correct column. i.e. shift all totals 1 column left to line up correctly.
The code used uses the first <td>
in the row to use as the group name so for example
<td>Joe Hammer</td>
is used as a group name.
This is the code I am using to calculate the totals
"fnFooterCallback": function (nRow, aasData, iStart, iEnd, aiDisplay) {
var columnas = [1, 2, 3, 4, 5, 6, 7]; //the columns you wish to add
for (var j in columnas) {
var columnaActual = columnas[j];
var total = 0;
for (var i = iStart; i < iEnd; i++) {
total = total + parseFloat(aasData[aiDisplay[i]][columnaActual]);
}
$($(nRow).children().get(columnaActual)).html(total);
} // end
Share
Improve this question
edited Sep 2, 2013 at 16:30
madth3
7,34412 gold badges52 silver badges74 bronze badges
asked Aug 11, 2013 at 15:11
RedwallRedwall
1,0205 gold badges31 silver badges56 bronze badges
2 Answers
Reset to default 2I believe you can fix it entirely through tweaking the JS.
Update the columns to add
var columnas = [2, 3, 4, 5, 6, 7, 8];
Then get columnaActual-1 instead of columnaActual
$($(nRow).children().get(columnaActual-1)).html(total);
Feels weird answering this myself, but just incase anyone else has the same issue here you go.
Updated JSFiddle http://jsfiddle/c5UXe/1/
I added an extra <th>
to the column total and I removed the 2nd <th>
in column total via CSS setting the style to none.
I then Updated the Columns to add to this
var columnas = [2, 3, 4, 5, 6, 7,8]; //the columns you wish to add
Removing the first 1
and adding number 8
It is a pretty easy fix which mostly involved tweaking the HTML rather than the JS.
本文标签: javascriptDatatablesCalculate Column Total when using Row GroupsStack Overflow
版权声明:本文标题:javascript - Datatables - Calculate Column Total when using Row Groups - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742355212a2459269.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论