网格中的 Vaadin 过滤器 [英] Vaadin filters in Grid

查看:34
本文介绍了网格中的 Vaadin 过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Vaadin 中遇到过滤器问题.为网格中的每一列制作过滤器很容易.但现在我需要为网格中的所有单元格做一个过滤器.我不知道该怎么做.

i have problem with filters in Vaadin. Its easy to make filters for each column in Grid. But now i need to do one filter for all cells in Grid. I don't know how to do this.

我试图在这个例子中这样做,但它不起作用

I was trying to do this like in this example, but it doesn't worked

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

推荐答案

我为我的案例创建了一个解决方案.我希望对某人有帮助

I created a solution to my case. I hope that help somebody

//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

For more information check here: http://krishnasjavaworld.blogspot.com.br/2015/04/step-by-step-vaadin-grid-part-3filters.html

这篇关于网格中的 Vaadin 过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