PDA

View Full Version : Adding store to ComboBox using JSON



zaiapa
18 May 2010, 6:31 AM
Hi All,
I'm new to ExtDesigner.
I defined my interface using Ext Designer. I load the example below via AJAX.
Where do I have to define 'MyStore' reference in my main js code to fill my combobox
in local mode ?
In designer there is no way to define the store and data associated to.



"items": [
{
"xtype": "fieldset",
"title": "Alarm Severity",
"layout": "form",
"flex": 1,
"labelWidth": 50,
"autoWidth": false,
"autoHeight": false,
"items": [
{
"xtype": "combo",
"fieldLabel": "MNGT/1",
"anchor": "100%",
"itemId": "cmbAlarmSeverityMngt1",
"store": "MyStore",
"triggerAction": "all",
"mode": "local"
},

Thanks in advance for reply

jarrednicholls
18 May 2010, 7:42 AM
On the upper right hand side of the Designer interface is a tab to switch to Data Stores, where you can create and configure your stores. Once a store is created and given a storeId, you can assign the store to the ComboBox by clicking on the ComboBox's handle (little gear icon) and choosing your store from the list.

At this time, stores only can load data from an URL, whether that's a local or remote web server. Loading local/static data into stores is a feature coming in a future release.

jjsciv
23 Dec 2010, 8:36 AM
I'm getting mad with combo box. No way to have it wok using ext designer.
Here is the combo definition from ui.js:


{
xtype: 'combo',
fieldLabel: 'Type paiement',
anchor: '100%',
store: 'mode_paiementStore',
displayField: 'Type_paiement',
valueField: 'Code_paiement',
forceSelection: true,
triggerAction: 'all',
selectOnFocus: true,
id: 'mode_paiement'
},

here is the store definition:


mode_paiementStore = Ext.extend(Ext.data.JsonStore, {
constructor: function(cfg) {
cfg = cfg || {};
mode_paiementStore.superclass.constructor.call(this, Ext.apply({
storeId: 'mode_paiementStore',
url: 'taches/communs.php',
sortField: 'Type_paiement',
autoSave: false,
baseParams: {
task: 'LISTMODESPAIEMENTS'
},
fields: [
{
name: 'Code_paiement',
mapping: 'Code_paiement',
type: 'int'
},
{
name: 'Type_paiement',
mapping: 'Type_paiement',
type: 'string'
}
]
}, cfg));
}
});
new mode_paiementStore();

When I click on the combo, there is a quick "loading" displayed and then an empty list.
I don't understand why because the PHP code is triggered and send correctly the data:


({"total":"5","results":[{"0":"1","Code_paiement":"1","1":"Espece","Type_paiement":"Espece"},{"0":"2","Code_paiement":"2","1":"Cheque","Type_paiement":"Cheque"},{"0":"3","Code_paiement":"3","1":"En compte","Type_paiement":"En compte"},{"0":"4","Code_paiement":"4","1":"Espece et Cheque","Type_paiement":"Espece et Cheque"},{"0":"5","Code_paiement":"5","1":"Traite","Type_paiement":"Traite"}]})

Please can someone help!

jarrednicholls
24 Dec 2010, 7:35 AM
You need to configure "root". Your results are under the "results" property of the returned JSON object. So the root of your results is named "results" (i.e. the array of records). So set "root" to "results".

jjsciv
27 Dec 2010, 3:09 AM
Thank you very much! That solved it!