DWRProxy for ExtJs 4

If you are using ExtJs version 4.x for your RIA and DWR for easy to communicate between server-side and client-side (that means “easy ajax”, transform JavaScript object into Java object and vice-versa and so on) in that case you might have noticed that data package of ExtJs4 doesn’t support loading data from DWR method. I’we created Ext.ux.data.DwrProxy class that supports loading data into store from DWR method. Let’s look at sample code:

 * Let's assume that we have already defined App.data.Store 
 * class with its Model class.
var store = Ext.create('App.data.Store', {
    proxy: {
        type : 'dwr',
        /*DWR method that will return data.*/
        dwrFn : MyDWRClass.getRecords,

        /** Function that returns parameters for remote
         * DWR Method for each request.
         getDwrArgs: function(operation, store) {
           var argObj = Ext.apply({}, operation.params);
           argObj.start = operation.start;
           argObj.limit = operation.limit;
            * If server side method takes several parameters
            * then array must be returned.
           return argObj;

       reader : {
           type: 'json',
           root: 'records',
           totalProperty: 'count'

The usage is very likely as DWRProxy classes for ExtJs 3.x and ExtJs 2.x but supports only loading data. I’m ready to implement create, update and destroy methods too if there will be any request for it (I only use DWRProxy just for loading data and paging).

I’ve implemented one additional config option – preprocessResponse that takes response data and fired before server response will be loaded into store. In very specific cases may be you need to do custom modifications to data before it will be load
ed by proxy.reader.

Please look at source of Ext.ux.data.DwrProxy and see more about what and how I’ve done and give me any feedback.

Wish you good luck with ExtJs4 and don’t forget to include DwrProxy.js. 🙂

reader propery of proxy depends on response format and structure. In given case reader can read the following structured JSON object:

  /* because root = 'records' */
  records: [{},{},{},{}...],
  /* because totalProperty = 'count' */
  count: 100