I have successfully put highlighting in my table but the problem is with alternating the row color. The row color is alternating only after the row is highlighted. In
other words, when the page is first loaded or refreshed, all the row color is colored white which is the default. I want to fix this in a way that whether its first time loading the page or it is refreshed the color is already alternating. By the way, I used a combo of JavaScrpt, and embedded ruby for this.
Here is the code fragment for my index.html.erb:
<table id="table_list">
<tr onMouseOver="this.className='highlight'" onMouseOut="this.className='<%= cycle :odd, :even %>'">
<td> Data 1 </td>
<td> Data 2 </td>
</tr>
</table>
and on my CSS:
<pre>
#table_list{
border: solid 1px #666;
border-collapse: collapse;
margin: 10px 0;
}
#table_list th{
font-size: 12px;
color: #FFF;
background-color: #404C99;
padding: 4px 8px;
padding-bottom: 4px;
text-align: left;
}
#table_list .highlight {
background-color: yellow;
}
#table_list td {
font-size: 12px;
padding: 2px 6px;
}
#table_list .even td {
background-color: #E3E6FF;
}
#table_list .odd td {
background-color: #D1D8F6;
}
</pre>
Here you can use JQuery for this coloring purpose.
You might find the :even and :odd selectors useful.
You could then use them like this (Working Copy):
Your can download jquery from jquery.com