Vaadin 中的过滤器树

发布于 2024-11-19 00:09:14 字数 116 浏览 1 评论 0原文

我想根据某些编辑框中的文本(在文本更改时)隐藏 vaadin 树的叶子。 即,如果编辑框中的文本是“ab”,我只想显示文本以“ab”开头的叶子。 如果文本为空,我想显示所有叶子。

我怎样才能做到这一点?

I want to hide leafs from vaadin tree according to text in some editbox (on text change).
ie if text in editbox is "ab" i want to show only leafs with text starting with "ab".
and if text is empty, i want to show all leafs.

How can i make that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

(り薆情海 2024-11-26 00:09:14

您必须过滤附加到树的数据容器。

版本 6.6.0 中引入了新的过滤器 API,它允许您创建自定义过滤器。我还没有尝试过新的 API,但在你的情况下,它应该像这样工作:

textField.addListener(new FieldEvents.TextChangeListener() {
    void textChange(FieldEvents.TextChangeEvent event) {
        // Remove existing filter (if any).
        // This is OK if you don't use any other filters, otherwise you'll have to store the previous filter and use removeContainerFilter(filter)
        dataContainer.removeAllContainerFilters();

        // Create a new filter which ignores case and only matches String prefix
        SimpleStringFilter filter = new SimpleStringFilter(propertyId, event.getText(), true, true);

        // Add the new filter
        dataContainer.addContainerFilter(filter);
    }
});

其中 textField 是你的“编辑框”,dataContainer 是数据容器,附加到您的树,properyId 是包含要过滤的文本的容器字段的属性 ID。

请注意,上述代码未经测试,因为我目前无法访问适当的开发工具。

You will have to filter the data container which is attached to the tree.

A new Filter API was introduced in version 6.6.0 which allows you to create custom Filters. I haven't tried the new API yet, but in your case it should work like this:

textField.addListener(new FieldEvents.TextChangeListener() {
    void textChange(FieldEvents.TextChangeEvent event) {
        // Remove existing filter (if any).
        // This is OK if you don't use any other filters, otherwise you'll have to store the previous filter and use removeContainerFilter(filter)
        dataContainer.removeAllContainerFilters();

        // Create a new filter which ignores case and only matches String prefix
        SimpleStringFilter filter = new SimpleStringFilter(propertyId, event.getText(), true, true);

        // Add the new filter
        dataContainer.addContainerFilter(filter);
    }
});

in which textField is your "editbox", dataContainer is the data container which is attached to your tree and properyId is the property id of the container field which contains the text you want to filter.

Note that the above code is untested because I currently can't access the appropriate development tools.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文