从vaadin中的另一个表过滤表

时间:2013-06-18 17:15:06

标签: filtering vaadin

我想知道如何根据我在另一个表中点击的内容过滤一个表。例如,如果我在国家/地区表中点击俄罗斯,它应该在名称表中过滤来自俄罗斯的所有人。我想知道如何使用vaadin来做到这一点。我在下面添加了一些相关代码。当我点击某个国家/地区时,国家/地区表格会过滤名称表。

这是我的过滤方法:

public class CountryFilter implements Filter {
    public String needle;
    public CountryFilter(String needle) {
        this.needle = needle;
    }

    public boolean appliesToProperty(Object id) {
        return true;
    }
    public boolean passesFilter(Object itemId, Item item) {
        String haystack = ("" + item.getItemProperty(Name) +
                                item.getItemProperty(Country)).toLowerCase();
        return haystack.contains(needle);
    }
}

这是我使用过滤器的搜索方法

    public void initCountrySearch() {   
    country.setSelectable(true);
    country.setImmediate(true);
    name.setVisibleColumns(new String[] {"name"});
    country.setVisibleColumns(new String[] {"country"});


country.addValueChangeListener(new Property.ValueChangeListener() {
    public void valueChange(ValueChangeEvent event) {
            // TODO Auto-generated method stub

            data.name.removeAllContainerFilters();
            data.name.addContainerFilter(new CountryFilter(event.getProperty().getValue().toString()));
        }

    });
}

1 个答案:

答案 0 :(得分:0)

您可以在选择条件表上设置ValueChangeListener,告知您有关值的更改。在值更改方法中,您可以获取所选项目,并根据此项目在目标表上进行加载。

相关问题