列表网格中的数据源实例
我在Windows系统上的mozilla浏览器中使用smart gwt 2.2。 我在我的应用程序中使用列表网格实例。 在该列表网格实例中,我使用数据源填充数据。 设置数据的方法:
// 入口点方法
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 ListGridRecord();
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);
}
单击网格的行时,我想向网格添加一个新的数据源实例,但它没有显示任何数据。 请帮忙
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 ListGridRecord();
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
grid.fetchData()
方法并再次绑定数据源来使用它。Try to use
grid.fetchData()
method and bind datasource one more time to use it.尝试grid.invalidateCache()
Try grid.invalidateCache()