Our Blog

If you ever used cfgrid, you know that it accepts a query as its data. Each cfgridcolumn of the grid has to be a column of the query. You cannot combine two or more columns or add something to the column. That means that any formatting of the data needs to be done before giving the query to the grid (unless you loop over it and use but in that case you are not using the query atttribute anyway).

Most likely, you would do this in sql, by creating a new column that is a combination of other columns or by adding strings to a given column. The same problem arises if you wanted to format the data using something different than the provided types (currency for example) and the mask attribute is known to be unpredictable sometimes. The requirement of having to provide only a column, and nothing else, to the tag has given grief to those wanting to have a cfgrid column of type "image" when the image was not in the same directory as the calling form. The solution to that is to append the full path to the column that contains the image file name, as it has been described in this post. But still, not everybody was happy with that. On top of that, the column type image seems to have a bug that makes the pictures randomly disappear.

So let me explain how to do data formatting on the client as opposed as in the query. We will use the onload function available in the 7.01 updater to change the "labelFunction" of the column we want to format. In this example, we will use three different columns to show an address in one column. This can also be used in combination with variableRowHeight, as shown in the second example, to have a multiple-line row (you can also set the height of the rows if it is fixed).

Note that the query columns are: id, address, city, state

<cfform name="myform" format="Flash" onload="formOnLoad()">
<cfformitem type="script">
   function formOnLoad(){
      <!--- get the first column and tell it to use setLabel as its label function
      starts at 1 because first column is CFGRIDROWINDEX
      if yours is not the first column, then just count the index--->

       myGrid.getColumnAt(1).labelFunction = setLabel;
   }

   <!--- function that gets called when cells are rendered --->
   function setLabel(item:Object, columnName:String): String {
      <!--- because we are using this function on only one column, we don't really
      need to use the columnName parameter, but we would need it if
      used the same function for several columns and wanted to know which column
      we are supposed to format --->

      
      <!--- you can use item.address or item['address'] --->
      return item.address + ', ' + item.city + ', ' + item.state;
   };      
</cfformitem>

<cfgrid name="myGrid" query="properties">
   <cfgridcolumn header="Address" name="address">         
</cfgrid>
   
</cfform>

Example with multiple lines (adding "/n") and having variableRowHeight = true

<cfformitem type="script">
   function formOnLoad(){
      <!--- make the grid rows multiline --->
      myGrid.variableRowHeight = true;

       myGrid.getColumnAt(1).labelFunction = setLabel;
      <!--- if the data in this column is long and you want it to wrap --->
      myGrid.getColumnAt(1).wordWrap = true;
   }

   <!--- function that gets called when cells are rendered --->
   function setLabel(item:Object, columnName:String): String {
      
      <!--- insert a new line between the address and the city --->
      return item.address + '\n' + item.city + ', ' + item.state;
   };      
</cfformitem>

Suppose your database contain the filename of the image you want to show in the grid using . Your images, however, are not in the same directory as your form, so you need to give the full path to the picture. You can use labelFunction to add the path information to the filename coming from the query. In this case, the columns are: id, thumbnail, city and the column for thumbnail only contains the name of the file.

<cfform name="myform" format="Flash" onload="formOnLoad()">
<cfformitem type="script">
   function formOnLoad(){
       myGrid.getColumnAt(1).labelFunction = setLabel;
   }

   <!--- function that gets called when cells are rendered --->
   function setLabel(item:Object, columnName:String): String {

      if ( item[columnName] != undefined) {
         <!--- add the path to the item to that it knows where to find the picture, you can either use absolute or relative paths: /path/to/my/images --->
            return "images/" + item[columnName];
         }
      else {
         return "";
      }
   };      
</cfformitem>

   <cfgrid name="myGrid" rowHeight="50" rowheaders="false" query="properties">
      <cfgridcolumn type="image" width="75" name="thumbnail" header="Photo">                        
      <cfgridcolumn name="city" header="City">               
   </cfgrid>

</cfform>

From what I've seen so far since I've started using this technique, it has the nice effect of fixing the "mysteriously disappearing image" bug experienced in Firefox when using as reported by myself and other readers in this post: Thumbnails in a cfgrid

