2012-05-14 14 views
2
  1. 我想創建一個CellTable。但是celltable的列應該基於服務器的響應。我以List的形式獲得服務器響應。如何根據服務器的響應創建CellTable

    No of Columns = Size of the list. 
    
  2. CellTable列標題應該是來自服務器的值。 例如。服務器響應:List<Contacts> contacts

    標頭應爲contacts.getName()

回答

1

我通過以下代碼實現了它。

  for (Contacts contact : contacts) { 
       final String city = contact.getCity(); 
       final TextColumn<String> addressColumn = new TextColumn<String>() { 

       @Override 
       public String getValue(Contacts object) { 
        return city; 
       } 
      }; 

      cellTable.addColumn(addressColumn, contact.getAddress()); 
      } 

問候, Gnik

0

使用CellListAsyncDataProvider

//Create a cellList 
@UiField 
CellList<Contact> cellList; 

//Creating dataProvider and completion of the cellList 
@UiFactory 
CellList<Contact> makeCellList() { 
private AsyncDataProvider<Contact> provider = new AsyncDataProvider<Contact>() { 
    @Override 
    public void onRangeChanged(final HasData<Contact> display) { 
     rpcService.getContact(new AsyncCallback<List<Contact>>() { 
       @Override 
       public void onSuccess(List<Contact> result) { 
        display.setRowData(0, result); 
       } 
       @Override 
       public void onFailure(Exception ex) { 
        //TODO 
       } 
     }); 
    } 
}; 

//Adding the cellList to the provider in a constructor 
provider.addDataDisplay(cellList); 

這裏是全exampledocs

+0

感謝安德烈。但是我必須使用CellTable而不是CellList。 CellTable是我們客戶的要求。 – Prince

+0

無論如何使用'AsyncDataProvider'。這裏是適用的[示例](http://www.mytechtip.com/2010/11/gwt-celltable-example-using_8168.html)。 – kapand

相關問題