PDA

View Full Version : TimeField in EditorGrid



MarcinP
26 Oct 2008, 6:54 AM
Hi,
I'm trying to add TimeField to EditorGrid. Is it possible? because it doesn't work in my case.
My code:

ColumnConfig to = new ColumnConfig() {
{
setId("to");
setHeader("Do godziny");
setWidth(65);
setSortable(false);
setDataIndex("to");
setDateTimeFormat(DateTimeFormat.getShortTimeFormat());
setEditor(new CellEditor(new TimeField() {
{
setFormat(DateTimeFormat.getShortTimeFormat());
setIncrement(15);
}
}));
}
};
When I try to choose time I get an exception:
[ERROR] Uncaught exception escaped
java.lang.ClassCastException: java.util.Date cannot be cast to com.extjs.gxt.ui.client.data.ModelData
at com.extjs.gxt.ui.client.widget.form.ComboBox.setValue(ComboBox.java:1)

Thanks for help.

Regards,
Marcin

gslender
26 Oct 2008, 12:59 PM
you need to adjust the pre/post values to ensure its passing the right data...

eg...



CellEditor freqEditor = new CellEditor(freqCombo) {
public Object preProcessValue(Object value) {
for (FreqType ft : FreqType.values()) {
if (ft.toString().equalsIgnoreCase(value.toString())) {
return freqCombo.findModel(ft);
}
}
return FreqType.DAILY;
}

public Object postProcessValue(Object value) {
return ((ModelData) value).get("value");
}
};
freq.setEditor(freqEditor);

MarcinP
28 Jan 2009, 8:40 AM
Hi,
it works ...

public List<ColumnConfig> getColumnConfig() {
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

final TimeField timeFromTo = new TimeField() {
{
setFormat(DateTimeFormat.getShortTimeFormat());
setIncrement(15);
}
};

final CellEditor timeCellEditor = new CellEditor(timeFromTo) {

public Object preProcessValue(Object value) {
if (value == null) {
return value;
}
Date d = (Date)value;
return timeFromTo.findModel(d);
}

@Override
public Object postProcessValue(Object value) {
DateTimeFormat df = DateTimeFormat.getShortTimeFormat();
if (value == null) {
return df.parse("00:00");
}
ModelData bmd = ((ModelData) value);
String time = bmd.get("text");
return df.parse(time);
}

};