列表网格中的数据源实例

时间:2011-01-19 08:03:01

标签: gwt smartgwt

我在mozilla浏览器的Windows系统上使用智能gwt 2.2。 我在我的应用程序中使用List Grid实例。 在该列表网格实例中,我使用数据源填充数据。 设置数据的方法:

//入口点方法

  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);
  }

//虚拟数据

 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);
  }

单击网格行时,我想向网格添加一个新的数据源实例,但它没有显示任何数据。 请帮忙

2 个答案:

答案 0 :(得分:1)

尝试使用grid.fetchData()方法并再次绑定数据源以使用它。

答案 1 :(得分:0)

尝试 grid.invalidateCache()