Color code element based on condition of element in list

Status
Not open for further replies.

Bren

Member
Hello.
I have a list that has a calc element that occasionally has a negative number value in it. I'd like this element's font to change to red if the value is negative. I thought this would be easy; as I'm changing both background colors and font colors of rows in a list based on 1 or more elements in the list. I've been trying to make this work for a couple of days; but now I give up and I'm looking for help. I thought I was close when I read and tried to implement a custom template of default_row.php and custom_css.php; per the following threads:

http://fabrikar.com/forums/index.php?threads/color-code-element-based-on-reference-range.25561/
http://fabrikar.com/forums/index.php?threads/notice-undefined-variable-row.38717/#post-194476

Below is what I have so far in default_row.php:
Code:
<tr id="<?php echo $this->_row->id;?>" class="<?php echo $this->_row->class;?>">
    <?php foreach ($this->headings as $heading => $label) {
                $extra_class = "";
                if ($heading == 'bw_projects___bidlaborhoursremaining') {
                  if ($row->_data->bw_projects___bidlaborhoursremaining_raw < 0) {
                      $extra_class = "lessthanzero";
                  }
                  else {
                      $extra_class = "zeroormore";
                  }
                }
        $style = empty($this->cellClass[$heading]['style']) ? '' : 'style="'.$this->cellClass[$heading]['style'].'"';
        ?>
        <td class="<?php echo $extra_class . ' ' . $this->cellClass[$heading]['class']?>" <?php echo $style?>>
            <?php echo @$this->_row->data->$heading;?>
        </td>

Below is what I have so far in custom_css.php:
Code:
.lessthanzero {
    color:red;
}   
.zeroormore {
    color:black;
}

Unfortunately, the negative values in this element stays black. Please help, anyone. Thanks in advance.
 
I think $row->_data->bw_projects__bidlaborhoursremaining_raw needs to be $this->row->_data, not $row->_data.

-- hugh
 
Hi Hugh.
I just tried your suggestion &, unfortunately, the negative values in this element stay black.
Any other suggestions?
Thanks in advance. I hope to hear from you soon.
 
following this other thread it should be $ this->_data...
a link to your list would be helpful, too.

gesendet mit Tapatalk
 
Hi Troester.

Thank you for the suggestion; but that didn't work either for me.
I would be glad to give you a link; but the site is on a local server without internet access unless using a VPN connection.
So, attached is a zip file with my custom_css.php and default_row.php files within.
You'll notice that I have separate highlight row background process before the code I shared within the default_row.php. This other highlight process still works fine.
Also, if it's possible to change the font color directly within default_row.php (instead of dealing with the class and custom_css.php) then I would be interested on how; as I'm doing something similar for separate rows with my other highlight background process.
Thanks in advance. I hope to hear from you soon.
 

Attachments

  • customTemplateFiles.zip
    2.2 KB · Views: 157
We really can't work from files like that, as obviously we don't have the same table / element setups to match your customizations.

If the site isn't reachable, we can't really help much more.

-- hugh
 
Bummer.
OK, well, how about I share all of the following code from default_row.php. Maybe something beyond what I shared will stand out as a mistake on my part.
Code:
<?php
/**
* Fabrik List Template: Admin Row
*
* @package    Joomla
* @subpackage  Fabrik
* @copyright  Copyright (C) 2005-2013 fabrikar.com - All rights reserved.
* @license    GNU/GPL http://www.gnu.org/copyleft/gpl.html
*/
 
// No direct access
defined('_JEXEC') or die;
 
//this entire page of code runs for each row - over and over
?>
 
 
<?php
// Below creates a variable "biddate" and loads each row with the biddate field
$biddate = $this->_row->data->bw_projects___biddate;
// Below the 2 lines of code pulls from the biddate variable only what is needed to run conditional if statement later
$biddate = DateTime::createFromFormat("m-d-Y l h:i:s A", $biddate);
$biddate = date_format($biddate, 'm-d-Y');
 
// Below creates a variable containing todays date
$todaysdate = date("m-d-Y");
 
// Below creates a variable "status" and loads each row with the status field
$status = $this->_row->data->bw_projects___status;
 
// Below creates a variable "department" and loads each row with the department field
$department = $this->_row->data->bw_projects___department;
 
// Below creates a variable "bidlaborhoursremaining" and loads each row with the bidlaborhoursremaining field
$bidlaborhoursremaining = $this->_row->data->bw_projects___bidlaborhoursremaining;
?>
 
<?php
// Below displays the variable data for test purposes only - comment out the lines below normally
//echo 'Bid Date: ' . $biddate . "\n";
//echo 'Todays Date: ' . $todaysdate . "\n";
//if ($bidlaborhoursremaining < 0) {
//echo $bidlaborhoursremaining;
//}
?>
 
<!-- Highlight background color YELLOW for bid day & if the status = Estimate & if the department = Contracts-->
<?php if ($biddate == $todaysdate && $status == 'Estimate' && $department == 'Contracts') { ?>
<tr style="background-color:#FFFF99" id="<?php echo $this->_row->id;?>" class="<?php echo $this->_row->class;?>">
    <?php foreach ($this->headings as $heading => $label) {
        $style = empty($this->cellClass[$heading]['style']) ? '' : 'style="'.$this->cellClass[$heading]['style'].'"';
        ?>
        <td class="<?php echo $this->cellClass[$heading]['class']?>" <?php echo $style?>>
            <?php echo @$this->_row->data->$heading;?>
        </td>
<!-- Else below are regular not highlighted rows-->
<?php }} else { ?>
<tr id="<?php echo $this->_row->id;?>" class="<?php echo $this->_row->class;?>">
    <?php foreach ($this->headings as $heading => $label) {
                $extra_class = "";
                if ($heading == 'bw_projects___bidlaborhoursremaining') {
                  if ($this->row->_data->bw_projects___bidlaborhoursremaining_raw < 0) {
                      $extra_class = "lessthanzero";
                  }
                  else {
                      $extra_class = "zeroormore";
                  }
                }
        $style = empty($this->cellClass[$heading]['style']) ? '' : 'style="'.$this->cellClass[$heading]['style'].'"';
        ?>
        <td class="<?php echo $extra_class . ' ' . $this->cellClass[$heading]['class']?>" <?php echo $style?>>
            <?php echo @$this->_row->data->$heading;?>
        </td>
<?php }} ?>
</tr>

I hope this helps with a solution and I hope to hear from you soon. Thanks in advance.
 
It must be
if ($this->_row->data->bw_projects___bidlaborhoursremaining_raw < 0)

Better close this thread and continue in standard forum (two parallel threads are confusing).
 
Yay! It works!
Great job, Troester.
Thank you for your patience, guys. You have a great day.
I'll close both threads.
 
You got lucky this time ... but in general, trying to identify an error in that much code by just looking at it, and (in this case) spotting the transposed _ (and whatever other bug it was we spotted), just isn't going to happen. It's kind of like expecting a mechanic to fix your car engine by looking at photographs of it. You may get lucky, but on the whole ... the mechanic is going to need to get their hands on your car.

-- hugh
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top