Sum column values, but only selected rows
Sum column values, but only selected rows
Hi guys.
i need to solve this problem. please help me.
This code work fine and sum a column (9) with visible data in the page.:
$.fn.dataTable.Api.register( 'column().data().sum()', function () {
return this.reduce( function (a, b) {
var x = parseFloat( a ) || 0;
var y = parseFloat( b ) || 0;
return x + y;
} );
} );
$('<button class="dt-button">Sum visible hours</button>')
.prependTo('#somma_ore')
.on( 'click', function () {
alert( 'Le ore visibili sono: '+ table.column(9, {page:'current'} ).data().sum() );
} );
});
Now, i need another button to show, always in the same column, only selected rows.
thanks for the suggestions.
Replies
I think you are looking for the
selector-modifier
of{selected:true}
. The docs have examples.Kevin
Thank you kthorngren...
i've tried something like the code below, but don't work.....
$('<button class="dt-button">Somma Ore selezionate</button>')
.prependTo('#somma_ore')
.on( 'click', function () {
var lines = table.rows( {selected:true} ).data();
alert( 'Le ore selezionate sono: '+ table.column(9, lines, {page:'current'} ).data().sum());
});
because the modifier selected:true must be referred to the rows....not colums.
I don't know.....
Your
table.column(...)
call looks odd. There isn't a signature that would match that in the documentation forcolumn()
.Instead use:
Allan