Question

How do I change the color of a cfgrid row when the date field is older than 90 days?

Asked by: futr_vision

I have a ColdFusion 8 HTML cfgrid that contains a "last modified" column which is the date the record was last modified. I want to visually alert the user when the record is older than 90 days by changing the color of the row's background. How do I do this?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-06-10 at 13:01:25ID24480848
Tags

cfml

,

coldfusion 8

,

cfgrid

Topics

ColdFusion Application Server

,

Cold Fusion Markup Language

Participating Experts
1
Points
500
Comments
53

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. CFGRID
    I have a page where I use CFGRID to display the results. I need to validate that the filed type is always "slide". I have tried using the ONVALIDATE but cannot get the javascript correct. Does anybody know how to do this? The code is as follows: <cfform name=&qu...
  2. CFGRID finding column names
    How do you find the column names that are returned from a CFGRID form dynamically. I can see they are returned when I do a cfdump but don't know how to call them. My code: <cfif IsDefined("form.__CFGRID__CFFORM_2__GRIDEDIT") is True> <cfdump var="#...
  3. CFGRID MARGIN
    How do you get rid of the extra brown/grey looking margin on the right and bottom of the CFGRID HTML version???? it looks ugly!
  4. cfgrid clickable rows in mx7
    I am trying to implement cfgrid This part is wrking . What i am trying ot do is once the grid is loaded click on the or and get redirected to a diff page . I aknow that it has to be some JS here ANd the url shoud be something like this <cfif getSurvey.surveyID neq &qu...
  5. Change style of cfgrid row in a coldfusion flash form?
    Is there a way to specially format a particular row of a cfgrid (in a flash form) based on a returned query value? Here's an example In this example if the "compliant" column is false I would like to highlight that row and change the font color. Can this be done?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: larksysPosted on 2009-06-10 at 13:46:45ID: 24596216

The following goes in the <head>;

<cfajaximport tags="cfform, cfdiv, cfgrid">
<!--- Special rendering for company name colors --->
<script type="text/javascript" language="javascript">
// custom renderer for Color column
function renderName(data,cellmd,record,row,col,store) {
 if (record.data.STRUCTURE_COLOR_CODE && record.data.STRUCTURE_COLOR_CODE != 'undefined') return '<b style="color:#' + record.data.STRUCTURE_COLOR_CODE.replace(new RegExp("^[\\s]+", "g"), "") + ';">' + data + '<b>';
 else return data;
 }
// function to invoke custom renderers and return re-configured grid (called from ajaxonload()
function CompRendGrid() {
  mygrid = ColdFusion.Grid.getGridObject('grid_Companies');
  cm = mygrid.getColumnModel();
  cm.setRenderer(2,renderName); // assign custom renderer for Name column in the grid
  mygrid.reconfigure(mygrid.getDataSource(),cm); // reconfigure grid
}
</script>            
<!--- fire the custom grid renderers on pageload --->
<cfset ajaxOnLoad("CompRendGrid")>
</cfif>


The setRenderer function is passed the grid column number 2 for the company name column. In the function RenderName you will see that I test the grid column record.data.STRUCTURE_COLOR_CODE. You can change that to test for your date field. The column name ends up in all caps, so be sure to code it in caps.  I believe the column number is relative to zero. You might have to play around with it a bit to find out.

The CompGridRend function defines mygrid using the name of your cfgrid. Mine is grid_Companies.

This is using the default EXT that comes with CF8.

 

by: futr_visionPosted on 2009-06-10 at 13:55:18ID: 24596343

A couple of things. First, I probably should have stated that I am very green when it comes to programming so much of what you gave me is greek and I'm not really sure where to start with modifying it. Secondly, I see a closing </cfif> but no opening <cfif>. Am I missing something?

 

by: larksysPosted on 2009-06-10 at 14:03:46ID: 24596461

The closing /cfif needs to be ignored. I only include the EXT code on certain conditions and left out the opening cfif.

I understand being "green". No problem.  If you will just plop the code into your code and make the changes you understand, I will try to help you through the errors.  Do you use Firefox?  If you do, you need to add the Firebug plug-in. It's a great debugging tool.

 

by: futr_visionPosted on 2009-06-10 at 14:47:21ID: 24596916

Yes I have firebug installed but I don't really know how to use it to debug.

