Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Patrick on May 26, 2008 20:15
open dhtmlx forum
dhtmlxGrid - Changing Selected Cell Styles

How do you change the text color or text style on one cell or a series of cells with an event handler such as onMouseOver?

Is there a onMouseDown event for a selected cell?

Thanks in advance for your help.
Answer posted by Support on May 27, 2008 01:42
>>How do you change the text color or text style on one cell or a series of cells with an event handler such as onMouseOver?
Basically, you can use code similar to next
var old="";
grid.attachEvent("onMouseOver",function(id,ind){
       var cell=grid.cells(id,ind).cell;
       if (cell!=old){
          if (old) old.className="";
          cell.className="cell_under_mouse";   // assign any custom styles to cell under mouse
          old=cell;
      }
     return true;
})


>>Is there a onMouseDown event for a selected cell?
There is no special "onMouseDown", but you can use use onRowSelect

grid.attachEvent("onRowSelect",function(id,ind){
     if (id== grid.getSelectedId() && ind==grid.getSelectedCellIndex() ) alert("selected cell was clicked");
    return true;
})
Answer posted by Patrick on Jun 07, 2008 11:48
The code works great for a single cell, but how would I change the style for a group of cells onMouseOver of a single cell?

One, Can I avoid looping thru all the cells to update the class of the grouped cells.

Two, can I change the color attribute of the class (as opposed to changing the class for each cell in the group)?
Answer posted by Support on Jun 09, 2008 02:44
>> style for a group of cells onMouseOver of a single cell
The grid provides API to set some style to all rows in some cell, but there is no support for group processing any other kind of cell groups.


>>One, Can I avoid looping thru all the cells to update the class of the grouped cells.
In common case, you will need to loop through all rows (  http://www.dhtmlx.com/docs/products/dhtmlxGrid/doc/articles/Iterating_through_grid.html )

>>Two, can I change the color attribute of the class (as opposed to changing the class for each cell in the group)?
Basically you can change the style property directly
    cell.style.backgroundColor="red";
Please beware that color set in such manner will override the color of selected row|cell