1. #1
    Ext JS Premium Member stever's Avatar
    Join Date
    Mar 2007
    Posts
    1,406
    Vote Rating
    6
    stever will become famous soon enough stever will become famous soon enough

      0  

    Default Combo's with inline data

    Combo's with inline data


    Use a combo box with data inline like this:

    Code:
    {
    	xtype:'combo',
    	store:['Reader','Participant','Moderator','SuperUser']
    }
    or

    Code:
    {
    	xtype:'combo',
    	store:[['r','Reader'],['p','Participant'],['m','Moderator'],['s','SuperUser']]
    }


    Code:
    /**
     * @author Steven Roussey
     */
    
    Ext.ux.ComboBox = function(config){
    	if (Ext.isArray(config.store))
    	{
    		if (Ext.isArray(config.store[0]))
    		{
    			config.store = new Ext.data.SimpleStore({
    			    fields: ['value','text'],
    			    data : config.store
    			});
    	        config.valueField = 'value';
                config.displayField = 'text';
    		}
    		else
    		{
    			var store=[];
    			for (var i=0,len=config.store.length;i<len;i++)
    				store[i]=[config.store[i]];
    			config.store = new Ext.data.SimpleStore({
    			    fields: ['text'],
    			    data : store
    			});
    	        config.valueField = 'text';
                config.displayField = 'text';
    		}
    		config.mode = 'local';
    	}
        Ext.ux.ComboBox.superclass.constructor.call(this, config);
    }
    Ext.extend(Ext.ux.ComboBox,Ext.form.ComboBox,{
    	
    });
    Ext.reg('combo',Ext.ux.ComboBox);
    Last edited by stever; 14 Feb 2008 at 5:08 PM. Reason: Updated to v1.0.1 (uses Ext.isArray() to detect arrays)

  2. #2
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    NL
    Posts
    607
    Vote Rating
    1
    mdissel is on a distinguished road

      1  

    Default


    Thanks! This should be added as an option to the default combobox

    Marco

  3. #3
    Ext JS Premium Member jared's Avatar
    Join Date
    Mar 2007
    Posts
    14
    Vote Rating
    0
    jared is on a distinguished road

      0  

    Default


    Yes, this should be part of the Ext.form.ComboBox. This makes it possible to pass possible form value to the combobox via JSON config without having to manually instantiate a datatore. it's insane that a combobox is required to have a datastore.

  4. #4
    Ext JS Premium Member stever's Avatar
    Join Date
    Mar 2007
    Posts
    1,406
    Vote Rating
    6
    stever will become famous soon enough stever will become famous soon enough

      0  

    Default


    That is why i created it! Sometimes if the data is duplicated, it is better to create a store, but many times it is not needed. Glad you like it.

  5. #5
    Ext JS Premium Member stever's Avatar
    Join Date
    Mar 2007
    Posts
    1,406
    Vote Rating
    6
    stever will become famous soon enough stever will become famous soon enough

      0  

    Default


    Made an update so it uses Ext.isArray() for array detection.

  6. #6
    Ext User DigitalSkyline's Avatar
    Join Date
    Apr 2007
    Location
    Rochester, MI
    Posts
    461
    Vote Rating
    1
    DigitalSkyline is on a distinguished road

      0  

    Default


    Nice, thanks for sharing.

  7. #7
    Sencha User
    Join Date
    Apr 2012
    Location
    Austin, Texas
    Posts
    2
    Vote Rating
    0
    brian.moeskau is an unknown quantity at this point

      0  

    Default


    it's insane that a combobox is required to have a datastore.
    Well, that's a bit drastic. Stores buy you a lot of free functionality like events, automatic binding to the data source, etc. They also allow you to bind many types of data to a combo consistently (array, JSON, XML, etc.). But, I assume you mean that it's "insane that a store is required when all you want to do is throw a simple array into a combo." That I can agree with , and I have checked in a change to SVN that will enable this out of the box, providing the same functionality as Steve's extension.

  8. #8
    Ext User
    Join Date
    Feb 2008
    Posts
    9
    Vote Rating
    0
    ppelletier is on a distinguished road

      0  

    Default


    Is there an example somewhere on how to use this new functionality you checked in ? It doesn't seem to be in the documentation (or I was unable to find it)...

    Thanks
    Paul

  9. #9
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    NL
    Posts
    607
    Vote Rating
    1
    mdissel is on a distinguished road

      0  

    Default


    It's in the svn, the examples\forms\combo.js

  10. #10
    Sencha User
    Join Date
    Apr 2012
    Location
    Austin, Texas
    Posts
    2
    Vote Rating
    0
    brian.moeskau is an unknown quantity at this point

      0  

    Default


    Yep, the combo example has been updated. I also updated the API docs for the ComboBox.store config option accordingly. But really, it's pretty simple. The same inline array formats as shown in Steve's examples above are supported.