PDA

View Full Version : Get Item by ID from Store using getByID



himalpatel
24 Feb 2012, 4:15 AM
I am trying to get the item from the store using getById method but it returns null even if the id is present in the store.
see image from more detail.


32109



Thanks
Himal

friend
24 Feb 2012, 4:50 AM
Ext.data.Store.getById(id) assumes that your store's model declares an 'id' field. Below is simple, static data example where calling store.getById(3) would return the record for Aaron Conran. I chose to use a numeric 'id' field, but string would work just as well, assuming that the value for each record is unique.



var store = Ext.create('Ext.data.Store', {
fields: [
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'},
{name: 'id', type: 'int'},
],
data : [
{id: 1, firstName: 'Ed', lastName: 'Spencer'},
{id: 2, firstName: 'Tommy', lastName: 'Maintz'},
{id: 3, firstName: 'Aaron', lastName: 'Conran'},
{id: 4, firstName: 'Jamie', lastName: 'Avins'}
]
});

var record = store.getById(3);

himalpatel
24 Feb 2012, 4:52 AM
glad... It worked...

Thanks for your help

Himal