tableHover

Description:
A jQuery plugin to highlight table rows and columns when hovering over them.
It features different styles for row and column highlighting and fixing the highlight when a user clicks inside a cell.

Demo and Example page.

Files: (last update: 2007-12-17 - v 0.1.4)

License:
The plugin is available under both MIT and GPL licenses (as jQuery itself). This means that you can choose the license that best suits your project, and use it accordingly.

Usage, Examples and available options:
Please take a look at the demo page and the source of the jquery.tablehover.js file.

Changelog:

  • v 0.1.4 - 2007-12-17
    • fix: clicking on a link or child element inside a cell did not set the clickClass on the rows/columns
  • v 0.1.3 - 2007-09-04
    • fix: highlighting did not work when the hovered table cell had child elements inside
  • v 0.1.2 - 2007-08-13
    • fix/change: changed event binding routine, as is got really slow with jquery 1.1.3.1
    • change: added new option “ignoreCols”, through which columns can be excluded from the highlighting process
  • v 0.1.1 - 2007-06-05
    • fix: errors when using the plugin on a table not having a theader or tfoot

The plugin was successfully tested on Firefox 2, Opera 9.10/9.20 and IE 6/IE 7.

32 Responses to “tableHover”

  1. I am using your plug in , but it can’t work well if i am in document ready .add table hover function.
    in document ready :
    $.get(”customer-j.php”, {BN_CLUSTER:”"}, function(xml) {
    var result=”";var tmpresult=”";
    $.each( $(”customer”, xml), function(i, row){
    if(i%2==0) {
    tmpresult+=”";
    }else{
    tmpresult+=”";
    }
    tmpresult += “”+$(”name”, row).text()+
    “”+$(”code”, row).text()+
    “”+$(”cluster”, row).text()+
    “”+$(”dbmaster”, row).text()+
    Modify  Remove“;
    });
    result=result+tmpresult;
    $(”#datamin”).append(result);
    });
    $(”#maintable”).tableHover({colClass: ‘highlight’});

    then it can’t work well.

  2. Hi lily,

    is the #maintable filled with static data or is it filled dynamically through some ajax-calls?

    Do you maybe have an example page I could take a look at?

  3. The plugin works great. However, when given a TABLE element with a THEAD but an empty TBODY, it throws many JS errors. Once the table has rows, the errors disappear. Minor problem, of course :-)

  4. Aw, I’ve never thought of having a table without a body :D
    I’ll fix the errors. Thanks!

  5. When using the click class, cells do not stay highlighted after a click. That was the intention, right?

  6. Nevermind the click feature does work. The background color used was just too light for my monitor. But I noticed that the first cell (upper left) stays highlighted by default. How can I change that? Thanks for the great plugin!

  7. pytechd: I tried to recreate your problem with the empty tbody but I don’t get any errors - could you please send me the html markup you used?

    Izahg: can you please explain this in more detail? I don’t see any cell staying highlighted by default (in the demo page)

    thanks!

  8. It seems that if a bgcolor on single cell is defined, highlight has no effect on it.

    I have a table with different bgcolor for some cells…

    Thank u anyway, very smart plugin ;)

  9. Thanks!

    Bgcolor attributes should be overwritten by stylesheets. Maybe there is a problem with the other styles your’e using?
    If you can give me a link to your site, I can take a quick look at it.

  10. How about dimensions table must have?

    When I have more than 60 rows in a table with 18 column, highlighting stops work on next rows and the error

    “stop running this script? A script on this page is causing Internet Explorer to run slowly. If it continues to run, your computer may become unresponsive.”

    appears.
    The same error appears even if the number of rows grow up to 30, but in this case highlighting still works.

    Same error occur in Firefox too where the problem seems to be generated in jquery-1.1.3.1.js.

    Maybe the script is not scalable and works fine only with small tables? Or maybe there’s something more complex underneath?

    Thank u!
    Alessandro.

  11. I upgraded the script and don’t get any errors, so I wouldn’t worry about it. It could have been my markup, too, but it seemed very consistent (throwing errors on empty tables but not on full tables).

  12. Alessandro: I’ve never really tried the plugin with bigger tables, 60 rows and 18 columns doesn’t even sound that big. I’ll try to sort that out.

    pytechd: Thanks for clarifying this. I’m glad the problem doens’t occur with the latest version.

  13. Alessandro: That really was a problem with jQuery 1.1.3.1. The event binding got a lot slower, so I had to change this in the plugin (v0.1.2). The page load time should be normal again.

    Thanks for reporting the problem!

  14. Great, I’m glad to have been helpfull ^_^

    Thank you!

  15. When you have a table full of links the columns briefly de-highlight when you mouse over the link but then quickly re-highlight. Is there a way to avoid this flicker? Mere annoyance at best — it seems much more noticable with jQuery 1.1.4, perhaps due to speed-ups in JQ itself.

  16. When you hover over a hyperlink within a cell, the column and row are no longer highlighted. If you hover over plain text or or within the cell but outside the hyperlink, there’s no problem. Is there a way to make sure they stay highlighted? I tested it with ie7 and firefox2. I hope you can replicate it. Thanks again!

  17. I realized that if the cell contains anything but plain text, the highlight effect won’t work if you hover over the content of that cell. If there’s an image or link (or any other html object) within the cell, and you hover over it, the highlight is gone. Is there a way that could be fixed?

    Thank you again for this awesome plugin!

  18. Damn! That was a stupid mistake. It’s hopefully resolved now. :)

    Thank you for reporting this!

  19. Thanks for fixing it. It worked like a charm!

  20. Hi

    Your plugin does not work in Safari 2.0 (Mac OS X 10.4). Safari 3.0 (Mac OS X 10.5) however does work. Here is a page where I used it:
    http://info.hgk.fhz.ch/maccenter_status.html

    Do you know about this problem? Will there be a fix?

    Besides that, I like your plugin very much. Keep up the good work! Thank you.

    Mike

  21. Sorry, but as I don’t have a Mac, there probably won’t be a fix for that. I’ll try to check this on a friends Mac, though.
    Thanks for reporting this!

  22. Hi, I am trying ot use this on a table which uses striping i.e. td class=”row” With the classes already defined on each row it doesn’t do anything, as soon as I remove the classes it works fine. Can this be used with pre-defined classes? How will it know to return the row to the original class?

    Otherwise it’s brilliant, thanks
    Simon

  23. Hi Simon,

    the highlighting class probably doesn’t overwrite the class which does the striping. Please try to give the highlighting class a higher specificity or add !important to the css rule. If that doesn’t work, I can try to take a look at your site.

    The plugin only adds and removes it’s own class, it won’t touch all other set classes.

    Cheers!

  24. Thanks, setting the !important attribute fixed the problem perfectly.

    Cheers

  25. Hi

    Is there a possibility to exclude rows from hilightning? It would be nice to set a class like
    .... Something like “ignoreCols ()” won’t help, because I don’t know the exact row which I am going to exclude. My tables are all database driven.

    Greetings Mike

  26. Sorry, my code did not show up:

    <tr class="noHover">...</tr>

    Greetings Mike

  27. Mike, this should work:
    - set a background-color to your noHover class
    - make sure, it has a higher css specificity than the hover class or add !important to the rule

    The plugin will still set the hover class to the row, but it should have no effect.

  28. Thanks!

  29. Hi,

    I found that clicking on a link inside a cell doesn’t render the row/css/column highlighted when clickClass option is used.
    Can you fix this?

  30. Hi Syl,

    thank you!
    I’ve fixed the problem. Please take a look at the new version (v0.1.4).

  31. How to apply hover event to new tr elements after tableHover() inited on one table?

    $(table1).tableHover();
    $(table1).find("tbody").append("");
    //something like $(table1).trigger("update.tableHover"); ?
    
  32. Since jQuery 1.2.6 support namespace events. Maybe we can solve it this way(at last lines):

    if ( $(this).data("bind.tableHover") ) {
      $(this).unbind(".tableHover");
    }
    $(this).bind('mouseover.tableHover', over).bind('mouseout.tableHover', out).bind('click.tableHover',click).data("bind.tableHover",true);
    

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
Syntax Highlighting: You can use [js] .. [/js] and [html] .. [/html] for posting code snippets.