PDA

View Full Version : How to sum up a column with hours and minutes



samlinux
8 Apr 2013, 6:34 AM
Hi
how is the right way to sum up a grip with column formated "H:i" ?

I have a model like this


{name: 'stundenSt1', type: 'date', dateFormat: 'H:i:s'}



and a column render like this


renderer:Ext.util.Format.dateRenderer('H:i'),


my summaryTyp is sum

Thanks for any idear.

slemmon
9 Apr 2013, 9:02 PM
The summaryType can be sum, but that will be expecting a number, not a data object.
Instead you can pass a function to summaryType. If this is the case, the function is called with an array of records to calculate the summary value.

You may have to use some of the Ext.Date (http://docs.sencha.com/ext-js/4-2/#!/api/Ext.Date) methods to sum your date/time values.
Undoubtedly add() (http://docs.sencha.com/ext-js/4-2/#!/api/Ext.Date-method-add) will be used.

samlinux
12 Apr 2013, 10:39 PM
Thanks for your right direction.
Below my solution:

My Model looks like this:


{name: 'stundenSt', type: 'date', dateFormat: 'H:i:s'},




summaryType: function(values){
var gesamtMinuten=0;
Ext.Array.forEach(values, function (record){
var stunden = 0, minuten = 0;

if(record.data.stundenSt != null){
stunden = record.data.stundenSt.getHours();
minuten = record.data.stundenSt.getMinutes();
}

gesamtMinuten += (stunden*60);
gesamtMinuten += minuten;
});
return gesamtMinuten;
},
summaryRenderer: function(minuten, params, data) {
var std, min, out;
std = Math.floor(minuten/60);
min = (minuten - Math.floor(minuten/60) * 60);

if(min < 10){min = "0"+min;}
if(std < 10){std = "0"+std;}

out = std+":"+min;
return out;
}


I'm not sure if this is the best solution, but it works in my case.