2015-04-17 114 views
2

我試圖覆蓋Grid使用的StringFilter的行爲。 下面的代碼沒有一些功能,我只是想看看validateModel是否被調用。事情是,它並沒有被稱爲永遠。另一方面,onFieldKeyUp正在被調用,因爲它應該。我究竟做錯了什麼?StringFilter覆蓋不起作用

我使用Sencha GXT 3.1.0GWT 2.6.1Java 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; 
     } 
    } 
};  

回答

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); 
+0

的SETLOCAL(真)爲我做。非常感謝。 Upvoted和接受。 – alkis