PDA

View Full Version : GridPanel sending parameters in JSON format



flavouski
12 Jul 2010, 9:05 AM
Problem: With GridPanel there are several parameters that get sent to the server (i.e. dir, sort, limit, filter...). I want to take those parameters and have them get sent over in JSON format.

I am using the HttpProxy and am able to post to the JSON content-type, but the parameters aren't in the right format. They are still in RequestParameter format:

start=0&limit=25&sort=column1&dir=ASC

Is there a way to convert this into JSON (some sort of JsonWriter?)?
Thanks

Condor
12 Jul 2010, 11:48 AM
Try:

store.on('beforeload', function(store, options){
options.jsonData = options.params;
delete options.params;
});

flavouski
13 Jul 2010, 5:47 AM
Thanks for the code!

I messed around with it a bit. For some reason options.jsonData just didn't seem to be storing anything, so I ended up doing:

options.params = Ext.encode(options.params);And that seems to load everything and appear in the body of the request.
The event "beforeload" seems to fire the right times, but the values don't ever seem to account for the "filters" (i.e. the JSON changes when I change how to sort, but when I add a filter onto the grid, there is no JSON that accounts for the new filter). (and yes my filter is remote)

Before I inserted the encoding:

start=0&limit=25&sort=column1&dir=ASC&filter%5B0%5D%5Bfield%5D=id&filter%5B0%5D%5Bdata%5D%5Btype%5D=numeric&filter%5B0%5D%5Bdata%5D%5Bcomparison%5D=lt&filter%5B0%5D%5Bdata%5D%5Bvalue%5D=6
After I inserted the encoding:

{"start":0,"limit":25,"sort":"column1","dir":"ASC"}