如何在GWT中合并两个单元格表的内容

如何在GWT中合并两个单元格表的内容,gwt,Gwt,我有一张牢房表的清单。如何合并这两个表的行并返回结果。 比如说 List<CellTable> cellTables = new ArrayList<CellTable>(); celltables.add(table1); celltables.add(table2); celltables.add(table3); 但我无法看到全部内容 我认为这里最好的方法是为每个单元格表以及最终的单元格表使用数据提供程序 示例代码: // Create a CellList. C

我有一张牢房表的清单。如何合并这两个表的行并返回结果。 比如说

List<CellTable> cellTables = new ArrayList<CellTable>();
celltables.add(table1);
celltables.add(table2);
celltables.add(table3);

但我无法看到全部内容

我认为这里最好的方法是为每个
单元格表以及最终的
单元格表使用
数据提供程序

示例代码:

// Create a CellList.
CellList<String> cellList = new CellList<String>(new TextCell());

// Create a data provider.
MyDataProvider dataProvider = new MyDataProvider();

// Add the cellList to the dataProvider.
dataProvider.addDataDisplay(cellList);

// Get the underlying list from data dataProvider.
List<String> list = dataProvider.getList();

// Add the value to the list. The dataProvider will update the cellList.
list.add(newValue); // you can do this in a loop so that you merge all values
//创建一个单元格列表。
CellList CellList=新的CellList(new TextCell());
//创建一个数据提供者。
MyDataProvider dataProvider=新的MyDataProvider();
//将单元格列表添加到数据提供程序。
dataProvider.addDataDisplay(单元格列表);
//从数据提供程序获取基础列表。
List List=dataProvider.getList();
//将该值添加到列表中。数据提供程序将更新单元列表。
列表。添加(newValue);//可以在循环中执行此操作,以便合并所有值

对于使用
CellTable
列表
的场景,您同样需要保留相应
数据提供程序的
列表
,我假设您想要制作一个大表来显示小表的行:

table1                       table2
col1 | col2 | col3           col1 | col2 | col3 | col4
------------------           -------------------------
a    | b    | c              1    | 2    | 3    | 4

big table
col1 | col2 | col3 | col1 | col2 | col3 | col4
----------------------------------------------
a    | b    | c    | 1    | 2    | 3    | 4
用例如

CellTable<String[]> table1 = new CellTable<String[]>();
table1.addColumn( new Column<String[], String>(new TextCell()){

    public String getValue(String[] object){
        return object[0];
    }

}, "col1"); 
现在将小表的泛型类型更改为
RowObject

CellTable<RowObject> table1 = new CellTable<RowObject>();
table1.addColumn ( new Column<RowObject, String>(new TextCell()){

    public String getValue(RowObject object){
        // The data of table1 has been moved into the table1RowObject
        // old: String[] object; return object[0];
        return object.table1RowObject[0];
    }

}, "col1" );
CellTable table 1=新的CellTable();
表1.addColumn(新列(新TextCell()){
公共字符串getValue(RowObject对象){
//table1的数据已移动到table1RowObject中
//旧:字符串[]对象;返回对象[0];
返回对象。table1RowObject[0];
}
},“col1”);
然后,大桌子可以很容易地构造成这样:

CellTable<RowObject> bigTable = new CellTable<RowObject>();
for (CellTable<RowObject> ct : tablesList){
    for (int i = 0; i < ct.getColumnCount(); i++)
        bigTable.addColumn( ct.getColumn(i) );
}
CellTable bigTable=newcelltable();
for(单元表ct:tablesList){
对于(int i=0;i
在数据提供程序的帮助下,同时加载所有表的数据,例如

ListDataProvider<RowObject> dataSource = new ListDataProvider<RowObject>();
dataSource.addDataDisplay( table1 );
dataSource.addDataDisplay( table2 );
dataSource.addDataDisplay( bigTable );
ListDataProvider数据源=新建ListDataProvider();
dataSource.addDataDisplay(表1);
dataSource.addDataDisplay(表2);
addDataDisplay(bigTable);
然后,只要更新
数据源
,所有小表都会与大表同时更新

CellTable<RowObject> bigTable = new CellTable<RowObject>();
for (CellTable<RowObject> ct : tablesList){
    for (int i = 0; i < ct.getColumnCount(); i++)
        bigTable.addColumn( ct.getColumn(i) );
}
ListDataProvider<RowObject> dataSource = new ListDataProvider<RowObject>();
dataSource.addDataDisplay( table1 );
dataSource.addDataDisplay( table2 );
dataSource.addDataDisplay( bigTable );