View Full Version : Json Interception when using Proxy and reader with grid

30 Nov 2010, 10:17 PM
I am hoping that someone can help me out here, I am calling a remote url that is returning the json data in a structure that is not compatible with the grid. That is all fine and dandy so I thought I would extend the proxy and reader to convert the data before the grid gets it.

The problem I am having is that I am trying to intercept the call before this happens so that I can convert the data, the load event seems to fit this bill but it doesn't fire until the records have been created and added to the store.

Is it possible to convert this json string before sticking it into the store?

I am at a loss to get anything to work, not to mention that I am not even sure that I am doing this in the right spot either.

Anyone have any ideas?

1 Dec 2010, 12:22 AM
The root config of a JsonReader may now be a function which is passed the raw returned object, and must returns the root (The array of raw rows).

So you can massage the data as needed to return an array that can then be iterated to extract records.

1 Dec 2010, 1:13 AM
Ok I think I understand that, so if for example the json coming back to me is split with all the columns in one array and the data in another. You are saying that I can do something like

new Ext.Data.JsonReader({root: function(rawData) {
//Do converstion
return convertedData;

Now this is where I got stuck I didn't see anything like this, and was looking at readRecords and finding this to not fire.

If I have you right, this will work in ExtJS 3.1?

1 Dec 2010, 1:18 AM
But why would you be back on 3.1?

1 Dec 2010, 1:20 AM
Because ColdFusion only has 3.1 packaged up inside it.

1 Dec 2010, 2:00 AM
Ok I am not getting this to work

Here is what I have so far

reader: new Ext.ux.AndyScott.ExtReader(
root: 'records',
totalProperty: 'recordcount',
fields: [id]})});


console.log('ExtReader:', config);
Ext.ux.AndyScott.ExtReader.superclass.constructor.call(this, config);

Ext.extend(Ext.ux.AndyScott.ExtReader, Ext.data.JsonReader,{
read : function(response){
console.log('Read:', response);

var json = response.responseText;
var o = Ext.decode(json);
if(!o) {
throw {message: 'JsonReader.read: Json object not found'};
return this.readRecords(o);

However the read method is not being called in anyway shape or form, I tried the suggestion by Animal to make root a function and either I didn't set it up right or it just not firing either.