Binding an image to a cfgrid
74 comments Posted by: LauraWe were asked how to bind a cfgrid to a cfinput of type image, so that when the grid is clicked, the image corresponding to that row shows up. We implemented a solution, although without using cfinput type="image". We are using a cfformitem type html instead. Unless the button (and submit) of the image input is needed for some reason, we can use simple html to show the image and avoid the button altogether.
<!--- query contains one column with the name of the image file (photo column) --->
<cfform name="myform" format="Flash" height="450" width="600" >
<cfgrid name= "grid" query="properties" height="200">
<cfgridcolumn name="city" header="City">
<!--- this column can be hidden, shown here for illustration purposes only --->
<cfgridcolumn name="photo" header="Photo">
</cfgrid>
<!--- show the picture in an html cfforitem
paragraph is added because Firefox sometimes fail to load the picture --->
<cfformitem type="html" height="200" width="300"
bind="<p><img src='images/{grid.selectedItem.photo}'></p>"></cfformitem>
</cfform>
View live example
Download source
74 Comments so far
Write yourscfinput type image loads the picture at compile time , and that is the reason why it accepts gifs. cfinput type html brings the picture after loading. Because it is the player that loads the picture, it can only accept jpgs (the only format Flash can load).
For those reasons, we cannot change the source of the image once the form has loaded by binding it or otherwise.
<cfgridcolumn header="" name="doc_fileName" display="false" />
My output …
<cfformitem type="html"
bind="{data.dataProvider[data.selectedIndex]['doc_fileName']}">
</cfformitem>
This returns the file and folder name, but how do I convert it to a URL???
Thanking you in advance
You need to do something like this:
<cfformitem type="html" height="200" width="300"
bind="{'<p><img src=\'+grid.selectedItem. doc_fileName + '\'></p>'}"></cfformitem>
This doesn’t seem to work. I need to try a get a URL link not an image. I want it so that the user can click on it and it will open the document.
Thanks for your help and I appreciate any further assistance.
Try to do it on the onChange event of the grid.
onChange="getURL(grid.selectedItem.doc_fileName)"
Is it possible to set the size of the image?
If i use the code below and my image is bigger than height 100 width 100 it will be cut
<cfformitem type="html" height="100" width="100"
bind="{'<p><img src=\'images/'+grid.selectedItem.photo+ '\'></p>'}"></cfformitem>
thx for help / merci d´avance :-)
Im trying to do the url thing too, i dont want the hyperlink by clicking a row cause they have to edit it. I want a button that on click sends a new page with the house details.
example:
<cfformitem type="html" bind="<a href="{linkGrid.selectedItem.name}">NameOftheHouse</a>">
</cfformitem>
this doesn't work though
your brackets are in the wrong place and make sure you escape your quotes.
just add this
<cfformitem type="html" height="200" width="300" bind="{'<p><a href=\' '+grid.selectedItem.photo+' \'><img src=\'images/'+grid.selectedItem.photo+ '\'></a></p>'}"></cfformitem>
By doing this a user can click on the photo and go to a details page using the URL as a variable to feed a query. You can easily turn this into a text link.
-Alas (tha man)
???
<cfformitem type="html" height="200" width="300" bind="{'<p><a href=\'updatelead_ff.cfm?lead='+leadGrid.selectedItem.cust_code+' \'>'+leadGrid.selectedItem.cust_code+ ' View Detail</a></p>'}">
</cfformitem>
Looking for working not theory....
Thanks
I am trying to do something like:
<cfformitem type="html" height="200" width="300"
bind="{'<p>grid.selectedItem.firstName, gride.selectedItem.LastName</p>'}"></cfformitem>
but i couldn't get this work, thanks for any help.
Do this:
<cfformitem type="html" bind="<p>{grid.selectedItem.firstName}, {grid.selectedItem.LastName}</p>"></cfformitem>
Thank you for your help, but this code doesn't work for me. You got this work?
Thanks,
Yes, it works. Check that you have the right column name case.
<cfgrid name="grid" query="ShowViews" selectmode="single" height="240" width="300" onChange="getURL('javascript:doAlert(\'Hello\',\'There\',\'World'\)')">
These do NOT work:
<cfgrid name="grid" query="ShowViews" selectmode="single" height="240" width="300" onChange="getURL('javascript:doAlert(\'Hello\',\'There\',grid.selectedItem.name_pts)')">
<cfgrid name="grid" query="ShowViews" selectmode="single" height="240" width="300" onChange="getURL('javascript:doAlert(\'Hello\',\'There\',{grid.selectedItem.name_pts})')">
<cfgrid name="grid" query="ShowViews" selectmode="single" height="240" width="300" onChange="getURL('javascript:doAlert(\'Hello\',\'There\',\'{grid.selectedItem.name_pts}\')')">
Can anyone tell me why. I need to pass variables from my grid back to a JS fuction. Possible?
Concatenate it with +
It will be something like:
getURL('javascript:doAlert(\'Hello\' + grid.selectedItem.name_pts)')
Inserting the right quotes, commas, and all that. But you get the idea.
<cfgrid name="grid" query="ShowViews" selectmode="single" height="200" width="540" onChange="getURL('javascript:doIt(\''+ grid.selectedItem.long_pts + '\',\'' + grid.selectedItem.lat_pts + '\',\'1\')')">
The only thing I need to do now, and I don't know if it is possible, is to get the index of the line I have clicked. Can this be done without it being in query? So for example, if they click the 1st line of the grid is there a variable for this?
If you look in my example above I have hard coded the 1. I need this to be the line number (starting from 0 if possible) that they have clicked.
I have only just started with CF7 and your site has been a great help in working with CFGRID.
Cheers.
I think what you need is "myGrid.selectedIndex"
Cheers,
Ed
So, I have looked and looked, but can't find a way to get the rowheader number.
Is this possible?
Cheers,
Ed
Also if you send me an email I can send you a link to the site I am working on. It is currently in beta so I don't want to post the link just yet. Thanks again.
Cheers.
Ed
<cfquery name = "getIssue" dataSource = "forum">
Select * From process_issue Order By issueID
</cfquery>
<cfgrid name = "issueList" width="750" height="400" fontsize="11" query = "getIssue" selectmode="edit">.....
.....
<cfformitem type="html" bind="{'<p><img src=\'images/'+issueList.selectedItem.photo+ '\'></p>'}"></cfformitem>
There is no difference between a manually generated query or a query coming from a database. What you need to know is the name and case of your columns. Replace photo by the name of your column.
Actually I named the cfgridcolumn as photo .I tryed to just show the column name and it works,the code as follwing:
bind="{issueList.selectedItem.photo}">
But it can't show the image as following code:
bind="{'<p><img src=\'images/'+ issueList.selectedItem.photo + '\'></p>'}">
It's very weird.
Here are my code which can't show the image:
<cfif IsDefined("form.gridEntered")>
<cfgridupdate grid="issueList" datasource="forum" keyonly="yes" tablename="process_issue">
</cfif>
<cfquery name = "getIssue" dataSource = "forum">
Select * From process_issue Order By issueID
</cfquery>
<cfform name="frmIssue" format="flash" height="600" width="1200" skin="haloblue" timeout="600">
<cfformgroup type="horizontal">
<cfgrid name = "issueList" height="400" width="750" query = "getIssue" fontsize="11" selectmode="browse">
<cfgridcolumn name="issueID" width="50" header="issueID" display="no">
<cfgridcolumn name="product" width="100" header="Product">
<cfgridcolumn name="stage" width="120" header="Stage">
<cfgridcolumn name="issue" width="500" header="Issue">
<cfgridcolumn name="action_PE" width="500" header="Action">
<cfgridcolumn name="status" width="100" header="Status">
<cfgridcolumn name="photo" width="5" header="Photo" display="no">
</cfgrid>
<cfformitem type="html" height="360" width="320"
bind="{'<p><img src=\'images/'+ issueList.selectedItem.photo+ '\'></p>'}">
</cfformitem>
</cfformgroup>
<cfinput type="submit" name="gridEntered" value="Update">
</cfform>
I really don't know what's the problem.The image file path and name are all correct but just fail to show image.It let me feel depressed...#_#...
use the code in the post that is easier to read:
<cfformitem type="html" height="200" width="300"
bind="<p><img src='images/{grid.selectedItem.photo}'></p>"></cfformitem>
are your images in the folder images? this folder should be just below the one where the form is located. To see what your form is trying to load, if anything, use fiddler or livehttpheaders in Firefox.
my form's location:C:\CFusionMX7\wwwroot\MyTest
The cfinput above opens a new window page but it does not capture the V_ID value. The url comes up as:
javascript:%20window.open('photo/Scan.cfm?header=no&vid={data.selectedItem.V_ID}',%20'Lookup',%20'width=500,height=450,scrollbars=yes');
I can not seem to get the right syntax. Please help. I’ve tried so many different ways I’m confused between ‘\ ‘/ ‘\+ +’/ . I don’t know what’s what. Thanks for any help.
<cfgrid name="grid" query="ShowViews" selectmode="single" height="200" width="540" onChange="getURL('javascript:doIt(\''+ grid.selectedItem.long_pts + '\',\'' + grid.selectedItem.lat_pts + '\',\'1\')')">
Is this correct? After javascript:doIt (\'' This shows as two single quotes when I copied it here but looking at it above it looks like a double quote. Can someone decipher this for me? I want to getURL with the javascript: but I can not figure out the '\' '+ {grid.selectedItem} '\'
My page sometimes won't load because of the + but it has to be because I don't have the correct '\'.
Thanks for any direction.
<cfset filesDirectory2=ExpandPath("../icons/")>
<cfdirectory directory="#filesDirectory2#" name="fIcon" filter="*.*" sort="name ASC">
<cfform name="myform" height="250" width="600" format="Flash" timeout="100">
<cfformgroup type="horizontal">
<cfgrid name= "grid" query="fIcon" width="250" height="200" rowHeaders="No">
<cfgridcolumn name="name" header="Name">
</cfgrid>
<cfinput type="text" height="200" width="300" name="test" bind="{grid.selectedItem.name}">
</cfformgroup>
</cfform>
It loads the files from directory in fine, but no matter what I select in the grid it does NOT appear in the text box. Let alone appear in a cfinput type="html" img src tag!
Any ideas.. PLEASE :D
Feonyx
So I've been using this technique for quite a while with nooooo problems, and now i've got a page that just decides to not work in Firefox...
ironically, i have two grids on the page with bound images - one works fine, the other doesn't.
works fine in firefox on localhost, but not on my dev box...when you click on the grid row it justs says waiting for [myurl].....
works perfect in IE on both..
i'm pulling handfulls of hair out... :(
boooooo....
any suggestions? it acted quirky like this one time on localhost, but i restarted and everything was honkey dorey....
onchange="getUrl('javascript:window.open('vers.dataProvider[vers.selectedIndex]['LINK_TO_HOMEPAGE'])','newwindow');"
but nothing happens (the page will not diplay)
regards
herbert
How do I format the size of the picture within a bind? I tried using an inline style but to no avail.
bind="{'<p><img src=\'/staffDir/picture/'+Staff_List.selectedItem.IMG_Picture+'.jpg'+'\'+style=\'width:50px;'+'\'></p>'}">
You can add any swf by using the html cfformitem and an <img> tag inside.
herbert,
Your quotes do not close correctly and therefore the form does not compile. You have double quotes to enclose the AS statement and then inside the getURL function you have single quotes. But then, you use single quotes again inside the JavaScript function. You will need to scape them.
Anyway, something like this should work:
onclick="getUrl('javascript:window.open(\'' + vers.dataProvider[vers.selectedIndex].LINK_TO_HOMEPAGE + '\',\'newwindow\')');"
al,
Html is very limited inside flash and you cannot use inline styles. If you only need to set the size, use width="" and height="" in the image tag.
I did what you suggested and added... bind="{'<p><img height="175" width="175" src=\'/staffDir/picture/'+Staff_List.selectedItem.IMG_Picture+'.jpg'+'\'></p>'}">
when I do that I get a compiler error so I tried this....
bind="{'<p><img height='175' width='175' src=\'/staffDir/picture/'+Staff_List.selectedItem.IMG_Picture+'.jpg'+'\'></p>'}">
and nothing would display on the screen after that. Maybe I am making this harder than what it is. Any help on adjusting the image size not the area of which the image will be displayed.
Thank you very much
You have the same problem as herbert with the quotes/single quotes.
Use this:
bind="<p><img height='175' width='175' src='/staffDir/picture/{Staff_List.selectedItem.IMG_Picture}.jpg'></p>">
I was wondering Can we have default pic load first instead of a white space, and then when the user clicks the grid the picture will then change based on the selected item?
Thanks,
Jimmy
You could do something like
<cfformitem type="html" height="200" width="300"bind="<p><img src='images/{(grid.selectedItem != undefined)?grid.selectedItem.photo:'YOUR DEFAULT IMAGE'}'></p>"></cfformitem>
I have a cdselect called Animal (Cat, Dog, Horse, etc).
Can I do a similar code like what you mentioned, but bind on the "YOUR DEFAULT" subsitute for something like :'Animal.value' + '.jpg'}'></p.>"> Where Animal.value is the selected item from the cfselect
<cfformitem type="html" height="200" width="300"
bind="<p><img src='images/{(grid.selectedItem != undefined)?grid.selectedItem.photo:'YOUR DEFAULT IMAGE'}'></p>"></cfformitem>
Thanks,
Jimmy
Something like you have should work, just remove the quotes from Animal.value (it is a variable, not a string). As you have it now, it is looking for an image called "Animal.value.jpg".
Hope that helps
So all buttering up aside, I have a repeater bound to a remoting call that returns a description and a path to an icon. Ideally, I want to click the icon and perform a function. I have it all working - function, repeating, remoting - I just can't get a dynamic image to take a $^%&@% mouse click. Listeners don't seem to work either - or at least I can't bind them to a html or the hbox I stick around it.
I have one last thought, but I don't know how to do it. Can I load the icons at start (there are only 15), assign them IDs, and then somehow use them later on in the repeater? Any other ideas?
Help me ASFusion, you are my only hope!
-rj
Thanks!
We do have a solution that we've been using for those cases. I can't make a complete example now (maybe after CFUnited), but maybe this will help you:
<cfformitem type="html" height="90" width="90"bind="<p><a href='asfunction:_root.myFunction,{myRepeaterQuery.currentItem.picture_id}'><img src='thumbnails/{myRepeaterQuery.currentItem.filename}'></a></p>">
In this example, I am calling a function called myFunction and passing the second argument (which is the picture id, but it could be anything you want) as a parameter of that function.
The images in the grid are shown by calling the image by making an http request, just like an <img> tag would. So, in an img tag, you cannot dump your binary data. You need to set the source to a page that goes and get the data and sends it by using <cfcontent>. Since the grid works in a similar way, you need to create a column in your query that sets the path to your "image" (a cfm file that makes the query to the db, gets the binary data and outputs it.)
I have my image binding to the datagrid, but as soon as I add a type="image" to the cfgridcolumn, the row height is excessively large. The image that I have is 25x25, and it is sitting in a lonely corner on the left side of the data cell. When I use the dataalign="center", that won't position the image in the center. I have the rowheight set to 25, but the columns still are about 100px high. Is there any way to resolve the column height issue?
Have been googling to determine problem with displaying an image in a <cfformitem type='html'><img src=....></cfformitem> tag on a site that uses SSL. This was working a month ago on our test server. I'm not sure if the latest CF updater patch being installed or the Microsoft Daylight Savings Time patch being installed on our operating system caused the image to no longer display in the flash form or not. Has anyone come across any documentation or are there any forums seeking similar resolution for this? I can use a <cfinput type='image'> tag instead of the <cfformitem> tag and am able to display the image but it has added considerable size to my compiled .swf file (jumped from 24KB to 36KB). Any suggestions are greatly appreciated.
try to change the size of your cfgridcolumn width,.
<cfgridcolumn width="25">
try to change the size of your cfgridcolumn width,.
<cfgridcolumn width="25">
This works:
onChange="getURL('/intranet/Database/NTA/NTA_Ups/'+upGrid.selectedItem.Name)"BUT... What I really want is to open a new window onChange
I have tried all kinds of variations of the
'javascript:window.open('vers.dataProvider[vers.selectedIndex]['LINK_TO_HOMEPAGE'])','newwindow');getURL("javascript:popUpWindow('/intranet/Database/NTA/NTA_Ups/'+upGrid.selectedItem.Name)")Any help would be greatly appreciated!!!
onChange="getURL('/intranet/Database/NTA/NTA_Ups/'+upGrid.selectedItem.Name, '_blank')">Wow, so simple but when you don't know....
Thanks Anyway, This might help someone else.
I am having problems with the <cfformitem type=html> tag
I am trying to put <a href="javascript:ChooseObject('#XFA.ChoosePerson#','CreatorPerson','Creator Person')">Select Person</a>
and it now doesn't create the link. It worked in a plain form and it worked when I first converted it to the flash cfform, but now it doesn't. I have looked at all the posts but I can't seem to figure out what could be preventing it from working. The error is thrown in the Javascript:
document.getElementById(object_value_prefix + fieldName + object_value_suffix) has no properties.
thanks,
Loren
I'm doing something a little different than what your example is demonstrating. I'm building a form that will allow the user to click on an image (cfinput type="image") to select it. When they click on it, I want a value inserted into a text cfinput. Here is an example of what I'm trying to do... but it's not working. I can't find documentation to tell me if I can/can't do this.
<cfinput type="text" name="test" width="200" label="test:">
<cfinput type="image" name="image1" width="65" height="65" onClick="{test.text == 'myvalue'}">
The form compiles fine but when I click on 'image1', I get nothing. If I change it to ...onClick="alert('foo')".... I get an alert box as expected.
Does anybody know what's wrong here?
<cfformitem type="html" height="426" width="568" bind="<p><img src='images/{grdScaleModels.dataProvider[grdScaleModels.selectedIndex]['scale18']}/photo1.jpg' /></p>"></cfformitem>
It is not working.
Thanks in advance.
There are long delays in displaying these images. Is this a function of flash?
Great work and thank you for helping us all out. Your site is the one site all the blogs point to for this type of example.
Jojo
I have a question. Is it possible to make particular rows not editable. At this moment, I have a grid :
<cfgrid name="files" rowheaders="false" height="{Stage.height/2}" width="{Stage.width/3+160}" selectmode="edit" query="files" >But I need first N rows to be blocked from editing. Maybe, there is a way through actionscript, do you have any ideas?
Thank you .
Here's the javascript:
function openWindow(path,winH, winW) {
window.open(path,null,'resizable=yes,scrollbars=yes,height='+winH+',width='+winW+',status=no,toolbar=no,menubar=no,location=yes')
}
Here's the CFGrid onChange event that DOESN'T work:
onchange="getURL('javascript:openWindow(\'Customer/ActivityLogEdit_menu.cfm?ActivityLogID=+[ActivityLog.selectedItem.ActivityLogID]\', 450, 550)');">
It passes the selectedItem as a string - here's the URL:
http://localhost/encompass/Pigott/Customer/ActivityLogEdit_menu.cfm?ActivityLogID=+[ActivityLog.selectedItem.ActivityLogID]
I know this javascript works with CFButtons -have it working on buttons that don't pass a CFGrid selectedItem.
Any help would be GREATLY appreciated!!
Kim