2010-07-16 7 views

Répondre

3

Il n'existe pas encore de mode de tri pris en charge sur le CellTable. Cependant, il existe une solution de contournement manuelle impliquant beaucoup de corvée de code. Reportez-vous aux classes SortableHeader et SortableColumn dans l'abri à vélo sous l'échantillon des dépenses. Vous trouverez l'utilisation dans com.google.gwt.sample.expenses.gwt.client.ExpenseDetails. Vous pouvez l'utiliser jusqu'à ce que quelque chose de concret apparaisse dans la prochaine version.

départ répertoire: http://google-web-toolkit.googlecode.com/svn/trunk/bikeshed

+2

On dirait que le lien ne soit plus valide. Essayez celui-ci http://code.google.com/p/google-web-toolkit/source/browse/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ – stuff22

+0

@ stuff22 réponse éditée. –

0

Avec la version finale de GWT 2.1, a t-il eu un soutien pour les colonnes triables ajouté au CellTable? Ou est-ce encore un rouleau de votre propre solution après avoir regardé l'exemple bikeshed?

8

Solution pour les événements de clic:

Header<String> columnHeader = new Header<String>(new ClickableTextCell()) { 
    @Override 
    public String getValue() { 
     return columnName; 
    } 
}; 

columnHeader.setUpdater(new ValueUpdater<String>() { 
    @Override 
    public void update(String value) { 
     Window.alert("Header clicked!"); 
    } 
}); 

table.addColumn(column, columnHeader); 
0
CellTable<Contact> table = new CellTable<Contact>(); 

    // Create name column. 
    final TextColumn<Contact> nameColumn = new TextColumn<Contact>() { 
     @Override 
     public String getValue(Contact contact) { 
     return contact.name; 
     } 
    }; 
    // Create a data provider. 
    ListDataProvider<Contact> dataProvider = new ListDataProvider<Contact>(); 

    // Connect the table to the data provider. 
    dataProvider.addDataDisplay(table); 
    final List<Contact> list = dataProvider.getList(); 
    for (Contact contact : CONTACTS) { 
     list.add(contact); 
    } 
    final ListHandler<Contact> columnSortHandler = new ListHandler<Contact>(
      list); 
    Header<String> columnHeader = new Header<String>(new ClickableTextCell()) { 
     @Override 
     public String getValue() { 
      return "Name"; 
     } 
    }; 

    columnHeader.setUpdater(new ValueUpdater<String>() { 
     @Override 
     public void update(String value) { 
      if (Window.confirm("Want to do?")){ 
       nameColumn.setSortable(true); 
       columnSortHandler.setComparator(nameColumn, 
         new Comparator<Contact>() { 
          public int compare(Contact o1, Contact o2) { 
          if (o1 == o2) { 
           return 0; 
          } 

          // Compare the name columns. 
          if (o1 != null) { 
           return (o2 != null) ? o1.name.compareTo(o2.name) : 1; 
          } 
          return -1; 
          } 
         }); 
      } else nameColumn.setSortable(false); 
     } 
    }); 
    // Make the name column sortable. 
    nameColumn.setSortable(false); 

    // Create address column. 
    TextColumn<Contact> addressColumn = new TextColumn<Contact>() { 
     @Override 
     public String getValue(Contact contact) { 
     return contact.address; 
     } 
    }; 

    // Add the columns. 
    table.addColumn(nameColumn, columnHeader); 
    table.addColumn(addressColumn, "Address"); 




    // Add the data to the data provider, which automatically pushes it to the 
    // widget. 


    // Add a ColumnSortEvent.ListHandler to connect sorting to the 
    // java.util.List. 
    //------------------ Code to add --------------------------------// 
    VerticalPanel vp = new VerticalPanel(); 




    table.addColumnSortHandler(columnSortHandler); 
    //------------------ Code end --------------------------------// 
    // We know that the data is sorted alphabetically by default. 
    table.getColumnSortList().push(nameColumn); 

    // Add it to the root panel. 
    vp.add(table); 
    RootPanel.get().add(vp); 
Questions connexes