Created
May 14, 2020 07:24
-
-
Save reachkamrul/3177825e707bac4ec37d8b6d2cfc2eb1 to your computer and use it in GitHub Desktop.
avgFFtoNT.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myClasses= "ratings"; //give your columns key. | |
var totalText = "Average: "; //give you text | |
if(!$table.find('tfoot').length){ | |
jQuery("<tfoot></tfoot>").appendTo($table); | |
} | |
function getSum(classes) | |
{ | |
var sum = 0; | |
var index = 0; | |
var counter = 0; | |
jQuery("tbody ."+classes+"").each(function() { | |
var val = $.trim( $(this).text() ); | |
if ( val ) { | |
val = parseFloat( val.replace( /^\$/, "" ) ); | |
sum += !isNaN( val ) ? val : 0; | |
counter++; | |
} | |
}); | |
index += jQuery("."+classes+"").index()+1; | |
console.log(counter); | |
return [sum, index, counter]; | |
} | |
getSum(); | |
function renderTfoot(){ | |
var counts = $table.find(".footable-header th").length; | |
var num = parseInt(counts); | |
var container = $("<tr class='final_result' />"); | |
for(var i = 1; i <= num; i++) { | |
$('<td />', { | |
id: "id" + i, | |
name: "name" + i | |
}).appendTo(container); | |
} | |
$('tfoot').prepend(container); | |
} | |
function setSumAmount() { | |
var substr = myClasses.split(','); | |
$.each(substr , function(index, val) { | |
var singleClass = "ninja_clmn_nm_"+val.trim(); | |
$table.find('tfoot .final_result td:nth-child('+getSum(singleClass)[1]+')').html(totalText + '<b>'+(getSum(singleClass)[0]/getSum(singleClass)[2]).toFixed(2) +'</b>' ); | |
}); | |
} | |
setSumAmount(renderTfoot(), getSum()); | |
$table.on('after.ft.filtering','after.ft.paging', function() { | |
setSumAmount(); | |
}); | |
$table.on('after.ft.paging', function() { | |
setSumAmount(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment