tags:

views:

271

answers:

2

I am using a GroupingStore to load data into a grid, data is loaded from server and read via a JSON reader. Here is the releveant code

var reader = new Ext.data.JsonReader({
    successProperty: 'success',
    idProperty: 'id',
    root: 'data',
    messageProperty: 'message'  
}, [
    {name: 'id'},
    {name: 'creator'},
    {name: 'first_name', allowBlank: false},
    {name: 'last_name', allowBlank: false}
]);

var store = new Ext.data.GroupingStore({
    id: 'person',
    proxy: proxy,
    reader: reader,
    groupField:'creator',
    sortInfo:{field: 'first_name', direction: "ASC"}
});

It is correctly being loaded into grid, but with this data I want to send some more data, which is not realted to grid but will save me a trip to server. So is there anyway I can access the orginal data returned from server?

I have tried using a callback in load

store.load({'callback':loadCallback})

but data in loadCallback is only list of records not orginal data.

Edit: a example from server i return {'form_items':[ ], 'data': [] }, data node is used as root of store and contains row for grid, i want to access form_items or actually the the orginal data which server returned to the store.

+1  A: 

It sounds like you want access to the original response from the server when the store is finished loading. Try this (untested) code.

store.proxy.on('onread', function(a, o, response) {
  var data = Ext.util.JSON.encode(response.responseText);
  console.dir(data.form_items);
}
Jonathan Julian
No it is now working, it doesn't even get called? anyway i have found the solution
Anurag Uniyal
A: 

I have found a way to do it in load callback by directly accessing the store.reader.jsonData

e.g.

store.load({'callback':function(a,b,c){
   console.log(store.reader.jsonData)
 }});
Anurag Uniyal
Oh good. I thought you had said the store load callback didn't work, which is why I was using the proxy.
Jonathan Julian
@jonathan, in question i have written "I have tried using a callback in load, but data in loadCallback is only list of records not orginal data."
Anurag Uniyal
yeah, using the raw response from the proxy is just another way of getting the original http body. glad it's working.
Jonathan Julian