Hi,
I am creating a datatable using SQL query datastore
$sql_query = "SELECT TIMEDIFF(check_out, check_in) AS time_diff FROM.........";
$this->src("db")
->query($sql_query)
->pipe($this->dataStore("dataStore"))
->requestDataSending();
and in my view I am grouping the time_diff column to get the total of time which is in H:i:s format (ex: 16:30:23)
"grouping" => [
"time_diff" => [
"calculate" => [
"{sumTime}" => function ($store) {
$sum = 0;
foreach ($store as $row) {
list($h, $i, $s) = explode(":", $row["worktime"]);
if (is_numeric($h) && is_numeric($i) && is_numeric($s)) {
$sum += $h * 3600 + $i * 60 + $s;
}
}
$h = floor($sum / 3600);
$i = floor(($sum - $h * 3600) / 60);
$s = $sum - $h * 3600 - $i * 60;
return (($h<10) ? "0$h" : $h) .":". (($i<10) ? "0$i" : $i).":".(($s<10) ? "0$s" : $s);
},
],
"bottom" => "<td><b>Total Time {sumTime}</b></td>"
],
],
but this seems to not generate the sum at the bottom of the datatable
Can you please advise?