PDA

View Full Version : Setting displayfield on combobox



evanisha
31 Jul 2012, 10:47 PM
Hi All,

I created an application to load data from xml file.All controls loading correctly,my combobox is populating correctly but not setting the displayfield string .It shows the valuefield.
My code for combo is :

xtype: 'combobox',
autoRender: true,
autoShow: true,
hidden: false,
width: 259,
name: 'state',
fieldLabel: 'State of Domicile',
editable: false,
displayField: 'name',
forceSelection: false,
store: 'xmlStStates',
typeAhead: true,
valueField: 'code'


Xml format is :

<?xml version="1.0" encoding="UTF-8"?>
<message success="true">
<customer>
<code>BAT</code>
<name>Benoy A Tharu</name>
<adds>Adukaliyil</adds>
<dob>16/04/1980</dob>
<gen>M</gen>
<md>Y</md>
<state>AP</state>
</customer>
</message>

Please give me a solution for correcting the pblm.


Thanks in advance,
Nisha Benoy.

sword-it
31 Jul 2012, 11:44 PM
Hi evanisha,

Problem may be in your combo store, I would like to see your code for combo store.

evanisha
1 Aug 2012, 12:22 AM
Hi,

My code for combo store is as follows..

Ext.define('CustomerDetails.store.xmlStStates', {
extend: 'Ext.data.Store',
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'MyXmlStore',
proxy: {
type: 'ajax',
url: 'data/states.xml',
reader: {
type: 'xml',
record: 'state'
}
},
fields: [
{
name: 'code',
type: 'string'
},
{
name: 'name',
type: 'string'
}
]
}, cfg)]);
}
});

One thing that i noticed, when loading combo the displayed field is "AP" (Valuefield) instead of "AndraPradesh" (DisplayField) .After selecting displayfield (AndraPradesh) from combobox , when i click load button then it loads the displayField.




Nisha Benoy

sword-it
1 Aug 2012, 1:56 AM
Problem in your reader's record config, it will be record:'customer' (or use root: 'customer').
I would like suggest you use Ext.data.XmlStore() instead of Ext.data.store(). This class automatically configured with a xml reader.

Read API docs http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.XmlStore

evanisha
1 Aug 2012, 10:24 PM
Hi ,


I tried it but not getting displayfield.
I am maintaining two xml files one for load data in form window (Including combobox),other is for populating combobox(For states).The xml that i had posted was for loading form and store is for populating combo.
Store for loading form window is

extend: 'Ext.data.Store',
requires: [
'CustomerDetails.model.custModel'
],
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
storeId: 'custStoreID',
model: 'CustomerDetails.model.custModel'
}, cfg)]);
}
});

Model for loading form window is

Ext.define('CustomerDetails.model.custModel', {
extend: 'Ext.data.Model',
fields: [
{
name: 'code'
},
{
name: 'name'
},
{
name: 'adds'
},
{
name: 'dob'
},
{
name: 'gen'
},
{
name: 'md'
},
{
name: 'state'
}
],
proxy: {
type: 'ajax',
url: 'data/custxml.xml',
reader: {
type: 'xml',
successProperty: '@success',
record: 'customer'
}
}
});

xml for populating combo is
<states>
<state>
<code>KL</code>
<name>Kerala</name>
</state>
<state>
<code>AP</code>
<name>Andhra Pradesh</name>
</state>
</states>

Please help me to solve this....

Nisha