PDA

View Full Version : Newbie - ComboBox



francescoNemesi
20 Apr 2007, 4:29 AM
Hi All,

newbie with extjs, so please excuse me if this is a very dumb question... I am trying to create a combo box using an xml data store... but it does not work... I am sure the xml returned is correct... Below is my code:

<script type="text/javascript">

Ext.onReady(function(){
/*
// simple array store
var store = new Ext.data.SimpleStore({
fields: ['abbr', 'state'],
data : Ext.exampledata.states // from states.js
});
*/

var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: '/context/ReturnXmlData'}),
reader: new Ext.data.XmlReader({record: 'record'},
['name','age'])
});

var combo = new Ext.form.ComboBox({
store: store,
displayField:'name',
typeAhead: true,
mode: 'local',
triggerAction: 'all',
emptyText:'Select a name...',
selectOnFocus:true
});
combo.applyTo('names');

});

</script>
...
<div id="ext-gen6">

<div style="width: 144px;"
id="ext-gen7"
class="x-form-field-wrap">

<input autocomplete="off"
class="x-form-text x-form-field x-form-empty-field"
id="local-states"
size="20"
type="text">

</div>

</div>

Also another simple question... I can not find any documentation for Ext.data.HttpProxy... any ideas?

Thanks for your help,
Francesco

buzz
20 Apr 2007, 6:03 AM
Since you are using a HttpProxy, the mode needs to be set to remote.
You need to remove the configuration mode: 'local' or set it to mode:'remote' which is the default when you create a ComboBox

francescoNemesi
20 Apr 2007, 8:02 AM
Hi,

thanks for your reply... I made some progress now. I have a servlet that creates this output to be fed to the comboBox:

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<row>
<id>1</id>
<name>Alfred</name>
<sex>M</sex>
<age>14,0</age>
<height>69,0</height>
<weight>112,5</weight>
</row>
<row>
<id>2</id>
<name>Alice</name>
<sex>F</sex>
<age>13,0</age>
<height>56,5</height>
<weight>84,0</weight>
</row>
...
</dataset>

For some reason if I set this property in the HttpProxy

proxy: new Ext.data.HttpProxy({url: "/context/ReturnXmlData"}),

the combobox is empty, but if I save the servlet response to a static xml file, all works without problems. The same applies if I use a grid object as a viewer...

Any ideas?

Thanks again,
Francesco

buzz
20 Apr 2007, 8:12 AM
You have problems in the your XMLReader. It should look something like

reader: new Ext.data.XmlReader({
record: 'row',
totalProperty: '@total',
id: 'id'
},['name','age'])