Ask a Jedi: Can I bind an image to a cell in cfgrid?

Zach asks, “Is there a way to bind an image to a column in a Flash Grid?” The answer is yes. From the docs for cfgridcolumn, we see that the type attribute for cfgridcolumn allows for “image” as a value. Some notes though:

  • If you use a relative path, i.e., "images/jedi.jpg", CF will assume the image lies under CFIDE/classes. Read on for a way to handle that.
  • If the image is too big to fit in the column cell, it will be clipped.
  • The image must be a JPEG file. </ul> So, if you are like me, you don't normally store the full path to an image in the database. This means you will have relative image paths in your data and the gridcolumn won't display right. There are a few ways you can fix that. You can actually write your sql so that it returns the data with the proper path. As an example: select name, '<img src="/images/"' & img & '>' as imagepath
    from foo (Note - I always forget the proper character to join strings in SQL - it may be + instead of &, but you get the idea.) You could also use QueryOfQuery to modify the query to contain the full path. You get the idea.
Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments