Reputation: 59
I'm building an app in Coldfusion, basically it's a module that tracks when memberships expire. I'm building an index of all members, I am wanting to use cfgrid.
Is there a way to specificy that within x days of the membership expiring for the row to get highlighted?
Thanks!
Upvotes: 0
Views: 1280
Reputation: 1397
Yes
<cfajaximport/>
<html>
<head>
<script>
myf = function(data,cellmd,record,row,col,store) {
// hard code a date to check against "13 Jan 2011"
// note 0 based month index
var today = new Date(2011,0,13);
if(data < today) {
//before displaying format the date
var curr_date = data.getDate();
var curr_month = data.getMonth();
//javascript has month as a 0 based index so add one
curr_month++;
var curr_year = data.getFullYear();
return "<span style='color:red;font-weight:bold;'>" + curr_date + "-" + curr_month + "-" + curr_year + "</span>";
}
else {
//before displaying format the date
var curr_date = data.getDate();
var curr_month = data.getMonth();
//javascript has month as a 0 based index so add one
curr_month++;
var curr_year = data.getFullYear();
return curr_date + "-" + curr_month + "-" + curr_year;
}
}
testgrid = function() {
mygrid = ColdFusion.Grid.getGridObject('data');
cm = mygrid.getColumnModel();
// render the first column (0 based index) using the myf function above
cm.setRenderer(0,myf);
mygrid.reconfigure(mygrid.getDataSource(),cm);
}
</script>
</head>
<body>
<!--- create a hard coded query for testing --->
<cfset data = queryNew("expiryDate,member")>
<cfloop from=1 to=31 index="i">
<cfset expiryDate = createDate(2011,1,i)>
<cfset member = "Member #i#">
<cfset queryAddRow(data)>
<cfset querySetCell(data, "expiryDate", expiryDate, i)>
<cfset querySetCell(data, "member", member, i)>
</cfloop>
<cfform name="test">
<cfgrid autowidth="true" name="data" format="html" query="data" width="600">
<cfgridcolumn name="expiryDate" header="Expiry Date">
<cfgridcolumn name="member" header="Member">
</cfgrid>
</cfform>
<cfset ajaxOnLoad("testgrid")>
</body>
</html>
Upvotes: 0
Reputation: 4118
To do this you would probably have to write some JavaScript yourself. First get the ExtJS object via ColdFusion.Grid.getGridObject then look at the ExtJS docs (http://dev.sencha.com/deploy/dev/docs/) to see what can be done.
Another option would be to do the calculation in ColdFusion and add another column to the grid.
Upvotes: 1