Reputation: 3
Straight to the problem.
I have a 6-columns grid, one of those 6 fields being a date.
While editing is enabled DateCell is not editable, as intended, but it changes its display format from "dd/mm/yyyy"
, as stated in ColumnConfig
, to a non-specified anywhere full date format.
How to resolve this?
Obviously I can't treat dates as strings, as I thought at first, because I'm going to lose all the possible filtering on date.
Upvotes: 0
Views: 1543
Reputation: 621
Did you try something like that?
DateTimeFormat dtf = DateTimeFormat.getFormat("yyyyMMddHHmmss");
DateField df = new DateField();
df.setPropertyEditor(new DateTimePropertyEditor(dtf));
Cell c = new DateCell(DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss"));
grid.getColumnModel().getColumn(0).setCell(c);
editing.addEditor(df);
Hope it will help. It worked for me.
EDIT: Set column date format without making cell editable.
You should try that:
ColumnConfig<Plant, Date> date = editableGrid.getColumnModel().getColumn(3);
rowEditing.addRenderer(date, new AbstractSafeHtmlRenderer<Date>() {
@Override
public SafeHtml render(Date object) {
SafeHtmlBuilder builder = new SafeHtmlBuilder();
DateTimeFormat df = DateTimeFormat.getFormat("MM-dd-yyyy");
builder.appendHtmlConstant("<div qtip='" + Format.htmlEncode(object.toString()) + "'>" + df.format(object)
+ "</div>");
return builder.toSafeHtml();
}
});
Upvotes: 1