views:

184

answers:

2

How can you programatically disable the grid from highlighting a row when you hover over it with your mouse? Looking to do disable this only at certain times.


This is the code from Oleg which worked:

  $('#result-close').click(function() {  
      //Turn off hover highlighting
      $("#list").unbind('mouseover');
      $("#list").unbind('mouseout');

      //Highlight row                    
      $("#" + selid).effect("highlight", {}, 5000);  

      //Turn on hover highlighting 
      setTimeout(function(){ 
                    $("#list").bind('mouseover',function(e) {
                        ptr = $(e.target).closest("tr.jqgrow");
                        if($(ptr).attr("class") !== "subgrid") {
                            $(ptr).addClass("ui-state-hover");
                        }
                        return false;
                    }).bind('mouseout',function(e) {
                        ptr = $(e.target).closest("tr.jqgrow");
                        $(ptr).removeClass("ui-state-hover");
                        return false;
                    });
      }, 2000);         

      $('#dialog').dialog( "close" );
  });
A: 

A simple Google search revealed this source: http://www.trirand.net/examples/appearance/highlight_on_hover/default.aspx

"By default, jqGrid hightlight rows on hover. This is controlled by the AppearanceSettings.HighlightRowsOnHover property - setting it to false will disable that."

ChessWhiz
Saw that. Didn't see any JavaScript example of how to set that object. Seems to be controlled somehow by .NET code.. ??
Marcus
Strange. Looks like a property of the <trirand:JQGrid>. You can see AppearanceSettings in action in the code provided in this question: http://stackoverflow.com/questions/2058692/how-to-change-a-specific-rowdata-value-in-a-jqgrid
ChessWhiz
+1  A: 

Use hoverrows:false option.

Oleg
I can get this to work when I set this in the initial grid configuration. But if I try setting this after the initial load using `$("#list").setGridParam({hoverrows:true});` the new setting doesn't seem to take affect. Tried reloading the grid (`$("#list").trigger("reloadGrid");`) after changing the property but this didn't seem to work either. The docs do say that this can be changed.. any ideas?
Marcus
@Marcus: You are right in the table on the page http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options. I think it is more an error in the documentation. Nevertheless you can switch off hovering of rows dynamically **one time** with respect of `$("#list").unbind('mouseover');$("#list").unbind('mouseout');`. See demo on http://www.ok-soft-gmbh.com/jqGrid/Pager.htm (click on "Disable hover rows"). You can not so easy restore the initial state. To restore this you have to bind the events one more time to the corresponding functions (see grid.base.js lines 2109-2119)
Oleg
@Marcus: look at http://github.com/tonytomov/jqGrid/blob/master/js/grid.base.js#L2111 (lines 2111-2121) which will be used in case of `hoverrows:true`
Oleg
Thanks Oleg - really I need a way to rebind the event in order to turn off and then on the hovering..
Marcus
@Marcus: Why not just bind 'mouseover' and 'mouseout' to your small event handler which do exactly like the lines 2111-2121 from http://github.com/tonytomov/jqGrid/blob/master/js/grid.base.js#L2111 ?
Oleg
@Marcus: OK! The coping of the code is so simple. I modified for you one more time the code of http://www.ok-soft-gmbh.com/jqGrid/Pager.htm so that one can use "Disable hover rows" to switch on/off of hovering of the rows.
Oleg
That works nicely - thanks Oleg. I'll add a jqGrid feature request to add this functionality to the basic API.
Marcus
@Marcus: good idea with the feature request.
Oleg