Vaadin 网格 - gridpro 组合框编辑器

发布于 2025-01-18 10:21:54 字数 279 浏览 3 评论 0原文

Grid Pro 具有三个推荐的内置编辑器:文本字段、复选框和选择。 您可以管理具有键和值属性的列表吗? 例如: 国家/地区列表

我无法在选择中显示国家/地区名称值并将 id 保存在数据库记录中。 当我管理带有键和值的列表时,我通常依赖 ComboBox。 组合框不存在于内置编辑器列表中。 您建议编写自己的编辑器吗?

Grid Pro features three recommended built-in editors: Text Field, Checkbox, and Select.
Ho can you manage a list with key and value properties?
For example:
Country list

I'm unable to show country name in the select value and save the id in the database record.
I usually rely on ComboBox when I manage a list with key and value.
Combobox is not present in the list of built-in editors.
Do you suggest to write your own editor?

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

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

发布评论

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

评论(1

巾帼英雄 2025-01-25 10:21:54

让我们假设您有一个country具有属性ID名称的类。和Person country属性的类。您显示gridpro< person>

您可以制作选择编辑器并定义其是itemlabelgenerator(或者,如果要显示标志或其他内容)以显示country :: getName。 **

The saving to the database should be handled by the annotations on the relation.通常使用JPA,人与国家之间会有@manytoone的关系,并将其保存在人表中的国家 /地区(ID,使用@ID指定)。

**我不使用GRID PRO,但是在检查代码后,我可以通过使用gridpro.addeditcolumn(Person :: GetCountry)。Select(Person :: SetCountry,code)您无法指定itemLabelgenerator/Renderer。
但是,您可以准备自己的选择组件,并使用editcolumnconfigurator :: custom方法。

Select<Country> countryEditorComponent = new Select<>();
countryEditorComponent.setItems(countriesList);
countryEditorComponent.setItemLabelGenerator(country -> country.getName());
gridPro.addEditColumn(Person::getCountry).custom(countryEditorComponent , Person::setCountry).setHeader("Country");

Let's assume you have a Country class with the properties id and name. And a Person class with a country property. You display a GridPro<Person>.

You can make a Select editor and define it's itemLabelGenerator (or renderer, if you want to show a flag or something) to show Country::getName. **

The saving to the database should be handled by the annotations on the relation. Usually using JPA, there would be a @ManyToOne relation between Person and Country, and save the country-FK (id, specified using @Id) in the person table.

** I don't use Grid Pro, but upon inspection of the code I can see that by using gridPro.addEditColumn(Person::getCountry).select(Person::setCountry, countriesList) you cannot specify the itemLabelGenerator/renderer.
However, you could prepare your own Select component and use the EditColumnConfigurator::custommethod.

Select<Country> countryEditorComponent = new Select<>();
countryEditorComponent.setItems(countriesList);
countryEditorComponent.setItemLabelGenerator(country -> country.getName());
gridPro.addEditColumn(Person::getCountry).custom(countryEditorComponent , Person::setCountry).setHeader("Country");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文