PDA

View Full Version : Combo's with inline data


stever
10-03-2007, 11: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
01-19-2008, 12:06 PM
Thanks! This should be added as an option to the default combobox

Marco

jared
01-24-2008, 11: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
01-31-2008, 12:37 PM
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
02-14-2008, 08:08 PM
Made an update so it uses Ext.isArray() for array detection.

DigitalSkyline
02-14-2008, 08:57 PM
Nice, thanks for sharing.

brian.moeskau
03-12-2008, 03:41 AM
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
03-12-2008, 12:01 PM
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
03-12-2008, 04:09 PM
It's in the svn, the examples\forms\combo.js

brian.moeskau
03-12-2008, 04: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
03-12-2008, 04: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
07-14-2008, 03:30 AM
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'.