Page 1 of 1
How to generate different colored rows in tables?
Posted: 2006-10-16 03:14:48
by RRUU
Is there anyway to have every 2nd row in a table a differnt color to make it more easier to read?
Something like this...

Posted: 2006-10-16 08:02:23
by antp
You mean in HTML export? It is probably possible using Javascript to change the layout dynamically.
Posted: 2006-10-16 21:21:12
by kazgor
ok first you need to create a stylesheet for the alternate colours, eg OddRow & EvenRow
then when you're drawing the table in each TD add a class but instead of using the CSS (eg odd or even row) use a variable instead.
Now there will be some kind of FOR loop to draw the table you show, so you would have a line like
if (d % 2 == 0) {cellcolour=EvenRow'} else {cellcolour='OddRow'}
D being your loop variable.
heres an example line i used to build up an HTML tag
hotnews=hotnews+"<td width='20%' valign='top' class=" + cellcolour + ">"+ bold + v_date[d] + "</td>"
later i do a document.write(hotnews) do display the HTML i've buildup.
but really depends on the script you're using and how you can integrate the above into it.
Posted: 2006-10-17 14:56:02
by antp
Another solution is to browse the HTML "tree" in Javascript and add a class to the table elements, so the table is built in HTML and only colors are added to Javascript.