Skip to content

Instantly share code, notes, and snippets.

@reachkamrul
Created April 17, 2020 15:29
Show Gist options
  • Save reachkamrul/bcacf02720857404ea2c5d92e5257e83 to your computer and use it in GitHub Desktop.
Save reachkamrul/bcacf02720857404ea2c5d92e5257e83 to your computer and use it in GitHub Desktop.
// Count Footer with fix
function myCustomFunction() {
var sum = 0;
var counts = 0;
$(".totals").each(function() {
var val = $.trim( $(this).text() );
if ( val ) {
val = parseFloat( val.replace( /^\$/, "" ) );
sum += !isNaN( val ) ? val : 0;
}
});
$(".footable tbody tr:first-child td").each(function() {
counts++;
});
if(!jQuery('table').find('tfoot').length){
jQuery("<tfoot></tfoot>").appendTo(jQuery('table'));
}
jQuery("<tr class='final_result'><td colspan='"+counts+"'style='text-align: right'></td></tr>").prependTo(jQuery('table').find('tfoot'));
jQuery('table').find('tfoot .final_result td').html('Total of the column: ' + sum );
}
myCustomFunction();
$table.on('after.ft.paging', function () {
jQuery('.final_result').remove();
myCustomFunction();
});
$table.on("after.ft.filtering", function () {
jQuery('.final_result').remove();
myCustomFunction();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment