PDA

View Full Version : ComboBox store indexOfId returning wrong value !



armandoxxx
4 Aug 2009, 8:18 AM
Hi Guys ..

been strugling with this one for some time now so any help would be appreciated !

this is my store



var findCustomersStore = new Ext.data.Store({
id : 'find-customers-store',
autoLoad : true,
proxy : new Ext.data.HttpProxy({
url : '${pageContext.request.contextPath}/ajax/customers/searchCustomers',
method : 'POST'
}),
baseParams : { showAll:0 },
reader : new Ext.data.JsonReader(
{
root : 'data',
totalProperty : 'total',
id : 'id'
},
[
{name: 'id', type: 'int', mapping: 'id'},
{name: 'name', type: 'string', mapping: 'name'}
]
)
});



this is my combo box



var comboBox = new Ext.form.ComboBox(
{
id : 'doc-filter-customer-combo',
name : 'customerName',
editable : true,
hiddenName : 'customerName',
forceSelection : false,
minChars : 3,
displayField : 'name',
typeAhead : true,
triggerAction : 'all',
fieldLabel : 'Customer',
valueField : 'id',
selectOnFocus : false,
currentSelectedRecordId : 0,
width : 210,
mode : 'local',
store : findCustomersStore,
listeners:{
'select' : function(component, record, index) {
console.log(component.getStore().indexOfId(record.id));
},
scope:this
}
}
),


the problem is when the code bellow is executed I get the wrong Index in the record set !!!



component.getStore().indexOfId(record.id);


it returns the index of the combo shown record not the index in stores data set .. I made sure my records in the store get loaded before anybody enters text in combo to search for the records ..

Any help would be appreciated

Kind regards

Armando

steffenk
4 Aug 2009, 8:30 AM
you use wrong id's

store: storeId
reader: idProperty

armandoxxx
4 Aug 2009, 8:34 AM
I did not understand you .. can you please explain your fast reply ?

Kind regards

Armando

steffenk
4 Aug 2009, 8:37 AM
store has no property id (deprecated) - use storeId (http://extjs.com/deploy/dev/docs/?class=Ext.data.Store&member=storeId)
reader has no property id, use idProperty (http://extjs.com/deploy/dev/docs/?class=Ext.data.JsonReader&member=idProperty)

armandoxxx
4 Aug 2009, 8:44 AM
Hey man 10x for your reply ..

changed it .. same effect ...

I get the index of the record in combo dropdown view instead of stores record set ..

Kind regards

Armando

steffenk
4 Aug 2009, 9:04 AM
why not
console.log(record.id);

in the listener? I don't understand what the problem is about.

armandoxxx
4 Aug 2009, 10:11 AM
the problem is when data is loaded from a server to a store data, it has 300 records in record set .. Then I write something into combobox and 4 records are searched and appear in the list. Then I select ONE of them and I get it's index, which is one of 0, 1, 2 or 3 (index of item in the list displayed) instead of index of the record in the stores data recordset. In my case If I write string starting with S... I should receive index of 250+ ;) Note, that data is not received from the server again and is already loaded ! (check combo config)

do you understand now ?


Kind regards

Armando

armandoxxx
4 Aug 2009, 10:13 AM
why not
console.log(record.id);

in the listener? I don't understand what the problem is about.

It returns the right record ID value ... when searching the store data with this record id, I receive the wrong value for index

Kind regards

Armando

armandoxxx
4 Aug 2009, 11:22 PM
my gues is that this is a bug .. if I'm searching for the index of a record in a store it should return the index of a record in a stores data record set .. not the index of a record that component showed to user !
If index of a record shown to user is needed, component itself should know what it is .. not the store behind !

I've attached the code so someone can tryit ..


Kind regards

Armando

Condor
4 Aug 2009, 11:41 PM
store.indexOfId returns the index of the record in the filtered dataset.

If you want the index of the record in the original dataset you could use:

var index = (store.snapshot || store.data).indexOfKey(id);

But why would you ever need this?

armandoxxx
5 Aug 2009, 12:12 AM
hey man .. I just figured it out !

I cleared filter on the store and now i got th right record index ...

10x

Kind regards

Armando

armandoxxx
5 Aug 2009, 12:30 AM
But why would you ever need this?


I'm working on a proof of concept project that Ext can be as good as and as usefull as desktop apps with all the features and stuff... so one of the things I needed to show was, to move to next record in dataset with a click of a button and show next record data on the screen ..

Kind regards ..

Armando