how to sum and average various columns at same time
how to sum and average various columns at same time
when i try this
$('#bateo').DataTable( {
drawCallback: function () {
var api = this.api();
api.table().footer().to$().html(
api.column( 4, {page:'current'} ).data().sum()
);
}
} );
result on this
col1 col2 col3 col4 col5 col6
1 1 2 3 1 1
1 2 2 4 0 3
TOTALS
when i try this
$('#bateo').DataTable( {
drawCallback: function () {
var api = this.api();
api.table().footer().to$().html(
api.columns( 4, {page:'current'} ).data().sum()
);
}
} );
result on this
col1 col2 col3 col4 col5 col6
1 1 2 3 1 1
1 2 2 4 0 3
TOTALS
when i do this
$('#bateo').DataTable( {
drawCallback: function () {
var api = this.api();
api.columns().footer().to$().html(
api.columns( 4, {page:'current'} ).data().sum()
);
}
} );
col1 col2 col3 col4 col5 col6
1 1 2 3 1 1
1 2 2 4 0 3
TOTALS 7 7 7 7 7 7
when i do that
$('#bateo').DataTable( {
drawCallback: function () {
var api = this.api();
api.columns([1,2,3,4]).footer().to$().html(
api.columns( 4, {page:'current'} ).data().sum()
);
}
} );
col1 col2 col3 col4 col5 col6
1 1 2 3 1 1
1 2 2 4 0 3
TOTALS 7 7 7 7
if i do
$('#bateo').DataTable( {
drawCallback: function () {
var api = this.api();
api.columns([1,2,3,4]).footer().to$().html(
api.columns( [1,2,3,4], {page:'current'} ).data().sum()
);
}
} );
col1 col2 col3 col4 col5 col6
1 1 2 3 1 1
1 2 2 4 0 3
TOTALS 7 7 7 7 7 7
but if i do this
$('#bateo').DataTable( {
drawCallback: function () {
var api = this.api();
api.columns(1).footer().to$().html(
api.columns(1, {page:'current'} ).data().sum()
);
var api = this.api();
api.columns(2).footer().to$().html(
api.columns(2, {page:'current'} ).data().sum()
);
var api = this.api();
api.columns(3).footer().to$().html(
api.columns(3, {page:'current'} ).data().sum()/11.00
);
var api = this.api();
api.columns(4).footer().to$().html(
api.columns(4, {page:'current'} ).data().sum()
);
var api = this.api();
api.columns(5).footer().to$().html(
api.columns(5, {page:'current'} ).data().sum()
);
var api = this.api();
api.columns(6).footer().to$().html(
api.columns(6, {page:'current'} ).data().sum()
);
}
} );
col1 col2 col3 col4 col5 col6
1 1 2 3 1 1
1 2 2 4 0 3
TOTALS 2 3 4 7 1 4
the same happen with average but with 16 decimal places after the decimal separator (.)
so what wrong with my code , i just want to sum or average various columns at the table footer at the sametime with 3 or 4 decimal places after the decimal separator
thanks