View Full Version : Problem applying a StoreFilter

28 Apr 2010, 7:34 AM

I am having some problem with applying a filter to a TreeStore

I have a local TreeStore which contains Folder and Page objects in a tree.

I use the store with a TreeGrid but I also want to reuse it with a TreePanel but only want to display the Folders. So I thought I would try a StoreFilter like this:


public class FolderTree extends LayoutContainer {

protected void onRender(Element parent, int index) {
super.onRender(parent, index);
final TreeStore<TreeModel> treeStore = Registry

StoreFilter<TreeModel> filter = new StoreFilter<TreeModel>() {
public boolean select(Store<TreeModel> store, TreeModel parent,
TreeModel item, String property) {
if (item instanceof Page) {
return false;
return true;
treeStore .addFilter(filter);
final TreePanel<TreeModel> folderTreePanel = new TreePanel<TreeModel>(treeStore);

However, I am note sure when to call the applyFilters method.

- If I apply it to the store before creating the TreePanel it does not work, that makes sense.
- If I apply filters at the end of the onRender method I get "Method must be called after the component is rendered" that again makes sense.

So I am not sure where to put it to get the filter to apply automatically.

I tried adding and afterRender method like this:

protected void afterRender() {

but again I got Method must be called after the component is rendered

I assume I need to add some sort of listener to the folderTreePanel listening for an afterRender event but I am not sure how to do that.

Any help will be appreciated.


19 Sep 2010, 7:21 AM
This worked for me.

19 Sep 2010, 7:24 AM

You will need to call that inside an Event.Render listener added to the TreePanel or before creating the TreePanel.

I will fix the exception so it will also work with your current code.