问题
I would like to filter a tree without type in the textfield, but when an event is triggered. I tried subclassing StoreFilterField like this:
class MyStoreFilter<M extends ModelData> extends StoreFilterField<M>{
public MyStoreFilter() {
super();
}
public void startFilter(){
super.onFilter();
}
@Override
protected boolean doSelect(Store<M> store, M parent, M record,
String property, String filter) {
String name = record.get("name");
name = name.toLowerCase();
if (name.startsWith(filter.toLowerCase()))
return true;
else
return false;
}
};
And when i want to filter my tree:
MyStoreFilter<ModelData> f=new MyStoreFilter<ModelData>();
f.setRawValue(myText);
f.bind(store);
f.startFilter();
But doesn't work, and my filter shows all items of my tree. What is wrong?
回答1:
I solved myself adding this constructor:
public MyStoreFilter(String f) {
filtro=f;
setAutoValidate(true);
setValidateOnBlur(false);
setTriggerStyle("x-form-clear-trigger");
filter = new StoreFilter<M>() {
public boolean select(Store<M> store, M parent, M model, String property) {
String v = filtro;
return doSelect(store, parent, model, property, v);
}
};
}
来源:https://stackoverflow.com/questions/15006376/gwt-storefilterfield-auto-filter