PDA

View Full Version : Setting Store field value gives "el is null" error



harman
12 Jul 2012, 1:03 AM
HI,

I am using an ExtJS 4.0.7 Store for a grid which i populate using JSON data from server.
In the load event of store i set a field value like this



var gridStore = new Ext.data.Store({
pageSize: 15,
model: 'gridModel',
//remoteSort : true,
proxy: {
type: 'ajax',
url: 'someurl.json',
timeout : 60000,
reader: {
type: 'json',
root: 'root',
successProperty: 'success',
totalProperty : 'totalCount'
}
},
listeners: {
load : function( store, records, successful, operation){
if(successful){
for(var i = 0; i < store.count(); i++){
store.getAt(i).set('field1',123);
}
}
}
}
});


However it loads and reflects the value 123 in grid but also gives an error in firebug saying 'el is null'.
If i comment the set() command it works fine.
Am i using it in the wrong listener?
I need to do this after store loads but before it is reflected in the grid.

redraid
12 Jul 2012, 4:11 AM
Try:


if(successful){
Ext.Array.forEach(records, function (record) {
record.set('field1', 123);
});
}

harman
12 Jul 2012, 7:02 AM
Sorry that this doesn't work. Its the same thing i am doing. I am still facing the same prob.
However if i use the convert for field in model i am not getting the error.
May be this part is not the cause of the prob.

scottmartin
12 Jul 2012, 9:45 AM
I do not see this error using the following:



Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'change'],
data:{'items':[
{ 'name': 'Lisa', "email":"lisa@simpsons.com", "change":100 },
{ 'name': 'Bart', "email":"bart@simpsons.com", "change":-20 },
{ 'name': 'Homer', "email":"home@simpsons.com", "change":23 },
{ 'name': 'Marge', "email":"marge@simpsons.com", "change":-11 }
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
},

listeners: {
load: function(store,records,successful) {

if(successful){
Ext.Array.forEach(records, function (record) {
record.set('name', 123);
});
}

}
}
});

Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{ header: 'Name', dataIndex: 'name' },
{ header: 'Email', dataIndex: 'email', flex: 1 },
{ header: 'Change', dataIndex: 'change', tdCls: 'x-change-cell' }
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});


Scott.