CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> General/Other

 Highlight Grid Row based on Grid Field Variabe/Value

Print topic Send  topic

Author Message
doug_mize

Posts: 12
Posted: 04/08/2008, 7:06 PM

I'm going crazy trying to get my grid to change the background color of a row based on the value of a field in the row. I found a bunch of different discussions in this forum on the subject but they're all either really vague, or when they do show actual code, it's not cut-and-paste usable. It seems as though the forum contributors assume that they are talking with CCS veterans or something.

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

This is what I found on the subject:

http://forums.codecharge.com/posts.php?post_id=85962&s_...d=highlight+row

http://forums.codecharge.com/posts.php?post_id=71212&s_...d=dynamic+image

http://forums.codecharge.com/posts.php?post_id=90764&s_keyword=checkbox

http://forums.codecharge.com/posts.php?post_id=68718&s_...light+grid+rows


I even found this on another site and it seemed promising:

http://www.gotocode.com/art.asp?art_id=309&

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

Unfortunately I guess I'm too much of a newbee to get what they're talking about.

I NEED to SEE the code for doing this.

One of the posts mentioned that..

"It is explained in the CCS3.1 Help, search for Component Attribute." but I have CCS 4 and can't find any USABLE example in the Help files.

Could anyone please send me a snippet of code (PHP) with comments to show exactly how this is done?

OR

Could you please send me the CCS 3 help files if they indeed do contain a section on this.

And to anyone from the CCS crew: It really seems like a basic feature that most people would want from their grid. Highlighting certain rows based on a field value should be something you could add to any grid or results via a wizard that simply asks for the field and values to be tested and then helps you configure the highlighting format wanted (bold font, change background color, underline, etc.).

Any help would be greatly appreciated.
View profile  Send private message
DonB
Posted: 04/09/2008, 10:30 AM

Link #3 from datadoit has the complete code in his example.

--
DonB



"doug_mize" <doug_mize@forum.codecharge> wrote in message
news:247fc249066645@news.codecharge.com...
> I'm going crazy trying to get my grid to change the background color of a
> row
> based on the value of a field in the row. I found a bunch of different
> discussions in this forum on the subject but they're all either really
> vague, or
> when they do show actual code, it's not cut-and-paste usable. It seems as
> though
> the forum contributors assume that they are talking with CCS veterans or
> something.
>
> //////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> This is what I found on the subject:
>
> http://forums.codecharge.com/posts.php?post_id=85962&s_...d=highlight+row
>
> http://forums.codecharge.com/posts.php?post_id=71212&s_...d=dynamic+image
>
> http://forums.codecharge.com/posts.php?post_id=90764&s_keyword=checkbox
>
> http://forums.codecharge.com/posts.php?post_id=68718&s_...light+grid+rows
>
>
> I even found this on another site and it seemed promising:
>
> http://www.gotocode.com/art.asp?art_id=309&
>
> //////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> Unfortunately I guess I'm too much of a newbee to get what they're talking
> about.
>
> I NEED to SEE the code for doing this.
>
> One of the posts mentioned that..
>
> "It is explained in the CCS3.1 Help, search for Component Attribute." but
> I
> have CCS 4 and can't find any USABLE example in the Help files.
>
> Could anyone please send me a snippet of code (PHP) with comments to show
> exactly how this is done?
>
> OR
>
> Could you please send me the CCS 3 help files if they indeed do contain a
> section on this.
>
> And to anyone from the CCS crew: It really seems like a basic feature
> that
> most people would want from their grid. Highlighting certain rows based on
> a
> field value should be something you could add to any grid or results via a
> wizard that simply asks for the field and values to be tested and then
> helps you
> configure the highlighting format wanted (bold font, change background
> color,
> underline, etc.).
>
> Any help would be greatly appreciated.
>
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

doug_mize

Posts: 12
Posted: 04/09/2008, 3:08 PM

OK, so I checked into the post you refer to:

http://forums.codecharge.com/posts.php?post_id=90764&s_keyword=checkbox

and it says this:

////////////////////////////////////////////////////////////////////////////////////////////////

Okay, if you're familiar with setting template variables, set one for
the row style. In your HTML:

