Monday, December 21, 2009

Changing the contents of a ColdFusion 9 CFGRID control

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")>

2 comments:

Freddy said...

I am trying to add a rowclick event to a cfgrid in cf9 that will load a "drill down" grid in a cfdiv using ColdFusion.navigate.

I cannot get the data "key" from the initial cfgrid using the cf8 syntax mygrid.getDataSource() This fails as getDataSource is not a function. Any help on this?

src105 said...

Freddy, any luck with your issue? I'm having the same issue. Trying to pass row info using the rowclick listener, and grid.getDataSource appears to be unsupported in the latest version of Ext.

Post a Comment