1 Reply Latest reply on Apr 3, 2010 12:37 PM by cheftimo

    if myText.text == any value in a datagrid column

    joshy_888 Level 1

      Hey guys, in a simple form, I am trying to achieve what's in my title.


      I have a text box in which you type in a value (number).


      I have a submit button which inserts the value into my data-grid which  is populated by a data provider to display that information (ZendAMF).


      For my submit button function I need it to loop through all the  values(rows) in a column (my dataprovider) of my data-grid to check if my text box value  is equal to any of the data in the rows for that column.


      I found a function on another forum that should help me achieve this but I still cannot get it to work as I don't think I'm using the function correctly. Note the function is called "findItem()"


      Here is my example code:


      //I have a datagrid
      <mx:DataGrid id="myDataGrid"  dataProvider="amfcall.getData.lastResult}">
                  <mx:DataGridColumn  headerText="MyHeading" dataField="myDataField"/>
      //I  have a form for adding data into the datagrid
      <mx:Form  id="addData">
              <mx:TextInput  id="myText"/>
      //I  have a button to submit the form data by calling a function
      <mx:Button  label="Add" id="addData" click="findItem()"/>
      //I  have the function to find any item in the datagrid column that is equal  to the text input in the form. This is what I can't code correctly.
      public  function findItem(myDataGrid.dataProvider, myDataField:String,  myText.text):Boolean 
           for each(var item:Object in  myDataGrid.dataProvider)     
                if(item[myDataField] == myText.text)             
                  return  true;     
           return false; 



      So I don't think I'm correctly typing the first line of the 'findItem' function as I'm currently receiving [I]1084: Syntax error: expecting rightparen before dot.[/I] for this line [I]public function findItem(myDataGrid.dataProvider, myDataField:String, myText.text):Boolean [/I]
      Also, the error does not change if I strict type those things to ':Object' etc.


      I may just be using the function totally wrong, can anyone hlpe me out?

        • 1. Re: if myText.text == any value in a datagrid column
          cheftimo Level 2

          Hard to tell what’s going on from the information you are providing; but just looking at the first line of your sample code:


          Have you checked in the debugger to see what your dataProvider looks like?


          You want a resultHandler to set some kind of list – let’s say a previously declared AC, which then becomes your dataProvider for the DataGrid. Something like:


          private function amfCallResultHandler(event:ResultEvent):void{

                Var someVar:ArrayCollection = event.result as ArrayCollection;

                blah blah blah;

                myDataProvider = someVar;