40pro
40pro

Reputation: 1281

ExtJS: Fetching information from selected store in combo

I have the following ExtJS Textfield that lives in a form. I have a store called store_Product that fetches data via ajax proxy and suggest them to the PCODE field.

In reality this store has many other fields such as price,color,size and so on.. I am trying to set an onchange listener on this field such that when the user select the PCODE, it delivers other information (of the Product selected) to other fields in the page.

The code bellows work. The console.log(store_Product.data) correctly fetches the data from the model. However, the data fetched is of the whole store. I just want the one selected. How would I change this code to do that.

            {
                fieldLabel: 'PCODE  ',
                name: 'pcode',
                typeAhead: true,
                xtype: 'combo',
                store: store_Product,
                displayField: 'pcode',
                valueField: 'pcode',
                allowBlank:false,
                minChars:1,
                forceSelection:true,
                hideTrigger:true,
                queryDelay: 0,
                listeners:{
                   change: function(combo,value){
                       console.log(store_Product.data)
                   }
                }
            }

Thanks.

Upvotes: 0

Views: 127

Answers (2)

rixo
rixo

Reputation: 25001

If pcode is the id of your records, you can use Store.getById:

store_Product.getById(value)

Upvotes: 0

sha
sha

Reputation: 17860

Of course it's gonna log everything. Have you tried looking at the value you're receiving in the handler?

change: function(combo, value) {
   console.log(value);
   var idx= store_Product.find('pcode', value),
       record = store_Product.getAt(idx);

   console.log(record);
}

Upvotes: 1

Related Questions