1 Reply Latest reply on Feb 7, 2012 3:01 AM by Mathangi Ramachandran

    Using dynamic column name in datagrid selectedItems

    Mathangi Ramachandran

      Hi

       

      I have a datagrid loaded with 2 columns. Allowmultiselect is turned on.

       

      Based on the values selected at run time, I get the corresponding selected column name and its values and shown it on HTML screen.

       

      // grp is datagrid

      // dgrcl is a data grid column

      // selflds is an array which has 0,1,2,3 values

      //selflds[0] = name,selflds[1]=age

      for (var l:int=0; l<grp.columnCount; l++)

      {

      dgrcl =grp.columns[l];

      selflds[l] = dgrcl.dataField;

      }

       

      // srhVals will have only one selected value at any point

      // getting the corresponding selected column name and its value

      var  srhVals:String;

      srhVals = String(grp.selectedItem[selflds[1]]);

       

      I am trying to achieve the above selection instead by .selectedItems somthing like this below. By doing like this, I will get all the selected items but not only one. If i try below syntax, i get error. Any one has ideas on how to do.

       

      srhVals = String(grp.selectedItems.selflds[1]);

        • 1. Re: Using dynamic column name in datagrid selectedItems
          Mathangi Ramachandran Level 1

          Hi

          I got my mistake, there should be no dot operator after selectedItems;

           

          I got a solution - it goes like this:

           

          for(var g:int=0;g<grp.selectedItems.length;g++)

          {

          srhVals = srhVals + String(grp.selectedItems[g][selflds[1]]);

          }

           

          So the complete scenario is like this:

           

          Datagrid:

          Name      Age    

          a               20

          b               30

          c               40

          d               50

           

          I am selecting b,d in UI. At run time, I get programatically the selecteditem column name as "Name", loop through the selecteditems and store the value in srhVals as b,d.

           

          b,d will be finally shown in UI.