views:

19

answers:

2

Hello friends, I tried using filterFunction not get any results, check out this example:

[Bindable]
public  var SearchLoadlistOneDP:ArrayCollection;


public function SearchList():void {


 SearchLoadlistOneDP.filterFunction = filter;
 SearchLoadlistOneDP.refresh()


}


public function filter(item:Object):Boolean
{
 var beginsWithString:String = SearchLoadlistOneInput.text;



 return String(item["email"]).indexOf(beginsWithString) == 0;
}

And I used the datagrid like this:

<mx:DataGrid x="10" dataProvider="{SearchLoadlistOneDP}" y="49" width="891" height="408" id="listamail" creationComplete="LoadlistOne(0)">


     <mx:columns>
      <mx:DataGridColumn headerText="id" dataField="id" width="80"/>
      <mx:DataGridColumn headerText="E-mail" dataField="email"/>
      <mx:DataGridColumn headerText="Nome" dataField="nome"/>
     </mx:columns>


    </mx:DataGrid>

And text input like this:

<s:TextInput x="62.6" y="9.75" width="408" id="SearchLoadlistOneInput" keyUp="SearchList()"  />

But unfortunately I can not any results, and the datagrid already has data from the database already has data listed on it.

Can anyone help?, Thank you all now

A: 

Flex SDK 4.0.0, This works for me:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" applicationComplete="_init();">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            [Bindable]
            public  var SearchLoadlistOneDP:ArrayCollection;

            private function _init() :void
            {
                SearchLoadlistOneDP = new ArrayCollection();
                SearchLoadlistOneDP.addItem({id: 1, email: '[email protected]', name:'Bill'});
                SearchLoadlistOneDP.addItem({id: 2, email: '[email protected]', name:'Todd'});
                SearchLoadlistOneDP.addItem({id: 3, email: '[email protected]', name:'Beth'});
                SearchLoadlistOneDP.addItem({id: 4, email: '[email protected]', name:'Tiffany'});
            }

            public function SearchList():void {
                SearchLoadlistOneDP.filterFunction = filter;
                SearchLoadlistOneDP.refresh()
            }


            public function filter(item:Object):Boolean
            {
                var name:String = String(item["email"]);
                var beginsWithString:String = SearchLoadlistOneInput.text;

                return name.indexOf(beginsWithString) == 0;
            }
        ]]>
    </fx:Script>

    <mx:DataGrid x="10" dataProvider="{SearchLoadlistOneDP}" y="49" width="891" height="408" id="listamail">


        <mx:columns>
            <mx:DataGridColumn headerText="id" dataField="id" width="80"/>
            <mx:DataGridColumn headerText="E-mail" dataField="email"/>
            <mx:DataGridColumn headerText="Name" dataField="name"/>
        </mx:columns>


    </mx:DataGrid>


    <s:TextInput x="62.6" y="9.75" width="408" id="SearchLoadlistOneInput" keyUp="SearchList()"  />

</s:Application>
cynicaljoy
A: 

Hello, unfortunately did not work in my application, this datagrid is receiving data from AMFPHP and not an array collection, you know?

When I put the data in datagrid via additem

SearchLoadlistOneDP.addItem({id: 1, email: '[email protected]', name:'Bill'}); 

works, but if I get this data from AMFPHP, there does not work, can you tell me why?

The function I use to send data to the datagrid is:

public function listrecordsmail(source:ResultEvent,arrayDefinitionsargs:Array):void {




    //var arrayok:ArrayCollection = new ArrayCollection(source.result);
    listamail.dataProvider = source.result;




}

Could you help me? Thanks in advance.

luiz henrique
I haven't worked with AMFPHP for awhile but my first guess would be is that you aren't using an ` ArrayCollection` when the ` dataProvider` is changed to the result of the AMFPHP service. Debug your application and figure out the result type that you are getting back and then appropriately iterate through that object. You could try casting the result as an ArrayCollection:` listamail.dataProvider = source.result as ArrayCollection` but that might give you an error.
cynicaljoy