• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

getting and setting cfgrid cell value

Participant ,
Nov 23, 2011 Nov 23, 2011

Copy link to clipboard

Copied

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') ???;

        }   

    }

}

TOPICS
Advanced techniques

Views

4.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 23, 2011 Nov 23, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 23, 2011 Nov 23, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 23, 2011 Nov 23, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 28, 2011 Nov 28, 2011

Copy link to clipboard

Copied

thanks, that thread kind of shows how to delete a record in a very convoluted way, i can't believe there is not a simpler way to "set" the value of a grid cell programatically

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 29, 2011 Nov 29, 2011

Copy link to clipboard

Copied

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'});

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 30, 2011 Nov 30, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2011 Dec 01, 2011

Copy link to clipboard

Copied

Number of records in grid

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

var myDatastore = myGrid.getStore();

var numberOfRecords = myDatastore.getTotalCount();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2011 Dec 01, 2011

Copy link to clipboard

Copied

LATEST

ion wrote:

... 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

The grid's RowSelectionModel might also come in handy.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation