动态创建 GWT CellTable [英] Create GWT CellTable Dynamically

查看:23
本文介绍了动态创建 GWT CellTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了 GWT CellTable 的问题.我需要动态创建单元表,但我没有实体(Bean)类来这样做.celltable的例子我都看过了,搜索了很多,没有实体类.

I am stuck in a problem with GWT CellTable. I need to create celltable dynamically and I dont have entity (Bean) class to do so. I have seen all the examples of celltable and searched a lot to do so without entity class.

我需要根据存储在数据库中的一些元数据动态填充表.我能够创建表结构

I need to populate table dynamically according to some metadata stored in database. I am able create table structure

考虑有两个类,一个是 GRID,另一个是元数据和列定义的 COLUMN.GRID 会将 COLUMNS 列表作为列定义

Consider there are two classes one is GRID and another is COLUMN for the metadata and columns definition. GRID will have list of COLUMNS as a columns definition

    Class GRID {
List<COLUMN> columns;
}

Class COLUMN {
  String columnName;
}

现在我需要从数据库中获取网格并循环列以填充单元格(列),例如:

Now i need to get grid from database and loop the columns to populate the cells (Columns) like :

com.google.gwt.user.cellview.client.Column<String, String> textColumn = new Column<String, String>(
                        new EditTextCell()) {
                    @Override
                    public String getValue(String object) {
                        return object;
                    }
                };

现在,我需要向单元格表中添加一些数据.但没有实体,就没有如何填充不同列的示例.我试过自己喜欢:(考虑网格有 3 列)

Now, I need to add some data to the celltable. but without entity there are no example how to populate the different columns. I have tried my self like : (Consider Grid have 3 columns)

List<String> data;

String a1 = "A1";
            String a2 = "A2";
            String a3 = "A3";

            data = new ArrayList<String>();
            data.add(a1);
            data.add(a2);
            data.add(a3);

final AsyncDataProvider<String> provider = new AsyncDataProvider<String>() {
            @Override
            protected void onRangeChanged(HasData<String> display) {
                updateRowData(0, data);
            }
          };
          provider.addDataDisplay(grid);
provider.updateRowCount(data.size(), true);

我能够产生如下输出:

A1 A1 A1

A2 A2 A2

A3 A3 A3

实际上输出应该只有一行就像

Actually output should be one row only like

A1 A2 A3

但未能如愿.

请帮忙.

谢谢,

问候,

推荐答案

您可以将您的行"表示为 List 实例,您必须从 String<更改您的参数化/code> 到 List 在你的 GridColumn 和数据提供者中;当然,您必须使用 List> 而不是 List 来调用 updateRowData.

You can represent your "rows" as List<String> instances, you have to change your parameterization from String to List<String> in your Grid, Column and data provider; and of course you have to call updateRowData with a List<List<String>>, not a List<String>.

您还需要每列一个 Column 实例,通过索引从 List 中取出值:

You also need one Column instance per column, taking the value out of the List<String> by index:

class IndexedColumn extends Column<List<String>, String>
   private final int index;
   public IndexedColumn(int index) {
     super(new EditTextCell();
     this.index = index;
   }

   @Override
   public String getValue(List<String> object) {
      return object.get(this.index);
   }
}

这篇关于动态创建 GWT CellTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