PDA

View Full Version : Grid Proxy with custom request.



solovieff13
24 Nov 2010, 11:18 AM
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:

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.

Condor
25 Nov 2010, 8:01 AM
Use the PagingStore user extension, optionally combined with a DirectProxy to do the remote call.

solovieff13
25 Nov 2010, 11:10 PM
Hi, Condor, thanx for your reply. I am using ArrayStore and it looks like enough for me, but my server request looks like this:

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?

Condor
26 Nov 2010, 12:44 AM
Example:

proxy: new Ext.data.DirectProxy({
paramsAsHash: true,
api: {
read: function(args, callback){
request(Ext.encode(args), callback);
}
}
})
(needs this patch (http://www.sencha.com/forum/showthread.php?95706-DISCUSS-Allow-non-RemotingProvider-directFn-method))

solovieff13
26 Nov 2010, 12:55 AM
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).

Condor
26 Nov 2010, 12:57 AM
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).

solovieff13
26 Nov 2010, 1:29 AM
All my callbacks are done like this and it could not be changed due to our architecture:

function myCallBack(success, idOfRequest, replyObject) {
someActionsHere
}

What should my callBack return to be properly processed by Ext Methods?

Condor
26 Nov 2010, 2:39 AM
You could try:

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

solovieff13
26 Nov 2010, 4:28 AM
Great thanks, looks like now I understand (:

That means that my callBack should always call

callback(replyObject, {status: success});

inside itself, and be located in proxy api; so it can not be separate fuction, yapp?