I have a mySQL database field, 'dischargeDate', with the type of 'date', and dates stored in the field like this: '2014-07-01' and '2013-12-23'
I'm displaying that date in the grid.
I would like to highlight the 'dischargeDate' cell WHEN the dischargeDate is less then 2014-06-01
I have this code in my grid config:
$f = array();
$f["column"] = "dischargeDate";
$f["op"] = "<";
$f["value"] = "2014-06-01";
$f["cellcss"] = "'background-color':'red'";
$f_conditions[] = $f;
This code does not highlight either: '2014-07-01' and '2013-12-23'
if I change it to: ">" it highlights BOTH: '2014-07-01' and '2013-12-23'
How do I compare date cells?
-Tom
This comparison is done on clientside (via js) so first we need to convert date format to a numeric value.
e.g.
in sql: date_format(invdate,'%Y%m%d') as invdate_calc
Now, make a hidden column to hold this formatted date.
$col = array();
$col["title"] = "Date Calc";
$col["name"] = "invdate_calc"; // sql aliased column of invdate with date format (20120101)
$col["width"] = "20";
$col["editable"] = false; // this column is editable
$col["hidden"] = true; // this column is hidden, just used for formatting
$col["search"] = false;
$cols[] = $col;
And then use this column in conditional formatting:
// If date is > than 20120101, highlight row with red
$f = array();
$f["column"] = "invdate_calc";
$f["op"] = ">";
$f["value"] = "20120101";
$f["class"] = "focus-row";
$f_conditions[] = $f;
Complete demo is located in demos/appearance/conditional-format.php