SmartGWT 3.1 LGPL
Hi guys,
I have a problem with a ListGrid backed by a ClientOnly datasource.
Below you can find the simplest code that you need to reproduce the problem (sorry, my company forbids uploading files).
Scenario #1:
1. Open the page.
2. Click on the "Add" button.
3. Enter some value.
4. Click on the "Save" button (while focus is still in the listgrid cell with the entered data).
In the handler we inspect the datasource data and see no records.
If you can see in the commented code, I did try to use saveAllEdits method, but in this case we get a duplicate in the datasource (you can try it by uncommenting several lines for Test#2 in the code).
How can I get the correct records? I expect only one saved record that I entered.
Hi guys,
I have a problem with a ListGrid backed by a ClientOnly datasource.
Below you can find the simplest code that you need to reproduce the problem (sorry, my company forbids uploading files).
Scenario #1:
1. Open the page.
2. Click on the "Add" button.
3. Enter some value.
4. Click on the "Save" button (while focus is still in the listgrid cell with the entered data).
In the handler we inspect the datasource data and see no records.
If you can see in the commented code, I did try to use saveAllEdits method, but in this case we get a duplicate in the datasource (you can try it by uncommenting several lines for Test#2 in the code).
How can I get the correct records? I expect only one saved record that I entered.
Code:
import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.Window; import com.smartgwt.client.core.Function; import com.smartgwt.client.data.*; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.layout.VLayout; import static com.smartgwt.client.types.FieldType.SEQUENCE; import static com.smartgwt.client.types.FieldType.TEXT; public class TestGridEntryPoint implements EntryPoint { @Override public void onModuleLoad() { VLayout vLayout = new VLayout(); final ListGrid listGrid = new ListGrid(); listGrid.setWidth(100); listGrid.setHeight(100); listGrid.setAutoSaveEdits(true); listGrid.setDataSource(new TestDataSource()); vLayout.addMember(listGrid); IButton addRecordButton = new IButton("Add"); addRecordButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { listGrid.startEditingNew(); } }); vLayout.addMember(addRecordButton); IButton saveButton = new IButton("Save"); saveButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { // Test #1: we get 0 records // Record[] records = listGrid.getDataSource().getCacheData(); Window.alert(String.valueOf(records.length)); // Test #2: we get 2 records (duplicate) // listGrid.saveAllEdits(new Function() { // @Override // public void execute() { // Record[] records = listGrid.getDataSource().getCacheData(); // Window.alert(String.valueOf(records.length)); // } // }); } }); vLayout.addMember(saveButton); vLayout.draw(); } public static class TestDataSource extends DataSource { public TestDataSource() { DataSourceField idField = new DataSourceField("id", SEQUENCE); idField.setPrimaryKey(true); idField.setHidden(true); DataSourceField nameField = new DataSourceField("name", TEXT); setFields(idField, nameField); setClientOnly(true); } @Override protected DSResponse getClientOnlyResponse(DSRequest request, Record[] serverData) { return super.getClientOnlyResponse(request, serverData); //To change body of overridden methods use File | Settings | File Templates. } } }
Comment