Link to home
Start Free TrialLog in
Avatar of earwig75
earwig75

asked on

Trying to change CFGRID column color

I am trying to use the below example to change the color of a grid column based on output. The difference between my grid and the example below is, my grid uses a "bind" to the query. Can someone help me understand what I need to change (other than taking out the loop)?

Thank you.

<cfajaximport/>
<html>

<head>
<script>
		
myf = function(data,cellmd,record,row,col,store) {
	if(data == "Product 4") return "<font color='red'>" + data + "</font>";
	else if(data == "Product 5") return "<font color='green'>" + data + "</font>";
	else return data;
}
testgrid = function() {
	mygrid = ColdFusion.Grid.getGridObject('data');
	cm = mygrid.getColumnModel();
	cm.setRenderer(0, Ext.util.Format.usMoney);
	cm.setRenderer(1,myf);
	mygrid.reconfigure(mygrid.getStore(),cm);
}
</script>
</head>

<body>

<cfset data = queryNew("price,product")>
<cfloop from=1 to=10 index="x">
	<cfset total = randRange(20,100) & "." & randRange(1,99)>
	<cfset product = "Product #X#">
	<cfset queryAddRow(data)>
	<cfset querySetCell(data, "price", total+0, x)>
	<cfset querySetCell(data, "product", product, x)>
</cfloop>

<cfform name="test">
<cfgrid autowidth="true" name="data" format="html" query="data" width="600">
   <cfgridcolumn name="price" header="Price">
   <cfgridcolumn name="product" header="Product">
</cfgrid>
</cfform>

<cfset ajaxOnLoad("testgrid")>
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Coast Line
Coast Line
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial