我正在尝试使用以下内容在表的两列中显示日期和字符串列表:
leaveTable.addGeneratedColumn("LeaveDate ",
new RequestedLeaveTextShortenerColumnGenerator(1));
leaveTable.addGeneratedColumn("LeaveType ",
new RequestedLeaveTextShortenerColumnGenerator(2));
其中,Date将来自List,而leave类型只是一个String
如何使用:
添加它generateCell(表源,对象itemId,对象columnId){...}
请帮忙!
答案 0 :(得分:2)
在book of vaadin,中有一个关于生成的表列的部分。
它有一些代码示例。
// Define the generated columns and their generators.
table.addGeneratedColumn("date", new DateColumnGenerator());
然后在某处:
/** Formats the value in a column containing Date objects. */
class DateColumnGenerator implements Table.ColumnGenerator {
String format; /* Format string for the Date values. */
/**
* Creates date value column formatter with the given
* format string.
*/
public DateColumnGenerator(String format) {
this.format = format;
}
/**
* Generates the cell containing the Double value.
* The column is irrelevant in this use case.
*/
public Component generateCell(Table source, Object itemId,
Object columnId) {
// Get the object stored in the cell as a property
Property prop =
source.getItem(itemId).getItemProperty(columnId);
if (prop.getType().equals(Date.class)) {
Label label = new Label(.......);
return label;
}
return null;
}
}