列表网格中的数据源实例

发布于 2024-10-12 14:15:46 字数 2165 浏览 1 评论 0原文

我在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别念他 2024-10-19 14:15:46

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

Try to use grid.fetchData() method and bind datasource one more time to use it.

∞觅青森が 2024-10-19 14:15:46

尝试grid.invalidateCache()

Try grid.invalidateCache()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文