-
3 Oct 2007 7:30 AM #1
Combo's with inline data
Combo's with inline data
Use a combo box with data inline like this:
orCode:{ xtype:'combo', store:['Reader','Participant','Moderator','SuperUser'] }
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)
-
19 Jan 2008 9:06 AM #2
Thanks! This should be added as an option to the default combobox
Marco
-
24 Jan 2008 8:19 PM #3
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.
-
31 Jan 2008 9:37 AM #4
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.
-
14 Feb 2008 5:08 PM #5
Made an update so it uses Ext.isArray() for array detection.
-
14 Feb 2008 5:57 PM #6
Nice, thanks for sharing.
-
11 Mar 2008 11:41 PM #7
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 withit's insane that a combobox is required to have a datastore.
, 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.
-
12 Mar 2008 8:01 AM #8
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
-
12 Mar 2008 12:09 PM #9
It's in the svn, the examples\forms\combo.js
-
12 Mar 2008 12:34 PM #10
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.


Reply With Quote
