0

When my grids load via an AJAX proxy, I use the response's "message" key to pass an error message for exceptions or an optional informational message for successful loads. For example:

{ 
  results: 100, 
  success: true,
  rows: [ { ...data here... } ], 
  message: "Query took 2.2 milliseconds"
}

I asked a similar question when using ExtJS 4.x and 5.0, and I was able to use the Proxy's afterRequest event to peek at the response, extract the message, and display it.

But this was removed in 5.1, and I can't seem to figure out an equivalent in 6.0. I also found this answer from someone with a very similar question, but the accepted answer of extending Ext.data.proxy.Ajax doesn't work for me in 6.0 -- it bails on calling "this.callParent(arguments)".

I've been at this for hours, poking and prodding at the proxy, reader, store, and grid configurations, and searching Google. The documentation for 6.0 is, as usual, useless when it comes to events.

The only event I can find that fires when the AJAX load is successful is the Store's "load" event. Unfortunately, the Store doesn't have access to the JSON response that the Proxy handled, at least as far as I can tell. Code:

var ResultsDataStore = Ext.create("Ext.data.Store", {
    listeners: {
        load: function() { console.log("storeload"); }
    },
    proxy: ...

How can I either:

(1) Access the Response from the Store's load event, or

(2) Listen for some other event that has access to the message passed in the response?

Community
  • 1
  • 1
richardtallent
  • 34,724
  • 14
  • 83
  • 123

1 Answers1

0

I would suggest using Reader's transform config option:

var resultStore = new Ext.data.Store({
    proxy: {
        reader: {
            type: 'json',
            transform: function(data) {
                var message = data.message;
                ...
                return data;
            }
        }
    }
});

See more in the docs: http://docs.sencha.com/extjs/6.0/6.0.0-classic/#!/api/Ext.data.reader.Reader-cfg-transform

Alex Tokarev
  • 4,821
  • 1
  • 20
  • 30