3.2.0

Best way to set cell onmouseover style

Hi everyone,

I have a grid which has alternate rows styled with:
.aw-alternate-even {background: #fff;}
.aw-alternate-odd {background: #eee;}

and with the row selector enabled:
obj.setSelectionMode("single-row");

In one particular column (col 8) I want to have an additional style effect which is a cell background color change when the mouse is over a cell. This is what I've got so far:

obj.onCellMouseOver = function(event, column, row){ 
    if(column == 8)	{
    obj.getCellTemplate(column, row).setStyle("background","#bbb");
    } 
};

obj.onCellMouseOut = function(event, column, row){ 
    if(column == 8)	{
    // test for whether row number is odd or even
    // if modulus is zero condition is false
    var row_position = obj.getRowPosition(row);
        
    if (row_position%2)   {
    obj.getCellTemplate(column, row).setStyle("background","#eee");
    }
    else  {
    obj.getCellTemplate(column, row).setStyle("background","#fff");
        }
    } 
};


This nearly works but not quite. It changes the background of the cell when hovered over and changes it back again to the correct odd/even background OK. Where it fails, however, is when a row is selected (that has previously had column 8 hovered over) then the selected row style (white text color on blue background) disappears on that cell (OK on the rest of the row).

What I need to be able to do I think is somthing like "reset" the class .aw-row-selected for the cell that has been previouslyhovered over.

I can't help thinking that there must be more elegant & efficient ways of doing all this.

If anybody has any ideas on this your input would be gratefully received as always.

WIll
Will
April 4,
Will,

this probably should work better -

obj.onCellMouseOver = function(event, column, row){
    if(column == 8)    {
        obj.getCellTemplate(column, row).setStyle("background","#bbb");
    }
};

obj.onCellMouseOut = function(event, column, row){
    if(column == 8)    {
        obj.getCellTemplate(column, row).setStyle("background","none");
    }
};


Alex (ActiveWidgets)
April 4,
Alex

Yes that's spot on: it doesn't interfere with the style of the row selector which was the problem I was having.

Thanks once again!

Will
Will
April 5,

This topic is archived.

See also:


Back to support forum