smartgwtlistgrid

smartgwt listgrid set cursor to hand over an icon field


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


Solution

  • 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.