Last active
August 31, 2021 12:59
-
-
Save rafiahmedd/3209992f385e6e05967f5aeff2466e3d to your computer and use it in GitHub Desktop.
Calculate Total Hours Minutes in Ninja Tables
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
function calc(){ | |
let time = document.querySelectorAll('td.ninja_clmn_nm_tunnid'); | |
let hours = 0; | |
let minute = 0; | |
let second = 0; | |
let totalHours = 0; | |
let newMinutes = 0; | |
for(let temp of time){ | |
let [hh,mm,ss] = temp.innerText.split(':'); | |
let hour = parseInt(hh); | |
let min = parseInt(mm); | |
let sec = parseInt(ss); | |
if(isNaN(hour)===false)hours+= hour; | |
if(isNaN(min)===false)minute+= min; | |
if(isNaN(sec)===false)second+= sec; | |
} | |
const newHours = Math.floor(minute / 60); | |
newMinutes = minute % 60; | |
if(newHours != undefined && newMinutes != undefined){ | |
totalHours = hours + newHours; | |
} | |
$table.find('tbody').after(`<tfoot class="ninja_tfoot"> | |
<tr> | |
<td></td> | |
<td></td> | |
<td></td> | |
<td></td> | |
<td></td> | |
<td>Total: ${totalHours}:${newMinutes}</td> | |
</tr> | |
</tfoot>`); | |
} | |
calc(); | |
$table.on("after.ft.filtering", function() { | |
calc(); | |
let tfoot = document.querySelectorAll('.ninja_tfoot'); | |
tfoot[1].remove() | |
}); | |
$table.on('after.ft.paging', function() { | |
calc(); | |
let tfoot = document.querySelectorAll('.ninja_tfoot'); | |
tfoot[1].remove() | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment