If you double click inside the `ListGrid`, you should see **3** rows instead of **2**. What is happening is the `DataSource` is refreshing the `CacheData` but the `ListGrid` isn't showing the added row.
What am I missing?
What am I missing?
Code:
public void onModuleLoad() {
DataSourceTextField continentField = new DataSourceTextField("continent");
continentField.setPrimaryKey(true);
DataSource dataSource = new DataSource();
dataSource.setClientOnly(true);
dataSource.setFields(continentField);
dataSource.setCacheData(CountryData.getNewRecords());
final ListGrid myGrid = new ListGrid();
myGrid.setWidth(200);
myGrid.setHeight(100);
myGrid.setDataSource(dataSource);
myGrid.fetchData();
myGrid.draw();
myGrid.addDoubleClickHandler(new DoubleClickHandler() {
@Override
public void onDoubleClick(DoubleClickEvent event) {
List<Record> records = new ArrayList<Record>(Arrays.asList(myGrid.getDataSource().getCacheData()));
records.add(new CountryRecord("Japan"));
myGrid.getDataSource().setCacheData(records.toArray(new Record[0]));
myGrid.fetchData();
SC.say("Number of records: " + myGrid.getDataSource().getCacheData().length);
}
});
}
static class CountryData {
public static CountryRecord[] getNewRecords() {
return new CountryRecord[] {
new CountryRecord("North America"),
new CountryRecord("Asia") };
}
}
static class CountryRecord extends ListGridRecord {
public CountryRecord(String continent) {
setContinent(continent);
}
public void setContinent(String continent) {
setAttribute("continent", continent);
}
public String getContinent() {
return getAttributeAsString("continent");
}
}
Comment