Skip to main content
Inspiring
November 23, 2011
Question

getting and setting cfgrid cell value

  • November 23, 2011
  • 2 replies
  • 4563 views

in cf9 i have a bound cfgrid with an ID (numerical) column and a checkbox column. onChange calls a js function where i have a list of numbers (corresponding to some of the ID's in the ID column). i want to loop through both my list and the ID column of the grid, and, if a match, set the corresponding checkbox to "checked".  i can't figure out the correct syntax. i've marked with ??? the stuff i'm having problems with

any help appreciated

 

var mygrid=ColdFusion.Grid.getGridObject("aGrid"); // get number of rows in grid

var mydata = mygrid.getStore();

var rowCount = mydata.totalLength;

var i = 0;

var myList = "2,4";

var myArr = myList.split( "," );  // convert list to array

while ( i < myArr.length) // loop through list array

{

    for (var r = 0; r < rowCount; r++)  // loop through grid rows

    {

// get the id value corresponding to the r row - throws error "exception thrown and not caught"

    ??? var thisID = ColdFusion.getElementValue('aGrid', 'aForm', 'app_id'); ???

    if (myArr == thisID)

        {

// set the status of the corresponding checkbox to "checked" - no idea how to do this

        ??? ColdFusion.setElementValue('aGrid', 'myCheckboxColumn', 'checked', 'true') ???;

        }   

    }

}

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
November 29, 2011

ion wrote:

thanks, what i'm trying to do with that line is to get the app_id value from the grid row corresponding to my loop index (r), app_id is the grid column name. if  r = 0 i should get the app_id value in the first row, r = 1 get the second row, etc

now that i think of it, the grid row loop should probably start with 1, not 0.

that line should probably be

var thisID = ColdFusion.getElementValue('aGrid', 'aForm', 'app_id');

but i still don't know how to pass the loop index to the getElementValue function so that i'll get only that particular row value

In my opinion, the way to go is indeed ColdFusion.getElementValue('aGrid', 'aForm', 'app_id'). I am assuming that app_id is the column representing IDs.

Remember that an event triggers the script. When the event occurs the state of the grid at that moment includes the currently selected row. That row-value is implicitly stored in app_id.

??? ColdFusion.setElementValue('aGrid', 'myCheckboxColumn', 'checked', 'true') ???;

I am unaware of the existence of the system function ColdFusion.setElementValue(). When I googled, the initial hits confirmed my suspicion.

You could go for something like

Ext.get('myCheckboxColumn').set({value:'true'});

ionAuthor
Inspiring
November 30, 2011

thanks BKBK, the script is attached to the onChange event of the grid, when user checks or unchecks a box. it's passing indeed the corresponding app_id, but what i want is to loop through all the grid rows, not just the select one. if one of the app_id value in a row matches a value in my list, i want to check or uncheck the checkbox programatically

regards

BKBK
Community Expert
Community Expert
December 1, 2011

Number of records in grid

var myGrid = ColdFusion.Grid.getGridObject("aGrid");

var myDatastore = myGrid.getStore();

var numberOfRecords = myDatastore.getTotalCount();

Inspiring
November 23, 2011

Just glancing at your code, this line seems to have a syntax error:

    ??? var thisID = ColdFusion.getElementValue('aGrid', 'aForm', 'app_id'); ???

First, the last parameter: 'app_id' is being passed in as a string and not a variable to evaluate.  I would expect to see something like this:

var thisID = ColdFusion.getElementValue('aGrid', 'aForm', app_id);

Secondly, is the app_id array a Javascript array or a CF array variable?  I didn't see a mention of it in your sample code, so I wanted to make sure you weren't confusing client-side and server-side variables.

ionAuthor
Inspiring
November 23, 2011

thanks, what i'm trying to do with that line is to get the app_id value from the grid row corresponding to my loop index (r), app_id is the grid column name. if  r = 0 i should get the app_id value in the first row, r = 1 get the second row, etc

now that i think of it, the grid row loop should probably start with 1, not 0.

that line should probably be

var thisID = ColdFusion.getElementValue('aGrid', 'aForm', 'app_id');

but i still don't know how to pass the loop index to the getElementValue function so that i'll get only that particular row value

regards

Inspiring
November 23, 2011

You may be able to access the underlying ExtJS grid controls using ColdFusion.Grid

some of the syntax can be seen on this thread:

http://forums.adobe.com/thread/239807