Using dates for applying conditional formatting on the client side to a Grid is harder than it should be IMHO. I was battling with this for a few hours today with some pretty confusing results but have come up with this solution thanks to some posts on and off this forum.
Notes:
In my case I use dates in dd/mm/yyyy format which I think causes additional challenges when comparing dates in Alpha, however this solution works regardless of date format.
The date Alpha passes from the Grid is a string, hence the need to convert it to a date as follows.
Paste these 2 functions into your Grid's Javascript Functions area.
function stringToDate(_date,_format,_delimiter)
{
var formatLowerCase=_format.toLowerCase();
var formatItems=formatLowerCase.split(_delimiter);
var dateItems=_date.split(_delimiter);
var monthIndex=formatItems.indexOf("mm");
var dayIndex=formatItems.indexOf("dd");
var yearIndex=formatItems.indexOf("yyyy");
var month=parseInt(dateItems[monthIndex]);
month-=1;
var formatedDate = new Date(dateItems[yearIndex],month,dateItems[dayIndex]);
return formatedDate;
}
function isOverdue(MyDate) {
var TodayDate = new Date();
var TestDate = stringToDate(MyDate,"dd/MM/yyyy","/");
if (TodayDate >= TestDate ) {
return true;
} else {
return false;
}
}
Paste this JS into your conditional style (client side) and set your conditional formatting (eg font colour) to suit
isOverdue(DateTargeted) = true
Note: DateTargeted was the name of the field on my Grid, you would use the name of your date field.
Depending on your situation you may also want to create a 2nd condition to set the style back to normal
isOverdue(DateTargeted) = false
I hope this helps.
Notes:
In my case I use dates in dd/mm/yyyy format which I think causes additional challenges when comparing dates in Alpha, however this solution works regardless of date format.
The date Alpha passes from the Grid is a string, hence the need to convert it to a date as follows.
Paste these 2 functions into your Grid's Javascript Functions area.
function stringToDate(_date,_format,_delimiter)
{
var formatLowerCase=_format.toLowerCase();
var formatItems=formatLowerCase.split(_delimiter);
var dateItems=_date.split(_delimiter);
var monthIndex=formatItems.indexOf("mm");
var dayIndex=formatItems.indexOf("dd");
var yearIndex=formatItems.indexOf("yyyy");
var month=parseInt(dateItems[monthIndex]);
month-=1;
var formatedDate = new Date(dateItems[yearIndex],month,dateItems[dayIndex]);
return formatedDate;
}
function isOverdue(MyDate) {
var TodayDate = new Date();
var TestDate = stringToDate(MyDate,"dd/MM/yyyy","/");
if (TodayDate >= TestDate ) {
return true;
} else {
return false;
}
}
Paste this JS into your conditional style (client side) and set your conditional formatting (eg font colour) to suit
isOverdue(DateTargeted) = true
Note: DateTargeted was the name of the field on my Grid, you would use the name of your date field.
Depending on your situation you may also want to create a 2nd condition to set the style back to normal
isOverdue(DateTargeted) = false
I hope this helps.
Comment