1. #1
    Sencha User
    Join Date
    Jun 2010
    Posts
    27
    Vote Rating
    0
    solovieff13 is on a distinguished road

      0  

    Question Grid Proxy with custom request.

    Grid Proxy with custom request.


    Hi all, I wonder if I can send custom request instead of using 'url' parameter in my Proxy for Grid.
    In other words I'd like to use my own function for sending requests each time the user changes the page or store gets loaded. For now, my Proxy looks like this:
    Code:
    Ext.extend(Ext.data.MyExchangeProxy, Ext.data.MemoryProxy, {
           doRequest : function(action, rs, params, reader, callback, scope, arg) {
                params = params || {};
    
                // filtering
                if (params.filter == undefined) {
                    params.filter = [];
                }
    
                    result = reader.readRecords(processes.rows); // i put data in processes in another callback
    
                // sorting
                sortExtRecords(result, params);
    
                // paging
                if (params.start !== undefined && params.limit !== undefined) {
                    result.records = result.records.slice(params.start, params.start + params.limit);
                }
                callback.call(scope, result, arg, true);
            }
        });
    Now I get processes.rows from another callback (and it is all rows not only rows I need), which fills in the data and asks the store to reload, but I do not want to pass all the data from server anymore, so I need to change my proxy. The behavior I'd like to have is the following:
    1) User clicks something, the store is loading (request is send using my own function where I should somehow know which page I need etc).
    2) The store is filled in with new values and shown to user.

    How can I send the request and wait for the response using Proxies and my own request-sending function?

    Also, I'd like to know how to tell the Paging Toolbar how much pages will be there.

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Use the PagingStore user extension, optionally combined with a DirectProxy to do the remote call.

  3. #3
    Sencha User
    Join Date
    Jun 2010
    Posts
    27
    Vote Rating
    0
    solovieff13 is on a distinguished road

      0  

    Default


    Hi, Condor, thanx for your reply. I am using ArrayStore and it looks like enough for me, but my server request looks like this:
    Code:
    request(stringWithParamsForServer, myCallBack);
    So, when reply comes myCallBack is being called (now it 'manually' reloads the store). Could you please point me to DirectProxy example which could help me?

  4. #4
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Example:
    Code:
    proxy: new Ext.data.DirectProxy({
      paramsAsHash: true,
      api: {
        read: function(args, callback){
          request(Ext.encode(args), callback);
        }
      }
    })
    (needs this patch)

  5. #5
    Sencha User
    Join Date
    Jun 2010
    Posts
    27
    Vote Rating
    0
    solovieff13 is on a distinguished road

      0  

    Default


    Am I right: this will call my request method with specified callback on store reload, than, when reply will come and callback will work to the end, store will be reloaded (doRequest method will be called)? (sorry, if I am too annoying, but I want to understand how all this works).

  6. #6
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    DirectProxy will call the 'read' api method when the store is loaded and it expects the callback function to be called with the returned data and the response object (for the status).

  7. #7
    Sencha User
    Join Date
    Jun 2010
    Posts
    27
    Vote Rating
    0
    solovieff13 is on a distinguished road

      0  

    Default


    All my callbacks are done like this and it could not be changed due to our architecture:
    Code:
    function myCallBack(success, idOfRequest, replyObject) {
    someActionsHere
    }
    What should my callBack return to be properly processed by Ext Methods?

  8. #8
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    96
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    You could try:
    Code:
    proxy: new Ext.data.DirectProxy({
      paramsAsHash: true,
      api: {
        read: function(args, callback){
          request(Ext.encode(args), function(success, idOfRequest, replyObject){
            callback(replyObject, {status: success});
          });
        }
      }
    })

  9. #9
    Sencha User
    Join Date
    Jun 2010
    Posts
    27
    Vote Rating
    0
    solovieff13 is on a distinguished road

      0  

    Default


    Great thanks, looks like now I understand (:

    That means that my callBack should always call
    Code:
    callback(replyObject, {status: success});
    inside itself, and be located in proxy api; so it can not be separate fuction, yapp?

Similar Threads

  1. Ajax.request VS Store proxy
    By merry andrew in forum Sencha Touch 1.x: Discussion
    Replies: 1
    Last Post: 23 Aug 2010, 4:09 PM
  2. Replies: 2
    Last Post: 29 Jun 2010, 2:46 PM
  3. [Feature Request] JsonStore proxy config option
    By patspam in forum Community Discussion
    Replies: 2
    Last Post: 31 Oct 2007, 11:54 PM
  4. Custom Mouse Selection Proxy Box Help (jQuery)
    By xtrafile in forum Ext 1.x: Help & Discussion
    Replies: 0
    Last Post: 16 Jul 2007, 7:01 PM

Thread Participants: 1

Tags for this Thread