Row colours depending on a field's value?

Discuss about features you want to see in the next versions of ApPHP DataGrid. Your requests and offers.

Moderators: ne_moj, zewa

fcsabihu
Junior
Junior
Posts: 14
Joined: Oct 14th, '09, 08:54

Row colours depending on a field's value?

Postby fcsabihu » Oct 30th, '11, 12:51

Hi all,

I'm pretty sure that there's a way to do this with custom templates, but it can be easier and v. useful when for example:

- displaying active/inactive records in view mode,
- displaying a date that has passed or is near,
- displaying low sales records...

Neils

administrator
Site Admin
Site Admin
Posts: 5937
Joined: Jan 7th, '09, 23:18
Contact:

Re: Row colours depending on a field's value?

Postby administrator » Oct 31st, '11, 08:40

The way to display active/inactive records in View Mode:
SELECT ....
IF(is_active = 1, '<font color=green>Yes</font>', '<font color=red>No</font>') as active

akroll
Senior
Senior
Posts: 33
Joined: Dec 27th, '11, 08:16

Re: Row colours depending on a field's value?

Postby akroll » Jan 17th, '12, 14:14

- displaying a date that has passed or is near

this point is interesting for me. how can i change the color of a date if it near or passed?
EDIT: I have found it. But why this doesn't work:

Code: Select all

    $datum = date("d-n-Y");
    function setColor($field_value){
           if($field_value >= $datum){
              return "<font color='red'>".$field_value."</font>";       
        }
    }

on_item_created exists

Code: Select all

         "Control"=>array("header"=>"Control",      "type"=>"Textbox",  "align"=>"left", "width"=>"200px", "wrap"=>"nowrap", "text_length"=>"-1", "tooltip"=>"false", "tooltip_type"=>"floating|simple", "case"=>"normal", "summarize"=>"false", "summarize_sign"=>"", "sort_type"=>"string|numeric", "sort_by"=>"", "visible"=>"true", "on_js_event"=>"", "on_item_created"=>"setColor"), 


EDIT: that's the solution

Code: Select all

   function setColor($field_value){               
                   if(strtotime($field_value) <= strtotime(date("d-m-Y"))){
                      return "<div class=\"redmark\">".$field_value."</div>";
                   }if(strtotime($field_value) == strtotime(date("d-m-Y"))){
                        return "<div class=\"normalmark\">".$field_value."</div>";               
                   }if(strtotime($field_value) > strtotime(date("d-m-Y"))){
                        return "<div class=\"normalmark\">".$field_value."</div>";                                             
                   }else{
                        return $field_value;
                        }
                  }

write the $datum in date(d-m-Y)! not as string (otherwise: undefinded variable (see it in debug mode...))

akroll
Senior
Senior
Posts: 33
Joined: Dec 27th, '11, 08:16

Re: Row colours depending on a field's value?

Postby akroll » Feb 27th, '12, 14:02

How can I color the entire row and not just a single value?
i have edit the colors.inc.php

Code: Select all

<?php
$verbindung = mysql_connect("xxxx", "xxxx" , "xxx")
or die("Verbindung zur Datenbank konnte nicht hergestellt werden");
mysql_select_db("xxx") or die ("Datenbank konnte nicht ausgewählt werden");
$abfrage = "SELECT DATE_FORMAT(eControl,'%d-%m-%Y') AS eControl FROM orders";
$ergebnis = mysql_query($abfrage);
$row = mysql_fetch_object($ergebnis);
$row->eControl;
if(!isset($eControl)){
          $eControl = "";
}
if(strtotime($eControl) < strtotime(date("d-m-Y"))){
                    $rowColor = array();
                    $rowColor[0] = "#FF0000";
                    //$rowColor[0] = "#F0F0F0"; // odd row color
                    $rowColor[1] = "#E0E0E0"; // even row color
                    $rowColor[2] = ""; // odd row color in main colomn
                    $rowColor[3] = ""; // even row color in main colomn
                    $rowColor[4] = "#E2F0D6"; // row mouse over lighting
                    $rowColor[5] = ""; // on mouse click
                    $rowColor[6] = ""; // header (th main) column
                    $rowColor[7] = ""; // selected row mouse over lighting
                    $rowColor[8] = "#e9e9e9";
                    $rowColor[9] = "#cdcdcd";
}else{
          echo "funktioniert nicht";
}

I want only add a css class in the <tr>
Is there an easier way?
maybe with sessions. if it works.

administrator
Site Admin
Site Admin
Posts: 5937
Joined: Jan 7th, '09, 23:18
Contact:

Re: Row colours depending on a field's value?

Postby administrator » Feb 28th, '12, 08:07

You have to add(develop) OnRowCreated trigger and there all needed functionality

akroll
Senior
Senior
Posts: 33
Joined: Dec 27th, '11, 08:16

Re: Row colours depending on a field's value?

Postby akroll » Feb 28th, '12, 08:51

i need more informations about that. is a non-documented feature?

administrator
Site Admin
Site Admin
Posts: 5937
Joined: Jan 7th, '09, 23:18
Contact:

Re: Row colours depending on a field's value?

Postby administrator » Feb 29th, '12, 09:09

No it doesn't exists, but you may create your own function (inside DataGrid), that creates a row background color variable and then assign it according to some field value.
There is only one problem - row is created before any TD (cell) in it.


Return to “ApPHP DataGrid {future features}”