Vaadin Grid cell not showing multiline rows(Vaadin Grid 单元格未显示多行行)
问题描述
使用 Vaadin Grid,我想为每个单元格生成多行单元格,这些单元格中的内容与宽度重叠.
With Vaadin Grid, I want to generate multiline cells for every cell that have more content in cell that overlaps its width.
我已经试过了:
java
white-space: pre;
但它似乎不起作用.(此解决方案适用于 Table)
java
white-space: pre;
but it does not seem to work. (This solution worked for Table)
自定义渲染器 setRenderer(HtmlRenderer)
带有 </br>
标签和不同的 CSS 显示设置
custom renderer setRenderer(HtmlRenderer)
with </br>
tags and different CSS display settings
期望的结果:
推荐答案
对于列中有大文本并且希望在网格列中显示大数据而不默认截断它们的人:
For people with large text in columns and who want to display large data in Grid Columns without having them cutoff by default:
为您的网格添加样式名称:
Add a Style name to your grid:
grid.addStyleName("commentsGrid");
如果您想自定义它们,请为您的行和单元格添加一些样式名称:
Add some style names to your rows and cells if you would like to customize them:
grid.setRowStyleGenerator(rowRef -> {// Java 8
return "bigRows";
});
和
grid.setCellStyleGenerator(new Grid.CellStyleGenerator(){
@Override
public String getStyle(CellReference cellReference) {
return "bigCell";
}
});
对我来说,问题栏是评论.因此,使用样式类 wrap 和固定宽度的 p
标签围绕文本.
For me the problem column was comments. So surround the text with p
tag with style class wrap and a fixed width.
Converter<String, String> commentsConverter = new Converter<String, String>(){
@Override
public String convertToModel(String value, Class<? extends String> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
return value;
}
@Override
public String convertToPresentation(String value, Class<? extends String> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
if(value !=null){
return "<p class="wrap">"+value+"</p>";
}else{
return "";
}
}
@Override
public Class<String> getModelType() {
return String.class;
}
@Override
public Class<String> getPresentationType() {
return String.class;
}
};
grid.getColumn("comments").setRenderer(new HtmlRenderer(), commentsConverter);
grid.getColumn("comments").setWidth(700d);
然后我将上面提到的类设置如下:
Then i styled the classes mentioned above as follows:
.commentsGrid td{
height:150px !important;
}
p.wrap{
width: 45em;
word-wrap: break-word;
word-break: break-all;
white-space: normal;
}
我得到了这样的结果:
我不是 CSS 忍者,所以你可以让它比这更漂亮.
I am not a CSS ninja, so you can make it way more beautiful than this.
如果您不希望所有行都具有同样大的高度,那么您可以即时计算 rowHeights,然后在第 2 步中设置它们.我不是 100% 确定.
If you don't like all rows to have equally large heights then you can calculate rowHeights on the fly and then set them in step 2. I am not 100% sure.
这篇关于Vaadin Grid 单元格未显示多行行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Vaadin Grid 单元格未显示多行行
基础教程推荐
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 降序排序:Java Map 2022-01-01