How to generate different colored rows in tables?

If you made a template for printing or HTML export, you can offer it to the others here. You can also ask here for help about these templates
Post Reply
RRUU
Posts: 13
Joined: 2006-02-21 11:22:33
Location: NZ

How to generate different colored rows in tables?

Post 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...
Image
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post by antp »

You mean in HTML export? It is probably possible using Javascript to change the layout dynamically.
kazgor
Posts: 175
Joined: 2006-05-08 13:13:52
Contact:

Post 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.
antp
Site Admin
Posts: 9651
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post 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.
Post Reply