PDA

View Full Version : Filter a store?



Olaus
21 Feb 2012, 7:17 AM
How do I filter a store?
In gxt 2 i could do store.filter(property); But that is removed.
applyFilters is protected. Should that be public like applySort?

icfantv
21 Feb 2012, 10:28 AM
Are you wanting to set a bunch of filters and then execute the search/sort?

Olaus
22 Feb 2012, 4:04 AM
Yes. I set a filter to a store. The filter depends an external property (date). So I want to rerun the filter when the date changes. I don't want to remove/add the filter in order to run it.

icfantv
22 Feb 2012, 7:38 AM
I need to do this as well because my filters are separate from my grid, i.e., the fields used to specify filter values are in a toolbar above the grid. The toolbar has a "Search" and "Reset Search" button.

The answer I got is that the filtering is done on the ListStore but I am awaiting some answers on how exactly to do this because the addFilter method on ListStore takes a StoreFilter and not a StringFilter or NumericFilter, etc...

The other issue is that the child classes of Filter do not allow you to set the value directly. I mitigated this by extending, e.g., StringFilter and adding a setValue() method. This way you can set the value(s) and then fire an update event.

I should hear back today and I can update this thread with the answer I received. Until then, I'm just playing around to see what works.

icfantv
22 Feb 2012, 5:24 PM
Ok, I never heard back but I got this working. Note that I disable the menus that display in the column headers - this is done via the ColumnConfig. Also, this assumes you are doing all your filtering and sorting on the server-side.

For setup, I constructed a new GridFilters<M> object passing in my FilterPagingLoadConfig and then called GridFilters.initPlugin passing in a reference to my grid. Finally, I iterated over my filters calling GridFilters.addFilter for each one.

I retained a reference to each of my filters (NB: which does not scale) and I have each one mapping to a corresponding form field (text field, combo box, etc...).

Because filters don't allow me to set the value directly, I had to extend the base classes to add a method to do so, however, I think if I call Filter.getValueProvider I can call the setter method there to set the value, but I've not tested this yet.

When I click my "Search" button, I check each form field to see if it has deviated from it's default value and if it has changed, I call Filter.setActive(true, true) and then call the method I added to set the value on the filter.

Finally, calling PagingLoader.load will fire the AJAX call to the server and my service method (which takes a FilterPagingLoadConfig object as its parameter). Calling FilterPagingLoadConfig.getFilters returns me my list of set filters in the form of FilterConfig objects.

I know I glossed over this, so if you need concrete examples, first look at the source code for the Remote Filter Grid here: http://sencha.com/examples-dev and I can provide snippets of my code.