PDA

View Full Version : find record in ComboBox by id



irritated
21 Feb 2012, 4:28 AM
Hi guys! It seems to be common in Ext that you have plenty of properties but cannot find how to do the simple things.

Let's suppose we have ComboBox populated from JsonStore. What I need to do - is the simplest thing and I didn't expect any obstacles. However they had come and made me completely stuck.

The store has quite simple structure



root: 'rows',
idProperty: 'Id',
remoteSort: false,
sortInfo: { field: 'Id', direction: "ASC" },
fields: [
{ name: 'Id', type: 'int'},
{ name: 'Name'}
],


Of course, I tried to use store.getById(id) to get the record.
But it does NOT find the record, because all records in the store have the string like "ext-record-22","ext-record-36" as a record key (and record ID as well). I tried to use store .find('Id', value) - but also no result. The record data itself are contained in .data property of the store, and it is not possible to find anything by its values.

I am desperate about this issue, it would be so stupid to write Ext.Each() to simply find the record by ID but I feel I will have to.

Does anybody know the solution? What's wrong in the 'store', maybe 'root' property? Google keeps silence about this issue although some developers faced to it, but their questions still have no answers.

thanks in advance, guys, appreciate your help, I will expect any answer and will have to write cycle.

mitchellsimoens
21 Feb 2012, 5:12 AM
When you search for a record, is the data loaded in the store at that point?

irritated
21 Feb 2012, 5:31 AM
yes, it is.

I do the search in the 'load' listener of JsonStore
Having set the breakpoint there I see in the debugger that actual data is available at

st.data.items[1].data // where 1 is index in the store

st.data.items[1].data = {Id:___, Name: ____} //the value of it is the actual json record in the collection

mitchellsimoens
21 Feb 2012, 5:32 AM
That was my only idea as I have not had any problems with the id mapping or find

irritated
21 Feb 2012, 5:46 AM
here's grabbed Json which returns from the controller. Maybe something wrong in it? Nothing suspicious at my sight, root = "rows", like assigned....


Ext.encode(st.reader.jsonData) = "{"records":12,"rows":[{"Id":1,"Name":"1-upd"},{"Id":2,"Name":"2"},{"Id":5,"Name":"5-u1"},{"Id":18,"Name":"blank333-4"},{"Id":19,"Name":"ttt-upd"},{"Id":20,"Name":"20"},{"Id":21,"Name":"new445"},{"Id":22,"Name":"new444"},{"Id":23,"Name":"new777"},{"Id":24,"Name":"rrrr"},{"Id":25,"Name":"www"},{"Id":26,"Name":"rrrr22"}],"userdata":null}"

irritated
21 Feb 2012, 6:07 AM
The only solution helped me to overcome the problem was iteration
Quite ugly, but works


Ext.each(st.data.items, function(record) // alas, have to do foreach ((
{
if (record.data.Id == lastId)
{
combo.setValue(lastId);
sel = true;
}
});

Disappointed that I am unable to manage without such perversions :-?

irritated
22 Feb 2012, 5:02 AM
Managed to find the solution


var ndx = st.findExact('Id',lastId); // it works!