具有延迟加载和过滤功能的 Vaadin 22 ComboBox
我的应用程序中有一个标记系统。现在有一个特定的实体,我只想允许为其添加一个标签。实际上我想将父级分配给标签。 为此,我想使用具有延迟加载和过滤功能的 VaadinCombobox。
我的数据层是 Spring Boot Neo4J Data。我有一个像这样的存储库:
Page<TagListDto> searchPaginated(String searchTerm, Pageable page);
这给了我一个数据传输对象,用于由 searchTerm 过滤的列表显示。该列表是可分页的。我使用相同的方法来过滤网格。
所以如果我知道从哪里获取 searchTerm,我就可以这样做。
ComboBoxLazyDataView<TagListDto> dataView = parentTag.setItems(query ->
tagRepository.searchPaginated(searchTerm,
PageRequest.of(query.getPage(), query.getLimit())).stream());
parentTag.setItemLabelGenerator(TagListDto::getName);
但可能我必须为 ComboBox 使用 DataProvider
和 FilterBuilder
,对吧?
I have a tagging system in my application. Now there is one specific entity, for which I want to allow only one tag. Actually I want to assign a parent to a tag.
For this purpose I want to use a VaadinCombobox with lazy loading and filtering.
My data layer is Spring Boot Neo4J Data. There I have a repository like this:
Page<TagListDto> searchPaginated(String searchTerm, Pageable page);
This gives me a data transfer object used for list displays filtered by the searchTerm. The list is pageable. I use the same method for filtering Grids.
So I could do it like this, if I knew where to get the searchTerm from.
ComboBoxLazyDataView<TagListDto> dataView = parentTag.setItems(query ->
tagRepository.searchPaginated(searchTerm,
PageRequest.of(query.getPage(), query.getLimit())).stream());
parentTag.setItemLabelGenerator(TagListDto::getName);
But probably, I'll have to use a DataProvider
and a FilterBuilder
for the ComboBox, right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以答案是使用 setItemsWithFilterConverter 方法。您在组合框字段中输入的内容将作为
String
发送到过滤器转换器(第二个方法参数),然后作为query
对象的属性传递以执行搜索(第一个方法参数)。因此,如果您需要将搜索项的类型从 String 转换为其他类型,添加通配符或其他类型,请在第二个 labda 中执行此操作。
使用第一个 lambda 中的
query.getFilter()
,您可以检索搜索词,然后使用它向后端进行查询。这是一个例子:
So the answer is to use
setItemsWithFilterConverter
-method. What you enter into the combo-box field will be sent to the filter converter (2nd method parameter) as aString
and then passed as property of thequery
object to execute the search (1st method parameter).So if you need to convert the type of the search term from String to some other type, add wildcards or whatever, do it in the 2nd labda.
With
query.getFilter()
in the 1st lambda you can retrieve the search term and then use that to make the query to your backend.Here's an example: