mardi 27 mars 2012

ListGrid Cell click handler and column number (numéro de colonne d'un champ)

Très simple, mais il y a tellement de propriétés et de méthodes que quelquefois je suis tenté d'écrire du code pas très propre pour éviter de chercher.
J'ai un ListGrid avec un champ de type icone, lorsque je click sur un champ si il s'agit de cette icone j'effectue une action.
ListGridField oeilField = new ListGridField("oeil");
        oeilField.setWidth(40);
        oeilField.setTitle("Voir");
        oeilField.setType(ListGridFieldType.ICON);
        oeilField.setCellIcon("16/oeil.png");
Jusqu'à présent je comparait le numéro de la colonne de la source de l'événement avec celui de l’icône:
 if(event.getColNum()== 3)
Aujourdh'ui j'ai rajouté un champ donc j'ai cherché un peu plus et il suffit de faire:

demandesGrid.addCellClickHandler(new CellClickHandler() {
 @Override
 public void onCellClick(CellClickEvent event) {
   if(event.getColNum()== demandesGrid.getFieldNum("oeil")){
       traiteDemandeClick();
     }

   }
});

Really easy, but there are so many properties and methods that I'm often tempted to write dirty code.
I got a listgrid with an icon ListGridField. When I click on this icon I want to take some action.
Since the beginning I compare the event source column number to the hard coded index of the field, but as today I added some fields  I went a little bit further in the javadoc and found that I just need to use the getFieldNum method which use the ListGridField name to give the index of the column.....