PDA

View Full Version : Grid TimeNumberer



lukefowell89
16 Feb 2011, 7:26 AM
I needed to be able to print out all the times in 15minute intervals between 2 given times. So I wrote a small extension called Ext.grid.TimeNumberer. Which needs a starttime and endtime.

I looks like this
24710

Here is the code:


Ext.grid.TimeNumberer = Ext.extend(Object, {

header: "",
width: 50,
sortable: false,

constructor : function(config){
Ext.apply(this, config);
if(this.rowspan){
this.renderer = this.renderer.createDelegate(this);
}
},

fixed:true,
hideable: false,
menuDisabled:true,
dataIndex: '',
id: 'numberer',
rowspan: undefined,

renderer : function(v, p, record, rowIndex){
if(this.rowspan){
p.cellAttr = 'rowspan="'+this.rowspan+'"';
}

if(!this.hourCount && this.hourCount != 0){
this.currentHour = rowIndex+this.startTime;
this.hourCount = 1;
}
else if(this.hourCount > 3)
{
this.currentHour++;
this.hourCount = 1;
}
else
{
this.hourCount++;
}

var minutes = 0;
if(!this.currentMinute)
{
var minutes = '00';
this.currentMinute = 15;
}
else
{
if(this.currentMinute == 0){
var minutes = '00';
this.currentMinute = 15;
}
else if(this.currentMinute == 45)
{
var minutes = this.currentMinute;
this.currentMinute = 0;
}
else
{
var minutes = this.currentMinute;
this.currentMinute += 15;
}
}
var hour = this.currentHour;
var time = hour+':'+minutes
return time;
}
});

What I need is to be able to get this working ina more flexible way. Anyone got any ideas so I can adjust the incremement so it could be every 30 mins etc. Anyone made or used something similar before?

Thanks

lukefowell89
17 Feb 2011, 1:22 AM
Anyone got any suggestions to this problem?

Condor
17 Feb 2011, 2:42 AM
I would be using the Date add() and dateFormat() methods instead of calculating hours and minutes yourself.

ps. Have a look at how TimeField fills it's store.