PDA

View Full Version : the year values in the combo box



sbodanapu
22 Jan 2012, 11:50 PM
i am working on an application in which the current and previous year values should only be displayed in the combo box.
For example, this is 2012 and i need to display only the years 2010,2011 and 2012
And for month values, i need to display only january value in 2012 and all months in 2010 and 2011 accordingly..
Can you please suggest me a solution?

Thanks in advance:):):)

chramer
23 Jan 2012, 4:07 AM
It's something like this..
Here is the example on jsfiddle (http://jsfiddle.net/serju/cGBzx/)!


Ext.application({
name : 'test',
launch : function()
{
var today = new Date(),
currYear = today.getFullYear(),
currMonth = today.getMonth();

var monthStore = Ext.create('Ext.data.Store', {
autoLoad : true,
fields : [
{name : 'id', type : 'int'}, {name : 'month', type : 'string'}
],
data : [
{"id" : 0, "month" : "January"},
{"id" : 1, "month" : "February"},
{"id" : 2, "month" : "March"},
{"id" : 3, "month" : "April"},
{"id" : 4, "month" : "May"},
{"id" : 5, "month" : "June"},
{"id" : 6, "month" : "July"},
{"id" : 7, "month" : "August"},
{"id" : 8, "month" : "September"},
{"id" : 9, "month" : "October"},
{"id" : 10, "month" : "November"},
{"id" : 11, "month" : "December"}
]
});

var year = Ext.create('Ext.form.ComboBox', {
forceSelection : true,
fieldLabel : 'Choose Year',
store : [currYear-2, currYear-1, currYear],
queryMode : 'local',
renderTo : Ext.getBody(),
listeners : {
'change' : function(combo, newvalue, oldvalue)
{
month.lastQuery = null;
month.clearValue();
if (newvalue == currYear) {
month.getStore().filter([
Ext.create('Ext.util.Filter', {filterFn: function(item) {return item.get('id') <= currMonth;}})
]);
}
else {
month.getStore().clearFilter();
}
}
}
});
var month = Ext.create('Ext.form.ComboBox', {
forceSelection : true,
fieldLabel : 'Choose Month',
store : monthStore,
displayField: 'month',
valueField: 'id',
queryMode : 'remote',
renderTo : Ext.getBody(),
listeners : {
'change' : function(combo, newvalue, oldvalue)
{
console.log(newvalue);
}
}
});
}});

Good luck!!