rbm1tch3ll
asked on
Coldfusion cfgrid textcolor
I am trying to make one of my columns display a different text color.
Is there a simple way of doing this?
<cfform>
<cfgrid
name="Gridforservice"
query="Gridserviceticket"
format="html"
autowidth="true"
striperows="true"
hrefkey="serviceid"
groupfield="companyid"
collapsible="true"
textcolor="Black"
>
<cfgridcolumn name="status" header="Status" textColor = "C1 eq Open ? Red : Blue" />
<cfgridcolumn name="companyid" header="Company" />
<cfgridcolumn name="storeid" header="Facility" />
<cfgridcolumn name="contact" header="Contact" />
<cfgridcolumn name="phone" header="Phone" />
<cfgridcolumn name="serviceid" header="ID" href="serviceticket_edit.c fm?id=#Gri dserviceti cket.servi ceid#" />
<cfgridcolumn name="servicedate" header="Date/Time" width="125" mask="m/d/Y - h:t" />
<cfgridcolumn name="subject" header="Subject" width="150" />
<cfgridcolumn name="request" header="Request" width="200" />
<cfgridcolumn name="urgent" header="Type" />
<cfgridcolumn name="equiptype" header="EquipType" />
</cfgrid>
Is there a simple way of doing this?
<cfform>
<cfgrid
name="Gridforservice"
query="Gridserviceticket"
format="html"
autowidth="true"
striperows="true"
hrefkey="serviceid"
groupfield="companyid"
collapsible="true"
textcolor="Black"
>
<cfgridcolumn name="status" header="Status" textColor = "C1 eq Open ? Red : Blue" />
<cfgridcolumn name="companyid" header="Company" />
<cfgridcolumn name="storeid" header="Facility" />
<cfgridcolumn name="contact" header="Contact" />
<cfgridcolumn name="phone" header="Phone" />
<cfgridcolumn name="serviceid" header="ID" href="serviceticket_edit.c
<cfgridcolumn name="servicedate" header="Date/Time" width="125" mask="m/d/Y - h:t" />
<cfgridcolumn name="subject" header="Subject" width="150" />
<cfgridcolumn name="request" header="Request" width="200" />
<cfgridcolumn name="urgent" header="Type" />
<cfgridcolumn name="equiptype" header="EquipType" />
</cfgrid>
<cfform>
<cfgrid
name="Gridforservice"
query="Gridserviceticket"
format="html"
autowidth="true"
striperows="true"
hrefkey="serviceid"
groupfield="companyid"
collapsible="true"
textcolor="Black"
>
<cfgridcolumn name="status" header="Status" textColor = "C1 eq Open ? Red : Blue" />
<cfgridcolumn name="companyid" header="Company" />
<cfgridcolumn name="storeid" header="Facility" />
<cfgridcolumn name="contact" header="Contact" />
<cfgridcolumn name="phone" header="Phone" />
<cfgridcolumn name="serviceid" header="ID" href="serviceticket_edit.cfm?id=#Gridserviceticket.serviceid#" />
<cfgridcolumn name="servicedate" header="Date/Time" width="125" mask="m/d/Y - h:t" />
<cfgridcolumn name="subject" header="Subject" width="150" />
<cfgridcolumn name="request" header="Request" width="200" />
<cfgridcolumn name="urgent" header="Type" />
<cfgridcolumn name="equiptype" header="EquipType" />
</cfgrid>
ASKER
Yes I know that can work,but what I am trying to do is have the text color be different when the field "status" is 'Open' it needs to be red, and when "status" is closed it needs to be normal black.
As you can see
<cfgridcolumn name="status" header="Status" textColor = "C1 eq Open ? Red : Black" />
Since status is my first column I have the above code but it does not work.
By the way my sql statement name is Gridserviceticket.
Your above code does change all the text in the phone column to green, but I need the above. Any help is greatly appreciated.
As you can see
<cfgridcolumn name="status" header="Status" textColor = "C1 eq Open ? Red : Black" />
Since status is my first column I have the above code but it does not work.
By the way my sql statement name is Gridserviceticket.
Your above code does change all the text in the phone column to green, but I need the above. Any help is greatly appreciated.
> textColor = "C1 eq Open ? Red : Black" />
Duh.. I missed that last part.
AFAIK, cfgrid doesn't provide a way to assign colors dynamically. You need to tap into the underlying ext grid, and assign a custom renderrer.
<cfset q = queryNew("")>
<cfset queryAddColumn(q, "status", listToArray("OPEN,closed,o pen,open,c losed,clos ed"))>
<html>
<head>
<style type="text/css">
.open { color: red; }
.closed { color: blue; }
</style>
<script type="text/javascript">
function formatStatus(data,cell,rec ord,row,co l,store) {
cell.css = data.toLowerCase() == "open" ? "open" : "closed";
return data
}
function formatCells() {
theGrid = ColdFusion.Grid.getGridObj ect("myGri d");
cm = theGrid.getColumnModel();
cm.setRenderer(0,formatSta tus);
}
</script>
</head>
<body>
<cfform>
<cfgrid name="myGrid" query="q" format="html">
<cfgridcolumn name="status" header="Status" textColor = "C1 eq Open ? Red : Blue" />
</cfgrid>
</cfform>
<cfset ajaxOnLoad("formatCells")>
</body>
</html>
Duh.. I missed that last part.
AFAIK, cfgrid doesn't provide a way to assign colors dynamically. You need to tap into the underlying ext grid, and assign a custom renderrer.
<cfset q = queryNew("")>
<cfset queryAddColumn(q, "status", listToArray("OPEN,closed,o
<html>
<head>
<style type="text/css">
.open { color: red; }
.closed { color: blue; }
</style>
<script type="text/javascript">
function formatStatus(data,cell,rec
cell.css = data.toLowerCase() == "open" ? "open" : "closed";
return data
}
function formatCells() {
theGrid = ColdFusion.Grid.getGridObj
cm = theGrid.getColumnModel();
cm.setRenderer(0,formatSta
}
</script>
</head>
<body>
<cfform>
<cfgrid name="myGrid" query="q" format="html">
<cfgridcolumn name="status" header="Status" textColor = "C1 eq Open ? Red : Blue" />
</cfgrid>
</cfform>
<cfset ajaxOnLoad("formatCells")>
</body>
</html>
ASKER
Looks GREAT!!! one question though....
to get the data from the sql into the above array what is the best way?
<cfset queryAddColumn(q, "status", listToArray("OPEN, closed....))>
if am using
<cfquery datasource="xxx" name="Gridserviceticket">
Select serviceid, status
FROM dbo.service_ticket
<cfquery>
Thanks in advance
to get the data from the sql into the above array what is the best way?
<cfset queryAddColumn(q, "status", listToArray("OPEN, closed....))>
if am using
<cfquery datasource="xxx" name="Gridserviceticket">
Select serviceid, status
FROM dbo.service_ticket
<cfquery>
Thanks in advance
Sorry ... didn't see your response yesterday.
> <cfset queryAddColumn(q, "status", listToArray("OPEN, closed....))>
> to get the data from the sql into the above array what is the best way?
That code was just for testing so could run the code standalone ie without db tables. Stick with your query and populate your grid the same way you were doing before.
> <cfset queryAddColumn(q, "status", listToArray("OPEN, closed....))>
> to get the data from the sql into the above array what is the best way?
That code was just for testing so could run the code standalone ie without db tables. Stick with your query and populate your grid the same way you were doing before.
> so could run the code standalone ie without db tables.
Gah... that should be "so ANYONE could run the code snippet without your db tables..."
Gah... that should be "so ANYONE could run the code snippet without your db tables..."
ASKER
Missing something here....
<cfajaximport tags="cfform,cfdiv, cfgrid"/>
<cfoutput> Employee:#users.user_first name# #users.user_lastname#</br>
Current Email: #users.user_email#
</cfoutput>
<cfquery datasource="xxx" name="Gridserviceticket">
SELECT serviceid, subject, userid, storeid, companyid, servicedate, request, urgent, status, equiptype, contact, phone
FROM dbo.service_ticket
ORDER BY companyid, servicedate, status ASC
</cfquery>
<cfset q = queryNew("")>
<cfset pricelist = valuelist(Gridserviceticke t.status," ,")/>
<cfset queryAddColumn(q, "status", listToArray("#Trim(priceli st)#"))>
<html>
<head>
<style type="text/css">
.open { color: red; }
.cancelled { color: green; }
</style>
<script type="text/javascript">
function formatStatus(data,cell,rec ord,row,co l,store) {
cell.css = data.toLowerCase() == "open" ? "open " : "cancelled";
return data
}
function formatCells() {
theGrid = ColdFusion.Grid.getGridObj ect("myGri d");
cm = theGrid.getColumnModel();
cm.setRenderer(0,formatSta tus);
}
</script>
</head>
<body>
<cfoutput>List: #pricelist#<br/>
</cfoutput>
<cfform>
<cfgrid name="myGrid" query="q" format="html">
<cfgridcolumn name="status" header="Status" textColor = "C1 contains Open ? Red : Blue" />
</cfgrid>
</cfform>
<cfform>
<cfgrid
name="Gridforservice"
query="Gridserviceticket"
format="html"
autowidth="true"
striperows="true"
hrefkey="serviceid"
groupfield="companyid"
collapsible="true"
textcolor="Black"
>
<cfgridcolumn name="status" header="Status" textColor = "C1 eq Open ? Red : Blue" />
<cfgridcolumn name="companyid" header="Company" />
<cfgridcolumn name="storeid" header="Facility" />
<cfgridcolumn name="contact" header="Contact" />
<cfgridcolumn name="phone" header="Phone" textcolor="green" />
<cfgridcolumn name="serviceid" header="ID" href="serviceticket_edit.c fm?id=#Gri dserviceti cket.servi ceid#" />
<cfgridcolumn name="servicedate" header="Date/Time" width="125" mask="m/d/Y - h:t" />
<cfgridcolumn name="subject" header="Subject" width="150" />
<cfgridcolumn name="request" header="Request" width="200" />
<cfgridcolumn name="urgent" header="Type" />
<cfgridcolumn name="equiptype" header="EquipType" />
</cfgrid>
</cfform>
<cfset ajaxOnLoad("formatCells")>
<cfajaximport tags="cfform,cfdiv, cfgrid"/>
<cfoutput> Employee:#users.user_first
Current Email: #users.user_email#
</cfoutput>
<cfquery datasource="xxx" name="Gridserviceticket">
SELECT serviceid, subject, userid, storeid, companyid, servicedate, request, urgent, status, equiptype, contact, phone
FROM dbo.service_ticket
ORDER BY companyid, servicedate, status ASC
</cfquery>
<cfset q = queryNew("")>
<cfset pricelist = valuelist(Gridserviceticke
<cfset queryAddColumn(q, "status", listToArray("#Trim(priceli
<html>
<head>
<style type="text/css">
.open { color: red; }
.cancelled { color: green; }
</style>
<script type="text/javascript">
function formatStatus(data,cell,rec
cell.css = data.toLowerCase() == "open" ? "open " : "cancelled";
return data
}
function formatCells() {
theGrid = ColdFusion.Grid.getGridObj
cm = theGrid.getColumnModel();
cm.setRenderer(0,formatSta
}
</script>
</head>
<body>
<cfoutput>List: #pricelist#<br/>
</cfoutput>
<cfform>
<cfgrid name="myGrid" query="q" format="html">
<cfgridcolumn name="status" header="Status" textColor = "C1 contains Open ? Red : Blue" />
</cfgrid>
</cfform>
<cfform>
<cfgrid
name="Gridforservice"
query="Gridserviceticket"
format="html"
autowidth="true"
striperows="true"
hrefkey="serviceid"
groupfield="companyid"
collapsible="true"
textcolor="Black"
>
<cfgridcolumn name="status" header="Status" textColor = "C1 eq Open ? Red : Blue" />
<cfgridcolumn name="companyid" header="Company" />
<cfgridcolumn name="storeid" header="Facility" />
<cfgridcolumn name="contact" header="Contact" />
<cfgridcolumn name="phone" header="Phone" textcolor="green" />
<cfgridcolumn name="serviceid" header="ID" href="serviceticket_edit.c
<cfgridcolumn name="servicedate" header="Date/Time" width="125" mask="m/d/Y - h:t" />
<cfgridcolumn name="subject" header="Subject" width="150" />
<cfgridcolumn name="request" header="Request" width="200" />
<cfgridcolumn name="urgent" header="Type" />
<cfgridcolumn name="equiptype" header="EquipType" />
</cfgrid>
</cfform>
<cfset ajaxOnLoad("formatCells")>
You don't need all of the code from the demo example, only the javascript. Everything else will stay the same.
<html>
<head>
<style type="text/css">
.open { color: red; }
.cancelled { color: green; }
</style>
<script type="text/javascript">
function formatStatus(data,cell,record,row,col,store) {
cell.css = data.toLowerCase() == "open" ? "open " : "cancelled";
return data
}
function formatCells() {
theGrid = ColdFusion.Grid.getGridObject("Gridforservice");
cm = theGrid.getColumnModel();
cm.setRenderer(0,formatStatus); //0- first column, 1-second column ....
}
</script>
</head>
<body>
<!--- YOUR CFGRID HERE ....--->
<cfform>
<cfgrid name="Gridforservice" query="Gridserviceticket" ...>
....
</cfgrid>
</cfform>
<cfset ajaxOnLoad("formatCells")>
</body>
</html>
ASKER
I have copied the above and inserted my code, still doesn't work...
I get all green "open"
Any ideas?
I get all green "open"
Any ideas?
What's your CF version? What are the possible values in the status column? Is one of them "open" exactly (no spaces..)?
Also, when you ran the demo example, did it work for you?
ASKER
Yes, the demo worked great...
The only possible solution I see is that the data is coming over with white spaces behind it....
Would I be better off to make the status a number?
The only possible solution I see is that the data is coming over with white spaces behind it....
Would I be better off to make the status a number?
ASKER
CF9
ASKER
GOT IT.
I had white spaces in the sql statement.
used the following
SELECT RTRIM(status) as status
from database table
IT WORKED THANKS SO MUCH!!!!
I had white spaces in the sql statement.
used the following
SELECT RTRIM(status) as status
from database table
IT WORKED THANKS SO MUCH!!!!
ASKER
Quick question...
If I wanted to have the following what would need to be modified?
Open = Red
Closed = Black
Cancelled = Blue
Thanks again!!!!!
If I wanted to have the following what would need to be modified?
Open = Red
Closed = Black
Cancelled = Blue
Thanks again!!!!!
You should only need to change the CSS here:
<style type="text/css">
.open { color: red; }
.closed { color: black; }
.cancelled { color: green; }
</style>
And if those 3 are the only possible values, change the javascript function formatStatus to:
function formatStatus(data,cell,rec ord,row,co l,store) {
cell.css = data.toLowerCase();
return data
}
<style type="text/css">
.open { color: red; }
.closed { color: black; }
.cancelled { color: green; }
</style>
And if those 3 are the only possible values, change the javascript function formatStatus to:
function formatStatus(data,cell,rec
cell.css = data.toLowerCase();
return data
}
> Would I be better off to make the status a number?
For comparisons, using a number is almost always better. Because then you don't have to worry about white space or upper/lower case. But they're less intuitive than seeing a string like "closed".
For comparisons, using a number is almost always better. Because then you don't have to worry about white space or upper/lower case. But they're less intuitive than seeing a string like "closed".
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks so much for your help....
ASKER
GREAT PROVIDER!!!!
very helpful.
very helpful.
You're welcome :)
ie <cfgridcolumn name="phone" header="Phone" textColor="green"/>