<tr style="{rowStyle}">

In your BeforeShowRow event:

global $Tpl;
if ($Container->ds->f("id") == CCGetParam("id", "")) {
$Tpl->SetVar("rowStyle", "bgcolor='RED'");
}
else {
$Tpl->SetVar("rowStyle", "bgcolor='WHITE'");
}

Where "id" is your link parameter to show the record detail. Note that
if you have any other inline styles in your <TD>'s, those will override
what's in your <TR>. You could just set your <TD> style also as such:

<td style="{dataStyle}">

////////////////////////////////////////////////////////////////////////////////////////////////

My questions now are:

1. How do I set a template variable?

2. Where does this (<tr style="{rowStyle}">) go in my html page? Somewhere around my grid???

3. My IF statement looks like this:

if ($custlist_stockstatus1->status->GetValue() == 1)
$custlist_stockstatus1>custlist_stockstatus1->SetVar("rowStyle", "bgcolor='RED'");
else if ($custlist_stockstatus1->status->GetValue() == 2)
$custlist_stockstatus1->custlist_stockstatus1->SetVar("rowStyle", "bgcolor='YELLOW'");
else if ($custlist_stockstatus1->status->GetValue() == 3)
$custlist_stockstatus1->custlist_stockstatus1->SetVar("rowStyle", "bgcolor='GREEN'");
else if ($custlist_stockstatus1->status->GetValue() == 4)
$custlist_stockstatus1>custlist_stockstatus1->SetVar("rowStyle", "bgcolor='BLUE'");

and I am trying to get the entire row to change color based on the value of the status field. Is this code correct?

4. Where would this (<td style="{dataStyle}">) go in my html, and what does it do?

Sorry a million times over for being such an uber newbee. I've been working with CCS 4 for a little over a week. It's AMAZING software and I'm intuitively picking up most of it, but I just need to get more familiar with the concepts involved I guess.

Any help would be VERY appreciated!

Doug
View profile  Send private message
DonB
Posted: 04/10/2008, 4:56 AM

{rowStyle} == Template Variable

$Tpl->SetVar("rowStyle", "bgcolor='WHITE'"); == Setting a template variable

The template variable occurs in a row, thus it's being set for each row by
doing it in the BeforeShowRow event, which occurs for every row in a grid

My preference is to always rely on CSS styling directives
(style="background-color:xyz"), not HTML styling (BGCOLOR='zyx'), so I'd
typically create:

tr.style1 td { background-color:red }
tr.style2 td { background-color: blue}

so I'd only need to set the <tr> and not each individual <td> element:

<tr {rowStyle}>
<td>sss</td><td>sss</td><td>sss</td><td>sss</td><td>sss</td>
</tr>

HTML styling is overridden by CSS styling, if both are defined for the same
element. having BGCOLOR='blue' and style="background-color:red" will result
in the element being RED. Read about 'CSS specificity' rules for a complete
explanation at w3c.org or other places on the web.

And lastly, template variable names are case-sensitive. {rowstyle} !=
{rowStyle}

--
DonB



