Sum the data of one column but filter
Sum the data of one column but filter
Massimo1974
Posts: 27Questions: 2Answers: 0
Hello,
I would like to add data to a column but add only the filtered rows.....dovrei usare ".filter()" ???
"footerCallback": function ( row, data, start, end, display ) {
var api = this.api(), data;
var intVal = function ( i ) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '')*1 :
typeof i === 'number' ?
i : 0;
};
var Total5 = api
.rows( { selected: true } ).indexes()
.column(5,{page:'all'})
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
$( api.column(5).footer()).html(Total5);
This discussion has been closed.
Replies
Hi @Massimo1974 ,
I don't entirely follow, but I think you just need to change line 10 to be
If that's not what you're after, please can you provide a test case, showing the current behaviour and what you want instead. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
http://live.datatables.net/temuguhi/1/edit
in this table table export-option does not work, i have another problem, exportOption:{columns:[ 7,8,9,10, ':visible' ]} no work
Hi @Massimo1974 ,
That fiddle doesn't run - please can you fix the errors. As I said before, can you show "the current behaviour and what you want instead" - simply saying it doesn't work doesn't help.
Thanks,
Colin
.rows( { selected: true, search: 'applied' } ).indexes()
not work
I'm not sure why you have
.rows( { selected: true } ).indexes()
in your original code snippet. But if you want to sum the value based on the search results then you can change.column(5,{page:'all'})
to use a differentselector-modifier
:{search:'applied'}
. I updated the FooterCallback Example to sum the values based on the search results:http://live.datatables.net/losejowi/1/edit
likely you will want to remove
.rows( { selected: true } ).indexes()
and just use.column(5,{search:'applied'})
. If you aren't able to get this to work then please create a simple example with your data and your FooterCallback. The reset of your code isn't needed for a test case.Kevin
good now is work thanks
var Total5 = api
.column(5,{search: 'applied'})
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );