Frage

I've been working on this problem for quite a while but have not been able to solve it. I have a listgrid with a field type icon. I would like to change the cursor to "hand" over the icon.

I've been searching the web and saw that a couple of solutions existed. One of them is using addCellOverHandler for the list grid. But I don't understand how you can change the cursor for the specified field of the listgrid.

this.addCellOverHandler(new CellOverHandler() {

    @Override
    public void onCellOver(CellOverEvent event) {
    // not able to get the field and setCursor()        
    }
});

My field in the listgrid is defined as:

ListGridField iconField = new ListGridField("icon");
iconField.setAlign(Alignment.CENTER);
iconField.setType(ListGridFieldType.ICON);
iconField.setIcon("icons/icon.gif");

Like someone pointed out on the forum, a setCursor() method exist for the listgrid, but not for the field only...

If anybody has a clue... Thanks

War es hilfreich?

Lösung

After some more (a lot more...) googling, I found this:

http://forums.smartclient.com/showthread.php?t=15748

The thing is to Override the getCellStyle method in the listgrid. Here is the code I use:

@Override
protected String getCellStyle(ListGridRecord record, int rowNum, int colNum) {
    if (colNum==6){
        return "EC_pointer";
    }
    return super.getCellStyle(record, rowNum, colNum);
}

and in my CSS file:

.EC_pointer { 
    cursor: pointer; 
}

The major fallout is that you have to know in advance the column number of the field.

Andere Tipps

Further to my comment and adding information from here I tested the following code which works with SmartGwt2.4 under Firefox 5.0.

demandesGrid.setCanHover(true);
demandesGrid.setShowHover(false);
demandesGrid.addCellHoverHandler(new CellHoverHandler() {
    @Override
    public void onCellHover(CellHoverEvent event) {
        if (event.getColNum() == demandesGrid.getFieldNum("icon")) {
        //  SC.say(demandesGrid.getChildren()[3].toString());
            demandesGrid.getChildren()[3].setCursor(Cursor.POINTER);
        } else {
            demandesGrid.getChildren()[3].setCursor(Cursor.DEFAULT);
        }
    }
});

I don't know if the index of the ListGridBody is constant; I found it with the SC.say line.

How about

grid.addCellOverHandler(new CellOverHandler() {
  @Override
  public void onCellOver(CellOverEvent event) {
    //cellOver event to get field and refresh the cell
    //grid.refreshCell(i, j);
  }
});

The best approach is fully demonstrated here (take a look at how "comments/stats" field is being initialized).

In short, u have to extend ListGrid and override createRecordComponent method. In this method you can make any custom component you like and it will be show in grid cell.

Also ListGrid should be initialized with:

listGrid.setShowRecordComponents(true);
listGrid.setShowRecordComponentsByCell(true);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top