You can use this technique to implement formatting other than the built-in types (I just couldn't think of a quick example). You can also do the same with cfselect, but you won't have all the query columns available unless you loaded the data via remoting, so you'll have label and data as the only sources.

Live example 1

Live example 2

Live example 3

Download the source

Laura

Laura

82 Comments

  1. William
    I had been formatting my image file URLs in my SQL queries. This is a MUCH better way to handle that.

    Also the fix for the Firefox bug is exactly what I needed!

    Thanks so much
  2. todd
    Any way to change the cfgridcol type after we load the data?

    For example, if you have a column with both text and dates and apply type=date cf magically removes all the non-dates from the col.

    I wonder if you change the type to date after load it would leave the non-dates in the col.
  3. felipe

    felipe

    Is there a way of showing bigger images in the grid?
    I tried set the width and heigth of the collumn but it still cropping the image.
  4. Neil Bailey

    Neil Bailey

    Larua, Nahuel, is it possible to set an individual cell in a grid, without affecting the other cells? I am just starting to look into this, so the answer might be right in front of my face; but I figured that if it can be done, you'd know it.

    Thanks for all the help and great work.

    neil
  5. Neil Bailey

    Neil Bailey

    gridName.editField() seems to fit the bill nicely. Thanks anyway guys. If nothing else, you've taught me where to look :)
  6. Laura
    todd,
    I don't think you can change the type on the fly.

    felipe,
    using rowHeight="some number" in cfgrid and width="some number" in cfgricolumn should work fine.
  7. Felipe

    Felipe

    Laura I tried it but it didn´t work is there any other way?
  8. Neil Bailey

    Neil Bailey

    Laura, can I change the vertical alignment of the data in the rows? I know horizontal alignment can be changed by dataAlign, but there doesn't appear to be a way to affect the vertical alignment - not that I can see.

    I set the rowHeight to 50, and now I want any data that doesn't need multiple lines to be top aligned. Any suggestions?
  9. Laura
    Felipe,
    As you know, showing images in the grid is quite buggy. It works for me for pictures coming from certain hosts, but not others. It's just weird. Without looking at the image renderer source of cfform, I can't tell exactly what the problem is, or might even be a Flash bug.

    Neil,
    Use myGrid.verticalAlign = "top"; in the onload function.
  10. Jorge Tejada

    Jorge Tejada

    Hi, I want to know, how did you get to work Pollster 2.0 with ColdFusion MX 7. It worked for me on CFMX 6.1. But since I installed CFMX 7 it stopped working, I am asking it again :(.
  11. Laura
    Jorge,
    We did nothing, it just worked. Perhaps something got misconfigured. I would check that remoting is working.
  12. WayneG
    Laura,
    Please find the code I have finally managed to get working to loop over specific gros rows columns that I want froma grid that has 6 columns. Is this the correct way.

    function confirmClick():Void{
    var timesheetConfirmation:mx.controls.DataGrid = timesheetConfirmation;
    var args:Array = [];

    for(var i:Number = 0; i &lt; timesheetConfirmation.length; i++){
    var item:Array = [];
    item.intTimesheetID = timesheetConfirmation.dataProvider[i].intTimesheetID;
    item.bitIsCaptured = timesheetConfirmation.dataProvider[i].bitIsCaptured;
    item.bitIsConfirmed = timesheetConfirmation.dataProvider[i].bitIsConfirmed;
    item.intLogUser = intLogUser.text;
    args.push(item);
    }
    _global.confirmation(args);
    }

    the args then go to via facade.cfm to cfc which is then giving me the following error:

    You have attempted to dereference a scalar variable of type class java.util.ArrayList as a structure with members.

    I am looping the cffunction, with a cfargument set as type=&quot;array&quot; name=&quot;args&quot;

    This is where I need help please.. I cant get the function to update the records of the array..Pleaseeeee
  13. Joshua Buttler
    Hi Laura,
    I am a very newbie to Actionscript so please bear with me. :)
    In regards to the above mentioned use of &quot;{(myGrid.selectedItem != undefined)myGrid.selectedItem.myColumn:'any default'}&quot; to not have an &quot;undefined&quot; showing, how exactly is that used and I assume I use it on the actual &quot;bind&quot; atribute of the cfformitem?
    Sorry for being so thick-headed and thanks for your help.
    :)
  14. Laura
    Wayne,
    That indicates you have a problem with your cfm code in the cfc. Your ActionScript seems ok (except for _global.confirmation(args);, which is a little strange). I would use getItemAt() instead of accessing the dataProvider directly.

    Joshua,
    That goes in the bind attribute of an input, textarea, etc. Don't forget the question mark after (myGrid.selectedItem != undefined)
  15. WayneG
    Laura,

    Thank you so much for your reply,..know u very busy.If I replace the datprovider with item.intTimesheetID = timesheetConfirmation.dataProvider[i].intTimesheetID; then the values in the grid are not passsed, only the array column names.

    I pass the args as an array to a cfc. With the cfargument set as type=&quot;array&quot;. When I try loop over the array to update the database I get the error in my previous post.
    My question: how do I script the cf code. Is the array coming from actionscript is starting at [0], so CF doent reconize the array type as a cf array starts at [1]?

    Thanks again !

  16. WayneG
    Laura,

    My sincere apologies, thank you for the advice getItemAt() works perfectly! Please don have a look at my question that I have posted adbove.

    Just been curious, why is it not a good idea to use the dataProvider versus the getItemAt()?

    You examples have been a tremendous help, thank again

  17. Javier Julio
    If I didn't want to break the address using line breaks, lets say I have a short description field in a cfgrid how do I set the wordWrap property to true on a cfgridcolumn?? I know it can be done through ActionScript but everything I've tried has not worked, any ideas??
  18. Steven Ross
    This is great, however how would you use this in combination with another query to include a select that gets populated based on the data in a grid.

    for instance we have a grid with the column &quot;NewsletterID&quot; but no &quot;NewletterName&quot; because the name of the newsletter is in another table.

    two queries are executed on the page one that populates the grid and another that is used to generate a dropdown box. When I select an item in a grid i want to pass the id of the newsletter to the select box which will select the item in it that has the matching ID.

    Can this be done?
  19. Laura
    Javier,
    You need to add wordWrap to every column:
    myGrid.getColumnAt(1).wordWrap = true;
    I added to the post example.

    Steven,
    Is something like the &quot;state&quot; dropdown in this example what you want? (the grid has only the state id, while the dropdown has id as value and name as display label)
    http://www.asfusion.com/apps/realestate/
  20. Javier Julio
    Laura, you are amazing. :) It worked! Thanks a bunch. I had done what you had said but only added it to the column I needed. I did not know I would have to do that to all of them but I did and it word wrapped the column I wanted it too. Thanks so much!
  21. Laura
    Steven
    First week of December :)

    Scott,
    not elegant, but you will need to have a break in the header:
    <cfgridcolumn header="Line 1
    line 2"
    name="address">

    then you will need to make the header taller. Add this to the formOnLoad() function
    myGrid.headerHeight = 50;//or whatever height you want in pixels
  22. Javier Julio
    Is there a way to use labelPlacement on a text input in a flash form?? I tried to look at the flex docs but nothing is there. What if I don't want the label for my text input box on the left?? Is there anyway I can move it above?? I'm doing this just to save some space on my final project for my flash class. If anyone knows how this can be done I figured it'd be you guys. Thanks as always for sharing your knowledge! I've learned so much.
  23. Laura
    Javier,
    The easiest way is to separate the label from the field. Look at the search panel in the Real Estate Sample app for example on how to do it.
  24. Chaz
    Laura

    you answer a question from Scott about displaying two line header, after I did this how can I align the text?
  25. Sami Hoda

    Sami Hoda

    Has someone figured out how to center align the images inside a column?
  26. DerekB
    Where can we find more information about getColumnAt() and other such functions that pertain to good ol' CFGrid?

    What I REALLY want is to get how many rows are in the grid, and to be able to easily get a cell's value at a particular row.

    Even more specifically, something like what is going on in the excellent Real Estate tutorial (http://www.asfusion.com/blog/entry/coldfusion-flash-forms-macromedia-2 )
    around about the
    <cfinput type="text" name="edit_city"
    bind="{(listingGrid.selectedItem!=undefined)?listingGrid.selected
    Item.city:''}"
    label="city" />

    But instead of selectedItem, I just want the City value for row 1.

    Much appreciated!
  27. KenM
    Hello!

    It seems that I should be able to use this same general idea (the onLoad function) to format a number value in a grid cell? I have a column like "income" and a column like "spent." If spent is greater than income I'd like the number to be red. Any ideas how to go about this, using just a query instead of a loop?

    Thx
  28. Dan
    Hi,

    Nice example. I not sure if this is a bug or not.

    I added a binding to get the value of the selected address... and found it returns the original data, not the formatted data as one might expect.

    &lt;cfinput type=&quot;text&quot; name=&quot;edit_Address&quot; bind=&quot;{(myGrid.selectedItem!=undefined)?myGrid.selectedItem.address:''}&quot; label=&quot;address&quot; /&gt;

    Example Code:

    &lt;cfscript&gt;
       properties = queryNew(&quot;id,thumbnail,city,address,state&quot;);
       queryAddRow(properties);
          querySetCell(properties,'id','1');
          querySetCell(properties,'thumbnail','house1Thum.jpg');
          querySetCell(properties,'city','Arrowhead');
          querySetCell(properties,'address','8734 Maple Rd');
          querySetCell(properties,'state','CA');
       queryAddRow(properties);
          querySetCell(properties,'id','2');
          querySetCell(properties,'thumbnail','house2Thum.jpg');
          querySetCell(properties,'city','Big Bear Lake');
          querySetCell(properties,'address','7687 Apple St');
          querySetCell(properties,'state','CA');
       queryAddRow(properties);
          querySetCell(properties,'id','3');
          querySetCell(properties,'thumbnail','house3Thum.jpg');
          querySetCell(properties,'city','Los Angeles');
          querySetCell(properties,'address','21242 Wilshire Blvd');
          querySetCell(properties,'state','CA');
       queryAddRow(properties);
          querySetCell(properties,'id','4');
          querySetCell(properties,'thumbnail','house4Thum.jpg');
          querySetCell(properties,'city','Berverly Hills');
          querySetCell(properties,'address','2384 Rodeo Drive');
          querySetCell(properties,'state','CA');
    &lt;/cfscript&gt;

    &lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
    &lt;html style=&quot;margin:0; height:100%;&quot;&gt;
    &lt;head&gt;
    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;&gt;
    &lt;title&gt;Showing data from 3 columns in one&lt;/title&gt;
    &lt;/head&gt;

    &lt;cfform name=&quot;myform&quot; height=&quot;300&quot; width=&quot;600&quot; format=&quot;Flash&quot; timeout=&quot;100&quot; onload=&quot;formOnLoad()&quot;&gt;
    &lt;cfformitem type=&quot;script&quot;&gt;
       function formOnLoad(){
          &lt;!--- make the grid rows multiline ---&gt;
          myGrid.variableRowHeight = true;
          
              myGrid.getColumnAt(1).labelFunction = setThumb;
          
          &lt;!--- get the first column and tell it to use setLabel as its label function
          starts at 1 because first column is CFGRIDROWINDEX ---&gt;
           myGrid.getColumnAt(2).labelFunction = setLabel;
          &lt;!--- if the data in this column is long and you want it to wrap ---&gt;
          myGrid.getColumnAt(2).wordWrap = true;
           myGrid.verticalAlign = &quot;top&quot;;
          
          
       }

       &lt;!--- function that gets called when cells are rendered ---&gt;
       function setLabel(item:Object, columnName:String): String {
          &lt;!--- because we are using this function on only one column, we don't really
          need to use the columnName parameter, but we would need it if
          used the same function for several columns and wanted to know which column
          we are supposed to format ---&gt;
          
          &lt;!--- insert a new line between the address and the city ---&gt;
          return item.address + '\n' + item.city + ', ' + item.state;
       };
       
          &lt;!--- function that gets called when cells are rendered ---&gt;
       function setThumb(item:Object, columnName:String): String {
          &lt;!--- because we are using this function on only one column, we don't really
          need to use the columnName parameter, but we would need it if
          used the same function for several columns and wanted to know which column
          we are supposed to format ---&gt;
          
          if ( item[columnName] != undefined) {
             &lt;!--- add the path to the item to that it knows where to find the picture ---&gt;
                return &quot;images/&quot; + item[columnName];
             }
          else {
             return &quot;&quot;;
          }
          };
             
    &lt;/cfformitem&gt;

          &lt;cfgrid name=&quot;myGrid&quot; rowHeight=&quot;50&quot; rowheaders=&quot;false&quot; query=&quot;properties&quot; width=&quot;350&quot; height=&quot;200&quot;&gt;
          &lt;cfgridcolumn type=&quot;image&quot; width=&quot;75&quot; name=&quot;thumbnail&quot; header=&quot;Photo&quot;&gt;      
          &lt;cfgridcolumn header=&quot;Address&quot; name=&quot;address&quot;&gt;                                    
          &lt;cfgridcolumn name=&quot;city&quot; header=&quot;City&quot;&gt;               
       &lt;/cfgrid&gt;

    &lt;cfinput type=&quot;text&quot; name=&quot;edit_city&quot; bind=&quot;{(myGrid.selectedItem!=undefined)?myGrid.selectedItem.city:''}&quot; label=&quot;city&quot; /&gt;
    &lt;cfinput type=&quot;text&quot; name=&quot;edit_Address&quot; bind=&quot;{(myGrid.selectedItem!=undefined)?myGrid.selectedItem.address:''}&quot; label=&quot;address&quot; /&gt;
    &lt;/cfform&gt;




  29. Dan
    Hi again..

    A little hacking and I found the &quot;fix&quot; for the previous bug.

    You need to call the setLabel function a second time when you &quot;render&quot; the cf input.


    Change
    &lt;cfinput type=&quot;text&quot; name=&quot;edit_myColumn&quot; bind=&quot;{(myGrid.selectedItem!=undefined)?myGrid.selectedItem.address:''}&quot; label=&quot;address&quot; /&gt;

    to

    &lt;cfinput type=&quot;text&quot; name=&quot;edit_Address&quot; bind=&quot;{(myGrid.selectedItem!=undefined)?setLabel(myGrid.selectedItem):''}&quot; label=&quot;address&quot; /&gt;

    You'll also need to call the method directly without the address attribute:

    setLabel(myGrid.selectedItem)

    Lesson learned here:
    The underlaying data stored in the grid does NOT change when a cell is rendered, only the display of the &quot;renderered&quot; the cell.

    Makes total sense when you think about it, but I'm sure there's others out there that made the assumption that the data binding would have been pointing to the rendered data vs the original data.






  30. Daveline

    Daveline

    Has anyone found a way to get an image larger than 75x70 in the datagrid? Basically the same issues Felipe (above) is having. My images are just getting cropped? I have looked into the ImageCellRenderer, but have not found much info. I HAVE got this to work in plain old Flash, but nothing I have tried has worked with cfform. :(
  31. Alex
    Hi,
    Could somebody please show me how to wordWrap on the Column Header...

    Thanks
  32. GKilla

    GKilla

    Question re: embedding images within cfgrid.

    Based on what I've read so far, it seems the only way to embed am image within a cfgrid is by pulling image URL info from a database. My question is can this be done without referring to a database at all and just include the path info to the image directory location?

    I am running into some difficulty where I would like to notify the user of the state of his/her item - i.e. an item that is flagged as "New", "Requires Attention" or "Overdue" based on the timestamp.

    Essentially, I am displaying a user's work queue in a grid and need to implement the aforementioned "flag" feature using images to indicate the current state. Ideally, I would like the image to display in a separate column by itself, but that is impossible since the header column must use an existing db table. I guess this leads to another question: can an image be placed into the same cell with actual data?

    Any suggestions or ideas are greatly appreciated.
  33. Laura
    GKilla,
    What you write in the setLabel function is up to you. You don't have to make reference to a column that contains an image filename only, you can make it up as in:
    if (item['status'] == 'New')
       return "images/newImage.jpg";
    else
       return "images/overdueImage.jpg";

    Don't copy the code as is :) it's just an example. You might want to use a switch, change your column names, compare it with the date or whatever. If you look at the other example that concatenates several columns can give you ideas of what to do. By the way, you can always manipulate a query before sending it to a grid to add whatever columns or values you want (meaning values and columns do not have to come straight from the database)
  34. GKilla
    Thanks for the response. The only problem is that the status images are not stored in a database, but rather are determined by 2 other queries that are not used in the cfgrid query attribute. The first query basically outputs the work history and loops for each record. Within this loop, however, are 2 queries that determine whether or not an item is New, Overdue or Archived. How can I use the result of these 2 queries to display the correct status icon with it's corresponding row?

    The following code is from the non-flash form version that I'm trying to emulate.

    ----------Initial queries ---------
    <cfquery datasource="#application.defaultdsn#" name="getDiscussionIDs">
       SELECT    Distinct discussionID
       FROM   discussionPosts
       WHERE   discussionPosts.userID = #session.tutorID# OR discussionPosts.viewerID = #session.tutorID#
    </cfquery>


    <cfquery datasource="#application.defaultdsn#" name="qQuestions">
    SELECT discussions.dateSubmitted, discussions.discussionID, discussions.subjectID, discussions.topic, users.firstName + ' ' + users.lastName AS stName, subjects.subjectID, subjects.subject
    FROM discussions INNER JOIN users ON discussions.userID = users.userid INNER JOIN subjects ON discussions.subjectID = subjects.subjectID

    WHERE 0=0
    <cfif getDiscussionIDs.recordCount GT 0>
    AND (
    <cfloop query="getDiscussionIDs">
    discussions.discussionID = #getDiscussionIDs.discussionID# <cfif getDiscussionIDs.currentRow NEQ getDiscussionIDs.recordCount>OR</cfif>
             
    </cfloop>
    )
    <cfelse>
    AND   0=1
    </cfif>
    </cfquery>

    ============ Queries used to determine status ============

    <cfoutput query="qQuestions">

    <cfquery datasource="#application.defaultdsn#" name="LatestMessage">
    SELECT   Max(discussionPosts.postID) AS NewestMessage
    FROM   discussionPosts
    WHERE   discussionPosts.discussionID = #discussionID#
    </cfquery>
             
    <cfset variables.userTypetoView = "tutor">
    <!--- <cfif LatestMessage.recordCount --->
    <cfquery datasource="#application.defaultdsn#" name="getLastInfo">
    SELECT    discussionPosts.userType, discussionPosts.dateSubmitted, discussionPosts.viewerID
    FROM   discussionPosts
    WHERE   discussionPosts.postID = #LatestMessage.NewestMessage#
    </cfquery>
          
    <cfif currentrow mod 2>
    <tr>
    <cfelse>
    <tr class="bodybkgd">   
    </cfif>
    <td align="center" valign="top">
    <cfif getLastInfo.recordCount GT 0 AND Trim(getLastInfo.userType) EQ "tutor">
    <img src="images/opts_16.gif" alt="Archived Item" border="0" align="">
    <cfelseif getLastInfo.viewerID EQ session.tutorID>
    <img src="images/redo_116.gif" alt="Waiting for your Response" border="0" align="">
    <cfelse>
    <img src="images/favs_16.gif" alt="New Question!" border="0" align="">
    </cfif>
  35. Laura
    GKilla,
    My response is still valid. If you look carefully, the image does not come from the database. You can make it up however you want, you just need to think a little harder ;)
    If you need data from other places, you will need to have them available, be it in a datagrid, in a hidden input, I don't know, it depends on what other data you require.
  36. GKilla
    Thank you for the response, but I must admit that I'm a little burnt out, so I may need some more insight. Plus, I'm still getting acquainted with ActionScript. I was also fooling around with the toScript() function to see if I could save the image path determined by the conditional statements into a AS variable, but I am unable to loop through the 2 nested queries within the cfgrid. Is that even possible?

    Ideally, if I nested the 2 other queries (that determine the status) within the grid and used one of the problems as a filter in my WHERE clause, then this problem could be resolved. Unfortunately, this is just not working out for me :(
  37. Joshua Scott
    I have a hidden field called httpPath so that I can dynamically get the full path to the image.

    How do I access this?

    I have:

    <cfinput type="hidden" name="httpPath" value="#httpPath#">A

    AND

    return #httpPath# + "model/FileExplorer/icons/" + item[columnName] + ".jpg";


    But I am getting an error. How do I access this variable.

    What am I doing wrong?
  38. Laura
    Joshua,
    In ActionScript, you can only access ActionScript variables. You can do some stuff by using ##, but that almost always makes your form recompile. (Your example above would give a syntax error as is because it is missing quotes.)

    Hidden fields are accessible by myFormName.myHiddenField. So in your example, it would be something like:
    return YouFormName.httpPath + "model/FileExplorer/icons/" + item[columnName] + ".jpg";
  39. Joshua
    Hello there,

    I have a interesting question for you guys pertaining the CFgrid. Have any of you tried to make some columns editable, while making other columns just browseable?

    For example:


    Column1 Column 2 Column 3
    Editable NotEditable NotEditable
  40. Laura
    Joshua,
    That is specified in the CF Docs. You need to set the columns that you don't want to be editable as select="false"

    <cfgrid name="myGrid" selectmode="edit" query="myQuery">
       <cfgridcolumn name="Column1">
       <cfgridcolumn name="Column2" select="false">
       <cfgridcolumn name="Column3" select="false">
    </cfgrid>
  41. Joshua
    Ya Simon Horwith helped me out :) Thanks again, I missed this in the DOCs my first read through - just didnt scroll down far enough :(
  42. Jeff
    First off: This is a great site!
    Second: Any way of controling the cfgrid so that I can word wrap the column headers with out going into flash and creating a new renderer?
  43. Jeff
    I saw that.. just did not have my cfform set to flash (or closed.. (cfdump cfabort to see variables). Now it works GREAT! but of course I want more. going to look at those DOCs now.. need to find a way to valign=baseline or top..

    ~J
  44. Guillermo

    Guillermo

    When I point to the file using the server IP works fine but when I try to access thru the domain name I got the clock spinning over the flash and the data never come up.
    I added the CFIDE as a virtual directory and still nothing.
    Any ideas?
    I have CF7.02 on Windows 2000 server
  45. Chris
    How do i use actionscript for a dynamical grid to set up a cell renderer and to avoid setting grid columns like the following?
    <cfgridcolumn type="image" width="75" name="thumbnail" header="Photo">
    Thanks in advance!
  46. Chris
    I found the solution and it works in my code!
    Thanks anyway!

    I used:
    dG.getColumnAt(x).labelFunction=_root.setLabel;
    dG.getColumnAt(x).cellRenderer="imageCellRenderer";
  47. Boybles Maldooney

    Boybles Maldooney

    How could I put select boxes into a grid? Can somebody give me a quick example?
    Thanks!
    Boybles
  48. Scott
    This is a great artical! I do have a question about some of the params in the script. I want to do some logic based on another colomn in order to format the image locations. this is what I have below, my mistake is that it pulls the item variable from the first row on the colomn i want to do the logic on by using the item.real_video_available. how can i call the data from the other rows accordingly?

    if (item.real_video_available = 'Y') {
             <!--- add the path to the item to that it knows where to find the picture --->
                return "../../images/VideoThumbs/" + item[columnName] + ".jpg";
                <!--- return item.real_video_available --->
             }
          else {
             return "../../images/AudioOnly.jpg";
          }

    This above only does logic on the first row collected... so the Else part of this function never happens.
  49. Laura
    Scott,
    I think your problem is not that only the first row gets evaluated but rather that the if statement will always give true since you are using "=" instead of "=="

    The expression should be:
    tem.real_video_available == 'Y'
  50. Fernando

    Fernando

    Is there any way to change a column's editable attribute programatically as the grid is being rendered?

    For example, if I have a column with checkboxes, and I want some of them to be "selectable" and others not depending on a value of the current record being rendered.
  51. Laura
    Fernando,
    I don't think you can easily do that because the grid uses two different cell renderers for editable/not editable columns (for the checkboxes), and the cell renderers apply to the whole column. The same happens with the editable property (for simple text columns), it applies to the whole column.
  52. Gary
    According to the Coldfusion documentation, textcolor and bgcolor in a cfgridcolumn can be conditionally controlled using an expression shaped like this:

    textcolor = "(CX LT 4 ? black : blue)"

    where CX references the current grid column, and if the value in that cell is less than 4, the text color is rendered as black, otherwise it is rendered as blue.

    Sounds good. But when I've tried to apply this code, the cfform (format = "flash") fails to appear. Any one spot what is wrong? Driving me nuts.
  53. Maggie

    Maggie

    Is there any way to conditionally format the color of text in a data grid? I tried Gary's example above, and got the message that "Binding is not allowed to style property color" (this is for textColor" Ideally, I want to bind my image of the color, which works, but when I bind an image, the rowHeight is ignored, and I'm not sure why. Any insight on how to address either one of these issues would be GREATLY appreciated!
  54. Laura
    Gary and Maggie,
    That code only works for the Java version of the datagrid. I don't think there is a way to change the color of only one row and one cell. I know for sure you can change the color of the row background with something like this:
    myGrid.setPropertiesAt(someIndexNumber, {backgroundColor:0xF7FFB7});
    as it is shown in this post http://www.asfusion.com/blog/entry/looping-over-the-records-of-a-large-cfgrid or change the color of the whole column.

    But I could be wrong, so I would check the Flex 1.5 docs for more info on that.
  55. Cesar Mejia

    Cesar Mejia

    Does anybody know how to link an image inside the grid to an outside .cfm doc? Also, how to enable the cfprocessingdirective tag with pageencoding="ISO8859-1" ? Thank you!
  56. Jeremie
    Hi Laura,

    I tested and adapted your code a little bit. I could display a jpg file but png and gif won't work. Is there a solution? Any ideas?
    Thanx a lot!!
  57. Cesar Mejia

    Cesar Mejia

    You are not going to be able to do it Jeremie, it only allows .jpg, sorry, better luck with ColdFusion 8 (aprox July 2007)
  58. Brian
    Anyone know why there seems to be a refresh bug? When I use the scroll bar, the images always seem to load on the fly, causing a constant disappearing and reappearing of the images I have loaded into the grid Visually, this is quite jarring. Do you know of a way to keep this from happening? Much appreciated,

    Brian
  59. drew
    Is there an easy way to center renderers? I know I can have my renderer be a container and have that centered, but I want to center it so that the mouseover highlights (I'm using a HorizontalList) are even on all sides...am I missing something? Seems there would be a rendererHorizontalAlign property or something somewhere...

    TIA. --Drew
  60. Jeff
    I too am having problems with the image being cropped in a weird way. I'm also having a problem getting the labelfunction part to accept my dynamic variable, so it is hardcoded at the moment. Here is my code:

    <cfscript>
    getphoto = queryNew("id,thumbnail");
    queryAddRow(getphoto);
    querySetCell(getphoto,'id','1');
    querySetCell(getphoto,'thumbnail','#source#');
    </cfscript>

    <cfformitem type="script">
    function formOnLoad(){
    detail2.headerHeight = 50;
    <!---Get the first column and tell it to use setLabel as its labelFunction. Starts at 1 because first column is CFGRIDROWINDEX--->
    photogrid.getColumnAt(1).labelFunction = setLabel;
    }

    function setLabel() {
    return "images/idbadge/broal.jpg";
    }
    ;
    </cfformitem>

    <cfgrid name="photogrid" format="applet" colheaders="no" rowheaders="no" width="100" height="100" query="getphoto">
    <cfgridcolumn name="thumbnail" type="image" header="Photo">
    </cfgrid>

    I would appreciate any further assistance. Thank you.
  61. Jeff
    OK, I am able to now get the picture posting that I want, however, it appears to be the same cropping problem that was mentioned a couple times above. Has there been any further suggestions as to how to fix this? Thanks.
  62. Maggie
    Hello,

    I am having a really strange error - any help would be greatly appreciated. I have the labelFunction and the wordWrap working just fine - until there is a large amount of text that causes the vertical scrollbars to appear in the cfgrid. When you attempt to scroll down, all the text slides off and disappears to the right. Has anyone else encountered this? It is happening in both FireFox and IE. Here is what I am using:
    var dgList = dgList;
    dgList.getColumnAt(1).wordWrap = true;
    dgList.getColumnAt(1).labelFunction = setPSLabel;
    dgList.getColumnAt(2).labelFunction = setISLabel;
    dgList.getColumnAt(2).wordWrap = true;
    dgList.getColumnAt(3).wordWrap = true;
    dgList.getColumnAt(4).wordWrap = true;

    Again - everything shows up fine, until the word wrapping is in effect, and it wraps enough to display the scroll bars in the data grid.
  63. Mossy
    I'm using CF7 on a Windows box and get an error that cfformitem type="script" is invalid. Am I missing some setup on the server or something even more obvious?
  64. Laura
    Mossy,
    To use the type "script" you need to have the ColdFusion updater. If I remember correctly, updater 1 should work.
  65. samantha

    samantha

    I can't seem to get the textcolor expression to work in cfgridcolumn. when I put in an expression it does nothing. I want it to change the color a parent_id shows up on the row. I'm doing a grid in html.
  66. samantha

    samantha

    I can't seem to get the textcolor expression to work in cfgridcolumn. when I put in an expression it does nothing. I want it to change the color a parent_id shows up on the row. I'm doing a grid in html.
  67. David Repas

    David Repas

    I'm again encountering (in Firefox 3) the "mysteriously disappearing" and "jumping around when scrolling" images inside of cfgrid. I do use the above fix, but it no longer seems to be working for the new version of Firefox.

    Anyone else having this issue? Any fixes?

    Thanks.
  68. David Repas

    David Repas

    Update: It appears that the issue I'm having occurs in both Firefox 2 and 3. When I have a cfgrid with numerous row and images - scrolling very quickly forces images to "jump" to other rows.

    The disappearing issue is solved with the above fix, but "jumping" images is not. This only occurs in Firefox, not IE.

    Any help?
  69. David Repas

    David Repas

    Update: It appears that the issue I'm having occurs in both Firefox 2 and 3. When I have a cfgrid with numerous row and images - scrolling very quickly forces images to "jump" to other rows.

    The disappearing issue is solved with the above fix, but "jumping" images is not. This only occurs in Firefox, not IE.

    Any help?
  70. ddidci
    Hi
    I have problem. This labelfunction doesn't wish to work correct for me. It works but only if i use your sample here, and i need to do some changes.
    I will so much appreciate if you can help me.
    Here is my code:
    <cfquery name="SelectQry" dbtype="query" datasource="#Application.DSN#">
    Select rank, firstname
    From Persons
    </cfquery>


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd";>
    <html style="margin:0; height:100%;">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Showing data from 3 columns in one</title>
    </head>

    <cfform name="myform" height="300" width="600" format="Flash" timeout="100" onload="formOnLoad()">
    <cfformitem type="script">
       function formOnLoad(){
           myGrid.getColumnAt(1).labelFunction = setLabel;
       }

       function setLabel(item:Object, columnName:String): String {
    if(item.rank == '1')
    {
    return 'active';
    }
    else
    {
    return 'not active';
    }
          
       };      
    </cfformitem>

       <cfgrid name="myGrid" rowHeight="50" rowheaders="false" query="SelectQry" width="250" height="230">
       <cfgridcolumn header="rank" name="rank">   
    <cfgridcolumn name="firstname" header="Name">      
       </cfgrid>
       
    </cfform>

    </body>
    </html>



    Thank you very much in advance!

    Kind regards,
    Diana
  71. Biswajit Mojumdar

    Biswajit Mojumdar

    Does anyone know how to word wrap the cfgridcolumn header names? Like I have the following code and I'm trying to word wrap the Effective Date header into two lines --
    <cfform>
    <cfgrid attributecollection="#args#">
    <cfgridcolumn name = "CTEffDt" header = "Effective Date">
    </cfgrid>
    </cfform>
  72. Biswajit Mojumdar

    Biswajit Mojumdar

    Does anyone know how to word wrap the cfgridcolumn header names using the cfgrid format as HTML? Like I have the following code and I'm trying to word wrap the Effective Date header into two lines --
    <cfform>
    <cfgrid attributecollection="#args#">
    <cfgridcolumn name = "CTEffDt" header = "Effective Date">
    </cfgrid>
    </cfform>

So, what do you think ?

Subscribe to this comment thread
Leave this field empty