8 Replies Latest reply on Dec 1, 2011 2:27 AM by BKBK

    getting and setting cfgrid cell value

    ion Level 1

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

       

          if (myArr[i] == thisID)

              {

       

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

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

              }   

          }

      }

        • 1. Re: getting and setting cfgrid cell value
          insuractive Level 3

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

           

           

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

           

          First, the last parameter: 'app_id[r]' 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[r]);

           

          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.

          • 2. Re: getting and setting cfgrid cell value
            ion Level 1

            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

            • 3. Re: getting and setting cfgrid cell value
              insuractive Level 3

              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

              1 person found this helpful
              • 4. Re: getting and setting cfgrid cell value
                ion Level 1

                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

                • 5. Re: getting and setting cfgrid cell value
                  BKBK Adobe Community Professional & MVP

                  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[r]', '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'});

                  • 6. Re: getting and setting cfgrid cell value
                    ion Level 1

                    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

                    • 7. Re: getting and setting cfgrid cell value
                      BKBK Adobe Community Professional & MVP

                      Number of records in grid

                       

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

                      var myDatastore = myGrid.getStore();

                      var numberOfRecords = myDatastore.getTotalCount();

                      • 8. Re: getting and setting cfgrid cell value
                        BKBK Adobe Community Professional & MVP

                        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.

                        1 person found this helpful