Categories > TinyButStrong general >

Highlight row in table

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Kevin Minnelli
Date: 2008-07-07
Time: 16:37

Highlight row in table

Guys I need help with adding a highlight row function to my table.This table lists out all of my drivers in my game, What I would like is to be able to highlight the selected driver (you).

So if the list is:
Joe 1
Tom 2
Steve 3
Frank 4
Bob 5
etc...

If you are Tom I want row 2 highlighted.

I tried something like
if (blkList.DriverID=2) {$foo='#CCC';}
then replace the $foo in the html for the color but this didn't work.

Can anyone help me? Feel free to ak questions if I missed something.





php file
$TBS->LoadTemplate('driversTBS.htm') ;
$sqlList="SELECT * from Driver ORDER BY (DriverID)";
$TBS->MergeBlock('blkList',$cnx_id, $sqlList) ;



html
<table width="100%"  border="0" cellpadding="2" cellspacing="0" >

<tr style="color:#FFFFFF;font-weight:bold;" bgcolor="#4a6f8e">
<td width="20%" bgcolor="#0066FF">Driver</td>
<td width="5%" bgcolor="#0066FF">Car</td>
</tr>

<tr valign="top" bgcolor="e4ebf1">
<td valign="middle" bgcolor="#CCCCCC" class="gridblack" style="color: #FFFFFF">[blkList.DriverName;]</td>
<td valign="middle" bgcolor="#333333" class="g_driver_number" style="color: #FFFFFF">[blkList.DriverID;block=tr]</td>
</tr>

<tr valign="top" bgcolor="e4ebf1">
<td valign="middle" bgcolor="#CCCCCC" class="gridbgrey" style="color: #FFFFFF">[blkList.DriverName;]</td>
<td valign="middle" bgcolor="#333333" class="g_driver_number" style="color: #FFFFFF">[blkList.DriverID;block=tr]</td>
</tr>

</table>
By: Skrol29
Date: 2008-07-07
Time: 22:57

Re: Highlight row in table

Hi Kevin,

You can use a conditional section:

<tr valign="top" bgcolor="e4ebf1">
<td valign="middle" bgcolor="#FFFF99" class="gridbgrey">[blkList.DriverName;]</td>
<td valign="middle" bgcolor="#FFFF99" class="g_driver_number">[blkList.DriverID;block=tr;when [blkList;DriverID]=[onload.UserId]]</td>
</tr>

<tr valign="top" bgcolor="e4ebf1">
<td valign="middle" bgcolor="#CCCCCC" class="gridblack" style="color: #FFFFFF">[blkList.DriverName;]</td>
<td valign="middle" bgcolor="#333333" class="g_driver_number" style="color: #FFFFFF">[blkList.DriverID;block=tr]</td>
</tr>

By: Kevin Minnelli
Date: 2008-07-08
Time: 04:45

Re: Highlight row in table

Ok - looks nice and I'm closer it works if I'm okay with having my table be the same color except form when the id matches. basically I have a zebra table - black and grey. When the id matches I want it to stand out say in white. So I tried this... Now I left the extra code out and only included the main line item in each <tr>

1st Row - if it matches make it class white this works but everything else in the table is black
<td valign="middle" bgcolor="#666666" class="g_white" style="color: #000000">[blkList.DriverID;block=tr;when [blkList.DriverID]=[onload.id]]</td>

2nd Row - since I say not equal - black #333 wins in the rest of the table :(
<td valign="middle" bgcolor="#333333" class="g_driver_number" style="color: #FFFFFF">[blkList.DriverID;block=tr;when [blkList.DriverID]!=[onload.id]]</td>

3rd Row - another not equal but grey  #666 doesn't get any rows
<td valign="middle" bgcolor="#666666" class="g_driver_number" style="color: #FFFFFF">[blkList.DriverID;block=tr;when [blkList.DriverID]!=[onload.id]]</td>

Trust me I'm making conditional a big part NOW that I know I can use it, but my black/grey or white/grey tables are critical since I pass a lot of info in my tables. Thanks for the fast response - I love TinyButStrong and all it does for me...

Minnelli
By: Kevin Minnelli
Date: 2008-07-09
Time: 17:21

Re: Highlight row in table

Skrol - any feedback? I know you are busy so I'm sorry.
By: Skrol29
Date: 2008-07-09
Time: 20:16

Re: Highlight row in table

Hi Kevin,

My code should display normal row, plus one more when the id matches.
I guess this is not what you want.

You can modify my code with one row having
[blkList.DriverID;block=tr;when [blkList.DriverID]=[onload.id]]
and a second one having
[blkList.DriverID;block=tr;default]

That should work better.
Of course you can change the color and the look of each row as you wish.
By: Kevin Minnelli
Date: 2008-07-09
Time: 20:57

Re: Highlight row in table

Yep it works but only has tow colors - say white when it matches and black when it doesn't. But I want the rows to go black, grey, black, grey oops match make that row white. Your code works fine I just want to keep the black, grey rows and show the hightlighted one when it comes up. Thanks and sorry not trying to be a pain. I appreciate the help.
By: Skrol29
Date: 2008-07-09
Time: 21:08

Re: Highlight row in table

Ok, I understand now. Sorry.

The more simple it that you use alternative rows, without conditional rows. That is without "when ..." or "default".

Then you can define a special call for the row that matches the id. And highlight the row, just use use something like:
class="[blkList.DriverID;if [val]=[onload.UserId];then myclass;else ''"