Here is what I have done:

1. Dropped the code in the head
2. Changed the grid name to the grid name I am using (I use two grids with the same name. One or the other is shown based on the user's access level. I don't think this will be an issue since I want the custom render to work on both.)

Questions:
1. The first column in my grid is not displayed. It still has a row number correct? (I believe the cfgrid index starts at "0")
2. What data source do I use in mygrid.getDataSource()?

 

by: larksysPosted on 2009-06-10 at 14:55:48ID: 24596988

All columns have a column number whether displayed or not. The mygrid.getdatasource is a quasi grid refresh. Nothing need to be changed there.

 

by: futr_visionPosted on 2009-06-10 at 15:07:41ID: 24597062

OK. Code is in place and it is not throwing any errors but I'm not seeing any changes in the grid either.

 

by: larksysPosted on 2009-06-10 at 15:13:08ID: 24597099

Show me the code you added and the code for one of your grids.

 

by: futr_visionPosted on 2009-06-10 at 15:23:44ID: 24597158

<cfajaximport tags="cfform, cfdiv, cfgrid">
<!--- Special rendering for company name colors --->
<script type="text/javascript" language="javascript">
// custom renderer for Color column
function renderName(data,cellmd,record,row,col,store) {
 if (record.data.STRUCTURE_COLOR_CODE &&  record.data.STRUCTURE_COLOR_CODE != 'undefined') return '<b style="color:#' + record.data.STRUCTURE_COLOR_CODE.replace(new RegExp("^[\\s]+", "g"), "") + ';">' + data + '<b>';
 else return data;
 }
// function to invoke custom renderers and return re-configured grid (called from ajaxonload()
function CompRendGrid() {
  mygrid = ColdFusion.Grid.getGridObject('clients');
  cm = mygrid.getColumnModel();
  cm.setRenderer(7,renderName); // assign custom renderer for Name column in the grid
  mygrid.reconfigure(mygrid.getDataSource(),cm); // reconfigure grid
}
</script>            
<!--- fire the custom grid renderers on pageload --->
<cfset ajaxOnLoad("CompRendGrid")>



<--- GRID ---->
  <cfif ListContains("user", Session.MM_UserAuthorization)>
    <cfform name="Clients" >
      <cfgrid name="clients"
         format="html"
         striperows="yes"
         colheaderbold="yes"
         colheaderfontsize="12"
         pagesize="15"
         selectmode="row"
         bind="cfc:CFC.clients.getData({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})">
        <cfgridcolumn name="client_ID" display="no"/>
        <cfgridcolumn name="client_name" width="275" header="Client"/>
        <cfgridcolumn name="alliance" width="60" header="Alliance"/>
        <cfgridcolumn name="owner" width="60" header="Owner"/>
        <cfgridcolumn name="FET_prospect" width="90" header="FET Prospect"/>
        <cfgridcolumn name="date_added" width="140" header="Date Added"/>
        <cfgridcolumn name="status" width="90" header="Status" values="Remove,NA,Interested,Contract Pending,Contract Signed"/>
        <cfgridcolumn name="last_modified" width="140" header="Last Modified"/>
      </cfgrid>
        <cfinput type="button" name="Download" value="Download" onClick="doDownload()">    
    </cfform>
  </cfif>

 

by: larksysPosted on 2009-06-10 at 15:35:49ID: 24597228

if (record.data.STRUCTURE_COLOR_CODE &&  record.data.STRUCTURE_COLOR_CODE != 'undefined') return '<b style="color:#' + record.data.STRUCTURE_COLOR_CODE.replace(new RegExp("^[\\s]+", "g"), "") + ';">' + data + '<b>';
 else return data;

You need to change the above script to check for your date field. A good test would be to not use an IF and just use;

 return '<b style="color:blue;"> + data + '</b>';

That should change the text color of column 7 (date modified) to blue on all rows.
 

 

by: larksysPosted on 2009-06-10 at 15:37:08ID: 24597236

return '<b style="color:blue;">' + data + '</b>';

I missed an apostrophe.

 

by: larksysPosted on 2009-06-10 at 15:39:06ID: 24597253

I don't know what format your "last modified" date is in, but you may have to dig up some javascript date handling to get the results you want.

 

