-
31 Jul 2008 9:39 PM #1
Combobox with SimpleStore
Combobox with SimpleStore
Hi can anybody tell me what's wrong with the following code?
Basically I need to populate a combobox with data from a url that's returning xml. The combobox is created and displayed correctly but the data won't load. I'm not getting any javascript error.
I have looked through the examples and forums but can't find a single case with exactly the same requirements.
I'm using extjs 2.1.
The code to create combobox:
The sample xml:Code:var c = new Ext.form.ComboBox({ id: 'ptype', name: 'ptype', renderTo:'combotest', fieldLabel: 'Type', store: new Ext.data.SimpleStore({ // load using HTTP url: '...', fields: ['id', 'title'], autoLoad: true, // the return will be XML, so lets set up a reader reader: new Ext.data.XmlReader({ record: 'row', id: 'id' }, [ {name: 'id'}, {name: 'title'} ]) }), displayField: 'title', valueField: 'id', editable: false, listeners: { 'render' : { fn: function() { this.store.load(); } } } });
The html:Code:<items> <row> <id>1</id> <title>Type 1</title> </row> <row> <id>2</id> <title>Type 2</title> </row> <row> <id>3</id> <title>Type 3</title> </row> </items>
Any help much appreciated!Code:<div id="combotest"></div>
-
31 Jul 2008 9:58 PM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
Some suggestions:
1. You set both autoLoad:true and load in the render event.
2. The xml MUST have content type text/xml or application/xml, otherwise IE will load text instead of xml.
3. Try adding a loadexception eventhandler to the store to see if there are any problems during load.
-
31 Jul 2008 11:18 PM #3
Yes I have tried with only one or the other, and the fact that both didn't work is the very reason I chuck both in there - call that desperation!
Yes the url that's returning the xml is tested on its own (when browsed) to be returning in xml format.
Yes I have tried that and the event was never fired. I have also added a 'load' listener which always fires.
-
1 Aug 2008 12:31 AM #4
Here is a modified version of your code that should work :
I made 2 modificationsPHP Code:var c = new Ext.form.ComboBox({
id: 'ptype',
name: 'ptype',
renderTo:'combotest',
store: new Ext.data.Store({
proxy : new Ext.data.HttpProxy({
url : '...'
}),
// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
record: 'row', id: 'id'
}, [
{name: 'id'},
{name: 'title'}
])
}),
triggerAction : 'all',
displayField: 'title',
valueField: 'id',
editable: false,
listeners: {
'render' : {
fn: function() {
this.store.load();
}
}
}
});
1 - instead of SimpleStore (designed for array) you should use a standard Store
2 - you forgot to specify a triggerAction for the ComboBox
-
1 Aug 2008 1:05 AM #5
Thanks thaiat adding 'triggerAction' works!
But is it just me or do you or anyone here find extjs's documentation can sometimes be mis-leading? Say in this case, before trying this forum, I did look at 'triggerAction' under 'form.ComboBox' but it says:"The action to execute when the trigger field is activated. Use 'all' to run the query specified by the allQuery config option"Now in my case I did not have "allQuery" specified as a config option, so I thought it did not apply. Sure it turns out I was wrong but am I entirely to blame?
-
1 Aug 2008 1:29 AM #6
I agree that triggerAction should be set to 'all' by default
Anyway that is what i do when i define a ComboBox
-
1 Aug 2008 5:34 AM #7
MJ
API Search || Ext 3: docs-demo-upgrade guide || User Extension Repository
Frequently Asked Questions: FAQs
Tutorial: Grid (php/mysql/json) , Application Design and Structure || Extensions: MetaGrid, MessageWindow


Reply With Quote