nicolaskruchten / pivottable

Open-source Javascript Pivot Table (aka Pivot Grid, Pivot Chart, Cross-Tab) implementation with drag'n'drop.
https://pivottable.js.org/
MIT License
4.33k stars 1.07k forks source link

Aggregation Function for summing hours #1344

Open ghmc91 opened 9 months ago

ghmc91 commented 9 months ago

I have an object with one of its attributes (disponibilidade) having its values in hours, in the format hh:mm (07:30). So that I can do the sum, I do manipulations to put the data in decimal format hh.mm (7.30). However, when I can the sum aggregation function, it calculates the values as decimal - as expected - and in the last line it is possible to find values after the decimal point equal to or above 60 (which would indicate an extra hour). Does anyone know how I can do the sum the hours correctly?

My Code:

$(function(){ var tpl = $.pivotUtilities.aggregatorTemplates; $('#tb-disponibilidade').pivotUI( result, { rows: ["operador"], cols: ["dias_uteis"], aggregators: { "SomaHoras": function(){ var resultFinal = tpl.sum()(["disponibilidade"]) return resultFinal; } }, aggregatorName: "SomaHoras", vals: ["disponibilidade"] } ) })