2
我想創建一個CellTable。但是celltable的列應該基於服務器的響應。我以List的形式獲得服務器響應。如何根據服務器的響應創建CellTable
No of Columns = Size of the list.
CellTable列標題應該是來自服務器的值。 例如。服務器響應:
List<Contacts> contacts
標頭應爲
contacts.getName()
。
我想創建一個CellTable。但是celltable的列應該基於服務器的響應。我以List的形式獲得服務器響應。如何根據服務器的響應創建CellTable
No of Columns = Size of the list.
CellTable列標題應該是來自服務器的值。 例如。服務器響應:List<Contacts> contacts
標頭應爲contacts.getName()
。
我通過以下代碼實現了它。
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
使用CellList
與AsyncDataProvider:
//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);
感謝安德烈。但是我必須使用CellTable而不是CellList。 CellTable是我們客戶的要求。 – Prince
無論如何使用'AsyncDataProvider'。這裏是適用的[示例](http://www.mytechtip.com/2010/11/gwt-celltable-example-using_8168.html)。 – kapand