Here's a handy little JavaScript function for dynamically changing the contents of a ColdFusion 9 CFGRID control:
function gridSetElementValue( gridname,row,column,thevalue)
{
var objGrid = ColdFusion.Grid.getGridObject(gridname);
objRow = objGrid.store.data.items[row];
objRow.set(column,thevalue);
objGrid.view.refreshRow(row);
}
In order to determine the row number of the currently selected grid row you must define an event listener for the grid as indicated below. Note the following:
- The function must be declared within the section of the page
- You must use ColdFusion’s ajaxOnLoad() function to invoke the event listener definition
var selectedRow = 0;
initGrid = function()
{
var grid = ColdFusion.Grid.getGridObject("incidentGrid");
grid.addListener("rowclick", function(objGrid, rowNumber, e){
selectedRow = rowNumber;
});
}
Invoke using the following:
<cfset ajaxonload("initgrid")>