"doug_mize" <doug_mize@forum.codecharge> wrote in message
news:247fd3e665e6b0@news.codecharge.com...
> OK, so I checked into the post you refer to:
>
> http://forums.codecharge.com/posts.php?post_id=90764&s_keyword=checkbox
>
> and it says this:
>
> ////////////////////////////////////////////////////////////////////////////////////////////////
>
> Okay, if you're familiar with setting template variables, set one for
> the row style. In your HTML:
>
> <tr style="{rowStyle}">
>
> In your BeforeShowRow event:
>
> global $Tpl;
> if ($Container->ds->f("id") == CCGetParam("id", "")) {
> $Tpl->SetVar("rowStyle", "bgcolor='RED'");
> }
> else {
> $Tpl->SetVar("rowStyle", "bgcolor='WHITE'");
> }
>
> Where "id" is your link parameter to show the record detail. Note that
> if you have any other inline styles in your <TD>'s, those will override
> what's in your <TR>. You could just set your <TD> style also as such:
>
> <td style="{dataStyle}">
>
> ////////////////////////////////////////////////////////////////////////////////////////////////
>
> My questions now are:
>
> 1. How do I set a template variable?
>
> 2. Where does this (<tr style="{rowStyle}">) go in my html page?
> Somewhere
> around my grid???
>
> 3. My IF statement looks like this:
>
> if ($custlist_stockstatus1->status->GetValue() == 1)
> $custlist_stockstatus1>custlist_stockstatus1->SetVar("rowStyle",
> "bgcolor='RED'");
> else if ($custlist_stockstatus1->status->GetValue() == 2)
> $custlist_stockstatus1->custlist_stockstatus1->SetVar("rowStyle",
> "bgcolor='YELLOW'");
> else if ($custlist_stockstatus1->status->GetValue() == 3)
> $custlist_stockstatus1->custlist_stockstatus1->SetVar("rowStyle",
> "bgcolor='GREEN'");
> else if ($custlist_stockstatus1->status->GetValue() == 4)
> $custlist_stockstatus1>custlist_stockstatus1->SetVar("rowStyle",
> "bgcolor='BLUE'");
>
> and I am trying to get the entire row to change color based on the value
> of the
> status field. Is this code correct?
>
> 4. Where would this (<td style="{dataStyle}">) go in my html, and what
> does it
> do?
>
> Sorry a million times over for being such an uber newbee. I've been
> working
> with CCS 4 for a little over a week. It's AMAZING software and I'm
> intuitively
> picking up most of it, but I just need to get more familiar with the
> concepts
> involved I guess.
>
> Any help would be VERY appreciated!
>
> Doug
>
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

CCT


Posts: 44
Posted: 04/10/2008, 11:05 AM

I think it's recommended to use Attributes rather then template variables here. CCS Grid builder already has decent example of filling "rowStyle" attribute. Just create Grid with builder and on 5th step check "Alternate records -> Use CSS style". "Set Row Style" action will be added to Grid BeforeShowRow. This action just fills "rowStyle" attribute depending on RowNumber. This action can be easily modified (copied) to your needs.

General action code:
  
    $styles = array("Row", "AltRow");  
    if (count($styles)) {  
        $Style = $styles[($Component->RowNumber - 1) % count($styles)];  
        if (strlen($Style) && !strpos($Style, "="))  
            $Style = (strpos($Style, ":") ? 'style="' : 'class="'). $Style . '"';  
        $Component->Attributes->SetValue("rowStyle", $Style);  
    }

_________________
Get more CodeCharge Studio builders at http://codechargetools.com
View profile  Send private message
doug_mize

Posts: 12
Posted: 04/10/2008, 3:39 PM

OK,

So I put this code in the Before Show Row Event on my grid:

global $Tpl;
$Tpl->SetVar("rowStyle", "bgcolor='RED'");

then put this {rowStyle} here:

<tr class="Row" {rowStyle}>
<td>{listname} </td>
<td>{stockstatus_Symbol} </td>
<td>{TradedMarket} </td>
<td>{Close} </td>
<td>{companyname} </td>
<td>{stockname} </td>
<td>{status} </td>
<td>
</tr>

And nothing happens. I'm not even trying to add my IF conditions and it still isn't turning any row RED.

So then I tried using the CSS value like this:

global $Tpl;
$Tpl->SetVar("rowStyle", "style='background-color:RED'");

And nothing happened. Am I doing this correctly? Is there something I'm not doing? Is there more to this than simply setting these two pieces of code?

Is there some conflict with the style sheet (Black) that CCS generated by the wizard?

And finally, where would I put my IF conditions? Right after the $Tpl line in the Before Show Row Event???

Again, sorry for being such a newbee.

Thanks for bearing with me.

Doug
View profile  Send private message
wkempees


Posts: 1679
Posted: 04/11/2008, 1:34 AM

Quote :
then put this {rowStyle} here:

How did you do that?
You need to put (in HTML) your cursor on position and then right-click 'insert attribute'

Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
DonB
Posted: 04/11/2008, 12:30 PM

You can take out the suspect stylesheet and answer the one question. You
can look at the page source to see the other answer (does the styling info
appear or does it not?)

--
DonB



