Alternate row colors

Alternate row colors

Unread postby parkerjnc » Fri Nov 02, 2012 4:59 am

I tried to search the forum to see if this had been addressed before but did not find anything. Maybe I didn't look in the right place. So I started digging into nubuilder and found it wasn't terribly difficult to do. For those who have a similar need, I thought I'd document the changes I made here.

The most common approach to alternating the background color of rows is to apply an even or odd class as the rows are being generated. In the browse.php file you can find where the "rows" are generated (actually they are div's) and see that a for loop is used with a counter of $browseRow. So within that code I made the changes you can see below. Basically added a string variable named $rowClass setting it to 'odd' initially. Then take the $browseRow and get the modulus with 2, if 0 then the row is 'even'. Add the $rowClass string within the div definition next to the 'nuUnselectedRow' class. Now you can create a Style under Setup for '.even' and '.odd' to set the background-color to the value you want. To ensure the style change takes affect you may want to include "!important" with the color value.
Code: Select all
$left        = 0;
$top         = $top + $this->rowHeight;
$rowClass = 'odd';
if ($browseRow % 2 == 0) {
     $rowClass = 'even';

for($i       = 0 ; $i < count($this->Column) ; $i++){
     $w     = $this->Column[$i]->sbr_width;
     $a     = align($this->Column[$i]->sbr_align);
     $s     = $s . "$this->TAB<div onmouseover='MIN($param)' onmouseout='MOUT($param)' onclick='doIt($theID)' class='nuUnselectedRow $rowClass' id='$rowname$i' style='position:absolute;overflow:hidden;$cur;text-align:$a;top:$top"."px;left:$left"."px;width:$w"."px;height:$this->rowHeight"."px'>$this->CRLF";

Posts: 15
Joined: Wed Sep 05, 2012 12:45 pm

Return to Custom Code

Who is online

Users browsing this forum: No registered users and 4 guests