Dear Isomorphic
Since I've updated from SmartGWT 2.4 to 2.5 the attached (sample) code does not work anymore.
In particular, the callback does not fire after saveAllEdits() if more than one row has been edited and the grid has fetched with criteria. Fetching without criteria (no restriction) works fine.
Is this a bug or do I have to change my code?
Since I've updated from SmartGWT 2.4 to 2.5 the attached (sample) code does not work anymore.
In particular, the callback does not fire after saveAllEdits() if more than one row has been edited and the grid has fetched with criteria. Fetching without criteria (no restriction) works fine.
Is this a bug or do I have to change my code?
Code:
public class Test extends VStack { int edits = 1; ListGrid grid = new ListGrid(); Label label1 = new Label("N/A"); Label label2 = new Label("N/A"); Label label3 = new Label("N/A"); { //create a local data source with test data and attach it to the grid DataSource localDs = new DataSource(); localDs.setClientOnly(true); localDs.setFields(getFields()); localDs.setTestData(getTestData()); grid.setDataSource(localDs); grid.setAutoSaveEdits(false); //define the form items final TextItem editItem = new TextItem("numberOfEdits", "<nobr>Number of edits</nobr>"); editItem.setValue(edits); ButtonItem edit = new ButtonItem("edit", "Edit"); edit.addClickHandler(new com.smartgwt.client.widgets.form.fields.events.ClickHandler() { @Override public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) { edits = Integer.parseInt(editItem.getValueAsString()); for (int i = 0; i < edits; i++) { Map<String, Object> values = new HashMap<String, Object>(); values.put("col2", "Z"); grid.setEditValues(i, values); } label1.setContents(DateUtil.formatAsShortDatetime(new Date()) + "-->hasChanges: " + grid.hasChanges()); label3.setContents(DateUtil.formatAsShortDatetime(new Date()) + "-->saveAllEdits callback not fired"); boolean saveSuccess = grid.saveAllEdits(new Function() { @Override public void execute() { label3.setContents(DateUtil.formatAsShortDatetime(new Date()) + "-->saveAllEdits callback fired"); } }); label2.setContents(DateUtil.formatAsShortDatetime(new Date()) + "-->saveAllEdits: " + saveSuccess); } }); edit.setStartRow(false); //create form and set the text and button DynamicForm form = new DynamicForm(); form.setAutoWidth(); form.setNumCols(3); form.setItems(editItem, edit); //set the layout this.addMember(form); this.addMember(grid); this.addMember(label1); this.addMember(label2); this.addMember(label3); //that works! //grid.fetchData(); //that doesn't work! grid.fetchData(new Criteria("col2", "S")); } private DataSourceField[] getFields() { DataSourceField[] dsFields = new DataSourceField[3]; DataSourceField dsField1 = new DataSourceField("pk", FieldType.INTEGER, "pKey"); dsField1.setPrimaryKey(true); dsFields[0] = dsField1; DataSourceField dsField2 = new DataSourceField("col1", FieldType.TEXT, "COL1"); dsFields[1] = dsField2; DataSourceField dsField3 = new DataSourceField("col2", FieldType.TEXT, "COL2"); dsFields[2] = dsField3; return dsFields; } private Record[] getTestData() { Record[] records = new Record[6]; for (int i = 0; i < 5; i++) { ListGridRecord record = new ListGridRecord(); record.setAttribute("pk" , i); record.setAttribute("col1" , "A"); record.setAttribute("col2" , "S"); records[i] = record; } return records; } }
Comment