Change row background color with condition tricks.

myfatebiz

Active Member
Hi all,

I just wanna share how i figure out according my title. All just need change default_row.php on your list template.

1. Create new date element.
2. Open your default_row.php

Code:
<?php
/**
* Fabrik List Template: Default Row
*
* @package    Joomla
* @subpackage  Fabrik
* @copyright  Copyright (C) 2005 Fabrik. All rights reserved.
* @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/
 
// No direct access
defined('_JEXEC') or die;
?>
<tr 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>
    <?php }?>
</tr>

Change to

Code:
<?php
/**
* Fabrik List Template: Default Row
*
* @package    Joomla
* @subpackage  Fabrik
* @copyright  Copyright (C) 2005 Fabrik. All rights reserved.
* @license    http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/
 
// No direct access
defined('_JEXEC') or die;
?>
 
<?php
 
$date= $this->_row->data->youtablename___date_raw;
$date = strtotime($date);
$now = time();
$diff = $now - $date;
$years = floor($diff / 31556926);
 
?>
 
<!-- Color 1 -->
<?php IF ($years <= 10) { ?>
<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>
    <?php }} ?>
</tr>
<!-- Color 2 -->
<?php IF ($years > 11 && $years < 30) { ?>
<tr style="background-color:#C0C0C0" 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>
    <?php }} ?>
</tr>
<!-- Color 3 -->
<?php IF ($years > 30) { ?>
<tr style="background-color:#00FFFF" 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>
    <?php }} ?>
</tr>

Insert new record with different year on the date and the background color on the row will be change base on condition above. This also can be use on cell if you know how to figure out.

Best Regards,
MyFateBiz
 
Thanks so much
I try to have a warning message (cell color or incon warning) in list view in the case the date is exipred.
Can you help me?
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top