footerCallback calculatte average...
footerCallback calculatte average...
BhavinBhatt
Posts: 27Questions: 9Answers: 0
, "footerCallback": function (row, data, start, end, display) {
var tdailyPI;
var api = this.api(), data;
//function to convert string values to numeric
var intVal = function (i) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '') * 1 :
typeof i === 'number' ?
i : 0;
}
//Total Qty
if (api.column(5, { search: 'applied' }).data().length > 0) {
avgPI = api
.column(5, { search: 'applied' })
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
//totWd = time_convert(totWd);
//totWd = $.fn.dataTable.render.number('', '.', 2, '').display(totWd);
avgPI = convertNumToTime(avgPI);
tdailyPI = avgPI;
//totWd = $.fn.dataTable.render.number('', '.', 2, '').display(totWd);
}
else {
avgPI = 0.0;
tDailyPI = avgPI;
}
//totWd = (totWd * 0.6);
//totWd = time_convert(totWd);
//totWd = $.fn.dataTable.render.number('', '.', 2, '').display(totWd);
$(api.column(5).footer()).html(avgPI);
//Daily PI
}
//I WANT TO CALCULATE AVERAGE OF avgPI with search effect...
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. 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
Colin, I just wanna know how to get total number of rows with search effect..
$(api.column(5).footer()).html(avgPI);
here, avgPI should be divided by total no of rows with search effect if user searched for anything, if not given search, avgPI should be divided by total nos of rows..
Thanks,
ßhavin.
Use something like this:
See the
selector-modifier
andcount()
docs.Kevin