我试图覆盖StringFilter
使用的Grid
的行为。
下面的代码没有一些功能,我只想看看是否正在调用validateModel
。问题是,它永远不会被称为。另一方面,onFieldKeyUp
正在被调用。我究竟做错了什么?
我使用Sencha GXT 3.1.0
,GWT 2.6.1
,Java 1.7
Filter<Record, ?> filter = new StringFilter<Record>(valueProvider)
{
@Override
protected void onFieldKeyUp(Event event)
{
Window.alert("onFieldKeyUp"); //--> This is called
int key = event.getKeyCode();
if (key == KeyCodes.KEY_ENTER && field.isValid())
{
event.stopPropagation();
event.preventDefault();
menu.hide(true);
return;
}
super.onFieldKeyUp(event);
}
@Override
protected boolean validateModel(Record model)
{
Window.alert("validateModel"); //--> This is NOT called
String rowValue = getValueProvider().getValue(model);
rowValue = (rowValue == null) ? "" : rowValue;
Object filterObject = getValue();
String filterValue = filterObject == null ? "" : String.valueOf(filterObject);
if (filterValue.isEmpty() && rowValue.isEmpty())
{
return true;
}
else
{
//Here I want to put some more code manipulating the filtevalue
return rowValue.toLowerCase().indexOf(filterValue.toLowerCase()) > -1;
}
}
};
答案 0 :(得分:2)
您是否放了filters.setLocal(true);
和filters.initPlugin(grid);
?
以下是我尝试过的代码:
GridFilters<MyRow> filters = new GridFilters<MyRow>();
filters.initPlugin(grid);
StringFilter<MyRow> filter = new StringFilter<MyRow>(nameValueProvider) {
@Override
protected boolean validateModel(MyRow model) {
Window.alert("Hello");
return super.validateModel(model);
}
};
filters.addFilter(filter);
filters.setLocal(true);