PDA

View Full Version : getById(id) always returns undefined for array store... wondering why?



predator
22 Mar 2012, 8:12 AM
Hello All,

I have been trying to make this work since yesterday without any luck.

Here is the store definition:



Ext.define('PR2.store.xyzStore', {
extend: 'Ext.data.ArrayStore',

constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'xyzStore',
//idProperty: 'application_status', // <-- here does not work either
fields: [
{

name: 'application_status',
type: 'int'
},

{
name: 'application_status_name'
}
],
reader: {
type: 'array',
idProperty: 'application_status',
root: ''
},
data: [
[2, 'New'],
[1, 'Accepted']
]
}, cfg)]);
}
});


Then I am using this store in a grid column renderer like so:



...
{
xtype: 'gridcolumn',
dataIndex: 'application_status',
text: 'Status',
renderer: function(v) {
//console.log(v);
var record = _applicationStatusesStore.getById(v);
//console.log(record);
if (record) {
return record.get('application_status_name');
} else {
return 'unknown';
}
}
},
...


I think that for some reason I am failing to define the record id properly. Does anyone else is facing similar issues?

Thank you

mitchellsimoens
22 Mar 2012, 12:47 PM
getById requires that you know the id and if you don't have an idProperty set then there is no way to know.

mankz
22 Mar 2012, 1:16 PM
Try using idIndex, not idProperty. See the sample in the docs: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.ArrayStore

mitchellsimoens
22 Mar 2012, 1:16 PM
Try using idIndex, not idProperty. See the sample in the docs: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.ArrayStore

Didn't even notice he was using ArrayStore