by: futr_visionPosted on 2009-06-10 at 15:57:32ID: 24597341

Ok. Got something to happen this time. All the text in the column is now blue even the hidden "null" values ;)

Ideally I'd like to change the background of the entire row if possible or just the color of those cells that validate to the date logic I need to put in place.

Would this be of any help in making that happen?

Here's how I change the color of a cfgrid row depending on the row's query variables.

1. Select a styles column into your query in your cfc. We'll querysetcell that column later when we know what it should be. I tried using row_number() in the select statement query to match to the cell numbers, but it wasn't working out.

<cfquery name="thisquery" datasource="#dsn#">
SELECT *, '' as styles FROM table
</cfquery>

2. You have to set the background color for cells individually, can't do whole specific rows, unfortunately, given the identifiers we have to work with. Since my grids never have more than 10 columns, I set the background colors for 10 cells for each row needing a bg color (to keep it standard across my grids.

For example, to change the first cell in the first row, set the class .x-grid-cell-0-1 to your bg color. For row 9, cell 4, the class is .x-grid-cell-8-4. Keep in mind that the row number is not simply currentrow-1 of the query. It is the row number of the current page of the grid (0 to #pagesize#, NOT 0 to #recordcount# unless you don't use paging). So, after I have my query, I then run this little blurb to set the styles, for the cells of each row. You can tailor it to be specific to rows that need color, of course:

<cfset this_row = 0>
<cfset this_limit = pagesize - 1>
<cfoutput query="thisquery">
   <cfset this_color = "dddddd">
   <cfif somequerycolumn IS "somevalue"><cfset this_color = "ffcc00"></cfif>
   <cfset temp = #QuerySetCell(thisquery, "styles", "<STYLE TYPE=""text/css"">.x-grid-cell-#this_row#-1,.x-grid-cell-#this_row#-2,.x-grid-cell-#this_row#-3,.x-grid-cell-#this_row#-4,.x-grid-cell-#this_row#-5,.x-grid-cell-#this_row#-6,.x-grid-cell-#this_row#-7,.x-grid-cell-#this_row#-8,.x-grid-cell-#this_row#-9,.x-grid-cell-#this_row#-10 {background:###this_color#;}</STYLE>", currentrow)#>
   <cfif this_row LT this_limit><cfset this_row = this_row + 1><cfelse><cfset this_row = 0></cfif>
</cfoutput>

3. In the cfgrid, I have a column for styles that is display="no". The styles are written but not displayed, and it seems to work fine after a lot of trial and error.

 

by: futr_visionPosted on 2009-06-10 at 15:59:24ID: 24597349

Oh - "date modified" is in datetime format. I'd like to mask the time portion but apparently that is only;y available for Flash cfgrids.

 

by: larksysPosted on 2009-06-10 at 16:35:48ID: 24597549

You could always try using ;

textColor = "(CX EQ Pam ? blue : black)">

on your cfgridcolumns.

 In your query you might want to evaluate the date against todays date and return a 1 or 0 or a number that represents the days difference.

something like;  select (datediff(now - last_modified) as datecheck

Then on your cfgridcolumn; bgcolor = "(c11 lt 30 ? blue : white)"
assuming the new cfgridcolumn for datecheck is column 11.

Hope I'm not confusing the issue.

 

by: futr_visionPosted on 2009-06-10 at 17:02:38ID: 24597709

Yeah. I'm a bit confused. I've spent too much time on the front end of applications and websites and not much time trolling around on the back end.

1. So, the proposal to use textColor = "(CX EQ Pam ? blue : black)">  will do what?

2. I should use select (datediff(now - last_modified) in my cfgrid query? I'm not sure how to implement that.

3. I'm not exactly sure what bgcolor = "(c11 lt 30 ? blue : white)" does. Is that basically saying to color the background of column 11 blue or white? I'm not clear what It 30 is.

 

by: larksysPosted on 2009-06-10 at 18:54:15ID: 24598191

!. textcolor and bgcolor are paramaters of the cfgricolumn tag. You can use it to color the text or background of a grid cell. You can use the same expression on all grid columns if you wish to color the row. But you need some test like I usedd in the example. You can use your grid bind query to create a column for the grid (datecheck) and use that column to set the color of all the other columns.

2. You can add the SQL statement to create the datecheck column for use in the cfgrid. Maybe you should post your SQL code.

These are the 2 options that I can think of to change the color of gridf columns;
         A. Use the EXT code and change the javascript to test the date column to determine if you want to change the column color.
         B. Use the textcolor or bgcolor paramaters of the cfgridcolumn tag to change the colors.


 

by: futr_visionPosted on 2009-06-10 at 19:29:06ID: 24598326

You are probably ready to give up on me at this point and I appreciate your dedication but I am still not getting how to put this all together. I get the logic behind what needs to happen but actually coding the test portion and pulling it all together in a nice neat package is beyond me.

Here is the SQL code for one of the queries. The query for the second cfgrid is nearly identical with the exception that it limits the results based on the user's credentials.

   <cffunction name="getClientsAdmin" access="remote" returntype="struct">
      <cfargument name="page" type="numeric" required="yes">
      <cfargument name="pageSize" type="numeric" required="yes">
      <cfargument name="gridsortcolumn" type="string" required="no" default="">
      <cfargument name="gridsortdir" type="string" required="no" default="">
 
      <!--- Get data for Admin grid --->
      <cfquery name="clients" datasource="#THIS.dsn#">
      SELECT *
      FROM Clients
      <cfif gridsortcolumn NEQ ""
         and gridsortdir NEQ "">
         ORDER BY #gridsortcolumn# #gridsortdir#
      </cfif>
      </cfquery>
 
 
    <cfreturn queryconvertforgrid(clients,page,pagesize)/>
   </cffunction>
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:

Select allOpen in new window

 

by: larksysPosted on 2009-06-10 at 19:45:01ID: 24598372

<cfquery name="clients" datasource="#THIS.dsn#">
      SELECT *,(datediff(now - last_modified) as datecheck<----------- add this code
      FROM Clients
      <cfif gridsortcolumn NEQ ""
         and gridsortdir NEQ "">
         ORDER BY #gridsortcolumn# #gridsortdir#
      </cfif>
      </cfquery>

Add this grid column;
<cfgridcolumn name="DateCheck" display="no"/>

Change this grid column;
<cfgridcolumn name="last_modified" width="140" header="Last Modified" bgcolor = "(c11 lt 30 ? blue : white)"/>

Actually make the datechecck column display="yes" so you can see the data (temporary).

 

by: futr_visionPosted on 2009-06-10 at 23:47:37ID: 24599341

Adding ,(datediff(now - last_modified) as datecheck causes the app to throw an error.

 

by: larksysPosted on 2009-06-11 at 08:05:38ID: 24603209

What's the error?  Post the SQL code

 

by: futr_visionPosted on 2009-06-11 at 12:07:48ID: 24605676

I get a dialogue box on loading that says:

 Error invoking CFC /CFC/clients.cfc : Internal Server Error [Enable debugging by adding 'cfdebug' to your URL parameters to see more information]


Firebug is showing the getClient method in the CFC failing.

 

by: larksysPosted on 2009-06-11 at 13:56:32ID: 24606793

Can you look at the application log on your CF server? It would have details of the error.

 

by: larksysPosted on 2009-06-11 at 14:08:43ID: 24606893

I believe I got the following code wrong;

  SELECT *,(datediff(now - last_modified) as datecheck<----------- add this code

It should be;

  SELECT *,(datediff("d", last_modified,#now()#) as datecheck<----------- add this code

I just verified this in my code.

 

by: futr_visionPosted on 2009-06-11 at 14:11:24ID: 24606919

I don't have access to that but I can ask for it. I'd try an test this locally but I'd have to spend some time setting up the DB and CF but that will probably take longer.

 

by: larksysPosted on 2009-06-11 at 14:29:38ID: 24607089

make the change I suggested and that will probably fix the error

 

by: futr_visionPosted on 2009-06-11 at 15:51:00ID: 24607697

Well, it's still throwing an error.

 

by: futr_visionPosted on 2009-06-11 at 16:01:34ID: 24607755

Aha!

The parentheses in front of datediff is the culprit. I'm now getting values in my grid of either 0 or 30. Now I need to get the last_modified column to check that value and color the row based on whether that value is 30 or greater right?

 

by: larksysPosted on 2009-06-11 at 17:31:35ID: 24608293

Right. You can do that with either the EXT code or the bgcolor parameter of the cfgridcolumn tag.

 

by: futr_visionPosted on 2009-06-11 at 17:52:45ID: 24608370

Maybe it's just a lack of sleep but I can't get this to work. Here is the code that I am currently using(not including the query in the cfc) and a screengrab of the current results.

<!--- Customer Render code in the head --->
 
<cfajaximport tags="cfform, cfdiv, cfgrid">
<!--- Rendering for date modified in excess of 90 days --->
<script type="text/javascript" language="javascript">
// custom renderer for Color column
function renderName(data,cellmd,record,row,col,store) {
 return '<b style="color:blue;">' + data + '</b>';
 }
// function to invoke custom renderers and return re-configured grid (called from ajaxonload()
function CompRendGrid() {
  mygrid = ColdFusion.Grid.getGridObject('clients');
  cm = mygrid.getColumnModel();
  cm.setRenderer(7,renderName); // assign custom renderer for Name column in the grid
  mygrid.reconfigure(mygrid.getDataSource(),cm); // reconfigure grid
}
</script>            
<!--- fire the custom grid renderers on pageload --->
<cfset ajaxOnLoad("CompRendGrid")>
 
 
<!--- Customer Render code in the grid --->
 
        <cfgridcolumn name="last_modified" width="140" header="Last Modified" bgcolor = "(c11 lt 90 ? blue : white)"/>
 	<cfgridcolumn name="DateCheck" display="yes"/></cfgrid>
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:

Select allOpen in new window

 

by: larksysPosted on 2009-06-11 at 18:04:05ID: 24608409

You're trying to use both methods. Comment out lines 1 through 19.  Now you're checking for less than 90 days and the bgcolor should be blue. Let's see what it does now.

 

by: futr_visionPosted on 2009-06-11 at 19:33:57ID: 24608697

I took out the method and not I am not getting any changes to the grid.

 

by: larksysPosted on 2009-06-11 at 23:04:05ID: 24609522

Use this;

// custom renderer for Color column
function renderName(data,cellmd,record,row,col,store) {
 if (record.data.DATECHECK < 90 return '<b style="background-color:ffff80>' + data + '<b>';
 else return data;
 }

// function to invoke custom renderers and return re-configured grid (called from ajaxonload()
function CompRendGrid() {
  mygrid = ColdFusion.Grid.getGridObject('clients');
  cm = mygrid.getColumnModel();
  cm.setRenderer(1,renderName); // assign custom renderer for Name column in the grid
 cm.setRenderer(2,renderName); // assign custom renderer for Name column in the grid
 cm.setRenderer(3,renderName); // assign custom renderer for Name column in the grid
 cm.setRenderer(4,renderName); // assign custom renderer for Name column in the grid
 cm.setRenderer(5,renderName); // assign custom renderer for Name column in the grid
 cm.setRenderer(6,renderName); // assign custom renderer for Name column in the grid
 cm.setRenderer(7,renderName); // assign custom renderer for Name column in the grid
 cm.setRenderer(8,renderName); // assign custom renderer for Name column in the grid
 cm.setRenderer(9,renderName); // assign custom renderer for Name column in the grid
 cm.setRenderer(10,renderName); // assign custom renderer for Name column in the grid
  mygrid.reconfigure(mygrid.getDataSource(),cm); // reconfigure grid
}

 

by: larksysPosted on 2009-06-11 at 23:06:50ID: 24609535

Sorry, only render columns 2 through 9.  I just realized that the datecheck column is number 10.

 

by: futr_visionPosted on 2009-06-12 at 03:40:13ID: 24610835

I gave it a try and the app fails silently. Firebug did pick up an error. Here is the syntax of that error
missing ) after condition
? in cfajax.js@99()cfajax.js (line 103)
? in cfajax.js@118("/CFC/clients.cfc", "GET", "method=getClientsAdmin&returnFormat=json&argumentCollection=%7B%22page%22%3A1%2C%22pageSize%22%3A15%2C%22gridsortcolumn%22%3A%22DATECHECK%22%2C%22gridsortdir%22%3A%22ASC%22%7D", true, function(), null, true)cfajax.js (line 119)
? in cfajax.js@454(Object async=true cfcPath=/CFC/clients.cfc httpMethod=GET, "getClientsAdmin", Object page=1 pageSize=15 gridsortcolumn=DATECHECK, Object bindToAttr=true bindToParams=Object)cfajax.js (line 488)
? in cfajax.js@1562(null, Object bindToAttr=true cfc=/CFC/clients.cfc)cfajax.js (line 1584)
? in my_page.cfm@103(Object events=Object _cf_actions=Object _cf_firstLoad=true, 1, 15, "DATECHECK", "ASC", null, function(), Object data=Object baseParams=Object paramNames=Object, Object params=Object, Object)my_page.cfm (line 105)
? in cfgrid.js@481(Object start=0 limit=15 sort=DATECHECK dir=ASC, Object, function(), Object data=Object baseParams=Object paramNames=Object, Object params=Object)cfgrid.js (line 498)
? in data.js@11(Object params=Object)data.js (line 11)
? in data.js@11("DATECHECK", "ASC")data.js (line 11)
? in grid.js@11(Object container=Object id=cfgrid1244802916990, 8)grid.js (line 11)
? in ext-core.js@12()ext-core.js (line 12)
? in ext-core.js@12()ext-core.js (line 12)
? in grid.js@9("click", Object browserEvent=Event unload button=-1 type=unload)grid.js (line 9)
? in grid.js@9(Object browserEvent=Event unload button=-1 type=unload)grid.js (line 9)
? in ext-core.js@13()ext-core.js (line 13)
? in yahoo-dom-event.js@135()yahoo-do...-event.js (line 135)
[Break on this error] if (record.data.DATECHECK < 90 return '...ckground-color:ffff80>' + data + '<b>';\n


I've even added a parenthese at the end of the if statement but it still throws the same error

 

by: futr_visionPosted on 2009-06-12 at 03:56:37ID: 24610914

I just added the parenth before the return statement and the error is now gone however I am not seeing any changes to the grid. I also added a closing quote on the the style. That didn't produce any results either.

 

by: larksysPosted on 2009-06-12 at 08:21:24ID: 24613150

Yeah, there was a missing paren after 90 and the semicolon and quote after the color code;

 if (record.data.DATECHECK < 90) return '<b style="background-color:#ffff80;">' + data + '<b>';
 else return data;
 }

You should also add the # sign in front of the color code.

 

by: futr_visionPosted on 2009-06-12 at 08:42:29ID: 24613342

Still nothing. No errors but no coloring either.

 

by: larksysPosted on 2009-06-12 at 09:02:29ID: 24613559

Is this a public page that I might look at?

 

by: futr_visionPosted on 2009-06-12 at 09:25:09ID: 24613772

Unfortunately it is behind registration.

 

by: larksysPosted on 2009-06-12 at 09:33:17ID: 24613849

Did you remove the bgcolor parameter from the cfgidcolumn tag? You should.

 

by: futr_visionPosted on 2009-06-12 at 09:51:35ID: 24613995

Yes. Here is what the cfgrid looks like now.

    <cfform name="Clients" >
      <cfgrid name="clients"
         format="html"
         striperows="yes"
         colheaderbold="yes"
         colheaderfontsize="12"
         pagesize="15"
         selectmode="edit"
         delete="yes"
         bind="cfc:CFC.clients.getClientsAdmin({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
         onchange="cfc:CFC.clients.editClient({cfgridaction},{cfgridrow},{cfgridchanged})">
        <cfgridcolumn name="client_ID" display="no" />
        <cfgridcolumn name="client_name" width="275" header="Client"/>
        <cfgridcolumn name="alliance" width="60" header="Alliance"/>
        <cfgridcolumn name="owner" width="60" header="Owner"/>
        <cfgridcolumn name="FET_prospect" width="90" header="FET Prospect"/>
        <cfgridcolumn name="date_added" width="140" header="Date Added"/>
        <cfgridcolumn name="status" width="90" header="Status"/>
        <cfgridcolumn name="last_modified" width="140" header="Last Modified" />
 		<cfgridcolumn name="DateCheck" display="yes"/></cfgrid>
        <cfinput type="button" name="Download" value="Download" onClick="doDownload()">     
   </cfform>
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:

Select allOpen in new window

 

by: larksysPosted on 2009-06-12 at 09:52:47ID: 24614009

This is what I'm using and it turns the background of all cells to yellow;

<!--- Special rendering for company name colors --->
<script type="text/javascript" language="javascript">
// custom renderer for Color column
function renderName2(data,cellmd,record,row,col,store) {
 if (record.data.DATECHECK < 10) return '<b style="background-color:#ffff80;">' + data + '<b>';
 else return data;
 }

// function to invoke custom renderers and return re-configured grid (called from ajaxonload()
function CompRendGrid2() {
  mygrid = ColdFusion.Grid.getGridObject('grid_Companiesviewed');
  cm = mygrid.getColumnModel();
  cm.setRenderer(1,renderName2); // assign custom renderer for Name column in the grid
 cm.setRenderer(2,renderName2); // assign custom renderer for Name column in the grid
 cm.setRenderer(3,renderName2); // assign custom renderer for Name column in the grid
 cm.setRenderer(4,renderName2); // assign custom renderer for Name column in the grid
 cm.setRenderer(5,renderName2); // assign custom renderer for Name column in the grid
  mygrid.reconfigure(mygrid.getDataSource(),cm); // reconfigure grid
}
</script>            
<!--- fire the custom grid renderers on pageload --->
<cfset ajaxOnLoad("CompRendGrid2")>

 

by: larksysPosted on 2009-06-12 at 09:54:26ID: 24614020

You might try removing the striperows parameter from the cfgrid tag.

 

by: futr_visionPosted on 2009-06-12 at 09:59:09ID: 24614051

Removed. No luck. You're really working for these 500 pts huh? I really appreciate your persistence.

 

by: larksysPosted on 2009-06-12 at 10:19:42ID: 24614223

Change the following line;

 if (record.data.DATECHECK < 90) return '<b style="background-color:#ffff80;">' + data + '<b>';
 else return data;

To;

 return '<b style="background-color:#ffff80;">' + data + '<b>';

Let's see what happens.

 

by: futr_visionPosted on 2009-06-12 at 11:14:40ID: 24614711

I hate to say this but nothing happens. No errors. No colors. Just data.

 

by: larksysPosted on 2009-06-12 at 13:01:28ID: 24615585

Post your code, please.

 

by: futr_visionPosted on 2009-06-12 at 13:54:21ID: 24616085

Here is the script and the grid

<script type="text/javascript">
 
<!---custom renderer for Color column--->
function renderName(data,cellmd,record,row,col,store) {
 return '<b style="background-color:#ffff80;">' + data + '<b>';
 }
 
 
<!---function to invoke custom renderers and return re-configured grid called from ajaxonload--->
function CompRendGrid() {
  mygrid = ColdFusion.Grid.getGridObject('clients');
  cm = mygrid.getColumnModel();
  cm.setRenderer(2,renderName); // assign custom renderer for Name column in the grid
  cm.setRenderer(3,renderName); // assign custom renderer for Name column in the grid
  cm.setRenderer(4,renderName); // assign custom renderer for Name column in the grid
  cm.setRenderer(5,renderName); // assign custom renderer for Name column in the grid
  cm.setRenderer(6,renderName); // assign custom renderer for Name column in the grid
  mygrid.reconfigure(mygrid.getDataSource(),cm); // reconfigure grid
}
</script>
 
 
 
    <cfform name="ClientsAdmin" >
      <cfgrid name="clients"
         format="html"
         colheaderbold="yes"
         colheaderfontsize="12"
         pagesize="15"
         selectmode="edit"
         delete="yes"
         bind="cfc:CFC.clients.getClientsAdmin({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
         onchange="cfc:CFC.clients.editClient({cfgridaction},{cfgridrow},{cfgridchanged})">
        <cfgridcolumn name="client_ID" display="no" />
        <cfgridcolumn name="client_name" width="275" header="Client"/>
        <cfgridcolumn name="alliance" width="60" header="Alliance"/>
        <cfgridcolumn name="owner" width="60" header="Owner"/>
        <cfgridcolumn name="FET_prospect" width="90" header="FET Prospect"/>
        <cfgridcolumn name="date_added" width="140" header="Date Added"/>
        <cfgridcolumn name="status" width="90" header="Status" />
        <cfgridcolumn name="last_modified" width="140" header="Last Modified"/>
 		<cfgridcolumn name="DateCheck" display="yes"/></cfgrid>
        <cfinput type="button" name="Download" value="Download" onClick="doDownload()">     
   </cfform>
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:

Select allOpen in new window

 

by: futr_visionPosted on 2009-06-12 at 13:58:51ID: 24616112

and the query

   <cffunction name="getClientsAdmin" access="remote" returntype="struct">
      <cfargument name="page" type="numeric" required="yes">
      <cfargument name="pageSize" type="numeric" required="yes">
      <cfargument name="gridsortcolumn" type="string" required="no" default="">
      <cfargument name="gridsortdir" type="string" required="no" default="">
 
      <!--- Get data for Admin grid --->
      <cfquery name="clients" datasource="#THIS.dsn#">
      SELECT *,(datediff("d", last_modified,#now()#) as datecheck
      FROM Clients
      <cfif gridsortcolumn NEQ ""
         and gridsortdir NEQ "">
         ORDER BY client_name ASC #gridsortcolumn# #gridsortdir#
      </cfif>
      </cfquery>
 
      <!--- And return it as a grid structure --->
    <cfreturn queryconvertforgrid(clients,page,pagesize)/>
   </cffunction> 
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:

Select allOpen in new window

 

by: larksysPosted on 2009-06-13 at 07:23:04ID: 24619327

You're missing some code.
<cfajaximport tags="cfform, cfdiv, cfgrid">

 <!--- fire the custom grid renderers on pageload --->
<cfset ajaxOnLoad("CompRendGrid2")>

 

by: futr_visionPosted on 2009-06-13 at 10:28:14ID: 24620000

I finally got this working. A good night's sleep and a peak at a few other examples and I believe I figured out what was going wrong. Once I moved the <cfset ajaxOnLoad("CompRendGrid2")> to the very bottom of the page just before the closing body tag it worked. That bit of code has to exist after the grid I want the custom renderer applied to. I've also gone ahead and switched the background style back to the text style. I thought that maybe the background color would fill the entire cell and not just the arae around the text but I was wrong. I also added a little extra code to color other values in the grid. I thought it may throw and error because I didn't define a range but what I have still appears to work. Below is my final code.

<!--- import for custom renderer since we are not using cf8 ajax controls. top of page above opening html tag --->
<cfajaximport/>
 
<!--- Custom renderer that colors the text in each row based on certain values in DATECHECK column --->
 
<script type="text/javascript">
renderName = function(data,cellmd,record,row,col,store) {
if (record.data.DATECHECK >= 90) return '<b style="background-color:red;">' + data + '</b>';
  else
if (record.data.DATECHECK >= 60 ) return '<b style="color:orange;">' + data + '</b>';
	else
if (record.data.DATECHECK >= 30 ) return '<b style="color:green;">' + data + '</b>';else return data;
 }
 
// function to invoke custom renderers and return re-configured grid (called from ajaxonload()
CompRendGrid = function() {
  mygrid = ColdFusion.Grid.getGridObject('clients');
  cm = mygrid.getColumnModel();
 cm.setRenderer(1,renderName); // assign custom renderer for Name column in the grid
 cm.setRenderer(2,renderName); // assign custom renderer for Name column in the grid
 cm.setRenderer(3,renderName); // assign custom renderer for Name column in the grid
 cm.setRenderer(4,renderName); // assign custom renderer for Name column in the grid
 cm.setRenderer(5,renderName); // assign custom renderer for Name column in the grid
 cm.setRenderer(6,renderName); // assign custom renderer for Name column in the grid
 cm.setRenderer(7,renderName); // assign custom renderer for Name column in the grid
 cm.setRenderer(8,renderName); // assign custom renderer for Name column in the grid
 mygrid.reconfigure(mygrid.getDataSource(),cm); // reconfigure grid
}
</script>
 
 
<!--- fires our custom grid renderers on pageload. Placed after grids before closing head tag --->
 
<cfset ajaxOnLoad("CompRendGrid")>
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:

Select allOpen in new window

 

by: futr_visionPosted on 2009-06-13 at 14:21:36ID: 31591067

It was a long hall and I appreciate your patience. Thanks. Turns out it was another post here at experts-exchange that included yourself that help me finally get this working.

 

by: larksysPosted on 2009-06-14 at 18:27:53ID: 24625900

Terrific.  

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...