PDA

View Full Version : JsonReader does not display data in grid



abaird
9 Sep 2010, 11:49 AM
Hi all,

I'm building a CRUD style grid panel using JsonReader / JsonWriter.

Strangely enough, as soon as I define a specific JsonReader instead of simply defining the fields on the JsonStore, it no longer displays my data. I'd like to use a JsonReader so I can get access to some of the properties that will affect the CRUD actions.

I have verified that the JSON load action returns valid JSON (and as I stated above it had no problem populating the data when I did not specify a JsonReader)

My code is as follows:



var MyDataType = Ext.data.Record.create([
{ name: 'id'},
{ name:'field1', type: 'integer' },
{ name:'field2', mapping: 'play_date', type: 'date', dateFormat: 'Y-m-d' },
{ name:'field3', type: 'time' }
]);
var MyReader = new Ext.data.JsonReader({
root: 'data'
},MyDataType);
var MyStore = new Ext.data.JsonStore({
proxy: new Ext.data.HttpProxy({
api: {
read : '/mydata/load',
create : '/mydata/create',
update : '/mydata/update',
destroy : '/mydata/delete'
}
}),
reader: MyReader,
baseParams: {
host_id: 1
},
writer: new Ext.data.JsonWriter({
encode: true
}),
storeId: 'mystore',
sortInfo: {field:'field2', direction:'DESC'}
});
MyStore.load();


Example JSON return from load call:


{"data":[{"id":"1792","field1":"3","field2":"2010-09-15","field3":"21:45:00"}],"total":1}


Is there a property I am missing in my reader or elsewhere?

Animal
9 Sep 2010, 12:08 PM
Use Store, not JsonStore.


Yet ANOTHER example of these horrible, code wasting "shortcut" classes tripping people up!

Ed!

abaird
9 Sep 2010, 1:20 PM
Wow, and just like that it works :) After wrestling with it for hours...

Yeah, it seemed common sense to me that I would use a JsonStore if I was using a JsonReader and JsonWriter. I wonder why it doesn't simply accept the "reader" parameter (and expect a JsonReader).

Thanks very much!