Best way to sum in v1.10
Best way to sum in v1.10
norglaw
Posts: 9Questions: 0Answers: 0
Hi,
I am calculating sums column by colum on a table with more than 1000 lines and 19 columns.
It takes a few seconds each time, and I'd like it to be fluid.
The trick is that some colums and rows can be hidden, so it can't just be an operation on DOM nodes.
Here the piece of code I use which I guess is not optimized :
[code]
var tabTotal = {};
$(latable.fnSettings().aoData).each(function(index, element) {
for (var index2=0 ; index2
I am calculating sums column by colum on a table with more than 1000 lines and 19 columns.
It takes a few seconds each time, and I'd like it to be fluid.
The trick is that some colums and rows can be hidden, so it can't just be an operation on DOM nodes.
Here the piece of code I use which I guess is not optimized :
[code]
var tabTotal = {};
$(latable.fnSettings().aoData).each(function(index, element) {
for (var index2=0 ; index2
This discussion has been closed.
Replies
If you are using fnSettings, then generally speaking, something has gone wrong somewhere. You should never need to do so.
In 1.10 by far the best way of calculating a column sum is:
[code]
var column0sum = table.column( 0 ).data().reduce( function (a, b) {
return a + b;
} );
[/code]
Allan
Thx for your help.
When you write [code]table.column(0)[/code]
Do you mean ? [code]table.api(true).column(0)[/code]
Alban
Allan