In the following example I have two datasources, one is a client only 'Testdatasource' and one is a mysql datasource. When editing and saving a record in the form, the selection in the grid gets lost with the mysql datasource but not with the local datasource. I would love to see selection kept also for mysql datasources.
Tested on SmartClient Version: SC_SNAPSHOT-2010-12-14/PowerEdition Deployment (built 2010-12-14) with GWT 2.1.0 and firefox 3.6.13
Form and grid code:
Client ds:
Server ds:
Tested on SmartClient Version: SC_SNAPSHOT-2010-12-14/PowerEdition Deployment (built 2010-12-14) with GWT 2.1.0 and firefox 3.6.13
Form and grid code:
Code:
package test.client;
import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.DataSource;
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.form.DynamicForm;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.events.SelectionChangedHandler;
import com.smartgwt.client.widgets.grid.events.SelectionEvent;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
public class SelectionTest implements EntryPoint {
@Override
public void onModuleLoad() {
//First ds: will keep selection
//DataSource dataSource = CustomerLocalDs.getInstance();
//Second ds: will throw away selection
DataSource dataSource = DataSource.get("Customer");
final ListGrid listGrid = new ListGrid();
listGrid.setWidth100();
listGrid.setShowResizeBar(true);
listGrid.setCanEdit(true);
listGrid.setCanPickFields(true);
listGrid.setDataSource(dataSource);
listGrid.fetchData();
final DynamicForm form = new DynamicForm();
form.setDataSource(dataSource);
listGrid.addSelectionChangedHandler(new SelectionChangedHandler() {
@Override
public void onSelectionChanged(SelectionEvent event) {
form.editSelectedData(listGrid);
}
});
IButton save = new IButton("Save");
save.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
form.saveData();
}
});
IButton doNew = new IButton("New");
doNew.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
form.editNewRecord();
}
});
VLayout layout = new VLayout();
layout.addMember(listGrid);
layout.addMember(form);
HLayout hlayout = new HLayout();
hlayout.addMember(save);
hlayout.addMember(doNew);
layout.addMember(hlayout);
layout.setHeight100();
layout.setWidth100();
layout.draw();
}
}
Code:
package test.client;
import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.*;
import com.smartgwt.client.widgets.form.validator.FloatPrecisionValidator;
import com.smartgwt.client.widgets.form.validator.FloatRangeValidator;
public class CustomerLocalDs extends DataSource {
private static CustomerLocalDs instance = null;
public static CustomerLocalDs getInstance() {
if (instance == null) {
instance = new CustomerLocalDs("customerLocalDs");
}
return instance;
}
public CustomerLocalDs(String id) {
setID(id);
DataSourceIntegerField pkField = new DataSourceIntegerField("cstm_pk");
pkField.setHidden(true);
pkField.setPrimaryKey(true);
DataSourceTextField nameField = new DataSourceTextField("cstm_name", "Name", 128, true);
setFields(pkField, nameField);
setClientOnly(true);
setTestData(CustomerData.getRecords());
}
}
Code:
package test.client;
public class CustomerData {
private static CustomerRecord[] records;
public static CustomerRecord[] getRecords() {
if (records == null) {
records = getNewRecords();
}
return records;
}
public static CustomerRecord[] getNewRecords() {
return new CustomerRecord[]{
new CustomerRecord(1, "Glue Pelikan Roll-fix Permanent #950"),
new CustomerRecord(2, "Glue Pelikan Roll-fix Refill Permanent #955"),
new CustomerRecord(3, "Glue Pelikan Roll-fix Non Permanent #960"),
new CustomerRecord(4, "Glue Pelikan Roll-fix Refill Non Permanent #965")
};
}
}
Code:
package test.client;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import java.util.Date;
public class CustomerRecord extends ListGridRecord {
public CustomerRecord() {
}
public CustomerRecord(int cstm_pk, String cstm_name ){
setCstm_pk(cstm_pk);
setCstm_name(cstm_name);
}
/**
* Set the itemID.
*
* @param itemID the itemID
*/
public void setCstm_pk(int cstm_pk) {
setAttribute("cstm_pk", cstm_pk);
}
/**
* Return the itemID.
*
* @return the itemID
*/
public int getCstm_pk() {
return getAttributeAsInt("cstm_pk");
}
/**
* Set the item.
*
* @param item the item
*/
public void setCstm_name(String cstm_name) {
setAttribute("cstm_name", cstm_name);
}
/**
* Return the item.
*
* @return the item
*/
public String getCstm_name() {
return getAttribute("cstm_name");
}
}
Server ds:
Code:
<DataSource serverType="sql" dbName="Mysql" tableName="Customer" ID="Customer" > <fields> <field primaryKey="true" type="sequence" name="cstm_pk" hidden="true"></field> <field type="text" length="45" name="cstm_name" title="" required="true" export="true"></field> </fields> </DataSource>
Comment