2014-01-13 58 views
1

我有一个CellTables的列表。我怎样才能合并这两个表的行并返回结果。 例如如何合并GWT中的两个单元格表的内容

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

我使用以下方法

private CellTable fetchAllCellTables() { 
      CellTable table=new CellTable(); 
      for(CellTable tempTable:cellTables){ 
        int numRows = tempTable.getRowCount(); 
        table.setRowCount(numRows+1); 
        table.setRowData((List) tempTable.getLayoutData()); 
      } 
      return table; 

    } 

,但我无法看到的总含量。

回答

1

什么,我认为这里将是最好的办法是用每个CellTable S以及最终CellTableDataProvider

示例代码:

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

对于您的情况为您正在使用一个ListCellTable,你将不得不同样保持各自的 s

2

我假设您要制作一张显示您的小桌子行的大桌子:

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

此解决方案仅适用,如果你可以编辑源代码构建小桌子!

我首先定义一个行对象类,它包含大表中单个行的全部信息,例如,

public class RowObject{ 

    public String[] table1RowObject; // the class of the field should be the generic 
            // type of the table1 CellTable 

    public MyObject table2RowObject; // the class of the field should 
            // be the generic type of table2 

    // ... other tables 

} 

现在改变泛型类型的小表来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<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); 

,然后只要你更新dataSource所有的小表,可能得到在同一时间为大表进行更新。

相关问题