tags:

views:

177

answers:

3

Hi,

I set cells of the first column of my grid, with a class as follow:

$("#myGrid").jqGrid('setCell',rowid,'column_1', '', '**ui-state-default**');

How to change the class of a cell when the mouse is over on it ?

Thanks you so much !

+2  A: 

How about this?

$("#myGrid").hover(function(){
        $(this).find("td:first").css("background-color", "black");
    });

EDIT

 $("#myGrid tr").hover(
              function(){
              $(this).find("td:first").addClass('ui-state-hover');
              },
              function(){
              $(this).find("td:first").removeClass('ui-state-hover');
              }   
            );

OR

$("#myGrid tr").mouseenter(function(){
      $(this).find("td:first").addClass('ui-state-hover');
    }).mouseleave(function(){
      $(this).find("td:first").removeClass('ui-state-hover');
    });
c0mrade
Thank you for your quick response!I try in this direction and come back...
Qualliarys
@Qualliarys I haven't tested any of these I'm sort of in a hurry
c0mrade
A: 

... i solved it with something like that :

$("#myGrid tr").hover(function() { 
    $(this).find("td").eq(1).addClass('ui-state-hover');
});

$("#myGrid tr").mouseout(function() {
    $(this).find("td").eq(1).removeClass('ui-state-hover')
});

What do you think about ?

Qualliarys
@Qualliarys whatever works for you its fine, however I'd do it like this see my edit
c0mrade
They work better as mine code... but i need still to replace find("td:first") by find("td").eq(1), why ?
Qualliarys
A: 

Here is my last solution. I will use it as follow :

$("#mygrid tr").hover(
  function(){
      $(this).find("td").eq(1).removeClass('ui-state-default');
      $(this).addClass("ui-state-hover");
  },
  function(){
     if(!$(this).hasClass("ui-state-active"))
     $(this).find("td").eq(1).addClass('ui-state-default');
  }
);

$("#mygrid tr").click(function(){
  $("#mygrid tr").each(function() {
    $(this).find("td").eq(1).addClass('ui-state-default');
  });

  $(".ui-state-active").removeClass("ui-state-active");
  $(".ui-state-highlight").removeClass("ui-state-highlight");
  $(this).find("td").eq(1).removeClass('ui-state-default');
  $(this).addClass("ui-state-active");

});

It works well also for a grid within input text tags !

Qualliarys