vaadin表必须按时间顺序对条目进行排序,即最新的顶部,然后是最早的音符 [英] vaadin table must sort entries in chronological order descending i.e. latest at the top then down to the earliest notes
问题描述
我有一个显示Notes的vaadin表,其中包含创建的日期时间。我希望按时间顺序降序排序(即最新的顶部然后降到最早的音符)。当我添加一个新值时,它应该在顶部。这是一个使用Vaadin的Java EE Web应用程序。
I have a vaadin table which is displaying Notes, with created date time. I want to sort entries in chronological order descending (i.e. latest at the top then down to the earliest notes) by default. When I added a new value it should be in top. This is a Java EE web application which is using Vaadin.
我试过......
setSortContainerPropertyId(NoteContainer.DATE_CREATED);
setSortAscending(false);
sort();
。但它只将排序功能添加到DATE_CREATED列。当我单击该列标题时,它才开始排序。请给我一个合适的解决方案......?
inside my NoteTable constructor. But it only added the sorting functionality to DATE_CREATED column. when I clicked the that column header only it starts to sort. Please give me a proper solution...?
注意表类构造函数..
Note Table class constructor..
public NoteTable()
{
dataSource = new NoteContainer();
setContainerDataSource(dataSource);
NoteTableColumnGenerator columnGenerator = new NoteTableColumnGenerator();
addGeneratedColumn(ACTION, columnGenerator);
addGeneratedColumn(CREATED_BY, columnGenerator);
addGeneratedColumn(TEXT, columnGenerator);
setVisibleColumns(NoteContainer.NATURAL_COL_ORDER);
setSizeFull();
Object[] columns = getVisibleColumns();
for (int i = 0; i < columns.length; i++)
{
if (((String) columns[i]).equals(NoteContainer.DATE_CREATED))
setColumnWidth(columns[i], 150);
else if (((String) columns[i]).equals(NoteContainer.CREATED_BY))
setColumnWidth(columns[i], 150);
else if (((String) columns[i]).equals(NoteContainer.ACTION))
setColumnWidth(columns[i], 150);
else
setColumnWidth(columns[i], 550);
}
setColumnHeaders(NoteContainer.COL_HEADERS_ENGLISH);
setSelectable(true);
setImmediate(true);
setSortContainerPropertyId(NoteContainer.DATE_CREATED);
setSortAscending(false);
sort();
}
注意容器类
public class NoteContainer extends BeanItemContainer<CaseNote> implements Serializable
{
private static final long serialVersionUID = -5926608449530066014L;
public static final String DATE_CREATED = "dateCreated";
public static final String CREATED_BY = "createdBy";
public static final String TEXT = "text";
public static final String ACTION = "Action";
public static final Object[] NATURAL_COL_ORDER = new Object[] {
ACTION, DATE_CREATED, CREATED_BY, TEXT
};
public static final String[] COL_HEADERS_ENGLISH = new String[] {
"ACTION", "Date Created/Updated", "Created/Updated By", "Note"
};
/**
* Default Constructor.
*
*/
public NoteContainer()
{
super(CaseNote.class);
}
}
注意:CaseNote是一个实体类。
Note : CaseNote is an Entity Class.
推荐答案
我自己解决了..
我添加了 sort();
在表格内 refresh()
方法而不是NoteTable构造函数。
I resolved it by my self..
I added sort();
inside the table refresh()
method instead of NoteTable constructor.
现在工作正常。谢谢大家,他们试图帮助我.. :)
Now it is working fine. thank you everyone, who tried to help me.. :)
这篇关于vaadin表必须按时间顺序对条目进行排序,即最新的顶部,然后是最早的音符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!