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

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

问题描述

我遇到了GWT CellTable的问题。我需要动态创建celltable,我没有实体(Bean)类来实现。我已经看到所有的celltable的例子,搜索了很多,没有实体类。



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



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

 类GRID {
列表< COLUMN>列;
}

类COLUMN {
String columnName;
}

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

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

现在,我需要向celltable添加一些数据。但没有实体,没有例子如何填充不同的列。我已经尝试过我的自我:(考虑网格有3列)

 列表< String>数据; 

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
pre>

实际输出应该只是一行,如

  A1 A2 A3 

但是没有这样做。



请帮助。



感谢,



请问,

解决方案

您可以将行表示为列表< String> 实例,您必须将您的参数化从 String 更改为列表< String> >网格,和数据提供者;当然,您必须使用列表< String< String> 调用 updateRowData ,而不是列表< String>



您还需要一个列,通过索引将值从列表< String> 中取值:

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


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

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

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

I am able to produce the output like :

A1 A1 A1

A2 A2 A2

A3 A3 A3

Actually output should be one row only like

A1 A2 A3

But failed to do so.

Please help.

Thankx,

Regards,

解决方案

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>.

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天全站免登陆