CONDITIONAL FORMATTING FOR DATE TYPE CELL

QuestionsCONDITIONAL FORMATTING FOR DATE TYPE CELL
Cedric asked 2 years ago

Hello,

I have been looking at other post for this solution by I am stuck with this:

DATEDIFF(Sa_Pdate,$today) as diffdate

// If peremption date is < than today, highlight row with red

$f = array();
$f[“column”] = “diffdate”;
$f[“op”] = “<“;
$f[“value”] = 1;
$f[“class”] = “focus-red”;
$f_conditions[] = $f;

// If peremption date is < 60, highlight row with yellow

$f = array();
$f[“column”] = “diffdate”;
$f[“op”] = “<“;
$f[“value”] = 60;
$f[“class”] = “focus-yellow”;
$f_conditions[] = $f;

The row remains highlited in yellow….

View post on imgur.com

3 Answers
Mike answered 2 years ago

I think the order of operations is causing your issue.

The yellow highlight function is coming after the red highlight function, so it’s turning red, then getting to the yellow function, which it also matches, and turning it yellow.

Negative 20 matches both conditions: It’s less than 1 and also less than 60.

I think you need to use a different method to set the datediff column. I would handle this with SQL Queries, so you can use if/then statements. Set the color to return and just match the color with PHP Grid. Having the logic in the dataset makes reporting a lot easier. Below is pseudo code in SQL Server Format as a guideline.

CASE

When DATEDIFF(Sa_Pdate,$today) < 1 Then ‘RED’

When DATEDIFF(Sa_Pdate,$today) > 1 and < 60 Then ‘YELLOW’

When DATEDIFF(Sa_Pdate,$today) > 60 Then ‘GREEN’

END AS DATEDIFF

 

// Set Color

$f = array();
$f[“column”] = “diffdate”;
$f[“op”] = “-“;
$f[“value”] = “YELLOW”;
$f[“class”] = “focus-yellow”;
$f_conditions[] = $f;

Cedric answered 2 years ago

Hi Mike,

Thanks for your answer. but I can\’t make this working… It\’s either one color or the other…

The class name should be dynamic like focus-$difffate right?

Abu Ghufran Staff answered 1 year ago

Hello,

Mike’s solution is correct.

It’s pretty late reply, however it would also work if you just change the array order. Set diffdate<60 format condition first in $f_conditions array and then diffdate<1.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Your Answer

14 + 8 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?