PDA

View Full Version : Problem applying a StoreFilter



MikeHat
28 Apr 2010, 7:34 AM
Hi,

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:

Code:


public class FolderTree extends LayoutContainer {

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

StoreFilter<TreeModel> filter = new StoreFilter<TreeModel>() {
@Override
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);
folderTreePanel.setDisplayProperty("title");
}
}



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:



@Override
protected void afterRender() {
super.afterRender();
folderTreePanel.getStore().applyFilters("");
}


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.

Thanks

richardcatlin
19 Sep 2010, 7:21 AM
Try:
treeStore.applyFilters(null);
This worked for me.

sven
19 Sep 2010, 7:24 AM
folderTreePanel.getStore().applyFilters("");


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.