"doug_mize" <doug_mize@forum.codecharge> wrote in message
news:247fe9732354a8@news.codecharge.com...
> OK,
>
> So I put this code in the Before Show Row Event on my grid:
>
> global $Tpl;
> $Tpl->SetVar("rowStyle", "bgcolor='RED'");
>
> then put this {rowStyle} here:
>
> <tr class="Row" {rowStyle}>
> <td>{listname} </td>
> <td>{stockstatus_Symbol} </td>
> <td>{TradedMarket} </td>
> <td>{Close} </td>
> <td>{companyname} </td>
> <td>{stockname} </td>
> <td>{status} </td>
> <td>
> </tr>
>
> And nothing happens. I'm not even trying to add my IF conditions and it
> still
> isn't turning any row RED.
>
> So then I tried using the CSS value like this:
>
> global $Tpl;
> $Tpl->SetVar("rowStyle", "style='background-color:RED'");
>
> And nothing happened. Am I doing this correctly? Is there something I'm
> not
> doing? Is there more to this than simply setting these two pieces of
> code?
>
> Is there some conflict with the style sheet (Black) that CCS generated by
> the
> wizard?
>
> And finally, where would I put my IF conditions? Right after the $Tpl
> line in
> the Before Show Row Event???
>
> Again, sorry for being such a newbee.
>
> Thanks for bearing with me.
>
> Doug
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

doug_mize

Posts: 12
Posted: 04/14/2008, 12:18 PM

OK, I must be totally retarded.

I first tried putting an attribute called "rowStyle" into my html via a right-click like this:

<tr class="Row" {custlist_stockstatus1:rowStyle}>
<td>{listname} </td>
<td>{stockstatus_Symbol} </td>
<td>{TradedMarket} </td>
<td>{Close} </td>
<td>{companyname} </td>
<td>{stockname} </td>
<td>{status} </td>

Along with this BeforeShowRow event for my grid:

global $Tpl;
$Tpl->SetVar("rowStyle", "bgcolor='BLACK'");

if ($custlist_stockstatus1->status->GetValue() == 1)
$Tpl->SetVar("rowStyle", "bgcolor='RED'");
else if ($custlist_stockstatus1->status->GetValue() == 2)
$Tpl->SetVar("rowStyle", "bgcolor='YELLOW'");
else if ($custlist_stockstatus1->status->GetValue() == 3)
$Tpl->SetVar("rowStyle", "bgcolor='GREEN'");
else if ($custlist_stockstatus1->status->GetValue() == 4)
$Tpl->SetVar("rowStyle", "bgcolor='BLUE'");

and nothing happens. I don't get any errors, but nothing happens to my rows.

//////////////////////////////////////////////////////////////////////////////////////////////////////

Next I tried removing the attribute and inserting a form label "rowStyle" like so:

<tr class="Row" {rowStyle}>
<td>{listname} </td>
<td>{stockstatus_Symbol} </td>
<td>{TradedMarket} </td>
<td>{Close} </td>
<td>{companyname} </td>
<td>{stockname} </td>
<td>{status} </td>

with the same BeforeShowRow event for my grid and still nothing happens.

//////////////////////////////////////////////////////////////////////////////////////////////////////

Finally I went and took out the entire Styles folder to make sure there were no offending/conflicting Style Sheet problems and still nothing happens.

I'm going downright crazy with this!!!

WHAT ON EARTH COULD I BE DOING WRONG???????

And thank you to everybody that's helping me with this. I'm sure I'm frustrating you folks too.\

Doug
View profile  Send private message
DonB
Posted: 04/14/2008, 4:21 PM

You're going to have to post a link to an example. Meanwhile, you should
use the Firefox browser and load the 'Firebug' add-in so you can inspect the
style information and see what it's doing, or not as the case may be.

--
DonB



