I am using smart gwt 2.2 on windows system in mozilla browser. I am using List Grid instance in my application. In that list grid instance I am filling data using data source. Method for set data:
// Entry point method
public void init() {
final ListGrid grid = new ListGrid();
DataSource ds= new DataSource();
ds.setClientOnly(true);
setDataSourceField(ds);
ds.setTestData(getGridData());
grid.setFields(getGridFields());
grid.setDataSource(ds);
setGridProperty(grid);
grid.addClickHandler(new ClickHandler(){
@Override
public void onClick(ClickEvent event) {
DataSource ds= new DataSource();
ds.setClientOnly(true);
setDataSourceField(ds);
ds.setTestData(getGridData());
grid.setFields(getGridFields());
grid.setDataSource(ds);
grid.draw();
}
});
myCanvas.addChild(grid);
}
//dummy data
private static ListGridRecord[] getGridData() {
ListGridRecord record = new ListGridRecord();
record.setAttribute("id", "1");
record.setAttribute("name", "11");
record.setAttribute("address", "111");
ListGridRecord record1 = new ListGridRec开发者_Python百科ord();
record1.setAttribute("id", "2");
record1.setAttribute("name", "222");
record1.setAttribute("address", "222");
return new ListGridRecord[] { record, record1 };
}
//grid property
private static void setGridProperty(ListGrid grid) {
grid.setWidth("90%");
grid.setHeight(125);
grid.setAutoFetchData(true);
}
//fields
private static ListGridField[] getGridFields() {
ListGridField field = new ListGridField("id");
ListGridField field1 = new ListGridField("name");
ListGridField field2 = new ListGridField("address");
return new ListGridField[] { field, field1 ,field2};
}
//data source field
protected static void setDataSourceField(DataSource dataSource) {
DataSourceField idField = new DataSourceField("id", FieldType.TEXT);
idField.setPrimaryKey(true);
DataSourceField nameField = new DataSourceField("name",
FieldType.TEXT);
DataSourceField addField = new DataSourceField("address", FieldType.TEXT);
dataSource.setFields(nameField, idField, addField);
}
On click of the row of the grid I want to add a new data source instance to the grid, but it is not showing any data. Please Help
Try to use grid.fetchData()
method and bind datasource one more time to use it.
Try grid.invalidateCache()
精彩评论