You are hereColorize - jQuery Table Plugin - 1.5.1
Colorize - jQuery Table Plugin - 1.5.1
Colorize is a jQuery plugin to add background color to alternate HTML table rows, highlight a row/column on mouse over, and colorize a row/column when you click your mouse button over it. You can colorize as many table rows or columns as you want. A repeat mouse click reverts the row/column to the original background color.
How to use it?
Use it with default options (colorizes a row)
$('#yourTableId').colorize() ;
Optional parameters:
altColor : alternate row background color. The default is '#ECF6FC', 'none' can be used for no alternate background color.
bgColor : background color (The default background color is white).
hoverColor : background color when you hover a mouse over a row. The default is '#BCD4EC'.
hoverClass: style class for mouseover; takes precedence over hoverColor property
hiliteColor : row highlight color. The default color is 'yellow'. 'none' can be used to disable highlighting.
hiliteClass : style class to be used to highlight a row or a column, takes precedence over the hiliteColor setting.
columns : true/false/'hover' - The default is false. if true, highlights columns instead of rows. If the value is 'hover', a column is highlighted on mouseover, but does not respond to clicking. Instead, a row is highlighted when clicked.
oneClick : true/false - Allows only one row or column to be highlighted at a time. A click on a new row/column cancels the current highlight. The default is false.
banColumns :[]- Prevents columns from being highlighted when clicked, and also on mouseover. Supply an array of column indices as an argument. A value of 'last' can be used to ban the last column.
Examples:
The order of parameters is not important.
$('#yourTableId').colorize({bgColor:'#EAF6CC', hoverColor:'green', hiliteColor:'red'});
$('#yourTableId').colorize({ oneClick:true});
$('#yourTableId').colorize({columns:true, banColumns :[0,1]});
$('#yourTableId').colorize({ hiliteClass:'myStyle'});
No highlighting:
$('#yourTableId').colorize( { hiliteColor:'none' } );
Demo 1 - Usage with default options: $('#tblId').colorize();
Demo 2 - Highlights columns, one column at at time. Usage : $('#tblId').colorize( {columns: true, oneClick:true} );
Download Colorize 1.5.1 plugin
Version History
Version 1.5.1 fixed a bug that caused not to highlight a row/column when clicking more than 2 times on the same row or column. (thanks to an anonymous user)
Version 1.5.0 introduced a new option, hoverClass, to indicate a style class to be used for hovering (thanks to a an idea from snobo). (Please be aware that the use of this option may degrade IE performance).
The altColor supports the value of 'none' now.
The columns option has a new value: 'hover' - changes columns background color or style on mouseover, but assigns a new style or background color to rows when they are clicked.
Includes support for multi-level headers by highlighting only the last header row. (However, the 'last' option does not work with multi-level headers)
In the banColumns option, a value of 'last' can be used to ban the last column.
Version 1.4.0 introduced a new option, hiliteClass, to indicate a style class to be used for highlighting (thanks to a tip from Skye Giordano). Also, the banColumns option now suppresses not only highlighting but also hover.
Version 1.3.0 allows to use the banColumns option even if the columns parameter is false (thanks to the code contributed by Aymeric Augustin)
Version 1.2.1 introduced a new feature : disable highlighting (thanks to a user comment):
Use 'none' value for hiliteColor option if you want to disable highlighting
Version 1.2.0 introduced new options :
columns : true/false
oneClick : true/false
banColumns :[]
Version 1.1.0 fixed a bug in the original version that highlighted all the tables on a page.
Thank you for this great plug-in. How can I make it to work with more than one level tr within thead. It works great if I only have one tr under thead.
Now when I click on "Total", "second level header middle" is also highlighted. I guess it's trying to match the 2nd th of the 3rd level tr to the 2nd level tr. It doesn't look right. Thanks in advance for any help.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
first level header
second level header left //colspan="4"
second level header middle //colspan="9"
second level header right //colspan="6"
//here is the last level table header I want to click on and highlight the column
Statistics by
Total
#PV
%Repl.HH
Type A
Type B
Type C
URE Int.
Par. Int.
Vac Rate
Resp. Rate
Salary of ref. per
HH Size
<14
14-19
20-29
30-39
40-49
50+
....
I am preparing a new version of the plugin for release that will address this problem. Check back in a day or two.
Hi, i love this plugin... However when i click on a hyperlink, the whole row got colorized :p
I seriously wanted the hiliteColor function but i doesn't want it to activate when i click on a hyperlink. How can i prevent that from happening? Cheers!
You can use the banColumns option to prevent it from happening. For example, if the hyperlink is in the first column, use it as follows: banColumns[0]. If it is in the second column, use banColumns[1], etc. Hope this helps.
Cheers!
I have another small suggestion, to allow skipping of the row alternation. Simply to add a check for "none" on the line #143:
if (options.altColor!='none') {
jQuery(this).find('tr:odd').css('background', options.bgColor);
jQuery(this).find('tr:even').css('background', options.altColor);
}
Also, in fact, would be good to change the alternation method from applying the css color attribute to applying the class, similar to how hiliteClass has been introduced. Using classes instead of css color attributes are essential, because only then we can arrange the prioritizing of overlapped backgrounds via CSS cascading. I mean, if I have my own class applied to a particular column, that changes its background, I want to arrange that alternate background is different from a "normal" alternate. With styles, it's possible (.altClass .myOwnClass { ... }), with CSS color attribute - no.
-=snobo=-
This is a worthy idea. I will implement it in the next version of the plugin.
Great little plugin Eric..thanks so much for sharing.
I may be missing something, but is there a way to ban some colums from having a hover state?
i.e i have a 5 column table..and only 3 of the columns should have a hover state.
Thanks in advance for your help :)
$("#editProfile").colorize({hiliteColor:'none', oneClick:'true', banColumn:["#last"] }); nor
$("#editProfile").colorize({hiliteColor:'none', oneClick:'true', banColumn:["last"] });
is not working to stop hi-lighting the column #last
please help!
The above syntax won't work. You will have to use a rather ugly workaround:
$("#editProfile").colorize(
{hiliteColor:'none',
oneClick:'true',
banColumn : [ $(this).find('td:last')[0].cellIndex ] }
);
The new version 1.4.0 supports banning columns from having a hover state.
Any way to get the plugin to work with different colors in multiple tables on the same page?
Any help would be greatly appreciated.
Sure, no problem.
Each table must have a unique id. For each table, you must include a call to the colorize function. Example:
$('#tbl1').colorize({bgColor:'#EAF6CC', hoverColor:'green', hiliteColor:'red'});
$('#tbl2').colorize({bgColor:'#aaa', hoverColor:'#bbb', hiliteColor:'green'});
Jquery 1.3.1 and latest colorizer ..
I am also using tablesorter .. each table has the tablesorter class --
I want to colorize all tables :
$("table").colorize();
gives nothing , but with columns: true , it works (doesn't let me click and select but atleast highlights onmouseover)
Hi, I appreciate all of you who create plugins and widgets because it makes life so much nicer for us non-programmers. I've hacked my way through a few hard coded sites, but now I've been shown WP I don't think I could go back.
Here's a code for animating a paragraph using slide animation, I found this interesting.
//Code for example B
$("input.buttonBslidedown").click(function(){ $("div.contentToChange").find("p.fourthparagraph:hidden").slideDown("slow"); });
$("input.buttonBslideup").click(function(){ $("div.contentToChange").find("p.fourthparagraph:visible").slideUp("slow"); });
//show code example B
$("a.codeButtonB").click(function(){$("pre.codeB").toggle()});
hi
i want to colorize only cells of a table on hover state...
how can i adapt this plugin ?
thx
I am afraid you can't. The plugin is designed to colorize table rows or columns on click.
However, you don't need the plugin to colorize individual cells on hover state.
You can easily accomplish it using the following code:
var cells=$("#myTable").find('td');
$.each(cells, function(index, cell){
cell.onmouseover = function(){
this.style.backgroundColor = "yellow";
}
cell.onmouseout = function(){
this.style.backgroundColor = "white";
}
});
Thank you for colorize!
I'm using it in my project with small modification. When highlight background is to dark and text colour dark also - it's not visible. So it's my code modification with new option "altTextColor":
jQuery.fn.colorize = function(params) {
options = {
altColor: '#ECF6FC',
bgColor: '#fff',
hoverColor: '#BCD4EC',
hiliteColor: 'yellow',
oneClick: false,
columns: false,
altTextColor: 'white',
banColumns: []
};
jQuery.extend(options, params);
var colorHandler = {
checkHover: function() {
if (!this.onfire) {
this.origColor = this.style.backgroundColor;
this.style.backgroundColor= options.hoverColor;
this.origTextColor = this.style.color;
this.style.color= options.altTextColor;
}
},
checkHoverOut: function() {
if (!this.onfire) {
this.style.backgroundColor=this.origColor;
this.style.color= this.origTextColor;
}
},
When I use the oneClick = true in Version 1.3.0
It has problem about toggle hiliteColor on the same TR row
This is intentional behavior. You have to click on another row before you can toggle color on the previous row again.
Thank you & kudos for the great plugin!
Just download the 1.3.0, and wondered why I have a Javascript error when using it... Turns out there's a function call on line 59:
msg.debug(timeDiff.getDiff());
I guess that's a kinda leftover in the code... Apart from that, the plugin works excellent, thanx again!
-=snobo=-
That's exactly what it was. I removed the offending line, and upped the version number to 1.3.1. Thank you for bringing it to my attention.
Like all other jQuery alt row colorizers I've looked at so far, it can't handle rowspan properly.
Also, breaks in Firefox if setting hiliteColor:'none' or hoverColor:'none'. I'm only guessing though that this is how we would turn these features off altogether. This works in IE6 but an error is raised.
I would have assumed that the default options would be that these features are turned off, and they should only be enabled if included in the parameter list.
Maybe I'm not understanding something?
If you would like to use a hiliteColor value of 'none', make the following change to the script file:
1) Find the following code: "hightlight : function()".
You will see the code for this function, which will be something like this:
this.style.backgroundColor= options.hiliteColor;
this.onfire = true;
2) Change it so that it is as follows:
if(options.hiliteColor != 'none') {
this.style.backgroundColor= options.hiliteColor;
this.onfire = true;
}
That's it! Now, when you initialize the table, just set the hiliteColor value to 'none', like this:
$("#mytable").colorize( {hiliteColor: 'none'} );Great plugin. Hope this helps.
Thanks for the tip. I've included it into the updated version of the plugin.
Sorry, the documentation was not clear on the subject of default options. I am going to update it.
The default options for parameters that accept color codes are as follows:
altColor : '#ECF6FC',
bgColor: '#FFFFFF',
hoverColor : '#BCD4EC',
hiliteColor : 'yellow'.
Also, 'none' is not a valid value. Only HTML color codes or named colors are.
There is some logic to your assumption that by default the color parameters should be turned off. However, I chose in favor of the easiest plugin initialization, and that meant making some assumptions about the default colors.
Coming back to your question about turning off hiliteColor or hoverColor parameters, you should set them equal to your table background color to make them invisible.
Hope this clears up your questions.
Yes, thank you, I figured that much out.
My much more serious issue is applying colorizer to a table with rowspans:
The result is a row that appears to have color applied to only part of it. Haven't seen any other similar plug-ins that resolve this problem either though.
I installed the plugin and had it up and running within two minutes! It's seriously great! The only question/feature request I had for the plugin was the ability to only highlight one row at a time onclick. In other words, after clicking a row, when you go to click a new row, the first row that you clicked will default back to its original color and the new row will obtain the hiliteColor.
I will try to include this feature in the new release that I am preparing right now.
The plugin is great, I just cant get it to work in the manner I need, ... it does not seem to stop.
I have jQuery.js latest version, and I am currently using jquery.colorize.js for one of my tables on my page. To explain I am calling an ajax.load to a div.id ("#showPanel"). Before the ajax.load, I have a php mysql query creating my table dynamically from a db. So thru jquery I load my URL into div.id("#showpanel"). And this works like a charm. jQuery finest features. But my problem is that when I colorize this dynamic table, ... it leaks into the other html markup, .. and colorize-es my entire page and not just div.id("#showpanel"), .. how can I isolate covorize or tell colorize to stop/remove/
My markup below:
//here is my function that calls the URL where my query makes the dynamic table,...
function setAjaxQuery(urlVar) {
$("#showPanel").load("http://myURL/ajaxfunc.php"+urlVar).show('fast');
};
//here a php switch to complete my url and case for the query selection,...
switch ($_GET['ajaxfunc']){
case transDBQuery :
print transDBQuery($_GET['tablerow']);
break;
//After the switch this function queries my db and creates the table with the results,...
function transDBQuery($transponder){
?>
$('table').colorize(({bgColor:'##BCCAE5', hoverColor:'white', hiliteColor:'#BADEF6'})) ;
<?php
$DBQuery="SELECT * FROM outagedb WHERE network LIKE '%$transponder%' ORDER by id DESC";
$result=mysql_query($DBQuery);
$output = "";
$output .= "StartDateStartTimeEventDevice AffectedNetworkStopDateStopTimeTest";
while ($row=mysql_fetch_array($result))
{
$output .= "$row[startDate]$row[startTime]$row[event]$row[device_aff]$row[network]$row[stopDate]$row[stopTime]$row[outID]";
}
$output .= "";
return $output;
}
OpenTable();
echo "Query Results:";
CloseTable();
Unfortunately, a bug crept into the original version that would colorize all the tables on a page, where you wanted it or not. I have fixed the bug, and released a new version of the plugin that has a version number of 1.1.0. Please download it from this page.
Also, you need to call it as follows:
$('#yourTableId').colorize();
Otherwise, if you supply a generic 'table' tag to jQuery, the plugin will be called on all the tables on a page.
The new version has resolved my fault, where colorize leaked onto my entire page. Colorize is working like a charm, ... GREAT plugin, I have upgraded to 1.1.0 on my test pages and will soon incorporate into my live pages. Thanks, your reply was fast and right on the money.
jQuery Rock !!!
This is just one of those one of a kind tools that makes the web even more look like a fullgrown application
I certainly gonna use it
Vinny
This is a great plugin - helpful in making tables readable. Are there any plans to expand the highlighter (say vertical instead of horizontal, and not highlight certain rows?)
I can't get jQuery Colorize plugin to work when my table has a CSS class attribute, as well as an ID. I'm using jQuery tablesorter, so I have to give my table a class attribute of .tablesorter in order for the various CSS values that come with tablesorter to work correctly: e.g . If I remove the class .tablesorter, colorize works, but I need this class in the markup for jQuery tablesorter. Is there any way around this?
There is a way around it. But if you use it, Colorize will lose most of its functionality, keeping only the striping.
Find the following piece of code in jquery.colorize.js:
return this.each(function(){
jQuery(this).find('tr:odd').css('background', options.bgColor);
jQuery(this).find('tr:even').css('background', options.altColor);
Now, change the last 2 lines to the following:
jQuery(this).find('tr:odd td').css('background', options.bgColor);
jQuery(this).find('tr:even td').css('background', options.altColor);
This will allow Colorize to overide the style settings for individual table cells set in the stylesheet.
If you want to use the sorting functionality from the tablesorter plugin, you could use something similar to the following code on (document).ready:
$(".tablesorter").tablesorter();
$('.tablesorter').colorize();
$($.tablesorter.defaults.headerList).each(function (index){
$(this).click (function (){
setTimeout(function() {
$('.tablesorter').colorize();
},10);
});
});