PDA

View Full Version : Combo's with inline data



stever
3 Oct 2007, 7:30 AM
Use a combo box with data inline like this:


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

or


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




/**
* @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);

mdissel
19 Jan 2008, 9:06 AM
Thanks! This should be added as an option to the default combobox

Marco

jared
24 Jan 2008, 8:19 PM
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.

stever
31 Jan 2008, 9:37 AM
That is why i created it! :D Sometimes if the data is duplicated, it is better to create a store, but many times it is not needed. Glad you like it.

stever
14 Feb 2008, 5:08 PM
Made an update so it uses Ext.isArray() for array detection.

DigitalSkyline
14 Feb 2008, 5:57 PM
Nice, thanks for sharing.

brian.moeskau
11 Mar 2008, 11:41 PM
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.

ppelletier
12 Mar 2008, 8:01 AM
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

mdissel
12 Mar 2008, 12:09 PM
It's in the svn, the examples\forms\combo.js

brian.moeskau
12 Mar 2008, 12:34 PM
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.

mscdex
12 Mar 2008, 12:55 PM
Is there a way to update this combo's array-based store later on after definition, to refresh its data with another array? Perhaps there is a pre-existing Ext.form.ComboBox method I am missing.

masuran
13 Jul 2008, 11:30 PM
Suppose I have this example:


{
xtype:"combo",
fieldLabel:"Betaald",
store:[['','Maybe'],['0','Yes'],['1','No']],
name:"filter_betaald",
id: "filter_betaald"
}

Can anyone tell me how I can get the non-text value of this combobox? Here I have three options but instead of getting the selected value 'Yes' I want to get the value '0'.