PDA

View Full Version : How to inject additional HTTP parameter to the sort and paging events on grid



MMirabito
15 Aug 2010, 12:26 PM
Hello to all,

I am not sure if this is a an EXT designer issue but since I am using the tool to build the UI I will start here.

1) added a JSON store and wired it to the GridPanel.
2) The store is not set to autoload since the data query needs to have search values associated prior to the execution.
3) Once the user executes the query based on the values selected I issue an ajax call and pass 6 params that will be used to narrow down my query results on the server (servlet/action) by dynamically building a where clause
4) I populate the grid from the results of the server action. See my simple code snippet.


Ext.Ajax.request({
url: 'executeQuery.do',
method: 'post',
params: {
values0: queryParam['values0'],
values1: queryParam['values1'],
values2: queryParam['values2'],
values3: queryParam['values3'],
values4: queryParam['values4'],
values5: queryParam['values5']
},
success: function(responseObject) {
jsonData = Ext.util.JSON.decode(responseObject.responseText);
var dataStore = Ext.StoreMgr.get('MyStore');
dataStore.loadData(jsonData);
Ext.getCmp("queryTabPanel").setActiveTab("queryResults");
}
failure: function() {
alert("error");
}
});


All of this appears to be working properly when I displaying the first page but now I need to include “paging” and “Remote Sorting” which I thought I could do easily.
I associated a URL (i.e. executeQuery.do) to the JSONStore but my problem is that any time the user pages or performs a sort I also need to pass the original query prams (which I keep available in my Javascript) in order for the servlet to generate the dynamic SQL.


queryParam['values0'],
queryParam['values1'],
queryParam['values2'],
queryParam['values3'],
queryParam['values4'],
queryParam['values5']

The actual values are something like (i.e. values0 "1,2,3,4,5,6" or values1 "ga, al, ca, fl" etc.) the servlet converts them into a series of where clauses using the IN SQL statement and feeds them to my SQL statement.

It is not oblivious to me how I can intercept the sort and paging ext events just before they are sent back to the server so that I can “inject” additional parameters that will be available to my servlet/action.
One thought that occurred to me is that I could probably do a quick fix by creating session variables and track state, then any time a sort or paging action is requested I can just access my session variables that provide my where clause. But I was hoping to avoid this, unless this is the best practice for EXT development.

Could anyone point me in the right direction as to how I can leverage EXT to do this? Or better yet if anyone has had the same dilemma I was it resolved

Thanks in advance,

Max