问题描述
我遇到了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
pre>
A2 A2 A2
A3 A3 A3
实际输出应该只是一行,如
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 fromString
toList<String>
in yourGrid
,Column
and data provider; and of course you have to callupdateRowData
with aList<List<String>>
, not aList<String>
.You also need one
Column
instance per column, taking the value out of theList<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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!