PDA

View Full Version : Implementing server side filters on grids without FiltersFeature.js



beckdawg
11 Aug 2011, 12:19 PM
To summarize my issue a bit, I have a use case where the filters need to be exposed and not buried in the column menu. Setting the form panel up was easy enough. However, after that things got difficult. I obviously have the FiltersFeature code but it's nearly 1000 lines. So, reverse engineering that to suit my use case is pretty daunting.

One thought I had was to just use my text fields and do some js hackery to push that data into the FiltersFeature inputs. That sounds like a horrible idea that may work but I'd regret it immediately.

I guess my question is does anyone have advice on the best way to go about this? I'm hoping there is something rather obvious I've missed.

skirtle
12 Aug 2011, 2:52 AM
I think you've got a few options. Unless I'm missing something it just comes down to setting some request parameters on the store's Ajax request.

One way to do it is with extraParams:


store.getProxy().extraParams.yourParamName = yourParamValue;

Using this approach, you would update the extraParams every time one of your form fields has a value change.

From a quick look at FiltersFeature.js it seems it takes an alternative approach. It adds a listener for the store's beforeload event called onBeforeLoad:


onBeforeLoad : function (store, options) {
options.params = options.params || {};
this.cleanParams(options.params);
var params = this.buildQuery(this.getFilterData());
Ext.apply(options.params, params);
}

This listener is passed the request options just before the request is made, so that it can modify them to add in the relevant filter parameters. You could build up request parameters from your form in a similar fashion.

beckdawg
12 Aug 2011, 5:54 AM
Think I figured this out on my own. I just set up a new proxy then attached the extra params I wanted on the "extraParams" of the proxy. After that, you just do store.setProxy(proxy) and then store.load(). However, the one down side to this is you lose any sort information you may have had and the user will have to resort.

skirtle
12 Aug 2011, 6:14 AM
You don't need to create a new proxy. If you do it one of the ways I suggested you won't lost any sort information.

beckdawg
12 Aug 2011, 8:08 AM
This is kind of a duh moment for me because looking at it now it seems rather obvious. But that worked great. Thanks.