1. #1
    Sencha User
    Join Date
    Jan 2012
    Posts
    23
    Vote Rating
    0
    sbodanapu is on a distinguished road

      0  

    Default Unanswered: the year values in the combo box

    Unanswered: the year values in the combo box


    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

  2. #2
    Sencha User chramer's Avatar
    Join Date
    Feb 2011
    Location
    Chisinau, Moldova
    Posts
    203
    Answers
    42
    Vote Rating
    10
    chramer will become famous soon enough

      0  

    Thumbs up


    It's something like this..
    Here is the example on jsfiddle!
    PHP Code:
    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-2currYear-1currYear],
                
    queryMode 'local',
                
    renderTo Ext.getBody(),
                
    listeners : {
                    
    'change' : function(combonewvalueoldvalue)
                    {
                        
    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(combonewvalueoldvalue)
                    {
                        
    console.log(newvalue);
                    }
                }
            });
        }}); 
    Good luck!!

Thread Participants: 1