2
  1. I want to create a CellTable. But Columns of the celltable should be based on the response from the server. I'm getting the server response as List.

    No of Columns = Size of the list. 
    
  2. CellTable column header should be the value from the server. For ex. Server response: List<Contacts> contacts

    Header should be contacts.getName().

Cœur
  • 37,241
  • 25
  • 195
  • 267
Gnik
  • 7,120
  • 20
  • 79
  • 129

2 Answers2

1

I achieved it by the following code.

          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());
            }

Regards, Gnik

Gnik
  • 7,120
  • 20
  • 79
  • 129
0

Use CellList with an 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);

Here's full example and docs.

kapandron
  • 3,546
  • 2
  • 25
  • 38
  • Thanks Andrey. But I must use CellTable not CellList. CellTable is our client's requirement. – Gnik May 14 '12 at 12:58
  • Anyway use the `AsyncDataProvider`. Here's applicable [example](http://www.mytechtip.com/2010/11/gwt-celltable-example-using_8168.html). – kapandron May 14 '12 at 13:05