PDA

View Full Version : How to find values in DirectStore



Dirk1
3 Feb 2011, 4:07 AM
Hi all,

I'm quite new in using ExtJS so sorry for my newbie question.

I need to find one column in a DirectStore (Ext.data.DirectStore). The DirectStore is filled from a database, so I don't know the index of the field to find. In my DirectStore I have 2 fields: ID (id from the database) and TESTFIELD (field with a name inside). After a user selected a value in a combobox, I can ask for the selected value via

Ext.getCmp('mrp.destinationcomboid').getValue()

So I would like to search for the corresponding TESTFIELD-value, but I cannot get it.

I can directly select it if I know the items index, but that doesn't help me at all when someone chooses a value in the combobox.

Ext.getCmp('test').getStore().data.items[0].data['TESTFIELD']

Is there a function like findByField('FIELDNAME', 'FIELDVALUE')? I couldn't find it in the extJS docs.

Thanks and best wishes!

fay
3 Feb 2011, 4:34 AM
Have you looked at the find, findBy, findExact, getAt, and getById methods in the docs (http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.DirectStore)? Btw, I don't completely get what you're trying to do, is the combobox populated from the DirectStore? Post it's config

Dirk1
3 Feb 2011, 6:22 AM
Hi fay,

yes, I tried, but no way. Perhaps I did something wrong

Ext.getCmp('test').getStore().getByAt(0)

gave me "undefined", even if ..getCount() gave me a number of data inside the store of 5.



this.testfieldStore = new Ext.data.DirectStore({
api:{
read: test.getTestfields
},
paramsAsHash: true,
root: 'TEST',
fields: ['ID', 'TESTFIELD'],
listeners: {
'exception': function(proxy,type,action,options,response,args){
var text = Ext.decode(response.result);
Ext.Msg.show({
title:'Failed',
msg: text.exception,
buttons: Ext.Msg.OK,
});
}
}
});


What I now have is a combobox, that is filled by that store. I HTML it wood look like this



<select ...>
<option value='ID'>TESTFIELD</option>
<option value='1'>A</option>
<option value='2'>B</option>
</select>


If a user now selects a value from the combobox I get ID via Ext.getCmp('test').getValue(). Now I need not the ID, but the corresponding TESTFIELD, because I have to display a confirm-message on the screen.
What I now want to do is: Put ID in any function that returns the corresponding TESTFIELD.

E.g., A is selected, using getValue() I get 1, I put 1 inside a function that returns A to me and I display a message "You just selected A".

Hopefully now it's clear what I want to do?!

Thanks and best wishes!

steffenk
3 Feb 2011, 8:43 AM
look to the docs:
http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Store&member=getAt

it's getAt or getById