ListGrid.hasChanges() detects a change in DateItem fields even if the user
does not actually make any changes in the cell, i.e. the user selects the cell
for editing, but navigates away from the cell without editing. Cells with
String or float values act as expected: hasChanges() is not triggered by
this behavior.
Is this a bug? I guess I need to explicitly check DateItem fields for changes?
I don't have a dataSource, so I think I need to manually check for changes
and then apply the changes myself. I think ListGrid.hasChanges() would
work but I don't want to detect non-existant changes.
does not actually make any changes in the cell, i.e. the user selects the cell
for editing, but navigates away from the cell without editing. Cells with
String or float values act as expected: hasChanges() is not triggered by
this behavior.
Is this a bug? I guess I need to explicitly check DateItem fields for changes?
I don't have a dataSource, so I think I need to manually check for changes
and then apply the changes myself. I think ListGrid.hasChanges() would
work but I don't want to detect non-existant changes.
Code:
<cut> ListGrid listGrid = new ListGrid(); listGrid.setWidth(800); listGrid.setHeight(224); listGrid.setShowAllRecords(true); listGrid.setCanEdit(true); listGrid.setEditByCell( true); listGrid.setEditEvent(ListGridEditEvent.DOUBLECLICK); listGrid.setFields( getFields()); listGrid.setCanResizeFields(true); listGrid.setAutoSaveEdits( false); listGrid.addEditorExitHandler(new EditorExitHandler() { @Override public void onEditorExit(EditorExitEvent event) { if( listGrid.hasChanges()) { Window.alert("has changes"); // let the user cancel or save changes here. } } }); listGrid.setData( getRecords()); // getRecords return ListGridRecords with // startTime attribute being java.util.Date // name attribute is String // distance attribute is float. <cut> public ListGridField[] getFields() { ListGridField[] fields = new ListGridField[3]; fields[0] = new ListGridField("name", "Name"); ListGridField field = new ListGridField("startTime", "Date"); DateItem dateItem = new DateItem(); dateItem.setDateFormatter( DateDisplayFormat.TOJAPANSHORTDATE); field.setEditorType( dateItem); field.setCellFormatter(new CellFormatter() { public String format(Object value, ListGridRecord record, int rowNum, int colNum) { if (value == null) { return null; } if (!(value instanceof Date)){ return value.toString(); } return DateTimeFormat.getFormat("yyyy-MM-dd").format((Date) value); } }); fields[1] = field; fields[2] = new ListGridField("distance", "Distance"); return fields; }
Comment