2015-10-31 1 views
1

У меня проблема с фильтрами в Ваадине. Его легко сделать фильтры для каждого столбца в Grid. Но теперь мне нужно сделать один фильтр для всех ячеек в Grid. Я не знаю, как это сделать.Фильтры Vaadin в сетке

Я пытался сделать это, как в этом примере, но он не работал

Filter f = 
new Or(new SimpleStringFilter(Columns.SEARCH.id(), "rpm-diastolic", true, false), 
new Or(new SimpleStringFilter(Columns.SEARCH.id(), "rpm-systolic", true, false)), 
new Or(new SimpleStringFilter(Columns.SEARCH.id(), "rpm-weight", true, false))) ; 
container.addContainerFilter(f); 

ответ

2

Я создал решение для моего дела. Я надеюсь, что кому-то помочь

//In my case, I created a class that extends Grid. 
public class GridExample extends Grid { 

    ... 

    //Method to add a filter on grid 
    public void setFilterGrid(BeanItemContainer<?> beanType) { 
     //This create a HeaderRow to add filter fields 
     HeaderRow filterRow = this.appendHeaderRow(); 
     for (Column column : getColumns()) { 
      //For each column from the grid 
      HeaderCell cellFilter = filterRow.getCell(column.getPropertyId()); 
      //Add a textfield 
      cellFilter.setComponent(createFieldFilter(beanType, column));  
     }  
    } 

    //This create a TextField to filter the information 
    private TextField createFieldFilter(final BeanItemContainer<?> container, final Column column) { 
     TextField filter = new TextField(); 
     filter.setImmediate(true); 
     filter.addTextChangeListener(new TextChangeListener(){ 
      @Override 
      public void textChange(TextChangeEvent event) { 
       String newValue = event.getText(); 
       //Remove the previous filter 
       container.removeContainerFilters(column.getPropertyId()); 
       if (newValue != null && !newValue.isEmpty()) { 
        //Filter the information 
        container.addContainerFilter(new SimpleStringFilter(column.getPropertyId(), newValue, true, false)); 
       } 
       recalculateColumnWidths(); 
      } 
     });  
     return filter; 
    } 
} 

Для дополнительной информации посетите здесь: http://krishnasjavaworld.blogspot.com.br/2015/04/step-by-step-vaadin-grid-part-3filters.html

+0

Что-то очень сломанные на этом блоге. Важный бит (как это сделать на самом деле) отсутствует, а на их месте просто слово Загрузка ... – NickJ

+0

@NickJ Я автор этого блога, похоже, что интерфейс gist с моим блоком сломан, скоро исправит его – Patton