I had what seemed like a simple task. Load a query into an html cfgid. Users could then click on a row (record) and be taken to an edit/update page.
Piece of cake. I have done this many times before. Unfortunately, this was my first time attempting it with ColdFusion 8 and all it’s ajaxy goodness. CFGRIDCOLUMN has an ‘href’ attribute, but I was not able to fire off javascript from it, it would only execute regular links. I wanted my edit screen to open up below the grid in a CFDIV.
After much googling and mucking around, I was able to piece together the following. Which adds a click event to the cell.
1: addLinksforaTasks = function()
2: {
3: gTask = ColdFusion.Grid.getGridObject(‘agrid_tasks’);
4: cm = gTask.getColumnModel();
5: gTask.on(‘cellclick’,function(grid,rowIndex,columnIndex,e)
6: {
7: var unitID = ColdFusion.getElementValue(‘agrid_tasks’,‘taskform’,‘taskid’);
8: ColdFusion.navigate(‘atasks.cfm?action=edit&taskid=’+unitID,‘taskedit’);
9: }
10: )
11: }
The hardest part to figure out was how to get the id field value (in this case taskid). It is such a simple thing that I was sure is used constantly, but I could not find much help on the web. Here is the function explained: ColdFusion.getElementValue(’grid_name’,'form_name’,'columnid’). That gave me the taksid of the selected row in the grid.
To execute the function when the grid loads you need to add
<cfset ajaxOnLoad(’addLinksforaTasks’)> to the page containing the grid.
One other thing to note, if you are loading a grid into a CFDIV, you need to put all helper functions on the parent page. They do not seem to execute correctly if they are included on the page loaded into the CFDIV.
Anyway… hope that can help someone…
Posted under
Ajax,
ColdFusion,
Samples