问题
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.
I tried ...
setSortContainerPropertyId(NoteContainer.DATE_CREATED);
setSortAscending(false);
sort();
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();
}
Note Container class
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);
}
}
Note : CaseNote is an Entity Class.
回答1:
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.. :)
来源:https://stackoverflow.com/questions/16064806/vaadin-table-must-sort-entries-in-chronological-order-descending-i-e-latest-at