"doug_mize" <doug_mize@forum.codecharge> wrote in message
news:24803ae0a4b379@news.codecharge.com...
> OK, I must be totally retarded.
>
> I first tried putting an attribute called "rowStyle" into my html via a
> right-click like this:
>
> <tr class="Row" {custlist_stockstatus1:rowStyle}>
> <td>{listname} </td>
> <td>{stockstatus_Symbol} </td>
> <td>{TradedMarket} </td>
> <td>{Close} </td>
> <td>{companyname} </td>
> <td>{stockname} </td>
> <td>{status} </td>
>
> Along with this BeforeShowRow event for my grid:
>
> global $Tpl;
> $Tpl->SetVar("rowStyle", "bgcolor='BLACK'");
>
> if ($custlist_stockstatus1->status->GetValue() == 1)
> $Tpl->SetVar("rowStyle", "bgcolor='RED'");
> else if ($custlist_stockstatus1->status->GetValue() == 2)
> $Tpl->SetVar("rowStyle", "bgcolor='YELLOW'");
> else if ($custlist_stockstatus1->status->GetValue() == 3)
> $Tpl->SetVar("rowStyle", "bgcolor='GREEN'");
> else if ($custlist_stockstatus1->status->GetValue() == 4)
> $Tpl->SetVar("rowStyle", "bgcolor='BLUE'");
>
> and nothing happens. I don't get any errors, but nothing happens to my
> rows.
>
> //////////////////////////////////////////////////////////////////////////////////////////////////////
>
> Next I tried removing the attribute and inserting a form label "rowStyle"
> like
> so:
>
> <tr class="Row" {rowStyle}>
> <td>{listname} </td>
> <td>{stockstatus_Symbol} </td>
> <td>{TradedMarket} </td>
> <td>{Close} </td>
> <td>{companyname} </td>
> <td>{stockname} </td>
> <td>{status} </td>
>
> with the same BeforeShowRow event for my grid and still nothing happens.
>
> //////////////////////////////////////////////////////////////////////////////////////////////////////
>
> Finally I went and took out the entire Styles folder to make sure there
> were no
> offending/conflicting Style Sheet problems and still nothing happens.
>
> I'm going downright crazy with this!!!
>
> WHAT ON EARTH COULD I BE DOING WRONG???????
>
> And thank you to everybody that's helping me with this. I'm sure I'm
> frustrating you folks too.\
>
> Doug
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

doug_mize

Posts: 12
Posted: 04/14/2008, 6:18 PM

Thanks you CCT, wkempees, Kate from support and especially DonB for all of the quick, in-depth and considerate support!!!

You guys ROCK!

After trying everything suggested I finally got the rows to dynamically change colors based on a field value using the following code...

I put this in the Before Show Row event:

if ($stockstatus->status->GetValue() == 1)
$stockstatus->Attributes->SetValue("rowStyle", "bgcolor='RED'");
else if ($stockstatus->status->GetValue() == 2)
$stockstatus->Attributes->SetValue("rowStyle", "bgcolor='YELLOW'");
else if ($stockstatus->status->GetValue() == 3)
$stockstatus->Attributes->SetValue("rowStyle", "bgcolor='GREEN'");
else if ($stockstatus->status->GetValue() == 4)
$stockstatus->Attributes->SetValue("rowStyle", "bgcolor='BLUE'");

where $stockstatus is my grid/component name, status is my field/column name where I'm testing the value and rowStyle is the attribute that I set in the HTML by right-clicking like so:

<!-- BEGIN Row -->
<tr class="Row" {stockstatus:rowStyle}>
<td>{Symbol} </td>
<td>{TradedMarket} </td>
<td style="TEXT-ALIGN: right">{TradeDate} </td>
<td style="TEXT-ALIGN: right">{Close} </td>
<td>{companyname} </td>
<td>{stockname} </td>
<td style="TEXT-ALIGN: right">{status} </td>
<td>{refreshdate} </td>
</tr>
<!-- END Row -->

And BOOM! She did exactly what I wanted. So for anyone that needs to dynamically set a row color (or any other HTML or CSS attribute) based on a field value this is how you do it!

My only problem now is sorting out the conflicting style sheet stuff, in that I had to remove the Styles folder in my published folder to see the rows change colors.

If there is any advice on the best/easiest way to do this without losing all of the cool styling made by CCS then by all means, please don't hesitate to let me know.

Other than that, thanks again folks for the love! Without this robust and active forum I would have been totally and utterly screwed!

Doug

View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.